simplevalidate

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package simplevalidate contains a Validator for secrets that can be validated with simple HTTP queries and result code comparison.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option[S veles.Secret] func(*Validator[S])

Option configures a Validator when creating it.

func WithBody

func WithBody[S veles.Secret](b func(S) string) Option[S]

WithBody configures the request body to set in the query based on the secret.

func WithClient

func WithClient[S veles.Secret](c *http.Client) Option[S]

WithClient configures the HTTP client this validator should use. Defaults to http.DefaultClient.

func WithEndpoint

func WithEndpoint[S veles.Secret](e string) Option[S]

WithEndpoint configures the API endpoint to query.

func WithHTTPHeaders

func WithHTTPHeaders[S veles.Secret](h func(S) map[string]string) Option[S]

WithHTTPHeaders configures HTTP headers to set in the query based on the secret.

func WithHTTPMethod

func WithHTTPMethod[S veles.Secret](m string) Option[S]

WithHTTPMethod configures HTTP request method to send (e.g. http.MethodGet, http.MethodPost)

func WithInvalidResponseCodes

func WithInvalidResponseCodes[S veles.Secret](r []int) Option[S]

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.

func WithValidResponseCodes

func WithValidResponseCodes[S veles.Secret](r []int) Option[S]

WithValidResponseCodes configures status codes that should result in a "ValidationValid" validation result.

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.

func New

func New[S veles.Secret](opts ...Option[S]) *Validator[S]

New creates a new Validator with the given options.

func (*Validator[S]) Validate

func (v *Validator[S]) Validate(ctx context.Context, secret S) (veles.ValidationStatus, error)

Validate validates a secret with a simple HTTP request.

Jump to

Keyboard shortcuts

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