http

package
v0.0.0-...-bf444b6 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2024 License: AGPL-3.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PathAuth           = "/auth"
	PathLogin          = "/login"
	PathOauthAuthorize = "/oauth/authorize"
	PathOauthToken     = "/oauth/token" // #nosec
)
View Source
const (
	DefaultLimit  = 10 // default limit for pagination
	DefaultOffset = 0  // default offset for pagination
)
View Source
const (
	PathRoot    = "/"
	PathSwagger = "/swagger.json"
	PathMetrics = "/metrics"

	DefaultRequestThrottleLimit   = 100
	DefaultRequestThrottleBacklog = 1000
	DefaultRequestThrottleTimeout = 10 * time.Second
)

Variables

View Source
var (
	ErrAuthCredentials       = errors.New("invalid credentials")              // invalid credentials
	ErrAuthNoPermission      = errors.New("no permission")                    // no permission
	ErrInvalidSwagger        = errors.New("invalid swagger provided")         // invalid swagger provided
	ErrNoAuthProvider        = errors.New("no auth provider provided")        // no auth provider provided
	ErrNoLicenseService      = errors.New("no license service provided")      // no license service provided
	ErrNoLogger              = errors.New("no logger provided")               // no logger provided
	ErrNoNotificationService = errors.New("no notification service provided") // no notification service provided
	ErrNoOrganizationService = errors.New("no organization service provided") // no organization service provided
	ErrNoPermissionService   = errors.New("no permission service provided")   // no permission service provided
	ErrNoRoleService         = errors.New("no role service provided")         // no role service provided
	ErrNoSystemService       = errors.New("no system service provided")       // no system service provided
	ErrNoTodoService         = errors.New("no todo service provided")         // no todo service provided
	ErrNoTracer              = errors.New("no tracer provided")               // no tracer provided
	ErrNoUserService         = errors.New("no user service provided")         // no user service provided
)

Functions

func NewMetricsServer

func NewMetricsServer(serverConfig *config.ServerConfig, tracer tracing.Tracer) (http.Handler, error)

NewMetricsServer creates a new HTTP server for Prometheus metrics.

func NewRouter

func NewRouter(strictServer StrictServer, serverConfig *config.ServerConfig, tracer tracing.Tracer) (http.Handler, error)

NewRouter creates a new HTTP router for the Server.

func WithContextObject

func WithContextObject(key pkg.CtxKey, value any) func(next http.Handler) http.Handler

WithContextObject returns a middleware that adds any value to the context associated with the given key.

func WithOtelTracer

func WithOtelTracer(next http.Handler) http.Handler

func WithPrometheusMetrics

func WithPrometheusMetrics(next http.Handler) http.Handler

func WithRequestLogger

func WithRequestLogger(next http.Handler) http.Handler

WithRequestLogger returns a middleware that logs the request.

The middleware depends on WithLogger. To use this middleware, you must call both of those first.

func WithTracedMiddleware

func WithTracedMiddleware(tracer tracing.Tracer, middleware func(next http.Handler) http.Handler) func(next http.Handler) http.Handler

WithTracedMiddleware returns an HTTP middleware that traces the middleware execution by creating a new span and passing the context to the next handler.

func WithUserID

func WithUserID(tokenValidator func(r *http.Request) (oauth2.TokenInfo, error)) func(next http.Handler) http.Handler

WithUserID returns a middleware that adds the user ID to the context, parsed from the Authorization header if present. Otherwise, an empty string is added.

func WriteJSONResponse

func WriteJSONResponse(w http.ResponseWriter, response any, status int)

WriteJSONResponse writes the JSON response to the response writer.

Types

type AuthController

