core

package module
v0.33.3 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2025 License: GPL-3.0 Imports: 25 Imported by: 83

README

MagaLu Core

This provides the core with generic elements to create a Software Development Kit (SDK) to be shared between code generator, TerraForm and command line (CLI).

Architecture

The solution works by ingesting the OpenAPI descriptions of the products to build an intermediate structure that will then be used to generate the CLI commands and TF components.

The intermediate structure is a tree made up of two types of nodes:

  • Grouper: can contain other groups and actions;
  • Executor: execute and retain information about HTTP requests.
graph TD;
    g1[Grouper] --> a1[Executor];
    g1[Grouper] --> g2[Grouper];
    g2[Grouper] --> a2[Executor];
    g2[Grouper] --> a3[Executor];

    g1:::gstyle
    g2:::gstyle
    a1:::astyle
    a2:::astyle
    a3:::astyle

    classDef gstyle stroke:#7BC1CF
    classDef astyle stroke:#D54552

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorResultHasNoValue = errors.New("result has no value")

Functions

func ConfirmPromptWithTemplate

func ConfirmPromptWithTemplate(msg string) func(parameters Parameters, configs Configs) string

ConfirmPromptWithTemplate parses and executes the template provided in the message. If the template fails to parse or execute, a default generic message is returned

func DefaultConfirmPrompt

func DefaultConfirmPrompt(parameters Parameters, configs Configs) string

func ExecutorAs

func ExecutorAs[T Executor](exec Executor) (T, bool)

func GetMgcTagBool

func GetMgcTagBool(t reflect.StructTag, name string) bool

func HMACSHA256

func HMACSHA256(key []byte, data []byte) []byte

HMACSHA256 computes a HMAC-SHA256 of data given the provided key.

func HMACSHA256String

func HMACSHA256String(key []byte, data string) []byte

func NewGrouperContext

func NewGrouperContext(parent context.Context, group func() Grouper) context.Context

func NewLinkConfirmableExecutor

func NewLinkConfirmableExecutor(linkExecutor LinkExecutor) *linkConfirmableExecutor

Wraps a linkExecutor that implements ConfirmableExecutor

linkExecutor.Unwrap() (target) must implement the ConfirmableExecutor interface, otherwise it will panic

func NewLinkExecutor

func NewLinkExecutor(
	target Executor,
	preparedParameters Parameters,
	preparedConfigs Configs,
	additionalParametersSchema *Schema,
	additionalConfigsSchema *Schema,
) *linkExecutor

Wraps the target executor, handling prepared values before calling it.

The returned Executor will expose additionalParametersSchema() as ParametersSchema() and additionalConfigsSchema as ConfigsSchema().

Then the Execute() will automatically copy the preparedParameters and preparedConfigs in the given parameters and configs (respectively), before calling target.Execute().

Other Executor methods will be passed thru target without further modifications.

func NewLinkPromptInputExecutor

func NewLinkPromptInputExecutor(linkExecutor LinkExecutor) *linkPromptInputExecutor

func NewLinkTerminatorExecutor

func NewLinkTerminatorExecutor(linkExecutor LinkExecutor) *linkTerminatorExecutor

Wraps a linkExecutor that implements TerminatorExecutor

linkExecutor.Unwrap() (target) must implement the TerminatorExecutor interface, otherwise it will panic

func NewRefPathResolverContext

func NewRefPathResolverContext(parent context.Context, refResolver RefPathResolver) context.Context

func NewResultWithOriginalSource

func NewResultWithOriginalSource(originalSource ResultSource, result Result) *resultWithOriginalSource

Wraps (embeds) a result and overrides the original source.

func NewSimpleLink(s SimpleLinkSpec) *simpleLink

func ResolveSchema

func ResolveSchema(refResolver RefPathResolver, ref string) (result *mgcSchema.Schema, err error)

func ResolveSchemaChildren

func ResolveSchemaChildren(r RefPathResolver, schema *mgcSchema.Schema) (result *mgcSchema.Schema, err error)

This changes schema *IN PLACE* so future resolutions will use the same pointers

This guarantees the Schema and internal elements are fully resolved.

func ResolveSchemaPath

func ResolveSchemaPath(refResolver RefPathResolver, path RefPath) (result *mgcSchema.Schema, err error)

func ResolveSchemaRef

func ResolveSchemaRef(refResolver RefPathResolver, schemaRef *mgcSchema.SchemaRef) (result *mgcSchema.Schema, err error)

