server

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: MIT Imports: 59 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OperationEncrypt requestOperation = iota
	OperationDecrypt
	OperationSign
	OperationVerify
	OperationWrapKey
	OperationUnwrapKey
)
View Source
const (
	// Request is pending
	StatusPending requestStatus = iota
	// Request is completed and was successful
	StatusComplete
	// Request is completed and was canceled
	StatusCanceled
	// Request has been removed
	// This is only used in the public response
	StatusRemoved
)

Variables

This section is empty.

Functions

func AbortWithErrorJSON added in v1.3.0

func AbortWithErrorJSON(c *gin.Context, err error)

AbortWithErrorJSON aborts a Gin context and sends a response with a JSON error message. Pass an ErrorResponse object to be able to customize the status code; it defaults to 500 otherwise. If the status code is >= 500, the message is not sent to users directly.

Types

type AccessToken

type AccessToken struct {
	TokenType        string `json:"token_type"`
	Resource         string `json:"resource"`
	Scope            string `json:"scope"`
	ExpiresIn        int    `json:"expires_in"`
	AccessToken      string `json:"access_token"`
	RefreshToken     string `json:"refresh_token"`
	Error            string `json:"error"`
	ErrorDescription string `json:"error_description"`
}

AccessToken contains the details of the access token

type AccessTokenMiddlewareOpts

type AccessTokenMiddlewareOpts struct {
	// If true, the request fails if the token is not present
	Required bool
	// If true, allows reading an access token directly from the Authorization header, as a Bearer token
	// This is an access token with permissions on Azure Key Vault directly
	AllowAccessTokenInHeader bool
}

type NewServerOpts added in v1.3.0

type NewServerOpts struct {
	Log           *slog.Logger
	Webhook       webhook.Webhook
	Metrics       *metrics.RevaulterMetrics
	TraceExporter sdkTrace.SpanExporter
	// contains filtered or unexported fields
}

NewServerOpts contains options for the NewServer method

type ResponseError added in v1.3.0

type ResponseError struct {
	// Error message
	Message string
	// Status code
	Code int
}

ResponseError is used to send JSON responses with an error

func NewResponseError added in v1.3.0

func NewResponseError(code int, message string) ResponseError

NewResponseError creates a new ErrorResponse with the code and message

func NewResponseErrorf added in v1.3.0

func NewResponseErrorf(code int, messageFmt string, args ...any) ResponseError

NewResponseErrorf creates a new ErrorResponse with the code and formatted message

func (ResponseError) Error added in v1.3.0

func (e ResponseError) Error() string

Error implements the error interface

func (ResponseError) MarshalJSON added in v1.3.0

func (e ResponseError) MarshalJSON() ([]byte, error)

MarshalJSON implements a JSON marshaller that returns an object with the error key

type Server

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

Server is the server based on Gin

func NewServer

func NewServer(opts NewServerOpts) (*Server, error)

NewServer creates a new Server object and initializes it

func (*Server) AccessTokenMiddleware

func (s *Server) AccessTokenMiddleware(opts AccessTokenMiddlewareOpts) func(c *gin.Context)

AccessTokenMiddleware is a middleware that requires the user to be authenticated and present a cookie with the access token for Azure Key Vault Note that this middleware doesn't validate the access token in any way (not even making sure it's a valid JWT), it just ensures the token is present; it's Azure Key Vault's responsibility to validate the token This injects the token in the request's context if it exists and it's valid

func (*Server) AllowIpMiddleware

func (s *Server) AllowIpMiddleware() (gin.HandlerFunc, error)

AllowIpMiddleware is a middleware that allows requests from certain IPs only

func (*Server) MiddlewareCountMetrics added in v1.3.0

func (s *Server) MiddlewareCountMetrics(c *gin.Context)

MiddlewareCountMetrics is a Gin middleware that records requests served by the server

func (*Server) MiddlewareLogger added in v1.3.0

func (s *Server) MiddlewareLogger(parentLog *slog.Logger) func(c *gin.Context)

MiddlewareLogger is a Gin middleware that uses slog for logging

func (*Server) MiddlewareLoggerMask added in v1.3.0

func (s *Server) MiddlewareLoggerMask(exp *regexp.Regexp, replace string) gin.HandlerFunc

MiddlewareLoggerMask returns a Gin middleware that adds the "log-mask" to mask the path using a regular expression

func (*Server) MiddlewareMaxBodySize added in v1.3.0

func (s *Server) MiddlewareMaxBodySize(c *gin.Context)

MiddlewareMaxBodySize is a middleware that limits the size of the request body

func (*Server) MiddlewareRequestId added in v1.3.0

func (s *Server) MiddlewareRequestId(c *gin.Context)

MiddlewareRequestId is a middleware that generates a unique request ID for each request

func (*Server) RequestKeyMiddleware added in v1.1.0

func (s *Server) RequestKeyMiddleware() gin.HandlerFunc

RequestKeyMiddleware is a middleware that asserts that the Authorization header contains the shared requestKey

func (*Server) RouteApiConfirmPost

func (s *Server) RouteApiConfirmPost(c *gin.Context)

RouteApiConfirmPost is the handler for the POST /api/confirm request This receives the results of the confirm/reject action

func (*Server) RouteApiListGet

func (s *Server) RouteApiListGet(c *gin.Context)

RouteApiListGet is the handler for the GET /api/list request This returns the list of all pending requests If the Accept header is `application/x-ndjson`, then this sends a stream of records, updated as soon as they come in, using the NDJSON format (https://github.com/ndjson/ndjson-spec)

func (*Server) RouteAuthConfirm

func (s *Server) RouteAuthConfirm(c *gin.Context)

RouteAuthConfirm is the handler for the GET /auth/confirm request This exchanges an authorization code for an access token

func (*Server) RouteAuthSignin

func (s *Server) RouteAuthSignin(c *gin.Context)

RouteAuthSignin is the handler for the GET /auth/signin request This redirects the user to the page where they can sign in

func (*Server) RouteHealthzHandler

func (s *Server) RouteHealthzHandler(w http.ResponseWriter, r *http.Request)

RouteHealthzHandler is the handler for the GET /healthz request as a http.Handler. It can be used to ping the server and ensure everything is working.

func (*Server) RouteRequestOperations

func (s *Server) RouteRequestOperations(op requestOperation) gin.HandlerFunc

RouteRequestOperations is the handler for the routes that perform operations: - POST /request/encrypt - POST /request/decrypt - POST /request/sign - POST /request/verify - POST /request/wrapkey - POST /request/unwrapkey

func (*Server) RouteRequestResult

func (s *Server) RouteRequestResult(c *gin.Context)

RouteRequestResult is the handler for the GET /request/result/:state request This can be invoked by the app to periodically poll for the result

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run the web server Note this function is blocking, and will return only when the servers are shut down via context cancellation.

Jump to

Keyboard shortcuts

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