type AuthController interface {
	// Authorize handles the authorization of a request.
	Authorize(w http.ResponseWriter, r *http.Request)
	// Token handles the generation and renewal of a token.
	Token(w http.ResponseWriter, r *http.Request)
	// PasswordAuthHandler handles the authorization of a user with a password.
	// If the authorization is successful, the user ID is returned. Otherwise,
	// an error is returned instead.
	PasswordAuthHandler(ctx context.Context, clientID, email, password string) (string, error)
	// UserAuthHandler handles the authorization of a user. If the
	// authorization is successful, the user ID is returned. Otherwise, an
	// error is returned instead.
	UserAuthHandler(w http.ResponseWriter, r *http.Request) (string, error)
	// ClientAuthHandler handles the client authorization.
	ClientAuthHandler(w http.ResponseWriter, r *http.Request)
	// LoginHandler handles the login of a user.
	LoginHandler(w http.ResponseWriter, r *http.Request)
	// ValidateBearerToken validates a bearer token and returns the token info
	// if the token is valid. Otherwise, an error is returned instead.
	ValidateBearerToken(r *http.Request) (oauth2.TokenInfo, error)
	// ValidateTokenHandler handles the validation of a token.
	ValidateTokenHandler(r *http.Request) error
}

AuthController provides handlers for authentication and authorization.

func NewAuthController

func NewAuthController(opts ...ControllerOption) (AuthController, error)

NewAuthController creates a new AuthController.

type ControllerOption

type ControllerOption func(*baseController) error

ControllerOption is a function that can be used to configure a controller.

func WithAuthProvider

func WithAuthProvider(authProvider *authServer.Server) ControllerOption

WithAuthProvider sets the authServer provider for the controller.

func WithConfig

func WithConfig(conf config.ServerConfig) ControllerOption

WithConfig sets the config for the controller.

func WithLicenseService

func WithLicenseService(licenseService service.LicenseService) ControllerOption

WithLicenseService sets the license service for the controller.

func WithLogger

func WithLogger(logger log.Logger) ControllerOption

WithLogger sets the logger for the controller.

func WithNotificationService

func WithNotificationService(notificationService service.NotificationService) ControllerOption

WithNotificationService sets the notification service for the controller.

func WithOrganizationService

func WithOrganizationService(organizationService service.OrganizationService) ControllerOption

WithOrganizationService sets the organization service for the controller.

func WithPermissionService

func WithPermissionService(permissionService service.PermissionService) ControllerOption

WithPermissionService sets the permission service for the controller.

func WithRoleService

func WithRoleService(roleService service.RoleService) ControllerOption

WithRoleService sets the role service for the controller.

func WithSystemService

func WithSystemService(systemService service.SystemService) ControllerOption

WithSystemService sets the system service for the controller.

func WithTodoService

func WithTodoService(todoService service.TodoService) ControllerOption

WithTodoService sets the todo service for the controller.

func WithTracer

func WithTracer(tracer tracing.Tracer) ControllerOption

WithTracer sets the tracer for the controller.

func WithUserService

func WithUserService(userService service.UserService) ControllerOption

WithUserService sets the user service for the controller.

type NotificationController

NotificationController is the controller for the notification endpoints.

func NewNotificationController

func NewNotificationController(opts ...ControllerOption) (NotificationController, error)

NewNotificationController creates a new NotificationController.

type OrganizationController