This changes schemaRef *IN PLACE* so future resolutions will use the same pointers

This guarantees the SchemaRef, Schema and internal elements are fully resolved.

func ResultAs

func ResultAs[T Result](result Result) (T, bool)

func SHA256Hex

func SHA256Hex(reader io.Reader) (string, error)

func VisitAllExecutors

func VisitAllExecutors(child Descriptor, path []string, includeInternal bool, visitExecutor func(executor Executor, path []string) (bool, error)) (bool, error)

Types

type BoundRefPathResolver

type BoundRefPathResolver struct {
	Resolver *MultiRefPathResolver

	CurrentUrl string // if RefPath's URL is this placeholder given to MultiRefPathResolver, use this URL instead.
}

Wraps MultiRefPathResolver and automatically pass CurrentUrl

func NewBoundRefResolver

func NewBoundRefResolver(currentUrl string, resolver *MultiRefPathResolver) *BoundRefPathResolver

func (*BoundRefPathResolver) Resolve

func (r *BoundRefPathResolver) Resolve(ref string) (result any, err error)

func (*BoundRefPathResolver) ResolvePath

func (r *BoundRefPathResolver) ResolvePath(path RefPath) (result any, err error)

type ChainedError

type ChainedError = utils.ChainedError

type Configs

type Configs = Parameters

type ConfirmableExecutor

type ConfirmableExecutor interface {
	Executor
	ConfirmPrompt(parameters Parameters, configs Configs) (message string)
}

func NewConfirmableExecutor

func NewConfirmableExecutor(
	exec Executor,
	confirmPrompt func(parameters Parameters, configs Configs) (message string),
) ConfirmableExecutor

type Descriptor

type Descriptor interface {
	Name() string
	Version() string
	Description() string
	Summary() string
	IsInternal() bool
	Scopes() Scopes
	DescriptorSpec() DescriptorSpec
	GroupID() string
}

General interface that describes both Executor and Grouper

type DescriptorSpec

type DescriptorSpec struct {
	Name         string `json:"name"`
	Version      string `json:"version"`
	Description  string `json:"description"`
	Summary      string `json:"summary"`
	IsInternal   *bool  `json:"isInternal,omitempty"`
	Scopes       Scopes `json:"scopes"`
	Observations string `json:"observation,omitempty"`
	GroupID      string `json:"groupId,omitempty"`
}

func (*DescriptorSpec) Validate

func (d *DescriptorSpec) Validate() error

type DescriptorVisitor

type DescriptorVisitor func(child Descriptor) (run bool, err error)

type DocumentRefPathResolver

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

Resolve within a single document, walks from root group to leaf Executors and their sub-fields

Most users will want BoundRefPathResolver instead.

func NewDocumentRefPathResolver

func NewDocumentRefPathResolver(getRoot utils.LoadWithError[any]) *DocumentRefPathResolver

NOTE: getRoot() will be called multiple times, make sure it caches its own results, ex utils.NewLazyLoaderWithError()

func (*DocumentRefPathResolver) Resolve

func (r *DocumentRefPathResolver) Resolve(ref string) (result any, err error)

func (*DocumentRefPathResolver) ResolvePath

func (r *DocumentRefPathResolver) ResolvePath(path RefPath) (result any, err error)

type Example

type Example = Value

Type comes from the Schema

type Executor

type Executor interface {
	Descriptor
	ParametersSchema() *Schema
	ConfigsSchema() *Schema
	// The general schema this executor can produce. It may be oneOf/anyOf with multiple schemas.
	// The Result.Schema() may be a subset of the schema, if multiple were available.
	ResultSchema() *Schema
	PositionalArgs() []string
	HiddenFlags() []string
	// Linkers wrap executors that can operate on the result of this executor.
	//
	// For other executors that may be associated or operate together with this one, see Related().
	//
	// NOTE: it's possible to add new links using Links().AddLink(), but it's not possible to delete
	// nor override any existing links
	Links() Links
	// Executors that may be associated or operate together with this one.
	//
	// For executors that can operate on the returned value, see Links().
	//
	// NOTE: This map should not be altered externally.
	Related() map[string]Executor
	// The maps for the parameters and configs should NOT be modified inside the implementation of 'Execute'
	Execute(context context.Context, parameters Parameters, configs Configs) (result Result, err error)
	// A zero value instantiation of the concrete Result type used by each Executor. Useful for Encoding/Decoding the Result
	EmptyResult() Result
}

