rest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool added in v0.1.0

func Bool(v bool) *bool

Bool returns a pointer value for the bool value passed in.

func Byte added in v0.1.0

func Byte(v byte) *byte

Byte returns a pointer value for the byte value passed in.

func Int added in v0.1.0

func Int(v int) *int

Int returns a pointer value for the int value passed in.

func NewAuth added in v0.1.0

func NewAuth(am *AuthMap) *actionAuthMap

func String added in v0.1.0

func String(v string) *string

String returns a pointer value for the string value passed in.

Types

type Action

type Action struct {
	Strategy             string             `yaml:"strategy"`
	Order                *int               `yaml:"order,omitempty"`
	Endpoint             string             `yaml:"endpoint"`
	GetEndpointSuffix    *string            `yaml:"getEndpointSuffix,omitempty"`
	PostEndpointSuffix   *string            `yaml:"postEndpointSuffix,omitempty"`
	PatchEndpointSuffix  *string            `yaml:"patchEndpointSuffix,omitempty"`
	PutEndpointSuffix    *string            `yaml:"putEndpointSuffix,omitempty"`
	DeleteEndpointSuffix *string            `yaml:"deleteEndpointSuffix,omitempty"`
	FindByJsonPathExpr   string             `yaml:"findByJsonPathExpr,omitempty"`
	PayloadTemplate      string             `yaml:"payloadTemplate"`
	PatchPayloadTemplate string             `yaml:"patchPayloadTemplate,omitempty"`
	Variables            map[string]any     `yaml:"variables"`
	RuntimeVars          *map[string]string `yaml:"runtimeVars,omitempty"`
	AuthMapRef           string             `yaml:"authMapRef"`
	HttpHeaders          *map[string]string `yaml:"httpHeaders,omitempty"`
	// contains filtered or unexported fields
}

Action defines the single action to make agains an endpoint and selecting a strategy Endpoint is the base url to make the requests against GetEndpointSuffix can be used to specify a direct ID or query params PostEndpointSuffix

func (*Action) WithHeader added in v0.2.0

func (a *Action) WithHeader() *Action

WithHeader allows the overwrite of default Accept and Content-Type headers both default to `application/json` and adding additional header params on per Action basis. NOTE: each rest call inside the action will inherit the same header

func (*Action) WithName

func (a *Action) WithName(name string) *Action

type AuthConfig added in v0.1.0

type AuthConfig struct {
	AuthStrategy AuthType     `yaml:"type"`
	Username     string       `yaml:"username"`
	Password     string       `yaml:"password"`
	OAuth        *ConfigOAuth `yaml:"oauth,omitempty"`
	CustomToken  *CustomToken `yaml:"custom,omitempty"`
}

Auth holds the auth strategy for all Seeders

type AuthMap added in v0.2.0

type AuthMap map[string]AuthConfig

type AuthType added in v0.1.0

type AuthType string

AuthType specifies the type of authentication to perform currently only a single authType per instance is allowed

const (
	Basic         AuthType = "BasicAuth"
	OAuth         AuthType = "OAuthClientCredentials"
	CustomToToken AuthType = "CustomToToken"
)

type Client

type Client interface {
	Do(req *http.Request) (*http.Response, error)
}

type ConfigOAuth added in v0.1.0

type ConfigOAuth struct {
	ServerUrl               string              `yaml:"serverUrl"`
	Scopes                  []string            `yaml:"scopes"`
	EndpointParams          map[string][]string `yaml:"endpointParams"`
	OAuthSendParamsInHeader bool                `yaml:"oAuthSendParamsInHeader"`
}

type CustomToken added in v0.2.0

type CustomToken struct {
	// Url to use to POST the customRequest
	AuthUrl string `yaml:"authUrl"`
	// holds the K/V credential pair. e.g.
	// email: some@one.com
	// password: pass123
	// will post this body or send in header params that payload
	CustomAuthMap map[string]any `yaml:"credential"`
	// whether to send the values in the header as params
	// defaults to false and map is posted in the body
	SendInHeader bool `yaml:"inHeader"`
	// JSONPAth expression to use to get the token from response
	// e.g. "$.token"
	// empty will take the entire response as the token - raw response must be string
	ResponseKey string `yaml:"responseKey"`
	// if ommited `Authorization` will be used
	// Could be X-API-Token etc..
	HeaderKey string `yaml:"headerKey"`
	// Token prefix - if omitted Bearer will be used
	// e.g. Admin ==> `Authorization: "Admin [TOKEN]"`
	TokenPrefix string `yaml:"tokenPrefix"`
}

