v1

package
v0.0.0-...-61cf9d3 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2022 License: AGPL-3.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ScopeUser  = "b3scale"
	ScopeAdmin = "b3scale:admin"
)

Scopes

Variables

View Source
var (
	// ErrMissingJWTSecret will be returned if a JWT secret
	// could not be found in the environment.
	ErrMissingJWTSecret = errors.New("missing JWT secret")

	// ErrAdminScopeRequired will be returned if the token
	// has insuficient rights.
	ErrAdminScopeRequired = echo.NewHTTPError(
		http.StatusForbidden,
		"b3scale:admin scope required")
)

Errors

Functions

func APIErrorHandler

func APIErrorHandler(next echo.HandlerFunc) echo.HandlerFunc

APIErrorHandler intercepts well known errors and renders a response.

func BackendCreate

func BackendCreate(c echo.Context) error

BackendCreate will add a new backend to the cluster. ! requires: `admin`

func BackendDestroy

func BackendDestroy(c echo.Context) error

BackendDestroy will start a backend decommissioning. ! requires: `admin`

func BackendMeetingsEnd

func BackendMeetingsEnd(c echo.Context) error

BackendMeetingsEnd will stop all meetings for a given backend_id.

func BackendMeetingsList

func BackendMeetingsList(c echo.Context) error

BackendMeetingsList will retrieve all meetings for a given backend_id.

func BackendRetrieve

func BackendRetrieve(c echo.Context) error

BackendRetrieve will retrieve a single backend by ID. ! requires: `admin`

func BackendUpdate

func BackendUpdate(c echo.Context) error

BackendUpdate will update the frontend with values provided by the request. Only keys provided will be updated. ! requires: `admin`

func BackendsList

func BackendsList(c echo.Context) error

BackendsList will list all frontends known to the cluster or within the user scope. ! requires: `admin`

func ErrorInvalidCredentials

func ErrorInvalidCredentials(c echo.Context) error

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 FrontendCreate

func FrontendCreate(c echo.Context) error

FrontendCreate will add a new frontend to the cluster.

func FrontendDestroy

func FrontendDestroy(c echo.Context) error

FrontendDestroy will remove a frontend from the cluster. The frontend is identified by ID.

func FrontendRetrieve

func FrontendRetrieve(c echo.Context) error

FrontendRetrieve will retrieve a single frontend identified by ID.

func FrontendUpdate

func FrontendUpdate(c echo.Context) error

FrontendUpdate will update the frontend with values provided by the request. Only keys provided will be updated.

func FrontendsList

func FrontendsList(c echo.Context) error

FrontendsList will list all frontends known to the cluster or within the user scope.

func Init

func Init(e *echo.Echo) error

Init sets up a group with authentication for a restful management interface.

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 RequireAdminScope

func RequireAdminScope(fn echo.HandlerFunc) echo.HandlerFunc

RequireAdminScope wraps a handler func and checks for the presence of the AdminScope before invoking the decorated function.

func SignAdminAccessToken

func SignAdminAccessToken(sub string, secret []byte) (string, error)

SignAdminAccessToken creates a new authorized JWT with an admin scope.

func Status

func Status(c echo.Context) error

Status will respond with the api version and b3scale version.

Types

type APIAuthClaims

type APIAuthClaims struct {
	Scope string `json:"scope"`
	jwt.StandardClaims
}

APIAuthClaims extends the JWT standard claims with a well-known `scope` claim.

type APIContext

type APIContext struct {
	echo.Context
}

APIContext extends the context and provides methods for handling the current user.

func (*APIContext) AccountRef

func (ctx *APIContext) AccountRef() string

AccountRef retrievs the subject from the JWT as the account reference.

func (*APIContext) Ctx

func (ctx *APIContext) Ctx() context.Context

Ctx is a shortcut to access the request context

func (*APIContext) FilterAccountRef

func (ctx *APIContext) FilterAccountRef() *string

FilterAccountRef when the b3scale:admin scope is present, this function retrieves the value of the query param `ref`. The value will be nil in absence of the parameter.

When the admin scope is not present, the requesting subject will be used.

func (*APIContext) HasScope

func (ctx *APIContext) HasScope(s string) (found bool)

HasScope checks if the authentication scope claim contains a scope by name. The scope claim is a space separated list of scopes according to RFC8693, Section 4.2, (OAuth 2).

func (*APIContext) Release

func (ctx *APIContext) Release()

Release will free any acquired resources of this context

type APIError

type APIError map[string]interface{}

