Documentation
¶
Index ¶
- Constants
- func GetOIDCClaims(r *http.Request) (map[string]interface{}, bool)
- func GetRequestID(ctx context.Context) string
- func GetRequesterIp(r *http.Request) string
- func IdempotencyKeyInterceptor(validateIdempotency ValidateIdempotency, cacheResponse CacheResponse) mux.MiddlewareFunc
- func LaunchMemStats()
- func NewElapsedTimeInterceptor() mux.MiddlewareFunc
- func OIDCInterceptor(cfg OIDCConfig, next http.Handler) http.Handler
- func Recoverer(next http.Handler) http.Handler
- func SendApiReqMessage(f ApiReqMiddleware) mux.MiddlewareFunc
- func StripBearerPrefixFromTokenString(tok string) (string, error)
- type ApiReqMiddleware
- type BodyRequestInfo
- type CacheResponse
- type CheckWeightWithDB
- type ErrorDTO
- type LogResponseWriter
- type MiddlewareChain
- type MiddlewareHandlerFunc
- type MiddlewareInterceptor
- type OIDCConfig
- type RoleValidator
- type ServiceConfig
- type ValidateIdempotency
- type WeightContainer
Constants ¶
const ( AUTHORIZATION string = "Authorization" HEADER_USER_NAME string = "User-Name" HEADER_CUSTOMER_ID string = "Customer-Id" HEADER_USER_ID string = "User-Id" HEADER_SERVICE_ID string = "Service-Id" HEADER_INPUT_APP string = "x-application-vkn" HEADER_APP_ID string = "App-Id" HEADER_REMOTE_IP string = "Remote-Ip" HEADER_REQUEST_WEIGHT_NAME string = "x-application-rw" HEADER_REQUEST_WEIGHT_VALUE string = "x-application-rv" HEADER_TIMESTAMP string = "x-application-alo" HEADER_PLAN_ID string = "Plan-Id" HEADER_PLAN_IPFS_STORAGE string = "Plan-Storage" HEADER_IPFS_STORAGE string = "Ipfs-Storage" HEADER_JTI string = "jti" HEADER_IDEMPOTENCY_KEY string = "fv-idempotency-key" )
const ( INSUFFICIENT_SCOPE_ERROR string = "INSUFFICIENT_SCOPE_ERROR" USER_AGENT_CHANGED string = "USER_AGENT_CHANGE" INVALID_TOKEN_ERROR string = "INVALID_TOKEN_ERROR" INVALID_APP_ID string = "INVALID_APP_ID" INVALID_CUSTOMER_ID string = "INVALID_CUSTOMER_ID" PARAM_NETWORK_ID string = "network" PARAM_OFFSET string = "o" PARAM_MAX_ROWS string = "n" CORE_VIEW_WEIGHT_NAME_DEFAULT string = "CORE_VIEW" CORE_VIEW_WEIGHT_VALUE_DEFAULT string = "1" )
Variables ¶
This section is empty.
Functions ¶
func GetOIDCClaims ¶ added in v2.1.0
GetOIDCClaims helper for extracting OIDC claims from request context
func GetRequestID ¶
func GetRequesterIp ¶
func IdempotencyKeyInterceptor ¶
func IdempotencyKeyInterceptor(validateIdempotency ValidateIdempotency, cacheResponse CacheResponse) mux.MiddlewareFunc
func LaunchMemStats ¶
func LaunchMemStats()
func NewElapsedTimeInterceptor ¶
func NewElapsedTimeInterceptor() mux.MiddlewareFunc
Intercepts the request and calculates the total run time from start to finish
func OIDCInterceptor ¶ added in v2.1.0
func OIDCInterceptor(cfg OIDCConfig, next http.Handler) http.Handler
OIDCInterceptor middleware configurable for OIDC validation
func Recoverer ¶
Recoverer is an interceptor that recovers from panics, logs the panic (and the stacktrace), and returns a HTTP 500 (Internal Server Error) status if possible.
func SendApiReqMessage ¶
func SendApiReqMessage(f ApiReqMiddleware) mux.MiddlewareFunc
func StripBearerPrefixFromTokenString ¶
Strips 'Bearer ' prefix from bearer token string
Types ¶
type ApiReqMiddleware ¶
type ApiReqMiddleware func(BodyRequestInfo)
type BodyRequestInfo ¶
type BodyRequestInfo struct {
ServiceID uint64 `json:"serviceId"`
AppId *types.SqlUuid `json:"appId"`
RequestBody []byte `json:"requestBody"`
Body []byte `json:"body"`
Username string `json:"username"`
CustomerID types.SqlUuid `json:"customerId"`
Url string `json:"url"`
Ip string `json:"ip"`
Method string `json:"method"`
HttpStatus int `json:"httpStatus"`
TimeUsed time.Duration `json:"timeUsed"`
RequestTime time.Time `json:"requestTime"`
}
func (*BodyRequestInfo) ToJson ¶
func (n *BodyRequestInfo) ToJson() string
Returns the json string representation
type ErrorDTO ¶
type ErrorDTO struct {
// The error code
// in: string
Code string `json:"code"`
// The error message
// in: string
Message string `json:"message"`
}
func NewErrorDTO ¶
NewErrorDTO returns a new ErrorDTO
type LogResponseWriter ¶
type LogResponseWriter struct {
http.ResponseWriter
// contains filtered or unexported fields
}
func NewLogResponseWriter ¶
func NewLogResponseWriter(w http.ResponseWriter) *LogResponseWriter
func (*LogResponseWriter) WriteHeader ¶
func (w *LogResponseWriter) WriteHeader(code int)
type MiddlewareChain ¶
type MiddlewareChain []MiddlewareInterceptor
MiddlewareChain is a collection of interceptors that will be invoked in there index order
func (MiddlewareChain) Handler ¶
func (chain MiddlewareChain) Handler(handler http.HandlerFunc) http.Handler
Handler allows hooking multiple middleware in single call.
type MiddlewareHandlerFunc ¶
type MiddlewareHandlerFunc http.HandlerFunc
MiddlewareHandlerFunc builds on top of http.HandlerFunc, and exposes API to intercept with MiddlewareInterceptor. This allows building complex long chains without complicated struct manipulation
func (MiddlewareHandlerFunc) Intercept ¶
func (cont MiddlewareHandlerFunc) Intercept(mw MiddlewareInterceptor) MiddlewareHandlerFunc
Intercept returns back a continuation that will call install middleware to intercept the continuation call.
type MiddlewareInterceptor ¶
type MiddlewareInterceptor func(http.ResponseWriter, *http.Request, http.HandlerFunc)
MiddlewareInterceptor intercepts an HTTP handler invocation, it is passed both response writer and request which after interception can be passed onto the handler function.
func TimestampHeaderInterceptor ¶
func TimestampHeaderInterceptor() MiddlewareInterceptor
type OIDCConfig ¶ added in v2.1.0
type OIDCConfig struct {
Client *oidc.Client
CheckExpiration bool
ExpirationLeeway int64 // seconds, 0 uses the client's default
ValidateKID bool
UseIntrospection bool // If true, uses remote introspection (validates everything)
RequiredScopes []string // Only if UseIntrospection=true
InjectClaims bool // If true, injects claims into context
}
type RoleValidator ¶
type RoleValidator func(request *http.Request, customerInfo *jwt.CustomerInfo) bool
Interface used to execute SecurityTokenInterceptor url filtering for authorization
type ServiceConfig ¶
ServiceConfig contains the ServiceID and Environment values of the application that uses Middleware to secure access to endpoints.
func (*ServiceConfig) JwtInterceptor ¶
func (config *ServiceConfig) JwtInterceptor(roleValidator RoleValidator, dbTokenValidator jwt.DBTokenValidator) MiddlewareInterceptor
JwtInterceptor Executes all operations necessary to validate that the token received contains the credentials required for the request. Receives as parameter RoleValidator from the applica
type ValidateIdempotency ¶
type WeightContainer ¶
type WeightContainer struct {
CheckWeightWithDB CheckWeightWithDB
}