apiutil

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const BearerPrefix = "Bearer "

BearerPrefix represents the token prefix for Bearer authentication scheme.

View Source
const ThingPrefix = "Thing "

ThingPrefix represents the key prefix for Thing authentication scheme.

Variables

View Source
var (
	// ErrValidation indicates that an error was returned by the API.
	ErrValidation = errors.New("something went wrong with the request")

	// ErrBearerToken indicates missing or invalid bearer user token.
	ErrBearerToken = errors.New("missing or invalid bearer user token")

	// ErrBearerKey indicates missing or invalid bearer entity key.
	ErrBearerKey = errors.New("missing or invalid bearer entity key")

	// ErrMissingID indicates missing entity ID.
	ErrMissingID = errors.New("missing entity id")

	// ErrInvalidAuthKey indicates invalid auth key.
	ErrInvalidAuthKey = errors.New("invalid auth key")

	// ErrInvalidIDFormat indicates an invalid ID format.
	ErrInvalidIDFormat = errors.New("invalid id format provided")

	// ErrNameSize indicates that name size exceeds the max.
	ErrNameSize = errors.New("invalid name size")

	// ErrEmailSize indicates that email size exceeds the max.
	ErrEmailSize = errors.New("invalid email size")

	// ErrInvalidStatus indicates an invalid user account status.
	ErrInvalidStatus = errors.New("invalid user account status")

	// ErrInvalidRole indicates that an invalid role.
	ErrInvalidRole = errors.New("invalid client role")

	// ErrLimitSize indicates that an invalid limit.
	ErrLimitSize = errors.New("invalid limit size")

	// ErrOffsetSize indicates an invalid offset.
	ErrOffsetSize = errors.New("invalid offset size")

	// ErrInvalidOrder indicates an invalid list order.
	ErrInvalidOrder = errors.New("invalid list order provided")

	// ErrInvalidDirection indicates an invalid list direction.
	ErrInvalidDirection = errors.New("invalid list direction provided")

	// ErrInvalidMemberKind indicates an invalid member kind.
	ErrInvalidMemberKind = errors.New("invalid member kind")

	// ErrEmptyList indicates that entity data is empty.
	ErrEmptyList = errors.New("empty list provided")

	// ErrMalformedPolicy indicates that policies are malformed.
	ErrMalformedPolicy = errors.New("malformed policy")

	// ErrMissingPolicySub indicates that policies are subject.
	ErrMissingPolicySub = errors.New("malformed policy subject")

	// ErrMissingPolicyObj indicates missing policies object.
	ErrMissingPolicyObj = errors.New("malformed policy object")

	// ErrMalformedPolicyAct indicates missing policies action.
	ErrMalformedPolicyAct = errors.New("malformed policy action")

	// ErrMalformedPolicyRel indicates missing policies relation.
	ErrMalformedPolicyRel = errors.New("malformed policy relation")

	// ErrMalformedPolicyPer indicates missing policies relation.
	ErrMalformedPolicyPer = errors.New("malformed policy permission")

	// ErrMissingCertData indicates missing cert data (ttl).
	ErrMissingCertData = errors.New("missing certificate data")

	// ErrInvalidCertData indicates invalid cert data (ttl).
	ErrInvalidCertData = errors.New("invalid certificate data")

	// ErrInvalidTopic indicates an invalid subscription topic.
	ErrInvalidTopic = errors.New("invalid Subscription topic")

	// ErrInvalidContact indicates an invalid subscription contract.
	ErrInvalidContact = errors.New("invalid Subscription contact")

	// ErrMissingEmail indicates missing email.
	ErrMissingEmail = errors.New("missing email")

	// ErrMissingHost indicates missing host.
	ErrMissingHost = errors.New("missing host")

	// ErrMissingPass indicates missing password.
	ErrMissingPass = errors.New("missing password")

	// ErrMissingConfPass indicates missing conf password.
	ErrMissingConfPass = errors.New("missing conf password")

	// ErrInvalidResetPass indicates an invalid reset password.
	ErrInvalidResetPass = errors.New("invalid reset password")

	// ErrInvalidComparator indicates an invalid comparator.
	ErrInvalidComparator = errors.New("invalid comparator")

	// ErrMissingMemberType indicates missing group member type.
	ErrMissingMemberType = errors.New("missing group member type")

	// ErrMissingMemberKind indicates missing group member kind.
	ErrMissingMemberKind = errors.New("missing group member kind")

	// ErrMissingRelation indicates missing relation.
	ErrMissingRelation = errors.New("missing relation")

	// ErrInvalidAPIKey indicates an invalid API key type.
	ErrInvalidAPIKey = errors.New("invalid api key type")

	// ErrMaxLevelExceeded indicates an invalid group level.
	ErrMaxLevelExceeded = errors.New("invalid group level (should be lower than 5)")

	// ErrBootstrapState indicates an invalid bootstrap state.
	ErrBootstrapState = errors.New("invalid bootstrap state")

	// ErrInvitationState indicates an invalid invitation state.
	ErrInvitationState = errors.New("invalid invitation state")

	// ErrMissingIdentity indicates missing entity Identity.
	ErrMissingIdentity = errors.New("missing entity identity")

	// ErrMissingSecret indicates missing secret.
	ErrMissingSecret = errors.New("missing secret")

	// ErrMissingOwner indicates missing entity owner.
	ErrMissingOwner = errors.New("missing entity owner")

	// ErrMissingPolicyOwner indicated malformed policy owner.
	ErrMissingPolicyOwner = errors.New("malformed policy owner")

	// ErrMissingPolicyEntityType indicates malformed policy entity type.
	ErrMissingPolicyEntityType = errors.New("malformed or missing entity type")

	// ErrMissingName indicates missing identity name.
	ErrMissingName = errors.New("missing identity name")

	// ErrInvalidSecret indicates invalid secret.
	ErrInvalidSecret = errors.New("missing secret")

	// ErrInvalidLevel indicates an invalid group level.
	ErrInvalidLevel = errors.New("invalid group level (should be between 0 and 5)")

	// ErrNotFoundParam indicates that the parameter was not found in the query.
	ErrNotFoundParam = errors.New("parameter not found in the query")

	// ErrInvalidQueryParams indicates invalid query parameters.
	ErrInvalidQueryParams = errors.New("invalid query parameters")

	// ErrInvalidVisibilityType indicates invalid visibility type.
	ErrInvalidVisibilityType = errors.New("invalid visibility type")

	// ErrUnsupportedContentType indicates unacceptable or lack of Content-Type.
	ErrUnsupportedContentType = errors.New("unsupported content type")

	// ErrRollbackTx indicates failed to rollback transaction.
	ErrRollbackTx = errors.New("failed to rollback transaction")
)