APIError will return the decoded json body when the response status was not OK or Accepted

func APIErrorFromResponse

func APIErrorFromResponse(res *http.Response) APIError

APIErrorFromResponse will create a new APIError from the HTTP response.

func (APIError) Error

func (err APIError) Error() string

Error implements the error interface

type Client

type Client interface {
	Status(ctx context.Context) (*StatusResponse, error)

	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)
	FrontendDelete(
		ctx context.Context, frontend *store.FrontendState,
	) (*store.FrontendState, error)

	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)
	BackendDelete(
		ctx context.Context, backend *store.BackendState,
		query url.Values,
	) (*store.BackendState, error)

	BackendMeetingsList(
		ctx context.Context,
		backendID string,
		query url.Values,
	) ([]*store.MeetingState, error)

	BackendMeetingsEnd(
		ctx context.Context,
		backendID string,
	) (*store.Command, error)
}

Client is an interface to the v1 API.

type JWTClient

type JWTClient struct {
	Host        string
	AccessToken string

	Client *http.Client
}

JWTClient is a http api v1 client

func NewJWTClient

func NewJWTClient(host, token string) *JWTClient

NewJWTClient initializes the client

func (*JWTClient) AuthorizeRequest

func (c *JWTClient) AuthorizeRequest(req *http.Request) *http.Request

AuthorizeRequest will add a http Authorization header with the access token to the request

func (*JWTClient) BackendCreate

func (c *JWTClient) BackendCreate(
	ctx context.Context, backend *store.BackendState,
) (*store.BackendState, error)

BackendCreate creates a new backend on the server

func (*JWTClient) BackendDelete

func (c *JWTClient) BackendDelete(
	ctx context.Context, backend *store.BackendState, query url.Values,
) (*store.BackendState, error)

BackendDelete removes a backend from the cluster

func (*JWTClient) BackendMeetingsEnd

func (c *JWTClient) BackendMeetingsEnd(
	ctx context.Context, backendID string,
) (*store.Command, error)

BackendMeetingsEnd ends all meetings on a given backend

func (*JWTClient) BackendMeetingsList

func (c *JWTClient) BackendMeetingsList(
	ctx context.Context, backendID string, query url.Values,
) ([]*store.MeetingState, error)

BackendMeetingsList retrieves all meetings for a given backend

func (*JWTClient) BackendRetrieve

func (c *JWTClient) BackendRetrieve(
	ctx context.Context, id string,
) (*store.BackendState, error)

BackendRetrieve retrieves a single backend by ID.

func (*JWTClient) BackendUpdate

func (c *JWTClient) BackendUpdate(
	ctx context.Context, backend *store.BackendState,
) (*store.BackendState, error)

BackendUpdate updates the backend

func (*JWTClient) BackendsList

func (c *JWTClient) BackendsList(
	ctx context.Context, query url.Values,
) ([]*store.BackendState, error)

BackendsList retrievs a list of backends from the server

func (*JWTClient) FrontendCreate

func (c *JWTClient) FrontendCreate(
	ctx context.Context, frontend *store.FrontendState,
) (*store.FrontendState, error)

FrontendCreate POSTs a new frontend to the server

func (*JWTClient) FrontendDelete

func (c *JWTClient) FrontendDelete(
	ctx context.Context, frontend *store.FrontendState,
) (*store.FrontendState, error)

FrontendDelete removes a frontend from the cluster.

func (*JWTClient) FrontendRetrieve

func (c *JWTClient) FrontendRetrieve(
	ctx context.Context, id string,
) (*store.FrontendState, error)

FrontendRetrieve retrieves a single frontend

func (*JWTClient) FrontendUpdate

func (c *JWTClient) FrontendUpdate(
	ctx context.Context, frontend *store.FrontendState,
) (*store.FrontendState, error)

FrontendUpdate PATCHes an already existing frontend.

func (*JWTClient) FrontendsList

func (c *JWTClient) FrontendsList(
	ctx context.Context, query url.Values,
) ([]*store.FrontendState, error)

FrontendsList retrievs a list of frontends

func (*JWTClient) Status

func (c *JWTClient) Status(
	ctx context.Context,
) (*StatusResponse, error)

Status retrievs the API / server status

type StatusResponse

type StatusResponse struct {
	Version    string `json:"version"`
	Build      string `json:"build"`
	API        string `json:"api"`
	AccountRef string `json:"account_ref"`
	IsAdmin    bool   `json:"is_admin"`
}

StatusResponse returns information about the API implementation and the current user.

Jump to

Keyboard shortcuts

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