rest

package
v1.55.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const MaxWaitTime = 1 * time.Minute
View Source
const MinWaitTime = 5 * time.Second

Variables

View Source
var Logger = logger

Functions

func ContainsViolation

func ContainsViolation(err error, message string) bool

func CorrectPayload added in v1.37.0

func CorrectPayload(err error, request *request) bool

CorrectPayload investigates a failed request and the error that got returned. If it is an error message originating from Settings 2.0 it may contain constraint violations complaining about unknown properties within the payload.

If it was possible to modify the payload of the request based on these constraint violations, CorrectPayload will return `true`, signalling that it makes sense to re-send the given request (with corrected payload).

Note: The `payload` field of the request won't be the original type after this.

func Envelope added in v1.43.0

func Envelope(data []byte, url string, method string) error

func MicrosecondsToUnixTime

func MicrosecondsToUnixTime(timeInMicroseconds int64) time.Time

MicrosecondsToUnixTime converts the UTC time in microseconds to a time.Time struct (unix time)

func Now

func Now() time.Time

func SetLogWriter

func SetLogWriter(writer io.Writer) error

func StringTimestampToHumanReadableFormat

func StringTimestampToHumanReadableFormat(unixTimestampAsString string) (humanReadable string, parsedTimestamp int64, err error)

StringTimestampToHumanReadableFormat parses and sanity-checks a unix timestamp as string and returns it as int64 and a human-readable representation of it

Types

type Client

type Client interface {
	Get(url string, expectedStatusCodes ...int) Request
	Post(url string, payload any, expectedStatusCodes ...int) Request
	Put(url string, payload any, expectedStatusCodes ...int) Request
	Delete(url string, expectedStatusCodes ...int) Request
	Upload(url string, reader io.ReadCloser, fileName string, expectedStatusCodes ...int) Request
}

func DefaultClient

func DefaultClient(envURL string, apiToken string) Client

type ClientFactory added in v1.28.0

type ClientFactory func(envURL, apiToken, schemaID string) Client

type ConstraintViolation

type ConstraintViolation struct {
	Description       string `json:"description,omitempty"`
	ParameterLocation string `json:"parameterLocation,omitempty"`
	Message           string `json:"message,omitempty"`
	Path              string `json:"path,omitempty"`
}

type Error

type Error struct {
	Code                 int                   `json:"code"`
	Message              string                `json:"message"`
	ConstraintViolations []ConstraintViolation `json:"constraintViolations,omitempty"`
	URL                  string                `json:"-"`
	Method               string                `json:"-"`
}

func (Error) ContainsViolation

func (me Error) ContainsViolation(message string) bool

func (Error) Error

func (me Error) Error() string

func (Error) PropertyViolations added in v1.37.0

func (me Error) PropertyViolations() PropertyViolations

func (Error) ViolationMessage

func (me Error) ViolationMessage() string

type Forbidden added in v1.28.0

type Forbidden struct {
	Method string
}

func (*Forbidden) Expect added in v1.28.0

func (me *Forbidden) Expect(codes ...int) Request

func (*Forbidden) Finish added in v1.28.0

func (me *Forbidden) Finish(vs ...any) error

func (*Forbidden) OnResponse added in v1.28.0

func (me *Forbidden) OnResponse(func(resp *http.Response)) Request

func (*Forbidden) Payload added in v1.28.0

func (me *Forbidden) Payload(any) Request

func (*Forbidden) Raw added in v1.28.0

func (me *Forbidden) Raw() ([]byte, error)

type PropertyViolation added in v1.37.0

type PropertyViolation []string

PropertyViolation represents the "address" of a property the Settings 2.0 API wasn't expecting at this position. Example: [ "0", "eventFilters", "0", "unsupportedProperty" ]

These entries originate from the `path` of a constraint violation, e.g. `builtin:alerting.profile/0/eventFilters/0/unsupportedProperty` The first part of the path is always the schemaID and is irrelevant

Entries that are convertible to an int are considered to be indizes of arrays within the payload

The first entry ALWAYS denotes an array index, because at least one setting has been sent for create or update

The last entry ALWAYS denotes the name of the property

func (PropertyViolation) Remove added in v1.37.0

func (me PropertyViolation) Remove(v any) bool

type PropertyViolations added in v1.37.0

type PropertyViolations []PropertyViolation

PropertyViolations represents ALL constraint violations the Settings 2.0 API returned complaining about properties that were not expected

func (PropertyViolations) Remove added in v1.37.0

func (me PropertyViolations) Remove(request *request) bool

If an error returned by the Settings 2.0 API contains constraint violations based on missing properties, this function tries to remove them from the payload of the given request. If it was possible to "correct" the payload according to the constraint violations, `true` will be returned, otherwise `false`

type Request

type Request interface {
	// Raw() ([]byte, error)
	Finish(v ...any) error
	Expect(codes ...int) Request
	Payload(any) Request
	OnResponse(func(resp *http.Response)) Request
}

type StriclyForbidden added in v1.28.0

type StriclyForbidden struct {
	Method string
	URL    string
}

func (*StriclyForbidden) Expect added in v1.28.0

func (me *StriclyForbidden) Expect(codes ...int) Request

func (*StriclyForbidden) Finish added in v1.28.0

func (me *StriclyForbidden) Finish(vs ...any) error

func (*StriclyForbidden) OnResponse added in v1.28.0

func (me *StriclyForbidden) OnResponse(func(resp *http.Response)) Request

func (*StriclyForbidden) Payload added in v1.28.0

func (me *StriclyForbidden) Payload(any) Request

func (*StriclyForbidden) Raw added in v1.28.0

func (me *StriclyForbidden) Raw() ([]byte, error)

Jump to

Keyboard shortcuts

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