rest

package
v0.0.0-...-5905bd6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2023 License: Apache-2.0 Imports: 61 Imported by: 0

Documentation

Overview

Package rest provides primitives to interact with the openapi HTTP API.

Code generated by unknown module path version unknown version DO NOT EDIT.

Index

Constants

View Source
const OtelName = "github.com/danicc097/openapi-go-gin-postgres-sqlc/internal/rest"
View Source
const ValidationErrorSeparator = "$$$$"

Variables

View Source
var Alphanumspace validator.Func = func(fl validator.FieldLevel) bool {
	return alphanumSpaceRegex.MatchString(fl.Field().String())
}

Functions

func CustomSchemaErrorFunc

func CustomSchemaErrorFunc(err *openapi3.SchemaError) string

func ReadOpenAPI

func ReadOpenAPI(path string) (*openapi3.T, error)

ReadOpenAPI parses and validates an OpenAPI spec by filename and returns it.

func RegisterHandlers

func RegisterHandlers(router gin.IRouter, si ServerInterface)

RegisterHandlers creates http.Handler with routing matching OpenAPI spec.

func RegisterHandlersWithOptions

func RegisterHandlersWithOptions(router gin.IRouter, si ServerInterface, options GinServerOptions)

RegisterHandlersWithOptions creates http.Handler with additional options

func Run

func Run(env, specPath, rolePolicyPath, scopePolicyPath string) (<-chan error, error)

Run configures a server and underlying services with the given configuration. NewServer takes its own config as is now.

func SSEHeadersMiddleware

func SSEHeadersMiddleware() gin.HandlerFunc

func ValidateRequestFromContext

func ValidateRequestFromContext(c *gin.Context, router routers.Router, options *OAValidatorOptions) error

ValidateRequestFromContext is called from the middleware above and actually does the work of validating a request.

Types

type AuthRestriction

type AuthRestriction struct {
	MinimumRole    models.Role
	RequiredScopes models.Scopes
}

type ClientChan

type ClientChan chan string

New event messages are broadcasted to all registered client connection channels.

type Config

type Config struct {
	// Port to listen to. Use ":0" for a random port.
	Address string
	Pool    *pgxpool.Pool
	SQLPool *sql.DB
	Redis   *rv8.Client
	Logger  *zap.SugaredLogger
	// SpecPath is the OpenAPI spec filepath.
	SpecPath               string
	MovieSvcClient         v1.MovieGenreClient
	ScopePolicyPath        string
	RolePolicyPath         string
	MyProviderCallbackPath string
}

type DemoTwoWorkItemCreateRequest

type DemoTwoWorkItemCreateRequest struct {
	ProjectName
	services.DemoTwoWorkItemCreateParams
}

type DemoTwoWorkItemsResponse

type DemoTwoWorkItemsResponse struct {
	db.WorkItem
	SharedWorkItemFields
	DemoTwoWorkItem db.DemoTwoWorkItem `json:"demoTwoWorkItem" required:"true"`
}

DemoTwoWorkItemsResponse represents an OpenAPI schema response for a ProjectBoard.

type DemoWorkItemCreateRequest

type DemoWorkItemCreateRequest struct {
	ProjectName
	services.DemoWorkItemCreateParams
}

type DemoWorkItemsResponse

type DemoWorkItemsResponse struct {
	db.WorkItem
	SharedWorkItemFields
	DemoWorkItem db.DemoWorkItem `json:"demoWorkItem" required:"true"`
}

DemoWorkItemsResponse represents an OpenAPI schema response for a ProjectBoard.

type ErrorHandler

type ErrorHandler func(c *gin.Context, message string, statusCode int)

ErrorHandler is called when there is an error in validation.

type Event

type Event struct {
	// Events are pushed to this channel by the main events-gathering routine
	Message  chan string
	Message2 chan string

	// New client connections
	NewClients  chan chan string
	NewClients2 chan chan string

	// Closed client connections
	ClosedClients chan chan string

	// Total client connections
	ClientsForMessage1 map[chan string]struct{}
	ClientsForMessage2 map[chan string]struct{}
}

It keeps a list of clients those are currently attached and broadcasting events to those clients.

type GinServerOptions

type GinServerOptions struct {
	BaseURL string
}

GinServerOptions provides options for the Gin server.

type Handlers

type Handlers struct {
	// contains filtered or unexported fields
}