func NewExecuteFormat

func NewExecuteFormat(
	executor Executor,
	getFormatter func(exec Executor, result Result) string,
) Executor

Wraps (embeds) an executor and add specific result formatting.

func NewExecuteResultOutputOptions

func NewExecuteResultOutputOptions(
	executor Executor,
	getOutputOptions func(exec Executor, result Result) string,
) Executor

Wraps (embeds) an executor and add specific result default output options getter.

func NewExecuteResultWrapper

func NewExecuteResultWrapper(
	executor Executor,
	wrapResult func(wrapperExecutor ExecutorWrapper, originalResult Result) (wrappedResult Result, err error),
) Executor

Wraps (embeds) an executor and wrap its result. This may be used to add extra interfaces to a result, such as formatting or output options

func NewHumanIdentifiableFieldsExecutor

func NewHumanIdentifiableFieldsExecutor(exec Executor, humanIdentifierFields []string) Executor

func NoOpExecutor

func NoOpExecutor() Executor

func ResolveExecutor

func ResolveExecutor(refResolver RefPathResolver, ref string) (exec Executor, err error)

func ResolveExecutorPath

func ResolveExecutorPath(refResolver RefPathResolver, path RefPath) (exec Executor, err error)

type ExecutorSpec

type ExecutorSpec struct {
	DescriptorSpec
	ParametersSchema *Schema
	ConfigsSchema    *Schema
	ResultSchema     *Schema
	Links            LinksSpecFn
	Related          RelatedSpecFn
	PositionalArgs   []string
	HiddenFlags      []string
	Execute          ExecutorSpecFn
}

func ReflectExecutorSpec

func ReflectExecutorSpec[ParamsT any, ConfigsT any, ResultT any](
	baseSpec ExecutorSpec,
	typedExecute func(context context.Context, params ParamsT, configs ConfigsT) (result ResultT, err error),
) (spec ExecutorSpec, err error)

func ReflectExecutorSpecSchemas

func ReflectExecutorSpecSchemas[ParamsT any, ConfigsT any, ResultT any](baseSpec ExecutorSpec) (spec ExecutorSpec, err error)

Given a base spec and types to be reflected, populate with the schemas

func (*ExecutorSpec) Validate

func (s *ExecutorSpec) Validate() (err error)

type ExecutorSpecFn

type ExecutorSpecFn func(executor Executor, context context.Context, parameters Parameters, configs Configs) (result Result, err error)

func ReflectExecutorSpecFn

func ReflectExecutorSpecFn[ParamsT any, ConfigsT any, ResultT any](
	typedExecute func(context context.Context, params ParamsT, configs ConfigsT) (result ResultT, err error),
) ExecutorSpecFn

type ExecutorWrapper

type ExecutorWrapper interface {
	Executor
	Unwrap() Executor
}

NOTE: whenever you wrap an executor remember to also wrap the result with ExecutorWrapResult() so the outmost executor is given as source

type FailedTerminationError

type FailedTerminationError struct {
	Result  Result
	Message string
}

func (FailedTerminationError) Error

func (e FailedTerminationError) Error() string

type Grouper

type Grouper interface {
	Descriptor
	VisitChildren(visitor DescriptorVisitor) (finished bool, err error)
	GetChildByName(name string) (child Descriptor, err error)
}

func GrouperFromContext

func GrouperFromContext(ctx context.Context) Grouper

func NewStaticGroup

func NewStaticGroup(spec DescriptorSpec, createChildren func() []Descriptor) Grouper

type GrouperLazyChildren

type GrouperLazyChildren[T Descriptor] struct {
	// contains filtered or unexported fields
}

Implements VisitChildren() and GetChildByName() by calling createChildren() only once, when/if needed, and storing the results.

Children will be automatically sorted by their names, so visitor are always in a predictable and stable order.

func NewGrouperLazyChildren

func NewGrouperLazyChildren[T Descriptor](createChildren func() ([]T, error)) *GrouperLazyChildren[T]

func (*GrouperLazyChildren[T]) GetChildByName

func (g *GrouperLazyChildren[T]) GetChildByName(name string) (child Descriptor, err error)

func (*GrouperLazyChildren[T]) VisitChildren

func (g *GrouperLazyChildren[T]) VisitChildren(visitor DescriptorVisitor) (finished bool, err error)

type HumanIdentifiableFieldsExecutor