customToken stores the required data to call and process custom auth Endpoints returning a token. the token will need to be extracted from the response it will then need adding to subsequent requests in the header under specified key and in specified format

type CustomTokenResponse added in v0.2.0

type CustomTokenResponse struct {
	HeaderKey   string
	TokenPrefix string
	TokenValue  string
}

type Diagnostic added in v0.1.0

type Diagnostic struct {
	Status          int
	Name            string
	Message         string
	HostPathMethod  string
	ProceedFallback bool
	IsFatal         bool
}

func (*Diagnostic) Error added in v0.1.0

func (d *Diagnostic) Error() string

func (*Diagnostic) WithIsFatal added in v0.1.0

func (d *Diagnostic) WithIsFatal(v bool) *Diagnostic

func (*Diagnostic) WithMessage added in v0.1.0

func (d *Diagnostic) WithMessage(m string) *Diagnostic

func (*Diagnostic) WithProceedFallback added in v0.1.0

func (d *Diagnostic) WithProceedFallback(v bool) *Diagnostic

func (*Diagnostic) WithStatus added in v0.1.0

func (d *Diagnostic) WithStatus(s int) *Diagnostic

type SeederImpl

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

func NewSeederImpl added in v0.2.0

func NewSeederImpl() *SeederImpl

func (*SeederImpl) FindDeletePost added in v0.1.0

func (r *SeederImpl) FindDeletePost(ctx context.Context, action *Action) error

FindDeletePost

func (*SeederImpl) FindPost

func (r *SeederImpl) FindPost(ctx context.Context, action *Action) error

FindPost strategy calls a GET endpoint and if item ***FOUND it does NOT do a POST*** this strategy should be used sparingly and only in cases where the service REST implementation does not support an update of existing item.

func (*SeederImpl) FindPutPatch added in v0.2.0

func (r *SeederImpl) FindPutPatch(ctx context.Context, action *Action) error

FindPutPatch is same as FindPutPost strategy but uses PATCH

func (*SeederImpl) FindPutPost

func (r *SeederImpl) FindPutPost(ctx context.Context, action *Action) error

FindPutPost strategy gets an item either by specifying a known ID in the endpoint suffix or by pathExpression. Get can look for a response in an array or in a single response object. once a single item that matches is found and the relevant ID is extracted it will do a PUT else it will do a POST as the item can be created

func (*SeederImpl) GetPost

func (r *SeederImpl) GetPost(ctx context.Context, action *Action) error

GetPost strategy calls a GET endpoint and if item ***FOUND it does NOT do a POST*** this strategy should be used sparingly and only in cases where the service REST implementation does not support an update of existing item.

func (*SeederImpl) GetPutPost

func (r *SeederImpl) GetPutPost(ctx context.Context, action *Action) error

GetPutPost strategy gets an item by specifying a known ID in the endpoint suffix If a non error or non empty response is found it will do a PUT else it will do a POST as the item can be created

func (*SeederImpl) Put

func (r *SeederImpl) Put(ctx context.Context, action *Action) error

Put strategy calls a PUT endpoint if standards compliant this should be an idempotent operation

func (*SeederImpl) PutPost

func (r *SeederImpl) PutPost(ctx context.Context, action *Action) error

Put strategy calls a PUT endpoint if standards compliant this should be an idempotent operation

func (*SeederImpl) WithAuth added in v0.1.0

func (r *SeederImpl) WithAuth(auth *AuthMap) *SeederImpl

func (*SeederImpl) WithClient

func (r *SeederImpl) WithClient(c Client) *SeederImpl

TODO: change this for an interface

func (*SeederImpl) WithLogger

func (r *SeederImpl) WithLogger(l log.Loggeriface) *SeederImpl

type Status added in v0.1.0

type Status int
const (
	StatusFatal Status = iota
	StatusRetryable
)

Jump to

Keyboard shortcuts

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