Handlers implements ServerInterface.

func NewHandlers

func NewHandlers(
	logger *zap.SugaredLogger, pool *pgxpool.Pool,
	moviesvcclient v1.MovieGenreClient,
	specPath string,
	usvc *services.User,
	demoworkitemsvc *services.DemoWorkItem,
	demotwoworkitemsvc *services.DemoTwoWorkItem,
	workitemtagsvc *services.WorkItemTag,
	authzsvc *services.Authorization,
	authnsvc *services.Authentication,
	authmw *authMiddleware,
	provider rp.RelyingParty,
) *Handlers

NewHandlers returns an server implementation of an openapi specification.

func (*Handlers) AdminPing

func (h *Handlers) AdminPing(c *gin.Context)

AdminPing ping pongs.

func (*Handlers) CreateWorkitem

func (h *Handlers) CreateWorkitem(c *gin.Context)

create workitem.

func (*Handlers) CreateWorkitemComment

func (h *Handlers) CreateWorkitemComment(c *gin.Context, id int)

create workitem comment.

func (*Handlers) CreateWorkitemTag

func (h *Handlers) CreateWorkitemTag(c *gin.Context, project models.Project)

func (*Handlers) DeleteUser

func (h *Handlers) DeleteUser(c *gin.Context, id uuid.UUID)

DeleteUser deletes the user by id.

func (*Handlers) DeleteWorkitem

func (h *Handlers) DeleteWorkitem(c *gin.Context, id int)

delete workitem.

func (*Handlers) Events

func (h *Handlers) Events(c *gin.Context, params models.EventsParams)

Events represents server events. TODO requires query param projectId=... to subscribe to the current project's topics only.

func (*Handlers) GetCurrentUser

func (h *Handlers) GetCurrentUser(c *gin.Context)

GetCurrentUser returns the logged in user.

func (*Handlers) GetProject

func (h *Handlers) GetProject(c *gin.Context, project models.Project)

GetProject.

func (*Handlers) GetProjectBoard

func (h *Handlers) GetProjectBoard(c *gin.Context, project models.Project)

GetProjectBoard.

func (*Handlers) GetProjectConfig

func (h *Handlers) GetProjectConfig(c *gin.Context, project models.Project)

GetProjectConfig.

func (*Handlers) GetProjectWorkitems

func (h *Handlers) GetProjectWorkitems(c *gin.Context, project models.Project, params models.GetProjectWorkitemsParams)

GetProjectWorkitems.

func (*Handlers) GetWorkitem

func (h *Handlers) GetWorkitem(c *gin.Context, id int)

get workitem.

func (*Handlers) InitializeProject

func (h *Handlers) InitializeProject(c *gin.Context, project models.Project)

InitializeProject.

func (*Handlers) MyProviderCallback

func (h *Handlers) MyProviderCallback(c *gin.Context)

func (*Handlers) MyProviderLogin

func (h *Handlers) MyProviderLogin(c *gin.Context)

func (*Handlers) OpenapiYamlGet

func (h *Handlers) OpenapiYamlGet(c *gin.Context)

OpenapiYamlGet returns this very openapi spec.

func (*Handlers) Ping

func (h *Handlers) Ping(c *gin.Context)

Ping ping pongs.

func (*Handlers) UpdateProjectConfig

func (h *Handlers) UpdateProjectConfig(c *gin.Context, project models.Project)

UpdateProjectConfig.

func (*Handlers) UpdateUser

func (h *Handlers) UpdateUser(c *gin.Context, id uuid.UUID)

UpdateUser updates the user by id.

func (*Handlers) UpdateUserAuthorization

func (h *Handlers) UpdateUserAuthorization(c *gin.Context, id uuid.UUID)

UpdateUserAuthorization updates authorization information, e.g. roles, scopes.

func (*Handlers) UpdateWorkitem

func (h *Handlers) UpdateWorkitem(c *gin.Context, id int)

update workitem.

type MiddlewareFunc

type MiddlewareFunc func(c *gin.Context)

type MultiErrorHandler

type MultiErrorHandler func(openapi3.MultiError) error

MultiErrorHandler is called when oapi returns a MultiError type.

type OAValidatorOptions