Errors defined in this file are used by the LoggingErrorEncoder decorator to distinguish and log API request validation errors and avoid that service errors are logged twice.

Functions

func ExtractBearerToken

func ExtractBearerToken(r *http.Request) string

ExtractBearerToken returns value of the bearer token. If there is no bearer token - an empty value is returned.

func ExtractThingKey

func ExtractThingKey(r *http.Request) string

ExtractThingKey returns value of the thing key. If there is no thing key - an empty value is returned.

func LoggingErrorEncoder

func LoggingErrorEncoder(logger *slog.Logger, enc kithttp.ErrorEncoder) kithttp.ErrorEncoder

LoggingErrorEncoder is a go-kit error encoder logging decorator.

func ReadBoolQuery

func ReadBoolQuery(r *http.Request, key string, def bool) (bool, error)

ReadBoolQuery reads boolean query parameters in a given http request.

func ReadMetadataQuery

func ReadMetadataQuery(r *http.Request, key string, def map[string]interface{}) (map[string]interface{}, error)

ReadMetadataQuery reads the value of json http query parameters for a given key.

func ReadNumQuery

func ReadNumQuery[N number](r *http.Request, key string, def N) (N, error)

ReadNumQuery returns a numeric value.

func ReadStringQuery

func ReadStringQuery(r *http.Request, key, def string) (string, error)

ReadStringQuery reads the value of string http query parameters for a given key.

Types

type ErrorRes

type ErrorRes struct {
	Err string `json:"error"`
	Msg string `json:"message"`
}

ErrorRes represents the HTTP error response body.

Jump to

Keyboard shortcuts

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