type HumanIdentifiableFieldsExecutor interface {
	Executor
	HumanIdentifiableFields() []string
}

type LinkExecutor

type LinkExecutor interface {
	Executor
	ExecutorWrapper
	// contains filtered or unexported methods
}

type Linker

type Linker interface {
	Name() string
	Description() string
	IsInternal() bool
	// Describes the additional parameters required by the created executor.
	//
	// This will match CreateExecutor().ParametersSchema()
	AdditionalParametersSchema() *Schema
	// Describes the additional configuration required by the created executor.
	//
	// This will match CreateExecutor().ConfigsSchema()
	AdditionalConfigsSchema() *Schema
	ResultSchema() *Schema
	// Create an executor based on a result.
	//
	// The returned executor will have ParametersSchema() matching AdditionalParametersSchema()
	// and ConfigsSchema() matching AdditionalConfigsSchema()
	CreateExecutor(originalResult Result) (exec Executor, err error)
	Links() Links

	IsTargetTerminatorExecutor() bool
}
type Links map[string]Linker

type LinksSpecFn

type LinksSpecFn func(e Executor) Links

type MergeGroup

type MergeGroup struct {
	SimpleDescriptor

	*GrouperLazyChildren[Descriptor]
	// contains filtered or unexported fields
}

func NewMergeGroup

func NewMergeGroup(desc DescriptorSpec, createToMerge func() []Grouper) (o *MergeGroup)

type MgcTag

type MgcTag [2]string

func GetMgcTag

func GetMgcTag(t reflect.StructTag, name string) (MgcTag, bool)

func GetMgcTags

func GetMgcTags(t reflect.StructTag) []MgcTag

Standard way to get the tags, splitting by comma

func (MgcTag) Name

func (t MgcTag) Name() string

func (MgcTag) Value

func (t MgcTag) Value() (string, bool)

type MissingFieldError

type MissingFieldError string

func (MissingFieldError) Error

func (e MissingFieldError) Error() string

type MultiRefPathResolver

type MultiRefPathResolver struct {
	Resolvers map[string]RefPathResolver // maps url => resolver

	CurrentUrlPlaceholder string // if RefPath's URL is this placeholder, use the given currentUrl
	EmptyDocumentUrl      string // if RefPath's URL is empty, then use this URL.
}

Discovers the document from the pointerPath and call the specific document resolver.

if RefPath's URL is CurrentUrlPlaceholder, then use the given currentUrl. If the placeholder if empty, currentUrl is also used.

if CurrentUrlPlaceholder is non-empty and RefPath's URL is empty, then use EmptyDocumentUrl.

func NewMultiRefPathResolver

func NewMultiRefPathResolver() *MultiRefPathResolver

func (*MultiRefPathResolver) Add

func (r *MultiRefPathResolver) Add(url string, docResolver RefPathResolver) error

Associates the given URL to a document resolver

func (*MultiRefPathResolver) Resolve

func (r *MultiRefPathResolver) Resolve(ref string, currentUrl string) (result any, err error)

func (*MultiRefPathResolver) ResolvePath

func (r *MultiRefPathResolver) ResolvePath(path RefPath, currentUrl string) (result any, err error)

type Parameters

type Parameters = map[string]Value

TODO: Evaluate if the typealias/type assign is needed at all. If a type assign is needed for some reason, the kin-openapi lib will need to be patched to accept type assigns of the correct structure on VisitJSON (likely through reflection). As it is now, validation fails with type assigns

type PromptInput

type PromptInput func(parameters Parameters, configs Configs) (message string, validate func(input string) error)

func NewPromptInput

func NewPromptInput(msgTemplate string, confirmationTemplate string) PromptInput

The msgTemplate represents a template used to generate the confirmation message for the user The confirmationValueTemplate define what the user need to type in order to confirm the operation

type PromptInputExecutor

type PromptInputExecutor interface {
	Executor
	PromptInput(parameters Parameters, configs Configs) (message string, validate func(input string) error)
}

func NewPromptInputExecutor

func NewPromptInputExecutor(
	exec Executor,
	promptInput PromptInput,
) PromptInputExecutor

type RefPath

type RefPath string

Similar to JSON Pointers - RFC6901

The difference is that it allow an URL to be specified before the JSON Pointer, so both are valid:

func (RefPath) Add

func (path RefPath) Add(parts ...string) RefPath

func (RefPath) Split