type OAValidatorOptions struct {
	ValidateResponse  bool
	ErrorHandler      ErrorHandler
	Options           openapi3filter.Options
	ParamDecoder      openapi3filter.ContentParameterDecoder
	UserData          interface{}
	MultiErrorHandler MultiErrorHandler
}

OAValidatorOptions customizes request validation.

type OperationID

type OperationID string
const (
	// Operation IDs for the 'admin' tag.
	AdminPing OperationID = "AdminPing"

	// Operation IDs for the 'default' tag.
	OpenapiYamlGet OperationID = "OpenapiYamlGet"
	Ping           OperationID = "Ping"

	// Operation IDs for the 'events' tag.
	Events OperationID = "Events"

	// Operation IDs for the 'oidc' tag.
	MyProviderCallback OperationID = "MyProviderCallback"
	MyProviderLogin    OperationID = "MyProviderLogin"

	// Operation IDs for the 'project' tag.
	CreateWorkitemTag   OperationID = "CreateWorkitemTag"
	GetProject          OperationID = "GetProject"
	GetProjectBoard     OperationID = "GetProjectBoard"
	GetProjectConfig    OperationID = "GetProjectConfig"
	GetProjectWorkitems OperationID = "GetProjectWorkitems"
	InitializeProject   OperationID = "InitializeProject"
	UpdateProjectConfig OperationID = "UpdateProjectConfig"

	// Operation IDs for the 'user' tag.
	DeleteUser              OperationID = "DeleteUser"
	GetCurrentUser          OperationID = "GetCurrentUser"
	UpdateUser              OperationID = "UpdateUser"
	UpdateUserAuthorization OperationID = "UpdateUserAuthorization"

	// Operation IDs for the 'workitem' tag.
	CreateWorkitem        OperationID = "CreateWorkitem"
	CreateWorkitemComment OperationID = "CreateWorkitemComment"
	DeleteWorkitem        OperationID = "DeleteWorkitem"
	GetWorkitem           OperationID = "GetWorkitem"
	UpdateWorkitem        OperationID = "UpdateWorkitem"
)

type ProjectBoardCreateRequest

type ProjectBoardCreateRequest struct {
	// services models not needed yet, projectId is trivial to include in every request...
	// if services use db CreateParams as is we can also have specific per-project logic
	// anyway
	Teams *[]db.TeamCreateParams        `json:"teams"`
	Tags  *[]db.WorkItemTagCreateParams `json:"tags"`
}

type ProjectBoardResponse

type ProjectBoardResponse struct {
	ProjectName
}

ProjectBoardResponse represents an OpenAPI schema response for a ProjectBoard.

type ProjectName

type ProjectName struct {
	ProjectName models.Project `json:"projectName" ref:"#/components/schemas/Project" required:"true"`
}

type PubSub

type PubSub struct {
	// contains filtered or unexported fields
}

func NewPubSub

func NewPubSub() *PubSub

