paramsbuilder

package
v0.0.0-...-42e523d Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package paramsbuilder provides common parameters used to initialize connectors. Implementor would pick every relevant parameter and use them to compose one unified parameters list. Then methods of format "With<some-property-name>" should be configured to connector needs and exposed to end user via delegation. Most would do delegation only.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingMetadata             = errors.New("missing authentication metadata")
	ErrIncorrectMetadataParamUsage = errors.New("metadata parameter must have required fields")
)
View Source
var ErrMissingClient = errors.New("http client not set")
View Source
var ErrMissingWorkspace = errors.New("missing workspace name")

Functions

func Apply

func Apply[P ParamAssurance](params P,
	opts []func(params *P),
	defaultOpts ...func(params *P),
) (output *P, err error)

Apply will apply options to construct a ready to go set of parameters. This is a generalized constructor of parameters used to initialize any connector. To qualify as a parameter one must have data validation laid out.

It is possible to give default options which will be applied first. Any other options supplied by the user may override defaults, as they are applied last and therefore take higher precedence.

func NewCatalogVariables

func NewCatalogVariables[V substitutions.RegistryValue](
	registry substitutions.Registry[V],
) []catalogreplacer.CatalogVariable

NewCatalogVariables converts JSON into supported list of Catalog Variables. This enforces type checking.

Types

type AuthClient

type AuthClient struct {
	// Caller is an HTTP client that knows how to make authenticated requests.
	// It also knows how to handle authentication and API response errors.
	Caller *common.HTTPClient
}

AuthClient params sets up authenticated proxy HTTP client.

func (*AuthClient) ValidateParams

func (p *AuthClient) ValidateParams() error

func (*AuthClient) WithAuthenticatedClient

func (p *AuthClient) WithAuthenticatedClient(client common.AuthenticatedHTTPClient)

WithAuthenticatedClient sets up an HTTP client that uses your implementation of authentication.

type Client

type Client struct {
	AuthClient
}

Client params sets up authenticated proxy HTTP client. There are many types of authentication, where only one must be chosen. Ex: oauth2.

func (*Client) WithApiKeyHeaderClient

func (p *Client) WithApiKeyHeaderClient(
	ctx context.Context, client *http.Client,
	provider providers.Provider, apiKey string,
	opts ...common.HeaderAuthClientOption,
)

WithApiKeyHeaderClient option sets up client that utilises API Key authentication. Passed via Header.

func (*Client) WithApiKeyQueryParamClient

func (p *Client) WithApiKeyQueryParamClient(
	ctx context.Context, client *http.Client,
	provider providers.Provider, apiKey string,
	opts ...common.QueryParamAuthClientOption,
)

WithApiKeyQueryParamClient option sets up client that utilises API Key authentication. Passed via Query Param.

func (*Client) WithBasicClient

func (p *Client) WithBasicClient(
	ctx context.Context, client *http.Client,
	user, pass string,
	opts ...common.HeaderAuthClientOption,
)

WithBasicClient option that sets up client that utilises Basic (username, password) authentication.

func (*Client) WithOauthClient

func (p *Client) WithOauthClient(
	ctx context.Context, client *http.Client,
	config *oauth2.Config, token *oauth2.Token,
	opts ...common.OAuthOption,
)

WithOauthClient option that sets up client that utilises Oauth2 authentication.

type Metadata

type Metadata struct {
	// Map is a registry of metadata values that are needed for connector to function.
	Map map[string]string
	// contains filtered or unexported fields
}

Metadata params sets metadata describing authentication information.

func (*Metadata) ValidateParams

func (p *Metadata) ValidateParams() error

func (*Metadata) WithMetadata

func (p *Metadata) WithMetadata(metadata map[string]string, requiredKeys []string)

type Module

type Module struct {
	Selection common.Module
	// contains filtered or unexported fields
}

Module represents a sub-product of a provider. This is relevant where there are several APIs for different sub-products, and the APIs are versioned differently or have different ways of constructing URLs and requests for reading/writing.

func (*Module) ValidateParams

func (p *Module) ValidateParams() error

func (*Module) WithModule

func (p *Module) WithModule(moduleID common.ModuleID, supported common.Modules, fallbackID common.ModuleID)

WithModule allows API module selection. Connector implementation must provide list of modules that are currently supported. This defines a list of module a user could switch to. Any out of scope module will be ignored. If user supplied unsupported module, then it will use this fallback.

type ParamAssurance

type ParamAssurance interface {
	ValidateParams() error
}

ParamAssurance checks that param data is valid Every param instance must implement it.

type Workspace

type Workspace struct {
	Name string
}

Workspace params sets up varying workspace name.

func (*Workspace) GetSubstitutionPlan

func (p *Workspace) GetSubstitutionPlan() catalogreplacer.SubstitutionPlan

GetSubstitutionPlan of the workspace describes how to insert its value into string templates. This makes Workspace parameter a catalog variable.

func (*Workspace) ValidateParams

func (p *Workspace) ValidateParams() error

func (*Workspace) WithWorkspace

func (p *Workspace) WithWorkspace(workspaceRef string)

Jump to

Keyboard shortcuts

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