func (path RefPath) Split() (parentPath RefPath, field string)

func (RefPath) SplitUrl

func (path RefPath) SplitUrl() (url string, p RefPath)

func (*RefPath) UnmarshalJSON

func (p *RefPath) UnmarshalJSON(data []byte) error

func (RefPath) Validate

func (path RefPath) Validate() (err error)

type RefPathResolveError

type RefPathResolveError struct {
	Path RefPath
	Err  error
}

func (*RefPathResolveError) Error

func (e *RefPathResolveError) Error() string

func (*RefPathResolveError) Unwrap

func (e *RefPathResolveError) Unwrap() error

type RefPathResolver

type RefPathResolver interface {
	// validate the given string, convert it to RefPath and resolve it
	Resolve(path string) (result any, err error)
	ResolvePath(path RefPath) (result any, err error)
}

func RefPathResolverFromContext

func RefPathResolverFromContext(ctx context.Context) RefPathResolver

type RelatedSpecFn

type RelatedSpecFn func() map[string]Executor

type Result

type Result interface {
	// What was used to produce this result
	Source() ResultSource

	Encode() ([]byte, error)
	Decode([]byte) error
}

func ExecutorWrapResult

func ExecutorWrapResult(executorWrapper ExecutorWrapper, result Result, err error) (Result, error)

The new Result with have Source().Executor set back to executorWrapper

func ExecutorWrapResultSource

func ExecutorWrapResultSource(source ResultSource, result Result, err error) (Result, error)

The new Result with have Source() set back to source

func NewResultWithOriginalExecutor

func NewResultWithOriginalExecutor(originalExecutor Executor, result Result) Result

type ResultSource

type ResultSource struct {
	// Will be nil if Result was decoded
	Executor Executor `json:"-"`
	// Will be nil if Result was decoded
	Context    context.Context `json:"-"`
	Parameters Parameters
	Configs    Configs
}

type ResultWithDefaultFormatter

type ResultWithDefaultFormatter interface {
	ResultWithValue
	DefaultFormatter() string
}

Implement this interface in Result that want to provide customized formatting of output. It's used by the command line interface (CLI) and possible other tools. This is only called if no other explicit formatting is desired

func NewResultWithDefaultFormatter

func NewResultWithDefaultFormatter(
	result ResultWithValue,
	formatter string,
) ResultWithDefaultFormatter

Wraps (embeds) a result and add specific result formatting.

type ResultWithDefaultOutputOptions

type ResultWithDefaultOutputOptions interface {
	ResultWithValue
	// The return should be in the same format as CLI -o "VALUE"
	// example: "yaml" or "table=COL:$.path.to[*].element,OTHERCOL:$.path.to[*].other"
	DefaultOutputOptions() string
}

Implement this interface in Results that want to provide default output options. It's used by the command line interface (CLI) and possible other tools. This is only called if no other explicit options are desired

func NewResultWithDefaultOutputOptions

func NewResultWithDefaultOutputOptions(
	result ResultWithValue,
	outputOptions string,
) ResultWithDefaultOutputOptions

Wraps (embeds) a result and add specific result default output options getter.

type ResultWithMultipart

type ResultWithMultipart interface {
	Result
	Multipart() *multipart.Part
}

type ResultWithReader

type ResultWithReader interface {
	Result
	Reader() io.Reader
}

type ResultWithValue

type ResultWithValue interface {
	Result
	Schema() *Schema
	// Check value against schema, reports any error
	ValidateSchema() error

	Value() Value
}

type ResultWrapper

type ResultWrapper interface {
	Result
	Unwrap() Result
}

type RetryUntil

type RetryUntil struct {
	MaxRetries int
	Interval   time.Duration
	Check      RetryUntilCheck
}

func (*RetryUntil) Run

func (r *RetryUntil) Run(ctx context.Context, cb RetryUntilCb) (result Result, err error)

type RetryUntilCb

type RetryUntilCb func() (result Result, err error)

type RetryUntilCheck

type RetryUntilCheck func(ctx context.Context, value Value) (finished bool, err error)

func NewRetryUntilCheckFromJsonPath

func NewRetryUntilCheckFromJsonPath(expression string) (check RetryUntilCheck, err error)

func NewRetryUntilCheckFromTemplate

func NewRetryUntilCheckFromTemplate(expression string) (check RetryUntilCheck, err error)

type RetryUntilConfig