in reality most messages wont run endlessly in a goroutine, we will e.g. send a message to event.WorkItemMoved every time services.WorkItems.Move(...) is called we would have a map of channels opened per user id like WorkItemMovedUserChans map[string]chan string (in the future we'll have many of these like MemberAssignedUserChans to notify when added to workitem, etc.) and send a message to all members with workitem.members' userIDs. We need specific channels so that when a message is consumed we add a hardcoded "event" name ( see enum Topics) and frontend properly handles it.

func (*PubSub) Close

func (ps *PubSub) Close()

func (*PubSub) Publish

func (ps *PubSub) Publish(topic models.Topics, msg string)

func (*PubSub) PublishTo

func (ps *PubSub) PublishTo(userIDs []string, msg string)

PublishTo sends a direct message to the specified user IDs.

func (*PubSub) Subscribe

func (ps *PubSub) Subscribe(topic models.Topics, userID string) <-chan string

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(conf Config, opts ...ServerOption) (*Server, error)

NewServer returns a new http server.

type ServerInterface

type ServerInterface interface {
	// Ping pongs
	// (GET /admin/ping)
	AdminPing(c *gin.Context)

	// (GET /auth/myprovider/callback)
	MyProviderCallback(c *gin.Context)

	// (GET /auth/myprovider/login)
	MyProviderLogin(c *gin.Context)

	// (GET /events)
	Events(c *gin.Context, params externalRef0.EventsParams)
	// Returns this very OpenAPI spec.
	// (GET /openapi.yaml)
	OpenapiYamlGet(c *gin.Context)
	// Ping pongs
	// (GET /ping)
	Ping(c *gin.Context)
	// returns board data for a project
	// (GET /project/{projectName}/)
	GetProject(c *gin.Context, projectName externalRef0.ProjectName)
	// returns board data for a project
	// (GET /project/{projectName}/board)
	GetProjectBoard(c *gin.Context, projectName externalRef0.ProjectName)
	// returns the project configuration
	// (GET /project/{projectName}/config)
	GetProjectConfig(c *gin.Context, projectName externalRef0.ProjectName)
	// updates the project configuration
	// (PUT /project/{projectName}/config)
	UpdateProjectConfig(c *gin.Context, projectName externalRef0.ProjectName)
	// creates initial data (teams, tags...) for a new project
	// (POST /project/{projectName}/initialize)
	InitializeProject(c *gin.Context, projectName externalRef0.ProjectName)
	// create workitem tag
	// (POST /project/{projectName}/tag/)
	CreateWorkitemTag(c *gin.Context, projectName externalRef0.ProjectName)
	// returns workitems for a project
	// (GET /project/{projectName}/workitems)
	GetProjectWorkitems(c *gin.Context, projectName externalRef0.ProjectName, params externalRef0.GetProjectWorkitemsParams)
	// returns the logged in user
	// (GET /user/me)
	GetCurrentUser(c *gin.Context)
	// deletes the user by id
	// (DELETE /user/{id})
	DeleteUser(c *gin.Context, id uuid.UUID)
	// updates the user by id
	// (PATCH /user/{id})
	UpdateUser(c *gin.Context, id uuid.UUID)
	// updates user role and scopes by id
	// (PATCH /user/{id}/authorization)
	UpdateUserAuthorization(c *gin.Context, id uuid.UUID)
	// create workitem
	// (POST /workitem/)
	CreateWorkitem(c *gin.Context)
	// delete workitem
	// (DELETE /workitem/{id}/)
	DeleteWorkitem(c *gin.Context, id externalRef0.Serial)
	// get workitem
	// (GET /workitem/{id}/)
	GetWorkitem(c *gin.Context, id externalRef0.Serial)
	// update workitem
	// (PATCH /workitem/{id}/)
	UpdateWorkitem(c *gin.Context, id externalRef0.Serial)
	// create workitem comment
	// (POST /workitem/{id}/comments/)
	CreateWorkitemComment(c *gin.Context, id externalRef0.Serial)
	// contains filtered or unexported methods
}

ServerInterface represents all server handlers.

type ServerInterfaceWrapper

type ServerInterfaceWrapper struct {
	Handler ServerInterface
}

ServerInterfaceWrapper converts contexts to parameters.

func (*ServerInterfaceWrapper) AdminPing

func (siw *ServerInterfaceWrapper) AdminPing(c *gin.Context)

AdminPing operation with its own middleware.

func (*ServerInterfaceWrapper) CreateWorkitem

func (siw *ServerInterfaceWrapper) CreateWorkitem(c *gin.Context)

CreateWorkitem operation with its own middleware.

func (*ServerInterfaceWrapper) CreateWorkitemComment

func (siw *ServerInterfaceWrapper) CreateWorkitemComment(c *gin.Context)

CreateWorkitemComment operation with its own middleware.

func (*ServerInterfaceWrapper) CreateWorkitemTag

func (siw *ServerInterfaceWrapper) CreateWorkitemTag(c *gin.Context)

CreateWorkitemTag operation with its own middleware.

func (*ServerInterfaceWrapper) DeleteUser

func (siw *ServerInterfaceWrapper) DeleteUser(c *gin.Context)

DeleteUser operation with its own middleware.

func (*ServerInterfaceWrapper) DeleteWorkitem

func (siw *ServerInterfaceWrapper) DeleteWorkitem(c *gin.Context)

DeleteWorkitem operation with its own middleware.

func (*ServerInterfaceWrapper) Events

func (siw *ServerInterfaceWrapper) Events(c *gin.Context)

Events operation with its own middleware.

func (*ServerInterfaceWrapper) GetCurrentUser

func (siw *ServerInterfaceWrapper) GetCurrentUser(c *gin.Context)

GetCurrentUser operation with its own middleware.

func (*ServerInterfaceWrapper) GetProject

func (siw *ServerInterfaceWrapper) GetProject(c *gin.Context)

GetProject operation with its own middleware.

func (*ServerInterfaceWrapper) GetProjectBoard

func (siw *ServerInterfaceWrapper) GetProjectBoard(c *gin.Context)

GetProjectBoard operation with its own middleware.

func (*ServerInterfaceWrapper) GetProjectConfig

func (siw *ServerInterfaceWrapper) GetProjectConfig(c *gin.Context)

GetProjectConfig operation with its own middleware.

func (*ServerInterfaceWrapper) GetProjectWorkitems

func (siw *ServerInterfaceWrapper) GetProjectWorkitems(c *gin.Context)

GetProjectWorkitems operation with its own middleware.

func (*ServerInterfaceWrapper) GetWorkitem

func (siw *ServerInterfaceWrapper) GetWorkitem(c *gin.Context)

GetWorkitem operation with its own middleware.

func (*ServerInterfaceWrapper) InitializeProject

func (siw *ServerInterfaceWrapper) InitializeProject(c *gin.Context)

InitializeProject operation with its own middleware.

func (*ServerInterfaceWrapper) MyProviderCallback

func (siw *ServerInterfaceWrapper) MyProviderCallback(c *gin.Context)

MyProviderCallback operation with its own middleware.

func (*ServerInterfaceWrapper) MyProviderLogin

func (siw *ServerInterfaceWrapper) MyProviderLogin(c *gin.Context)

MyProviderLogin operation with its own middleware.

func (*ServerInterfaceWrapper) OpenapiYamlGet

func (siw *ServerInterfaceWrapper) OpenapiYamlGet(c *gin.Context)

OpenapiYamlGet operation with its own middleware.

func (*ServerInterfaceWrapper) Ping

func (siw *ServerInterfaceWrapper) Ping(c *gin.Context)

Ping operation with its own middleware.

func (*ServerInterfaceWrapper) UpdateProjectConfig

func (siw *ServerInterfaceWrapper) UpdateProjectConfig(c *gin.Context)

UpdateProjectConfig operation with its own middleware.

func (*ServerInterfaceWrapper) UpdateUser

func (siw *ServerInterfaceWrapper) UpdateUser(c *gin.Context)

UpdateUser operation with its own middleware.

func (*ServerInterfaceWrapper) UpdateUserAuthorization

func (siw *ServerInterfaceWrapper) UpdateUserAuthorization(c *gin.Context)

UpdateUserAuthorization operation with its own middleware.

func (*ServerInterfaceWrapper) UpdateWorkitem

func (siw *ServerInterfaceWrapper) UpdateWorkitem(c *gin.Context)

UpdateWorkitem operation with its own middleware.

type ServerOption

type ServerOption func(*Server)

func WithMiddlewares

func WithMiddlewares(mws ...gin.HandlerFunc) ServerOption

WithMiddlewares adds the given middlewares before registering the main routers.

type SharedWorkItemFields

type SharedWorkItemFields struct {
	TimeEntries      *[]db.TimeEntry       `json:"timeEntries"`
	WorkItemComments *[]db.WorkItemComment `json:"workItemComments"`
	Members          *[]db.User            `json:"members"`
	WorkItemTags     *[]db.WorkItemTag     `json:"workItemTags"`
	WorkItemType     *db.WorkItemType      `json:"workItemType"`
}

type TeamCreateRequest

type TeamCreateRequest struct {
	db.TeamCreateParams
}

type TeamUpdateRequest

type TeamUpdateRequest struct {
	db.TeamUpdateParams
}

type User

type User struct {
	db.User
	Role models.Role `json:"role" ref:"#/components/schemas/Role" required:"true"`

	APIKey   *db.UserAPIKey `json:"apiKey,omitempty"`
	Teams    *[]db.Team     `json:"teams"`
	Projects *[]db.Project  `json:"projects"`
}

User represents an OpenAPI schema response for a User.

type UserNotificationsChan

type UserNotificationsChan chan string

type WorkItemCommentCreateRequest

type WorkItemCommentCreateRequest struct {
	db.WorkItemCommentCreateParams
}

type WorkItemResponse

type WorkItemResponse struct {
	db.WorkItem
}

WorkItemResponse represents an OpenAPI schema response for a WorkItem.

type WorkItemTagCreateRequest

type WorkItemTagCreateRequest struct {
	db.WorkItemTagCreateParams
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL