Documentation ¶
Index ¶
- Constants
- Variables
- func ContainsViolation(err error, message string) bool
- func CorrectPayload(err error, request *request) bool
- func MicrosecondsToUnixTime(timeInMicroseconds int64) time.Time
- func Now() time.Time
- func SetLogWriter(writer io.Writer) error
- func StringTimestampToHumanReadableFormat(unixTimestampAsString string) (humanReadable string, parsedTimestamp int64, err error)
- type Client
- type ClientFactory
- type ConstraintViolation
- type Error
- type Forbidden
- type PropertyViolation
- type PropertyViolations
- type Request
- type StriclyForbidden
Constants ¶
const MaxWaitTime = 1 * time.Minute
const MinWaitTime = 5 * time.Second
Variables ¶
var Logger = logger
Functions ¶
func ContainsViolation ¶
func CorrectPayload ¶ added in v1.37.0
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 MicrosecondsToUnixTime ¶
MicrosecondsToUnixTime converts the UTC time in microseconds to a time.Time struct (unix time)
func SetLogWriter ¶
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 }
func DefaultClient ¶
type ClientFactory ¶ added in v1.28.0
type ConstraintViolation ¶
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 (Error) PropertyViolations ¶ added in v1.37.0
func (me Error) PropertyViolations() PropertyViolations
func (Error) ViolationMessage ¶
type Forbidden ¶ added in v1.28.0
type Forbidden struct {
Method string
}
func (*Forbidden) OnResponse ¶ added in v1.28.0
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 StriclyForbidden ¶ added in v1.28.0
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)