base

package
v0.19.1-beta Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: MIT Imports: 19 Imported by: 1

Documentation

Index

Constants

View Source
const OpenAPITemplate = `` /* 1538-byte string literal not displayed */
View Source
const SecretKeyword = "__INSTILL_SECRET"

SecretKeyword is a keyword to reference a secret in a component configuration. When a component detects this value in a configuration parameter, it will used the pre-configured value, injected at initialization.

Variables

View Source
var InstillAcceptFormatsMeta = jsonschema.MustCompileString("instillAcceptFormats.json", `{
	"properties" : {
		"instillAcceptFormats": {
			"type": "array",
			"items": {
				"type": "string"
			}
		}
	}
}`)
View Source
var InstillFormatMeta = jsonschema.MustCompileString("instillFormat.json", `{
	"properties" : {
		"instillFormat": {
			"type": "string"
		}
	}
}`)

Functions

func CompileInstillAcceptFormats

func CompileInstillAcceptFormats(sch *structpb.Struct) error

func CompileInstillFormat

func CompileInstillFormat(sch *structpb.Struct) error

func ConvertFromStructpb

func ConvertFromStructpb(from *structpb.Struct, to interface{}) error

ConvertFromStructpb converts from structpb.Struct to a struct

func ConvertToStructpb

func ConvertToStructpb(from interface{}) (*structpb.Struct, error)

ConvertToStructpb converts from a struct to structpb.Struct

func FormatErrors

func FormatErrors(inputPath string, e jsonschema.Detailed, errors *[]string)

func NewUnresolvedSecret

func NewUnresolvedSecret(key string) error

NewUnresolvedSecret returns an end-user error signaling that the component configuration references a global secret that wasn't injected into the component.

func ReadFromSecrets

func ReadFromSecrets(key string, secrets map[string]any) string

ReadFromSecrets reads a component secret from a secret map that comes from environment variable configuration.

Config parameters are defined with snake_case, but the environment variable configuration loader replaces underscores by dots, so we can't use the parameter key directly. TODO using camelCase in configuration fields would fix this issue.

func RenderJSON

func RenderJSON(tasksJSONBytes []byte, additionalJSONBytes map[string][]byte) ([]byte, error)

func TaskIDToTitle

func TaskIDToTitle(id string) string

TaskIDToTitle builds a Task title from its ID. This is used when the `title` key in the task definition isn't present.

func TrimBase64Mime

func TrimBase64Mime(b64 string) string

func Validate

func Validate(data []*structpb.Struct, jsonSchema string, target string) error

Validate the input and output format

Types

type Component

type Component struct {
	Logger *zap.Logger
	// contains filtered or unexported fields
}

Component implements the common component methods.

func (*Component) GetDefinition

func (c *Component) GetDefinition(sysVars map[string]any, compConfig *ComponentConfig) (*pb.ComponentDefinition, error)

func (*Component) GetID

func (c *Component) GetID() string

func (*Component) GetLogger

func (c *Component) GetLogger() *zap.Logger

func (*Component) GetTaskInputSchemas

func (c *Component) GetTaskInputSchemas() map[string]string

func (*Component) GetTaskOutputSchemas

func (c *Component) GetTaskOutputSchemas() map[string]string

func (*Component) GetUID

func (c *Component) GetUID() uuid.UUID

func (*Component) IsSecretField

func (c *Component) IsSecretField(target string) bool

IsSecretField checks if the target field is secret field

func (*Component) ListSecretFields

func (c *Component) ListSecretFields() ([]string, error)

ListSecretFields lists the secret fields by definition id

func (*Component) LoadDefinition

func (c *Component) LoadDefinition(definitionJSONBytes, setupJSONBytes, tasksJSONBytes []byte, additionalJSONBytes map[string][]byte) error

LoadDefinition loads the component definitions from json files

func (*Component) Test

func (c *Component) Test(sysVars map[string]any, setup *structpb.Struct) error

func (*Component) UsageHandlerCreator

func (c *Component) UsageHandlerCreator() UsageHandlerCreator

UsageHandlerCreator returns a function to initialize a UsageHandler.

type ComponentConfig

type ComponentConfig struct {
	Type       string                  `json:"type,omitempty"`
	Task       string                  `json:"task,omitempty"`
	Input      map[string]any          `json:"input,omitempty"`
	Condition  *string                 `json:"condition,omitempty"`
	Setup      map[string]any          `json:"setup,omitempty"`
	Metadata   map[string]any          `json:"metadata,omitempty"`
	Definition *pb.ComponentDefinition `json:"definition,omitempty"`
}

func (*ComponentConfig) GetCondition

func (c *ComponentConfig) GetCondition() *string

func (*ComponentConfig) IsComponent

func (c *ComponentConfig) IsComponent()

