Documentation
¶
Index ¶
- Constants
- Variables
- func BackendFromAgentRef(ctx context.Context, api *API, tx pgx.Tx) (*store.BackendState, error)
- func BackendFromQuery(ctx context.Context, api *API, tx pgx.Tx) (*store.BackendState, error)
- func ContextMiddleware(next echo.HandlerFunc) echo.HandlerFunc
- func Endpoint(handler ResourceHandler) echo.HandlerFunc
- func ErrScopeRequired(scopes ...string) *echo.HTTPError
- func ErrorHandler(next echo.HandlerFunc) echo.HandlerFunc
- func ErrorInvalidCredentials(c echo.Context) error
- func ErrorValidationFailed(c echo.Context, err store.ValidationError) error
- func GenerateNonce(n int) string
- func GenerateRef(n int) string
- func Init(e *echo.Echo) error
- func InternalMeetingID(id string) string
- func MeetingFromRequest(ctx context.Context, api *API, tx pgx.Tx) (*store.MeetingState, error)
- func NewAPIEndpointsSchema() map[string]oa.Path
- func NewAPIJWTConfig() (middleware.JWTConfig, error)
- func NewAPIResponses() map[string]oa.Response
- func NewAPISchemas() map[string]oa.Schema
- func NewAPISecuritySchemes() map[string]oa.SecurityScheme
- func NewAPISpec() *oa.Spec
- func NewAgentAPISchema() map[string]oa.Path
- func NewBackendsAPISchema() map[string]oa.Path
- func NewCommandsAPISchema() map[string]oa.Path
- func NewCtrlEndpointsSchema() map[string]oa.Path
- func NewErrorSchema() oa.Schema
- func NewFrontendsAPISchema() map[string]oa.Path
- func NewMeetingsAPISchema() map[string]oa.Path
- func NewMetaEndpointsSchema() map[string]oa.Path
- func NewNotFoundErrorSchema() oa.Schema
- func NewRPCRequestSchema() oa.Schema
- func NewRPCResponseSchema() oa.Schema
- func NewRecordingsImportAPISchema() map[string]oa.Path
- func NewServerErrorSchema() oa.Schema
- func NewValidationErrorSchema() oa.Schema
- func SignAccessToken(sub string, scope string, secret []byte) (string, error)
- func SignAdminAccessToken(sub string, secret []byte) (string, error)
- type API
- type AgentResourceClient
- type AuthClaims
- type BackendResourceClient
- type Client
- type CommandResourceClient
- type FrontendResourceClient
- type MeetingAddAttendeeRequest
- type MeetingRemoveAttendeeRequest
- type MeetingResourceClient
- type MeetingSetRunningRequest
- type MeetingStateResetRequest
- type RPCHandler
- func (rpc *RPCHandler) MeetingAddAttendee(ctx context.Context, req *MeetingAddAttendeeRequest) (RPCResult, error)
- func (rpc *RPCHandler) MeetingRemoveAttendee(ctx context.Context, req *MeetingRemoveAttendeeRequest) (RPCResult, error)
- func (rpc *RPCHandler) MeetingSetRunning(ctx context.Context, req *MeetingSetRunningRequest) (RPCResult, error)
- func (rpc *RPCHandler) MeetingStateReset(ctx context.Context, req *MeetingStateResetRequest) (RPCResult, error)
- type RPCPayload
- type RPCRequest
- func NewRPCRequest(action string, params interface{}) *RPCRequest
- func RPCMeetingAddAttendee(params *MeetingAddAttendeeRequest) *RPCRequest
- func RPCMeetingRemoveAttendee(params *MeetingRemoveAttendeeRequest) *RPCRequest
- func RPCMeetingSetRunning(params *MeetingSetRunningRequest) *RPCRequest
- func RPCMeetingStateReset(params *MeetingStateResetRequest) *RPCRequest
- type RPCResponse
- type RPCResult
- type Resource
- type ResourceHandler
- type ResourceMiddleware
- type Scopes
- type ServerError
- type StatusResponse
Constants ¶
const ( ScopeUser = "b3scale" ScopeAdmin = "b3scale:admin" ScopeNode = "b3scale:node" )
Scopes
const ( RPCStatusOK = "ok" RPCStatusError = "error" )
RPC status
const ( ActionMeetingStateReset = "meeting_state_reset" ActionMeetingSetRunning = "meeting_set_running" ActionMeetingAddAttendee = "meeting_add_attendee" ActionMeetingRemoveAttendee = "meeting_remove_attendee" )
Actions
const (
// PrefixInternalID indicates that the ID is an 'internal' ID.
PrefixInternalID = "internal:"
)
Variables ¶
var ( ErrInvalidAction = errors.New("the requsted RPC action is unknown") ErrInvalidBackend = errors.New("backend not associated with meeting") )
Errors
var ErrCommandNotAllowed = store.ValidationError{ "action": []string{"this action is not allowed"}, }
ErrCommandNotAllowed is a validation error
var ( // ErrMissingJWTSecret will be returned if a JWT secret // could not be found in the environment. ErrMissingJWTSecret = errors.New("missing JWT secret") )
Errors
var ErrNotFound = errors.New("the resource could not be found (404)")
ErrNotFound is the error when a response is a 404
var ( ErrRequestBodyRequired = echo.NewHTTPError( http.StatusBadRequest, "the request must contain content of a metadata.xml") )
Errors
var ResourceAgentBackend = &Resource{ List: RequireScope( ScopeNode, )(apiAgentBackendShow), }
ResourceAgentBackend is the resource for retrieving the currently with the agent associated backend
var ResourceAgentHeartbeat = &Resource{ Create: RequireScope( ScopeNode, )(apiAgentHeartbeatCreate), }
ResourceAgentHeartbeat is the resource for receiving an agent heartbeat
var ResourceAgentRPC = &Resource{ Create: RequireScope( ScopeNode, )(func(ctx context.Context, api *API) error { rpc := &RPCRequest{} if err := api.Bind(rpc); err != nil { return api.JSON(http.StatusBadRequest, RPCError(err)) } tx, err := api.Conn.Begin(ctx) if err != nil { return err } defer tx.Rollback(ctx) backend, err := BackendFromAgentRef(ctx, api, tx) if err != nil { return err } if backend == nil { return echo.ErrForbidden } tx.Rollback(ctx) res := rpc.Dispatch(ctx, &RPCHandler{ AgentRef: api.Ref, Backend: backend, Conn: api.Conn, }) return api.JSON(http.StatusOK, res) }), }
ResourceAgentRPC is the API resource for creating RPC requests
var ResourceBackends = &Resource{ List: RequireScope( ScopeAdmin, )(apiBackendsList), Create: RequireScope( ScopeAdmin, ScopeNode, )(apiBackendCreate), Show: RequireScope( ScopeAdmin, ScopeNode, )(apiBackendShow), Update: RequireScope( ScopeAdmin, ScopeNode, )(apiBackendUpdate), Destroy: RequireScope( ScopeAdmin, )(apiBackendDestroy), }
ResourceBackends is a restful group for backend endpoints
var ResourceCommands = &Resource{ List: RequireScope( ScopeAdmin, )(apiCommandList), Show: RequireScope( ScopeAdmin, )(apiCommandShow), Create: RequireScope( ScopeAdmin, )(apiCommandCreate), }
ResourceCommands bundles read and create operations for manipulating the command queue.
var ResourceCtlMigrate = &Resource{ Create: RequireScope( ScopeAdmin, )(apiCtlMigrate), }
ResourceCtlMigrate is a restful group for applying migrations
var ResourceFrontends = &Resource{ List: RequireScope( ScopeAdmin, ScopeUser, )(apiFrontendsList), Create: RequireScope( ScopeAdmin, )(apiFrontendCreate), Show: RequireScope( ScopeAdmin, ScopeUser, )(apiFrontendShow), Update: RequireScope( ScopeAdmin, ScopeUser, )(apiFrontendUpdate), Destroy: RequireScope( ScopeAdmin, )(apiFrontendDestroy), }
ResourceFrontends is a restful group for frontend endpoints
var ResourceMeetings = &Resource{ List: RequireScope( ScopeAdmin, )(apiMeetingsList), Show: RequireScope( ScopeAdmin, ScopeNode, )(apiMeetingShow), Update: RequireScope( ScopeAdmin, ScopeNode, )(apiMeetingUpdate), Destroy: RequireScope( ScopeAdmin, ScopeNode, )(apiMeetingDestroy), }
ResourceMeetings is a restful group for meetings
var ResourceRecordingsImport = &Resource{ Create: RequireScope( ScopeAdmin, ScopeNode, )(apiRecordingsImport), }
ResourceRecordingsImport is the recordings import api resource
Functions ¶
func BackendFromAgentRef ¶
BackendFromAgentRef resolves the backend attached to the current node agent.
func BackendFromQuery ¶
BackendFromQuery resolves the backend, either identified by ID or by hostname. The hostname must be an exact match.
func ContextMiddleware ¶
func ContextMiddleware(next echo.HandlerFunc) echo.HandlerFunc
ContextMiddleware initializes the context with auth information and a database connection.
func Endpoint ¶
func Endpoint(handler ResourceHandler) echo.HandlerFunc
Endpoint wrapps a handler function and provides the request context and sets the correct APIContext type.
func ErrScopeRequired ¶
ErrScopeRequired will be returned when a scope is missing from the response.
func ErrorHandler ¶
func ErrorHandler(next echo.HandlerFunc) echo.HandlerFunc
ErrorHandler intercepts well known errors and renders a response.
func ErrorInvalidCredentials ¶
ErrorInvalidCredentials will create an API response for an unauthorized request
func ErrorValidationFailed ¶
func ErrorValidationFailed(c echo.Context, err store.ValidationError) error
ErrorValidationFailed creates an API response when validating a resource failed.
func GenerateNonce ¶
GenerateNonce will create a random string of length n
func GenerateRef ¶
GenerateRef will create a most likely unique combination of words.
func InternalMeetingID ¶
InternalMeetingID returns the internal id for accessing via the API.
func MeetingFromRequest ¶
MeetingFromRequest resolves the current meeting
func NewAPIEndpointsSchema ¶
NewAPIEndpointsSchema combines all the endpoints schemas
func NewAPIJWTConfig ¶
func NewAPIJWTConfig() (middleware.JWTConfig, error)
NewAPIJWTConfig creates a new JWT middleware config. Parameters like shared secrets, public keys, etc.. are retrieved from the environment.
func NewAPIResponses ¶
NewAPIResponses creates all default (error) responses
func NewAPISchemas ¶
NewAPISchemas creates the schemas we use in the API
func NewAPISecuritySchemes ¶
func NewAPISecuritySchemes() map[string]oa.SecurityScheme
NewAPISecuritySchemes creates the default security schemes
func NewAgentAPISchema ¶
NewAgentAPISchema creates the API schema for the node agent
func NewBackendsAPISchema ¶
NewBackendsAPISchema generates the schema for backend related endpoint.
func NewCommandsAPISchema ¶
NewCommandsAPISchema create the endpoint schema for commands
func NewCtrlEndpointsSchema ¶
NewCtrlEndpointsSchema creates the api ctrl endpoints
func NewFrontendsAPISchema ¶
NewFrontendsAPISchema generates the endpoints for the frontend
func NewMeetingsAPISchema ¶
NewMeetingsAPISchema create the endpoint schema for meetings
func NewMetaEndpointsSchema ¶
NewMetaEndpointsSchema creates the api meta endpoints
func NewNotFoundErrorSchema ¶
NewNotFoundErrorSchema creates a not found error object schema
func NewRPCRequestSchema ¶
NewRPCRequestSchema creates the RPCRequest schema
func NewRPCResponseSchema ¶
NewRPCResponseSchema creates the RPC response schema
func NewRecordingsImportAPISchema ¶
NewRecordingsImportAPISchema creates the api schema for accepting a BBB recodrings metadata document
func NewServerErrorSchema ¶
NewServerErrorSchema creates a fallback error schema with only contains the error message.
func NewValidationErrorSchema ¶
NewValidationErrorSchema creates the validation error schema
func SignAccessToken ¶
SignAccessToken creates an authorized JWT
Types ¶
type API ¶
type API struct {
// Authorization
Scopes []string
Ref string
// Database
Conn *pgxpool.Conn
echo.Context
}
API extends the context and provides methods for handling the current user.
type AgentResourceClient ¶
type AgentResourceClient interface {
AgentHeartbeatCreate(
ctx context.Context,
) (*store.AgentHeartbeat, error)
AgentBackendRetrieve(
ctx context.Context,
) (*store.BackendState, error)
AgentRPC(
ctx context.Context,
req *RPCRequest,
) (RPCResult, error)
}
AgentResourceClient defines node agent specific methods.
type AuthClaims ¶
type AuthClaims struct {
Scope string `json:"scope"`
jwt.StandardClaims
}
AuthClaims extends the JWT standard claims with a well-known `scope` claim.
type BackendResourceClient ¶
type BackendResourceClient interface {
BackendsList(
ctx context.Context, query ...url.Values,
) ([]*store.BackendState, error)
BackendRetrieve(
ctx context.Context, id string,
) (*store.BackendState, error)
BackendCreate(
ctx context.Context, backend *store.BackendState,
) (*store.BackendState, error)
BackendUpdate(
ctx context.Context, backend *store.BackendState,
) (*store.BackendState, error)
BackendUpdateRaw(
ctx context.Context, id string, payload []byte,
) (*store.BackendState, error)
BackendDelete(
ctx context.Context,
backend *store.BackendState,
opts ...url.Values,
) (*store.BackendState, error)
}
BackendResourceClient defines methods for using the backends api resource
type Client ¶
type Client interface {
Status(ctx context.Context) (*StatusResponse, error)
FrontendResourceClient
BackendResourceClient
MeetingResourceClient
CommandResourceClient
AgentResourceClient
}
Client is an interface to the api API.
type CommandResourceClient ¶
type CommandResourceClient interface {
BackendMeetingsEnd(
ctx context.Context,
backendID string,
) (*store.Command, error)
CommandCreate(
ctx context.Context,
cmd *store.Command,
) (*store.Command, error)
CommandRetrieve(
ctx context.Context,
id string,
) (*store.Command, error)
// Control commands
CtrlMigrate(
ctx context.Context,
) (*schema.Status, error)
}
CommandResourceClient defines methods for creating and polling commands
type FrontendResourceClient ¶
type FrontendResourceClient interface {
FrontendsList(
ctx context.Context, query ...url.Values,
) ([]*store.FrontendState, error)
FrontendRetrieve(
ctx context.Context, id string,
) (*store.FrontendState, error)
FrontendCreate(
ctx context.Context, frontend *store.FrontendState,
) (*store.FrontendState, error)
FrontendUpdate(
ctx context.Context, frontend *store.FrontendState,
) (*store.FrontendState, error)
FrontendUpdateRaw(
ctx context.Context, id string, payload []byte,
) (*store.FrontendState, error)
FrontendDelete(
ctx context.Context, frontend *store.FrontendState,
) (*store.FrontendState, error)
}
FrontendResourceClient defines methods for using the frontends resource of the api
type MeetingAddAttendeeRequest ¶
type MeetingAddAttendeeRequest struct {
InternalMeetingID string `json:"internal_meeting_id"`
Attendee *bbb.Attendee `json:"attendee"`
}
MeetingAddAttendeeRequest will add an attedee to the attendees list of a meeting
type MeetingRemoveAttendeeRequest ¶
type MeetingRemoveAttendeeRequest struct {
InternalMeetingID string `json:"internal_meeting_id"`
InternalUserID string `json:"internal_user_id"`
}
MeetingRemoveAttendeeRequest will remove an attendee from a meeting identified by the internal user id
type MeetingResourceClient ¶
type MeetingResourceClient interface {
BackendMeetingsList(
ctx context.Context,
backendID string,
query ...url.Values,
) ([]*store.MeetingState, error)
MeetingsList(
ctx context.Context,
query ...url.Values,
) ([]*store.MeetingState, error)
MeetingRetrieve(
ctx context.Context,
id string,
) (*store.MeetingState, error)
MeetingUpdateRaw(
ctx context.Context,
id string,
payload []byte,
) (*store.MeetingState, error)
MeetingUpdate(
ctx context.Context,
meeting *store.MeetingState,
) (*store.MeetingState, error)
MeetingDelete(
ctx context.Context,
id string,
) (*store.MeetingState, error)
}
MeetingResourceClient defines methods for accessing the meetings api resource
type MeetingSetRunningRequest ¶
type MeetingSetRunningRequest struct {
InternalMeetingID string `json:"internal_meeting_id"`
Running bool `json:"running"`
}
MeetingSetRunningRequest contains a meetingID
type MeetingStateResetRequest ¶
type MeetingStateResetRequest struct {
InternalMeetingID string `json:"internal_meeting_id"`
}
MeetingStateResetRequest contains a meetingID
type RPCHandler ¶
type RPCHandler struct {
AgentRef string
Backend *store.BackendState
Conn *pgxpool.Conn
}
RPCHandler contains a database connection
func (*RPCHandler) MeetingAddAttendee ¶
func (rpc *RPCHandler) MeetingAddAttendee( ctx context.Context, req *MeetingAddAttendeeRequest, ) (RPCResult, error)
MeetingAddAttendee insers an attendee into the list
func (*RPCHandler) MeetingRemoveAttendee ¶
func (rpc *RPCHandler) MeetingRemoveAttendee( ctx context.Context, req *MeetingRemoveAttendeeRequest, ) (RPCResult, error)
MeetingRemoveAttendee removes an attendee from the list
func (*RPCHandler) MeetingSetRunning ¶
func (rpc *RPCHandler) MeetingSetRunning( ctx context.Context, req *MeetingSetRunningRequest, ) (RPCResult, error)
MeetingSetRunning sets the meeting is running flag for a meeting. The meeting will be awaited.
func (*RPCHandler) MeetingStateReset ¶
func (rpc *RPCHandler) MeetingStateReset( ctx context.Context, req *MeetingStateResetRequest, ) (RPCResult, error)
MeetingStateReset clears the attendees list and sets the running flag to false
type RPCPayload ¶
type RPCPayload json.RawMessage
RPCPayload is a json raw message which then can be decoded into the actual request
type RPCRequest ¶
type RPCRequest struct {
Action string `json:"action"`
Payload RPCPayload `json:"payload"`
}
RPCRequest is an incomming request with an action and a payload.
func NewRPCRequest ¶
func NewRPCRequest( action string, params interface{}, ) *RPCRequest
NewRPCRequest creates a new RPC request
func RPCMeetingAddAttendee ¶
func RPCMeetingAddAttendee(params *MeetingAddAttendeeRequest) *RPCRequest
RPCMeetingAddAttendee creates a new add attendee request
func RPCMeetingRemoveAttendee ¶
func RPCMeetingRemoveAttendee(params *MeetingRemoveAttendeeRequest) *RPCRequest
RPCMeetingRemoveAttendee creates a remove attendee request
func RPCMeetingSetRunning ¶
func RPCMeetingSetRunning(params *MeetingSetRunningRequest) *RPCRequest
RPCMeetingSetRunning creates a set running request
func RPCMeetingStateReset ¶
func RPCMeetingStateReset(params *MeetingStateResetRequest) *RPCRequest
RPCMeetingStateReset creates an meeting state reset request
func (*RPCRequest) Dispatch ¶
func (rpc *RPCRequest) Dispatch( ctx context.Context, handler *RPCHandler, ) *RPCResponse
Dispatch will invoke the RPC handlers with the decoded request payload.
type RPCResponse ¶
RPCResponse is the result of an RPC request
func RPCSuccess ¶
func RPCSuccess(result RPCResult) *RPCResponse
RPCSuccess is a successful RPC response
type Resource ¶
type Resource struct {
List ResourceHandler
Show ResourceHandler
Create ResourceHandler
Update ResourceHandler
Destroy ResourceHandler
}
Resource is a restful handler group
type ResourceHandler ¶
ResourceHandler is a handler function for API endpoints
type ResourceMiddleware ¶
type ResourceMiddleware func(next ResourceHandler) ResourceHandler
ResourceMiddleware is a function returning a HandlerFunction
func RequireScope ¶
func RequireScope(scopes ...string) ResourceMiddleware
RequireScope creates a middleware to ensure the presence of at least one required scope.
type ServerError ¶
type ServerError map[string]interface{}
ServerError will contain the decoded json body when the response status was not OK or Accepted
func (ServerError) Error ¶
func (err ServerError) Error() string
Error implements the error interface
type StatusResponse ¶
type StatusResponse struct {
Version string `json:"version" doc:"The current b3scale server version."`
Build string `json:"build" doc:"Build identifier of the server."`
API string `json:"api" doc:"The API version." example:"v1"`
AccountRef string `json:"account_ref" doc:"The currently authenticated subject."`
IsAdmin bool `json:"is_admin" doc:"True if the subject has admin privileges."`
Database *schema.Status `json:"database" doc:"Status of the database" api:"SchemaStatus"`
}
StatusResponse returns information about the API implementation and the current user.