type RetryUntilConfig struct {
	MaxRetries    int           `json:"maxRetries,omitempty"`
	Interval      time.Duration `json:"interval,omitempty"`
	JSONPathQuery string        `json:"jsonPathQuery,omitempty"`
	TemplateQuery string        `json:"templateQuery,omitempty"`
}

func (*RetryUntilConfig) Build

func (c *RetryUntilConfig) Build() (r *RetryUntil, err error)

func (*RetryUntilConfig) UnmarshalJSON

func (c *RetryUntilConfig) UnmarshalJSON(data []byte) (err error)

type Schema

type Schema = schema.Schema

type Scope

type Scope string

type Scopes

type Scopes []Scope

func (*Scopes) Add

func (s *Scopes) Add(scopes ...Scope)

func (Scopes) AsScopesString

func (s Scopes) AsScopesString() ScopesString

func (*Scopes) Remove

func (s *Scopes) Remove(toBeRemoved ...Scope)

type ScopesString

type ScopesString string

func (ScopesString) AsScopes

func (s ScopesString) AsScopes() Scopes

type SimpleDescriptor

type SimpleDescriptor struct {
	Spec DescriptorSpec
}

func (*SimpleDescriptor) Description

func (d *SimpleDescriptor) Description() string

func (*SimpleDescriptor) DescriptorSpec

func (d *SimpleDescriptor) DescriptorSpec() DescriptorSpec

func (*SimpleDescriptor) GroupID

func (d *SimpleDescriptor) GroupID() string

func (*SimpleDescriptor) IsInternal

func (d *SimpleDescriptor) IsInternal() bool

func (*SimpleDescriptor) Name

func (d *SimpleDescriptor) Name() string

func (*SimpleDescriptor) Scopes

func (d *SimpleDescriptor) Scopes() Scopes

func (*SimpleDescriptor) Summary

func (d *SimpleDescriptor) Summary() string

func (*SimpleDescriptor) Version

func (d *SimpleDescriptor) Version() string

type SimpleExecutor

type SimpleExecutor struct {
	SimpleDescriptor
	// contains filtered or unexported fields
}

func NewReflectedSimpleExecutor

func NewReflectedSimpleExecutor[ParamsT any, ConfigsT any, ResultT any](
	baseSpec ExecutorSpec,
	execute func(context context.Context, params ParamsT, configs ConfigsT) (result ResultT, err error),
) *SimpleExecutor

Go Parameter and Config structs Note: we use both 'jsonschema' and 'mapstructure' for this helper. Be careful when using struct tags in your Params and Configs structs, as the tags from those libraries can't be out of sync when it comes to field names/json names See: - https://pkg.go.dev/github.com/invopop/jsonschema - https://pkg.go.dev/github.com/mitchellh/mapstructure

func NewReflectedSimpleExecutorSchemas

func NewReflectedSimpleExecutorSchemas[ParamsT any, ConfigsT any, ResultT any](
	baseSpec ExecutorSpec,
) *SimpleExecutor

Version that generates the schema, but uses baseSpec.Execute as is

func NewSimpleExecutor

func NewSimpleExecutor(spec ExecutorSpec) *SimpleExecutor

func NewStaticExecute

func NewStaticExecute[ParamsT any, ConfigsT any, ResultT any](
	spec DescriptorSpec,
	execute func(context context.Context, params ParamsT, configs ConfigsT) (result ResultT, err error),
) *SimpleExecutor

Go Parameter and Config structs Note: we use both 'jsonschema' and 'mapstructure' for this helper. Be careful when using struct tags in your Params and Configs structs, as the tags from those libraries can't be out of sync when it comes to field names/json names See: - https://pkg.go.dev/github.com/invopop/jsonschema - https://pkg.go.dev/github.com/mitchellh/mapstructure

func NewStaticExecuteSimple

func NewStaticExecuteSimple[ResultT any](
	spec DescriptorSpec,
	execute func(context context.Context) (result ResultT, err error),
) *SimpleExecutor

No parameters or configs

func (*SimpleExecutor) ConfigsSchema

func (e *SimpleExecutor) ConfigsSchema() *Schema

func (*SimpleExecutor) EmptyResult

func (*SimpleExecutor) EmptyResult() Result

func (*SimpleExecutor) Execute

func (e *SimpleExecutor) Execute(context context.Context, parameters Parameters, configs Configs) (result Result, err error)

func (*SimpleExecutor) HiddenFlags

