utils

package
v1.19.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ClusterGroupKind = v1.Kind("Cluster")
View Source
var ClusterResource = v1.Resource("Clusters")
View Source
var Validate = validator.New()
View Source
var WriteClientError = WriteFuncFactory(400)
View Source
var WriteForbiddenError = WriteFuncFactory(403)
View Source
var WriteNotFoundError = WriteFuncFactory(404)
View Source
var WriteServerError = WriteFuncFactory(500)
View Source
var WriteUnauthorizedError = WriteFuncFactory(401)

Functions

func Authenticate

func Authenticate(req *http.Request) bool

Authenticate only authenticate admin user token

func CreateResponeData

func CreateResponeData(err error, msg string, data interface{}) string

func NewForbidden

func NewForbidden(qualifiedResource schema.GroupResource, name string, err error) *errors.StatusError

func NewInternalError

func NewInternalError(err error) *errors.StatusError

func NewInvalid

func NewInvalid(qualifiedKind schema.GroupKind, name string, fieldName string, err error) *errors.StatusError

NewInvalid returns an error indicating the item is invalid and cannot be processed.

func NewNotFound

func NewNotFound(qualifiedResource schema.GroupResource, name string, message string) *errors.StatusError

NewNotFound returns a new error which indicates that the resource of the kind and the name was not found.

func NewUnauthorized

func NewUnauthorized(reason string) *errors.StatusError

NewUnauthorized returns an error indicating the client is not authorized to perform the requested action.

func ValidateAPIServerAddresses

func ValidateAPIServerAddresses(fl validator.FieldLevel) bool

ValidateAPIServerAddresses validates if given string is a valid apiserver addresses list. A valid addresses should be a list of URL concated with ';'

func WriteFuncFactory

func WriteFuncFactory(statusCode int) func(response *restful.Response, code int, message string)

WriteFuncFactory builds WriteXXX shortcut functions

func WriteKubeAPIError

func WriteKubeAPIError(rw http.ResponseWriter, err *errors.StatusError)

WriteKubeAPIError writes a standard error response

Types

type EmptyResponse

type EmptyResponse struct{}

type ErrorResponse

type ErrorResponse struct {
	Result  bool        `json:"result"`
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

func FormatValidationError

func FormatValidationError(errList error) *ErrorResponse

FormatValidationError turn the original validatetion errors into error response, it will only use the FIRST errorField to construct the error message.

Jump to

Keyboard shortcuts

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