Documentation ¶
Index ¶
- Variables
- func ConvertToPrivateError(e compat.Error) compat.PrivateError
- func DetermineListRange(obj interface{}, page int, size int) (list []interface{}, total int)
- func Handle(w http.ResponseWriter, r *http.Request, cfg *HandlerConfig, httpStatus int)
- func HandleDelete(w http.ResponseWriter, r *http.Request, cfg *HandlerConfig, httpStatus int)
- func HandleGet(w http.ResponseWriter, r *http.Request, cfg *HandlerConfig)
- func HandleList(w http.ResponseWriter, r *http.Request, cfg *HandlerConfig)
- func MakeReferenceId(id interface{}) (string, bool)
- func MetricsMiddleware(handler http.Handler) http.Handler
- func NewOpenAPIHandler(openAPIDefinitions []byte) *openAPIHandler
- func NewPrometheusMetricsHandler() *prometheusMetricsHandler
- func PresentError(err *errors.ServiceError, url string) compat.Error
- func PresentReferenceWith(id, obj interface{}, ObjectKind func(i interface{}) string, ...) compat.ObjectReference
- func ResetMetricCollectors()
- func ValidateJsonSchema(schemaName string, schemaLoader gojsonschema.JSONLoader, documentName string, ...) *errors.ServiceError
- type ErrorHandler
- func (h ErrorHandler) Create(w http.ResponseWriter, r *http.Request)
- func (h ErrorHandler) Delete(w http.ResponseWriter, r *http.Request)
- func (h ErrorHandler) Get(w http.ResponseWriter, r *http.Request)
- func (h ErrorHandler) List(w http.ResponseWriter, r *http.Request)
- func (h ErrorHandler) Patch(w http.ResponseWriter, r *http.Request)
- type ErrorHandlerFunc
- type EventStream
- type HandlerConfig
- type HttpAction
- type RestHandler
- type Validate
- func ValidateAsyncEnabled(r *http.Request, action string) Validate
- func ValidateDnsName(value *string, field string) Validate
- func ValidateExternalClusterId(value *string, field string) Validate
- func ValidateLength(value *string, field string, min int, maxVal *int) Validate
- func ValidateMaxLength(value *string, field string, maxVal *int) Validate
- func ValidateMinLength(value *string, field string, min int) Validate
- func ValidateNotEmptyClusterId(value *string, field string) Validate
- func ValidateQueryParam(queryParams url.Values, field string) Validate
- func ValidateServiceAccountClientId(value *string, field string, ssoProvider string) Validate
- func ValidateServiceAccountDesc(value *string, field string) Validate
- func ValidateServiceAccountId(value *string, field string) Validate
- func ValidateServiceAccountName(value *string, field string) Validate
- func Validation(field string, value *string, options ...ValidateOption) Validate
- type ValidateOption
Constants ¶
This section is empty.
Variables ¶
var ( ValidUuidRegexp = regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`) ValidClientIdUuidRegexp = regexp.MustCompile(`^srvc-acct-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`) ValidServiceAccountNameRegexp = regexp.MustCompile(`^[a-z]([-a-z0-9]*[a-z0-9])?$`) ValidServiceAccountDescRegexp = regexp.MustCompile(`^[a-zA-Z0-9.,\-\s]*$`) ValidAlphaNumeric = regexp.MustCompile(`^[a-zA-Z0-9]*$`) // taken from here: https://regex101.com/r/SEg6KL/1 - will likely be removed if we can use our permissions to get cluster dns from cluster id ValidDnsName = regexp.MustCompile(`^(?:[_a-z0-9](?:[_a-z0-9-]{0,61}[a-z0-9])?\.)+(?:[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?)?$`) MinRequiredFieldLength = 1 MaxServiceAccountNameLength = 50 MaxServiceAccountDescLength = 255 MaxServiceAccountId = 36 MaxServiceAccountClientId = 47 )
var MetricsLabels = []string{
metricsMethodLabel,
metricsPathLabel,
metricsCodeLabel,
}
MetricsLabels - Array of labels added to metrics:
var MetricsNames = []string{
requestCount,
requestDuration,
}
MetricsNames - Array of Names of the metrics:
var PathVarSub = "-"
PathVarSub replaces path variables to a same character
Functions ¶
func ConvertToPrivateError ¶
func ConvertToPrivateError(e compat.Error) compat.PrivateError
func DetermineListRange ¶
Prepare a 'list' of non-db-backed resources
func Handle ¶
func Handle(w http.ResponseWriter, r *http.Request, cfg *HandlerConfig, httpStatus int)
func HandleDelete ¶
func HandleDelete(w http.ResponseWriter, r *http.Request, cfg *HandlerConfig, httpStatus int)
func HandleGet ¶
func HandleGet(w http.ResponseWriter, r *http.Request, cfg *HandlerConfig)
func HandleList ¶
func HandleList(w http.ResponseWriter, r *http.Request, cfg *HandlerConfig)
func MakeReferenceId ¶
func MetricsMiddleware ¶
MetricsMiddleware creates a new handler that collects metrics for the requests processed by the given handler.
func NewOpenAPIHandler ¶
func NewOpenAPIHandler(openAPIDefinitions []byte) *openAPIHandler
func NewPrometheusMetricsHandler ¶
func NewPrometheusMetricsHandler() *prometheusMetricsHandler
NewPrometheusMetricsHandler adds custom metrics and proxy to prometheus handler
func PresentError ¶
func PresentError(err *errors.ServiceError, url string) compat.Error
func PresentReferenceWith ¶
func PresentReferenceWith(id, obj interface{}, ObjectKind func(i interface{}) string, ObjectPath func(id string, obj interface{}) string) compat.ObjectReference
func ResetMetricCollectors ¶
func ResetMetricCollectors()
ResetMetricCollectors resets all prometheus collectors
func ValidateJsonSchema ¶
func ValidateJsonSchema(schemaName string, schemaLoader gojsonschema.JSONLoader, documentName string, documentLoader gojsonschema.JSONLoader) *errors.ServiceError
Types ¶
type ErrorHandler ¶
type ErrorHandler struct{}
func NewErrorsHandler ¶
func NewErrorsHandler() *ErrorHandler
func (ErrorHandler) Create ¶
func (h ErrorHandler) Create(w http.ResponseWriter, r *http.Request)
func (ErrorHandler) Delete ¶
func (h ErrorHandler) Delete(w http.ResponseWriter, r *http.Request)
func (ErrorHandler) Get ¶
func (h ErrorHandler) Get(w http.ResponseWriter, r *http.Request)
func (ErrorHandler) List ¶
func (h ErrorHandler) List(w http.ResponseWriter, r *http.Request)
func (ErrorHandler) Patch ¶
func (h ErrorHandler) Patch(w http.ResponseWriter, r *http.Request)
type ErrorHandlerFunc ¶
type ErrorHandlerFunc func(r *http.Request, w http.ResponseWriter, err *errors.ServiceError)
type EventStream ¶
type EventStream struct { ContentType string // GetNextEvent should block until there is an event to return. GetNextEvent should unblock and return io.EOF when if context is canceled. GetNextEvent HttpAction Close func() }
type HandlerConfig ¶
type HandlerConfig struct { MarshalInto interface{} Validate []Validate Action HttpAction ErrorHandler ErrorHandlerFunc }
HandlerConfig defines the common things each REST controller must do. The corresponding handle() func runs the basic HandlerConfig. This is not meant to be an HTTP framework or anything larger than simple CRUD in handlers.
MarshalInto is a pointer to the object to hold the unmarshaled JSON. Validate is a list of Validation function that run in order, returning fast on the first error. Action is the specific logic a handler must take (e.g, find an object, save an object) ErrorHandler is the way errors are returned to the client
type HttpAction ¶
type HttpAction func() (interface{}, *errors.ServiceError)
type RestHandler ¶
type RestHandler interface { List(w http.ResponseWriter, r *http.Request) Get(w http.ResponseWriter, r *http.Request) Create(w http.ResponseWriter, r *http.Request) Patch(w http.ResponseWriter, r *http.Request) Delete(w http.ResponseWriter, r *http.Request) }
type Validate ¶
type Validate func() *errors.ServiceError
func ValidateAsyncEnabled ¶
ValidateAsyncEnabled returns a validator that returns an error if the async query param is not true
func ValidateDnsName ¶
func ValidateLength ¶
func Validation ¶
func Validation(field string, value *string, options ...ValidateOption) Validate
type ValidateOption ¶
type ValidateOption func(field string, value *string) *errors.ServiceError
func IsOneOf ¶
func IsOneOf(options ...string) ValidateOption
func Matches ¶
func Matches(regex *regexp.Regexp) ValidateOption
func MaxLen ¶
func MaxLen(max int) ValidateOption
func MinLen ¶
func MinLen(min int) ValidateOption
func WithDefault ¶
func WithDefault(d string) ValidateOption