type ComponentExecution

type ComponentExecution struct {
	Component       IComponent
	SystemVariables map[string]any
	Setup           *structpb.Struct
	Task            string
}

ComponentExecution implements the common methods for component execution.

func (*ComponentExecution) GetLogger

func (e *ComponentExecution) GetLogger() *zap.Logger

func (*ComponentExecution) GetSetup

func (e *ComponentExecution) GetSetup() *structpb.Struct

func (*ComponentExecution) GetSystemVariables

func (e *ComponentExecution) GetSystemVariables() map[string]any

func (*ComponentExecution) GetTask

func (e *ComponentExecution) GetTask() string

func (*ComponentExecution) GetTaskInputSchema

func (e *ComponentExecution) GetTaskInputSchema() string

func (*ComponentExecution) GetTaskOutputSchema

func (e *ComponentExecution) GetTaskOutputSchema() string

func (*ComponentExecution) UsageHandlerCreator

func (e *ComponentExecution) UsageHandlerCreator() UsageHandlerCreator

UsageHandlerCreator returns a function to initialize a UsageHandler.

func (*ComponentExecution) UsesSecret

func (e *ComponentExecution) UsesSecret() bool

UsesSecret indicates wether the connector execution is configured with global secrets. Components should override this method when they have the ability to be executed with global secrets.

type ExecutionWrapper

type ExecutionWrapper struct {
	Execution IExecution
}

ExecutionWrapper performs validation and usage collection around the execution of a component.

func (*ExecutionWrapper) Execute

func (e *ExecutionWrapper) Execute(ctx context.Context, inputs []*structpb.Struct) ([]*structpb.Struct, error)

Execute wraps the execution method with validation and usage collection.

type IComponent

type IComponent interface {
	GetID() string
	GetUID() uuid.UUID
	GetLogger() *zap.Logger
	GetTaskInputSchemas() map[string]string
	GetTaskOutputSchemas() map[string]string

	LoadDefinition(definitionJSON, setupJSON, tasksJSON []byte, additionalJSONBytes map[string][]byte) error

	// Note: Some content in the definition JSON schema needs to be generated
	// by sysVars or component setting.
	GetDefinition(sysVars map[string]any, compConfig *ComponentConfig) (*pb.ComponentDefinition, error)

	CreateExecution(sysVars map[string]any, setup *structpb.Struct, task string) (*ExecutionWrapper, error)
	Test(sysVars map[string]any, config *structpb.Struct) error

	IsSecretField(target string) bool

	UsageHandlerCreator() UsageHandlerCreator
}

IComponent is the interface that wraps the basic component methods. All component need to implement this interface.

type IExecution

type IExecution interface {
	GetTask() string
	GetLogger() *zap.Logger
	GetTaskInputSchema() string
	GetTaskOutputSchema() string
	GetSystemVariables() map[string]any

	UsesSecret() bool
	UsageHandlerCreator() UsageHandlerCreator

	Execute(context.Context, []*structpb.Struct) ([]*structpb.Struct, error)
}

IExecution allows components to be executed.

type InstillAcceptFormatsCompiler

type InstillAcceptFormatsCompiler struct{}

func (InstillAcceptFormatsCompiler) Compile

func (InstillAcceptFormatsCompiler) Compile(ctx jsonschema.CompilerContext, m map[string]interface{}) (jsonschema.ExtSchema, error)

type InstillAcceptFormatsSchema

type InstillAcceptFormatsSchema []string

func (InstillAcceptFormatsSchema) Validate

func (s InstillAcceptFormatsSchema) Validate(ctx jsonschema.ValidationContext, v interface{}) error

type InstillFormatCompiler

type InstillFormatCompiler struct{}

func (InstillFormatCompiler) Compile

func (InstillFormatCompiler) Compile(ctx jsonschema.CompilerContext, m map[string]interface{}) (jsonschema.ExtSchema, error)

type InstillFormatSchema

type InstillFormatSchema string

func (InstillFormatSchema) Validate

func (s InstillFormatSchema) Validate(ctx jsonschema.ValidationContext, v interface{}) error

type UsageHandler

type UsageHandler interface {
	Check(ctx context.Context, inputs []*structpb.Struct) error
	Collect(ctx context.Context, inputs, outputs []*structpb.Struct) error
}

UsageHandler allows the component execution wrapper to add checks and collect usage metrics around a component execution.

func NewNoopUsageHandler

func NewNoopUsageHandler(IExecution) (UsageHandler, error)

NewNoopUsageHandler is a no-op usage handler initializer.

type UsageHandlerCreator

type UsageHandlerCreator func(IExecution) (UsageHandler, error)

UsageHandlerCreator returns a function to initialize a UsageHandler.

Jump to

Keyboard shortcuts

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