externaldata

package
v0.0.0-...-aa99306 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2024 License: Apache-2.0 Imports: 16 Imported by: 29

Documentation

Index

Constants

View Source
const (
	HTTPScheme  = "http"
	HTTPSScheme = "https"
)

Variables

This section is empty.

Functions

func HandleError

func HandleError(statusCode int, err error) (*ast.Term, error)

func PrepareRegoResponse

func PrepareRegoResponse(regoResponse *RegoResponse) (*ast.Term, error)

Types

type CacheKey

type CacheKey struct {
	ProviderName string
	Key          string
}

type CacheValue

type CacheValue struct {
	Received   int64
	Value      interface{}
	Error      string
	Idempotent bool
}

type Item

type Item struct {
	// Key is the request from the provider.
	Key string `json:"key,omitempty"`
	// Value is the response from the provider.
	Value interface{} `json:"value,omitempty"`
	// Error is the error from the provider.
	Error string `json:"error,omitempty"`
}

Item is the struct that contains the key, value or error from a provider response.

type ProviderCache

type ProviderCache struct {
	// contains filtered or unexported fields
}

func NewCache

func NewCache() *ProviderCache

func (*ProviderCache) Get

func (*ProviderCache) Remove

func (c *ProviderCache) Remove(name string)

func (*ProviderCache) Upsert

func (c *ProviderCache) Upsert(provider *unversioned.Provider) error

type ProviderKind

type ProviderKind string

ProviderKind strings are special string constants for Providers. +kubebuilder:validation:Enum=ProviderRequestKind;ProviderResponseKind

const (
	// ProviderRequestKind is the kind of the request.
	ProviderRequestKind ProviderKind = "ProviderRequest"
	// ProviderResponseKind is the kind of the response.
	ProviderResponseKind ProviderKind = "ProviderResponse"
)

type ProviderRequest

type ProviderRequest struct {
	// APIVersion is the API version of the external data provider.
	APIVersion string `json:"apiVersion,omitempty"`
	// Kind is kind of the external data provider API call. This can be "ProviderRequest" or "ProviderResponse".
	Kind ProviderKind `json:"kind,omitempty"`
	// Request contains the request for the external data provider.
	Request Request `json:"request,omitempty"`
}

ProviderRequest is the API request for the external data provider.

func NewProviderRequest

func NewProviderRequest(keys []string) *ProviderRequest

NewProviderRequest creates a new request for the external data provider.

type ProviderResponse

type ProviderResponse struct {
	// APIVersion is the API version of the external data provider.
	APIVersion string `json:"apiVersion,omitempty"`
	// Kind is kind of the external data provider API call. This can be "ProviderRequest" or "ProviderResponse".
	Kind ProviderKind `json:"kind,omitempty"`
	// Response contains the response from the provider.
	Response Response `json:"response,omitempty"`
}

ProviderResponse is the API response from a provider.

func DefaultSendRequestToProvider

func DefaultSendRequestToProvider(ctx context.Context, provider *unversioned.Provider, keys []string, clientCert *tls.Certificate) (*ProviderResponse, int, error)

DefaultSendRequestToProvider is the default function to send the request to the external data provider.

type ProviderResponseCache

type ProviderResponseCache struct {
	TTL time.Duration
	// contains filtered or unexported fields
}

func NewProviderResponseCache

func NewProviderResponseCache(ctx context.Context, ttl time.Duration) *ProviderResponseCache

func (*ProviderResponseCache) Get

func (*ProviderResponseCache) Remove

func (c *ProviderResponseCache) Remove(key CacheKey)

func (*ProviderResponseCache) Upsert

func (c *ProviderResponseCache) Upsert(key CacheKey, value CacheValue)

type RegoRequest

type RegoRequest struct {
	// ProviderName is the name of the external data provider.
	ProviderName string `json:"provider"`
	// Keys is the list of keys to send to the external data provider.
	Keys []string `json:"keys"`
}

RegoRequest is the request for external_data rego function.

type RegoResponse

type RegoResponse struct {
	// Responses contains the response from the provider.
	// In each element of the outer array, the first element is the key and the second is the corresponding value from the provider.
	Responses [][]interface{} `json:"responses"`
	// Errors contains the errors from the provider.
	// In each item of the outer array, the first element is the key and the second is the corresponding error from the provider.
	Errors [][]interface{} `json:"errors"`
	// StatusCode contains the status code of the response.
	StatusCode int `json:"status_code"`
	// SystemError is the system error of the response.
	SystemError string `json:"system_error"`
}

RegoResponse is the response inside rego.

func NewRegoResponse

func NewRegoResponse(statusCode int, pr *ProviderResponse) *RegoResponse

NewRegoResponse creates a new rego response from the given provider response.

type Request

type Request struct {
	// Keys is the list of keys to send to the external data provider.
	Keys []string `json:"keys,omitempty"`
}

Request is the struct that contains the keys to query.

type Response

type Response struct {
	// Idempotent indicates that the responses from the provider are idempotent.
	// Applies to mutation only and must be true for mutation.
	Idempotent bool `json:"idempotent,omitempty"`
	// Items contains the key, value and error from the provider.
	Items []Item `json:"items,omitempty"`
	// SystemError is the system error of the response.
	SystemError string `json:"systemError,omitempty"`
}

Response is the struct that holds the response from a provider.

type SendRequestToProvider

type SendRequestToProvider func(ctx context.Context, provider *unversioned.Provider, keys []string, clientCert *tls.Certificate) (*ProviderResponse, int, error)

SendRequestToProvider is a function that sends a request to the external data provider.

Jump to

Keyboard shortcuts

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