api

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const JWTCookieName = "pyroscopeJWT"

Variables

View Source
var (
	ErrRequestBodyRequired    = model.ValidationError{Err: errors.New("request body required")}
	ErrRequestBodyJSONInvalid = model.ValidationError{Err: errors.New("request body contains malformed JSON")}
)

Functions

func AuthMiddleware

func AuthMiddleware(log logrus.FieldLogger, loginRedirect http.HandlerFunc, authService AuthService) func(next http.Handler) http.Handler

AuthMiddleware authenticates requests.

func Error

func Error(w http.ResponseWriter, logger logrus.FieldLogger, err error)

func ErrorCode

func ErrorCode(w http.ResponseWriter, logger logrus.FieldLogger, err error, code int)

ErrorCode replies to the request with the specified error message as JSON-encoded body and writes corresponding message to the log.

If HTTP code is less than or equal zero, it will be deduced based on the error. If it fails, StatusInternalServerError will be returned without the response body. The error can be of 'multierror.Error' type.

The call writes messages with the debug log level except the case when the code is StatusInternalServerError which is logged as an error.

It does not end the HTTP request; the caller should ensure no further writes are done to w.

func HandleError added in v0.11.0

func HandleError(w http.ResponseWriter, r *http.Request, logger logrus.FieldLogger, err error)

HandleError replies to the request with an appropriate message as JSON-encoded body and writes a corresponding message to the log with debug log level.

Any error of a type not defined in this package or pkg/model, will be treated as an internal server error causing response code 500. Such errors are not sent but only logged with error log level.

func IsJSONError added in v0.11.0

func IsJSONError(err error) bool

func Logger added in v0.11.0

func Logger(r *http.Request, logger logrus.FieldLogger) logrus.FieldLogger

Logger creates a new logger scoped to the request and enriches it with the known fields.

func MustJSON

func MustJSON(w http.ResponseWriter, v interface{})

Types

type APIKeyHandler

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

func NewAPIKeyHandler

func NewAPIKeyHandler(logger logrus.FieldLogger, apiKeyService APIKeyService) APIKeyHandler

func (APIKeyHandler) CreateAPIKey

func (h APIKeyHandler) CreateAPIKey(w http.ResponseWriter, r *http.Request)

func (APIKeyHandler) DeleteAPIKey

func (h APIKeyHandler) DeleteAPIKey(w http.ResponseWriter, r *http.Request)

func (APIKeyHandler) ListAPIKeys

func (h APIKeyHandler) ListAPIKeys(w http.ResponseWriter, r *http.Request)

type APIKeyService

type APIKeyService interface {
	CreateAPIKey(context.Context, model.CreateAPIKeyParams) (model.APIKey, string, error)
	GetAllAPIKeys(context.Context) ([]model.APIKey, error)
	DeleteAPIKeyByID(context.Context, uint) error
}

type AuthService

type AuthService interface {
	APIKeyFromToken(ctx context.Context, token string) (model.APIKey, error)
	UserFromJWTToken(ctx context.Context, token string) (model.User, error)
	AuthenticateUser(ctx context.Context, name, password string) (model.User, error)
}

type Errors

type Errors struct {
	Errors []string `json:"errors"`
}

type JSONError added in v0.11.0

type JSONError struct {
	Err error
}

func (JSONError) Error added in v0.11.0

func (e JSONError) Error() string

func (JSONError) Unwrap added in v0.11.0

func (e JSONError) Unwrap() error

type UserHandler

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

func NewUserHandler

func NewUserHandler(logger logrus.FieldLogger, userService UserService) UserHandler

func (UserHandler) ChangeAuthenticatedUserPassword

func (h UserHandler) ChangeAuthenticatedUserPassword(w http.ResponseWriter, r *http.Request)

func (UserHandler) ChangeUserPassword

func (h UserHandler) ChangeUserPassword(w http.ResponseWriter, r *http.Request)

func (UserHandler) ChangeUserRole

func (h UserHandler) ChangeUserRole(w http.ResponseWriter, r *http.Request)

func (UserHandler) CreateUser

func (h UserHandler) CreateUser(w http.ResponseWriter, r *http.Request)

func (UserHandler) DeleteUser

func (h UserHandler) DeleteUser(w http.ResponseWriter, r *http.Request)

func (UserHandler) DisableUser

func (h UserHandler) DisableUser(w http.ResponseWriter, r *http.Request)

func (UserHandler) EnableUser

func (h UserHandler) EnableUser(w http.ResponseWriter, r *http.Request)

func (UserHandler) GetAuthenticatedUser

func (h UserHandler) GetAuthenticatedUser(w http.ResponseWriter, r *http.Request)

func (UserHandler) GetUser

func (h UserHandler) GetUser(w http.ResponseWriter, r *http.Request)

func (UserHandler) ListUsers

func (h UserHandler) ListUsers(w http.ResponseWriter, r *http.Request)

func (UserHandler) UpdateAuthenticatedUser

func (h UserHandler) UpdateAuthenticatedUser(w http.ResponseWriter, r *http.Request)

func (UserHandler) UpdateUser

func (h UserHandler) UpdateUser(w http.ResponseWriter, r *http.Request)

type UserService

type UserService interface {
	CreateUser(context.Context, model.CreateUserParams) (model.User, error)
	FindUserByID(context.Context, uint) (model.User, error)
	GetAllUsers(context.Context) ([]model.User, error)
	UpdateUserByID(context.Context, uint, model.UpdateUserParams) (model.User, error)
	UpdateUserPasswordByID(context.Context, uint, model.UpdateUserPasswordParams) error
	DeleteUserByID(context.Context, uint) error
}

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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