server

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: MIT Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OperationWrap requestOperation = iota
	OperationUnwrap
)
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

This section is empty.

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 ErrorResponse

type ErrorResponse string

ErrorResponse is used to send JSON responses with an error

const InternalServerError ErrorResponse = "An internal error occurred"

InternalServerError is an ErrorResponse for Internal Server Error messages

func (ErrorResponse) MarshalJSON

func (e ErrorResponse) 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 (*Server) AccessTokenMiddleware

func (s *Server) AccessTokenMiddleware(required bool) 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 This injects the token in the request's context if it exists and it's valid If required is true, the request fails if the token is not present

func (*Server) AllowIpMiddleware

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

AllowIpMiddleware is a middleware that allows requests from certain IPs only

func (*Server) Init

func (s *Server) Init(log *utils.AppLogger) error

Init the Server object and create a Gin server

func (*Server) RequestIdMiddleware

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

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

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) RouteAuth

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

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

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) 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) RouteResult

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

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

func (*Server) RouteWrapUnwrap

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

RouteWrapUnwrap is the handler for the POST /wrap and /unwrap request

func (*Server) Start

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

Start 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