func (e *SimpleExecutor) HiddenFlags() []string
func (e *SimpleExecutor) Links() Links

func (*SimpleExecutor) ParametersSchema

func (e *SimpleExecutor) ParametersSchema() *Schema

func (*SimpleExecutor) PositionalArgs

func (e *SimpleExecutor) PositionalArgs() []string

func (*SimpleExecutor) Related

func (e *SimpleExecutor) Related() map[string]Executor

func (*SimpleExecutor) ResultSchema

func (e *SimpleExecutor) ResultSchema() *Schema

type SimpleGrouper

type SimpleGrouper[T Descriptor] struct {
	SimpleDescriptor
	*GrouperLazyChildren[T]
}

func NewSimpleGrouper

func NewSimpleGrouper[T Descriptor](spec DescriptorSpec, createChildren func() ([]T, error)) *SimpleGrouper[T]

type SimpleLinkSpec

type SimpleLinkSpec struct {
	Owner  Executor
	Target Executor
	// Maps parameters from Owner into Target
	FromOwner map[string]string
	// Maps parameters from Owner result into Target
	FromResult map[string]string
}

type SimpleResult

type SimpleResult struct {
	SourceData   ResultSource
	ResultSchema *Schema
	ResultValue  Value
}

func NewSimpleResult

func NewSimpleResult(source ResultSource, schema *Schema, value Value) *SimpleResult

func (*SimpleResult) Decode

func (s *SimpleResult) Decode(data []byte) error

func (SimpleResult) Encode

func (s SimpleResult) Encode() ([]byte, error)

func (SimpleResult) Schema

func (s SimpleResult) Schema() *Schema

func (SimpleResult) Source

func (s SimpleResult) Source() ResultSource

func (SimpleResult) ValidateSchema

func (s SimpleResult) ValidateSchema() error

func (SimpleResult) Value

func (s SimpleResult) Value() Value

type TerminatorExecutor

type TerminatorExecutor interface {
	Executor
	ExecuteUntilTermination(context context.Context, parameters Parameters, configs Configs) (result Result, err error)
}

func NewTerminatorExecutorWithCheck

func NewTerminatorExecutorWithCheck(
	executor Executor,
	maxRetries int,
	interval time.Duration,
	checkTerminate func(ctx context.Context, exec Executor, result ResultWithValue) (terminated bool, err error),
) TerminatorExecutor

Execute the operation and check the results until it's considered terminated. The executor will wait `interval` between retries, executing up to `maxRetries`

type Time

type Time time.Time

NOTE: This is so 'jsonschema' doesn't generate a schema with type string and format 'date-time'. We want the raw object schema for later validation

type UsageError

type UsageError struct {
	Err error
}

func (UsageError) Error

func (e UsageError) Error() string

func (UsageError) Unwrap

func (e UsageError) Unwrap() error

type UserDeniedConfirmationError

type UserDeniedConfirmationError struct {
	Prompt string
}

func (UserDeniedConfirmationError) Error

type Value

type Value = any

Type comes from the Schema

type VersionChecker

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

func NewVersionChecker

func NewVersionChecker(
	getHttp getCall, getConfig, setConfig configValue,
) *VersionChecker

NewVersionChecker creates a new VersionChecker getHttp - the getCall client to use for requests getConfig - a function to get a config value setConfig - a function to set a config value

func (*VersionChecker) CheckVersion

func (v *VersionChecker) CheckVersion(currentVersion string, args ...string)

CheckVersion checks if the current version is outdated and prints a message if it is. It also sets the last check time to the current time. currentVersion - the current version of the cli args - optional command line arguments

type WaitTerminationConfig

type WaitTerminationConfig struct {
	MaxRetries         int           `json:"maxRetries,omitempty"`
	Interval           time.Duration `json:"interval,omitempty"`
	JSONPathQuery      string        `json:"jsonPathQuery,omitempty"`
	TemplateQuery      string        `json:"templateQuery,omitempty"`
	ErrorJSONPathQuery string        `json:"errorJsonPathQuery,omitempty"`
	ErrorTemplateQuery string        `json:"errorTemplateQuery,omitempty"`
}

func (*WaitTerminationConfig) Build

func (c *WaitTerminationConfig) Build(exec Executor, getDocument func(result ResultWithValue) any) (tExec TerminatorExecutor, err error)

func (*WaitTerminationConfig) UnmarshalJSON

func (c *WaitTerminationConfig) UnmarshalJSON(data []byte) (err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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