Documentation
¶
Overview ¶
Package simplevalidate contains a Validator for secrets that can be validated with simple HTTP queries and result code comparison.
Index ¶
- type Option
- func WithBody[S veles.Secret](b func(S) string) Option[S]
- func WithClient[S veles.Secret](c *http.Client) Option[S]
- func WithEndpoint[S veles.Secret](e string) Option[S]
- func WithHTTPHeaders[S veles.Secret](h func(S) map[string]string) Option[S]
- func WithHTTPMethod[S veles.Secret](m string) Option[S]
- func WithInvalidResponseCodes[S veles.Secret](r []int) Option[S]
- func WithStatusFromResponseBody[S veles.Secret](f func(body []byte) (veles.ValidationStatus, error)) Option[S]
- func WithValidResponseCodes[S veles.Secret](r []int) Option[S]
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
Option configures a Validator when creating it.
func WithClient ¶
WithClient configures the HTTP client this validator should use. Defaults to http.DefaultClient.
func WithEndpoint ¶
WithEndpoint configures the API endpoint to query.
func WithHTTPHeaders ¶
WithHTTPHeaders configures HTTP headers to set in the query based on the secret.
func WithHTTPMethod ¶
WithHTTPMethod configures HTTP request method to send (e.g. http.MethodGet, http.MethodPost)
func WithInvalidResponseCodes ¶
WithInvalidResponseCodes configures status codes that should result in a "ValidationInvalid" validation result.
func WithStatusFromResponseBody ¶
func WithStatusFromResponseBody[S veles.Secret](f func(body []byte) (veles.ValidationStatus, error)) Option[S]
WithStatusFromResponseBody configures the function that performs additional custom validation on the response body. This will only run if none of the status codes from ValidResponseCodes and InvalidResponseCodes have been found.
type Validator ¶
type Validator[S veles.Secret] struct { // The API endpoint to query. Endpoint string // The HTTP request method to send (e.g. http.MethodGet, http.MethodPost) HTTPMethod string // HTTP headers to set in the query based on the secret. HTTPHeaders func(S) map[string]string // The body to set in the query based on the secret Body func(S) string // Status codes that should result in a "ValidationValid" validation result. ValidResponseCodes []int // Status codes that should result in a "ValidationInvalid" validation result. InvalidResponseCodes []int // Additional custom validation logic to perform on the response body. Will run if none of the // status codes from ValidResponseCodes and InvalidResponseCodes have been found. StatusFromResponseBody func(body []byte) (veles.ValidationStatus, error) // contains filtered or unexported fields }
Validator validates a secret of a given type by sending HTTP requests and checking the response status code. It implements veles.Validator.