strategyrestseeder

package module
v0.0.0-pre Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: MIT Imports: 6 Imported by: 0

README

strategy-rest-seeder

WIP

Executes a series of instructions against an endpoint using a specified authentication on a given strategy.

Problem space

Often we are faced with external products/services either self-hosted or SaaS where they require some level of configuration this often happens at CI (deploy) time, or on continous basis

Strategy

Strategy is a setting against which to perform one or more rest calls to ensure an idempotent update.

GET/POST

FindPostStrategyFunc 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.

FIND/POST

FindPostStrategyFunc 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.

PUT/POST

PutPostStrategyFunc is useful when the resource is created a user specified Id the PUT endpoint DOES NOT support a creation of the resource. PUT should throw a 4XX for the POST fallback to take effect

GET/PUT/POST

GetPutPostStrategyFunc known ID and only know a name or other indicator the pathExpression must not evaluate to an empty string in order to for the PUT to be called else POST will be called as item was not present.

FIND/PUT/POST

FindPutPostStrategyFunc is useful when the resource Id is unknown i.e. handled by the system. providing a pathExpression will evaluate the response. the pathExpression must not evaluate to an empty string in order to for the PUT to be called else POST will be called as item was not present

FIND/DELETE
FIND/DELETE/POST
PUT

AuthMap

Is a map of authentication objects

Rest Action

endpoint: https://postman-echo.com
strategy: FIND/PUT/POST
getEndpointSuffix: /get?json=provided&valid=true
postEndpointSuffix: /post
putEndpointSuffix: /put
findByJsonPathExpr: "$.array[?(@.name=='fubar')].id"
authMapRef: ouath1
payloadTemplate: |
    {
    "value": "$foo"
    }
variables:
    foo: bar
runtimeVars:
    someId: "$.array[?(@.name=='fubar')].id"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindDeletePostStrategyFunc

func FindDeletePostStrategyFunc(ctx context.Context, action *rest.Action, rest *rest.SeederImpl) error

FindDeletePostStrategyFunc is useful for when you cannot update a resource but it can be safely destroyed an recreated

func FindPostStrategyFunc

func FindPostStrategyFunc(ctx context.Context, action *rest.Action, rest *rest.SeederImpl) error

FindPostStrategyFunc 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 FindPutPostStrategyFunc

func FindPutPostStrategyFunc(ctx context.Context, action *rest.Action, rest *rest.SeederImpl) error

FindPutPostStrategyFunc is useful when the resource Id is unknown i.e. handled by the system. providing a pathExpression will evaluate the response. the pathExpression must not evaluate to an empty string in order to for the PUT to be called else POST will be called as item was not present

func GetPostStrategyFunc

func GetPostStrategyFunc(ctx context.Context, action *rest.Action, rest *rest.SeederImpl) error

FindPostStrategyFunc 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 GetPutPostStrategyFunc

func GetPutPostStrategyFunc(ctx context.Context, action *rest.Action, rest *rest.SeederImpl) error

GetPutPostStrategyFunc known ID and only know a name or other indicator the pathExpression must not evaluate to an empty string in order to for the PUT to be called else POST will be called as item was not present

func PutPostStrategyFunc

func PutPostStrategyFunc(ctx context.Context, action *rest.Action, rest *rest.SeederImpl) error

PutPostStrategyFunc is useful when the resource is created a user specified Id the PUT endpoint DOES NOT support a creation of the resource. PUT should throw a 4XX for the POST fallback to take effect

func PutStrategyFunc

func PutStrategyFunc(ctx context.Context, action *rest.Action, rest *rest.SeederImpl) error

PutStrategyFunc calls a PUT endpoint fails if an error occurs useful when there is a known Id of a resource and PUT supports creation

Types

type Seeders added in v0.1.0

type Seeders map[string]rest.Action

type StrategyConfig

type StrategyConfig struct {
	AuthConfig rest.AuthMap `yaml:"auth"`
	Seeders    Seeders      `yaml:"seed"`
}

StrategyConfig defines top level

type StrategyFunc

type StrategyFunc func(ctx context.Context, action *rest.Action, rest *rest.SeederImpl) error

type StrategyRestSeeder

type StrategyRestSeeder struct {
	Strategy map[StrategyType]StrategyFunc
	// contains filtered or unexported fields
}

func New

func New() *StrategyRestSeeder

New initializes a default StrategySeeder with error log level and os.StdErr as log writer uses standard http.Client as rest client for rest SeederImplementation

func (*StrategyRestSeeder) Execute

func (s *StrategyRestSeeder) Execute(ctx context.Context) []error

Execute the built actions list TODO: create a custom error object

func (*StrategyRestSeeder) WithActions

func (s *StrategyRestSeeder) WithActions(actions map[string]rest.Action) *StrategyRestSeeder

WithActions builds the actions list empty actions will result in no restActions executing

func (*StrategyRestSeeder) WithAuth added in v0.1.0

WithAuth adds the AuthLogic to the entire seeder NOTE: might make more sense to have a per RestAction authTemplate (might make it very inefficient)

func (*StrategyRestSeeder) WithLogger

func (s *StrategyRestSeeder) WithLogger(w io.Writer, lvl log.LogLevel) *StrategyRestSeeder

WithLogger overwrites the default logger and passes it down to rest.SeederImpl

func (*StrategyRestSeeder) WithRestClient

func (s *StrategyRestSeeder) WithRestClient(rc rest.Client) *StrategyRestSeeder

WithRestClient overwrites the default RestClient

type StrategyType

type StrategyType string
const (
	GET_POST         StrategyType = "GET/POST"
	FIND_POST        StrategyType = "FIND/POST"
	PUT_POST         StrategyType = "PUT/POST"
	GET_PUT_POST     StrategyType = "GET/PUT/POST"
	FIND_PUT_POST    StrategyType = "FIND/PUT/POST"
	FIND_DELETE      StrategyType = "FIND/DELETE"
	FIND_DELETE_POST StrategyType = "FIND/DELETE/POST"
	PUT              StrategyType = "PUT"
)

Directories

Path Synopsis
cmd
internal
pkg

Jump to

Keyboard shortcuts

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