type OrganizationController interface {
	V1OrganizationsGet(ctx context.Context, request api.V1OrganizationsGetRequestObject) (api.V1OrganizationsGetResponseObject, error)
	V1OrganizationsCreate(ctx context.Context, request api.V1OrganizationsCreateRequestObject) (api.V1OrganizationsCreateResponseObject, error)
	V1OrganizationDelete(ctx context.Context, request api.V1OrganizationDeleteRequestObject) (api.V1OrganizationDeleteResponseObject, error)
	V1OrganizationGet(ctx context.Context, request api.V1OrganizationGetRequestObject) (api.V1OrganizationGetResponseObject, error)
	V1OrganizationUpdate(ctx context.Context, request api.V1OrganizationUpdateRequestObject) (api.V1OrganizationUpdateResponseObject, error)
	V1OrganizationMembersGet(ctx context.Context, request api.V1OrganizationMembersGetRequestObject) (api.V1OrganizationMembersGetResponseObject, error)
	V1OrganizationMembersAdd(ctx context.Context, request api.V1OrganizationMembersAddRequestObject) (api.V1OrganizationMembersAddResponseObject, error)
	V1OrganizationMemberRemove(ctx context.Context, request api.V1OrganizationMemberRemoveRequestObject) (api.V1OrganizationMemberRemoveResponseObject, error)
	V1OrganizationRolesCreate(ctx context.Context, request api.V1OrganizationRolesCreateRequestObject) (api.V1OrganizationRolesCreateResponseObject, error)
	V1OrganizationRoleGet(ctx context.Context, request api.V1OrganizationRoleGetRequestObject) (api.V1OrganizationRoleGetResponseObject, error)
	V1OrganizationRolesGet(ctx context.Context, request api.V1OrganizationRolesGetRequestObject) (api.V1OrganizationRolesGetResponseObject, error)
	V1OrganizationRoleUpdate(ctx context.Context, request api.V1OrganizationRoleUpdateRequestObject) (api.V1OrganizationRoleUpdateResponseObject, error)
	V1OrganizationRoleDelete(ctx context.Context, request api.V1OrganizationRoleDeleteRequestObject) (api.V1OrganizationRoleDeleteResponseObject, error)
	V1OrganizationRoleMembersGet(ctx context.Context, request api.V1OrganizationRoleMembersGetRequestObject) (api.V1OrganizationRoleMembersGetResponseObject, error)
	V1OrganizationRoleMembersAdd(ctx context.Context, request api.V1OrganizationRoleMembersAddRequestObject) (api.V1OrganizationRoleMembersAddResponseObject, error)
	V1OrganizationRoleMemberRemove(ctx context.Context, request api.V1OrganizationRoleMemberRemoveRequestObject) (api.V1OrganizationRoleMemberRemoveResponseObject, error)
}

OrganizationController is a controller for organization endpoints.

func NewOrganizationController

func NewOrganizationController(opts ...ControllerOption) (OrganizationController, error)

NewOrganizationController creates a new OrganizationController.

type PermissionController

PermissionController is a controller for system endpoints.

func NewPermissionController

func NewPermissionController(opts ...ControllerOption) (PermissionController, error)

NewPermissionController creates a new PermissionController.

type Server

type Server interface {
	api.ServerInterface
	AuthController
	InternalErrorHandler(err error) *authErrors.Response
	ResponseErrorHandler(r *authErrors.Response)
	PreRedirectErrorHandler(w http.ResponseWriter, r *authServer.AuthorizeRequest, err error)
}

Server is the type alias for the generated server interface.

type StrictServer

type StrictServer interface {
	api.StrictServerInterface
	AuthController
	InternalErrorHandler(err error) (re *authErrors.Response)
	ResponseErrorHandler(r *authErrors.Response)
	PreRedirectErrorHandler(w http.ResponseWriter, r *authServer.AuthorizeRequest, err error)
}

StrictServer is the type alias for the generated server interface.

func NewServer

func NewServer(opts ...ControllerOption) (StrictServer, error)

NewServer creates a new HTTP server.

type SystemController

SystemController is a controller for system endpoints.

func NewSystemController

func NewSystemController(opts ...ControllerOption) (SystemController, error)

NewSystemController creates a new SystemController.

type TodoController

TodoController is the controller for the todo endpoints.

func NewTodoController

func NewTodoController(opts ...ControllerOption) (TodoController, error)

NewTodoController creates a new TodoController.

type UserController

UserController is a controller for user endpoints.

func NewUserController

func NewUserController(opts ...ControllerOption) (UserController, error)

NewUserController creates a new UserController.

Directories

Path Synopsis
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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