modules

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

Variables

View Source
var ErrNoSuchModule = errors.New("no such module registered")

Functions

func CategoryName

func CategoryName(c Category) string

func LogFileNameFormatter

func LogFileNameFormatter(mod ModuleWithMeta) logging.LogFileNameFormatter

Types

type BinaryNamer

type BinaryNamer interface {
	BinaryName(ctx context.Context) (binaryName string, err error)
}

type Category

type Category = commonv1.Category

func Categories

func Categories() []Category

type ContainerBindMount

type ContainerBindMount struct {
	Target   string `hcl:",label"`
	Source   string `hcl:"source"`
	ReadOnly bool   `hcl:"read_only,optional"`
}

type ContainerCapabilities

type ContainerCapabilities struct {
	Add  []string `hcl:"add,optional"`
	Drop []string `hcl:"drop,optional"`
}

type ContainerSpec

type ContainerSpec struct {
	Capabilities *ContainerCapabilities `hcl:"capabilities,block"`
	Image        string                 `hcl:"image"`
	User         string                 `hcl:"user,optional"`
	VolumeMounts []ContainerVolumeMount `hcl:"volume_mount,block"`
	TmpfsMounts  []ContainerTmpfsMount  `hcl:"tmpfs_mount,block"`
	BindMounts   []ContainerBindMount   `hcl:"bind_mount,block"`
	Privileged   bool                   `hcl:"privileged,optional"`
}

func (ContainerSpec) Mounts

func (s ContainerSpec) Mounts() []mount.Mount

type ContainerTmpfsMount

type ContainerTmpfsMount struct {
	Target   string `hcl:",label"`
	ReadOnly bool   `hcl:"read_only,optional"`
	Size     int64  `hcl:"size"`
}

type ContainerVolumeMount

type ContainerVolumeMount struct {
	Target   string `hcl:",label"`
	Name     string `hcl:"name,optional"`
	ReadOnly bool   `hcl:"read_only,optional"`
	NoCopy   bool   `hcl:"no_copy,optional"`
}

type Example

type Example struct {
	Spec        ModuleWithMeta
	Name        string
	Description string
}

type ExecutionContext

type ExecutionContext interface {
	context.Context
	Name() string
	WorkingDir() string
	OutDir() string
	BinariesDir() string
	StdOut() io.Writer
	StdErr() io.Writer
	Logger() *slog.Logger
	GetState(ctx context.Context, key string) ([]byte, state.Metadata, error)
	SetState(ctx context.Context, key string, value []byte) error
}

type Factory

type Factory interface {
	Create() ModuleWithMeta
}

type Help

type Help struct {
	Name        string
	Description string
	Examples    []Example
}

type Helper

type Helper interface {
	Help(ctx context.Context) (help Help, err error)
}

type Initializer

type Initializer interface {
	Init(hclCtx *hcl.EvalContext) (Module, error)
}

type JSONStateEncoder

type JSONStateEncoder[T any] struct {
	Context ExecutionContext
}

func NewJSONStateEncoder

func NewJSONStateEncoder[T any](ctx ExecutionContext) *JSONStateEncoder[T]

func (JSONStateEncoder[T]) Get

func (j JSONStateEncoder[T]) Get(ctx context.Context, key string) (val T, ok bool, meta state.Metadata, err error)

func (JSONStateEncoder[T]) Set

func (j JSONStateEncoder[T]) Set(ctx context.Context, key string, val T) error

type Metadata

type Metadata[T Module] struct {
	Module       T                 `hcl:",remain"`
	InputMapping map[string]string `hcl:"input_mapping,optional"`
	Container    *ContainerSpec    `hcl:"container,block"`
	Skip         *bool             `hcl:"skip_when,optional"`
	Id           string            `hcl:"id" hcl_write:"-"`
	ModuleName   string            `hcl:"name" hcl_write:"-"`
	OutputDir    string            `hcl:"out_dir" hcl_write:"-"`
	Deps         []string          `hcl:"depends_on,optional"`
}

func (*Metadata[T]) Category

func (m *Metadata[T]) Category() Category

func (*Metadata[T]) ContainerSpec

func (m *Metadata[T]) ContainerSpec() *ContainerSpec

func (*Metadata[T]) Dependencies

func (m *Metadata[T]) Dependencies() []string

func (*Metadata[T]) Execute

func (m *Metadata[T]) Execute(ctx ExecutionContext) error

func (*Metadata[T]) ID

func (m *Metadata[T]) ID() string

func (*Metadata[T]) InputMappings

func (m *Metadata[T]) InputMappings() (mappings map[string]string)

func (*Metadata[T]) Name

func (m *Metadata[T]) Name() string

func (*Metadata[T]) OutDir

func (m *Metadata[T]) OutDir() string

func (*Metadata[T]) SetModule

func (m *Metadata[T]) SetModule(mod Module)

func (*Metadata[T]) SetName

func (m *Metadata[T]) SetName(name string)

func (*Metadata[T]) ShouldSkip

func (m *Metadata[T]) ShouldSkip() bool

func (*Metadata[T]) Type

func (m *Metadata[T]) Type() string

func (*Metadata[T]) UnmarshalHCL

func (m *Metadata[T]) UnmarshalHCL(body hcl.Body, ctx *hcl.EvalContext) hcl.Diagnostics

func (*Metadata[T]) UnmarshalJSON

func (m *Metadata[T]) UnmarshalJSON(bytes []byte) error

func (*Metadata[T]) UnmarshalModuleSpec

func (m *Metadata[T]) UnmarshalModuleSpec(val *commonv1.ModuleSpec) error

func (*Metadata[T]) Unwrap

func (m *Metadata[T]) Unwrap() Module

type Module

type Module interface {
	Execute(ctx ExecutionContext) error
	Category() Category
	Type() string
}

type ModuleFactoryFunc

type ModuleFactoryFunc func() ModuleWithMeta

func (ModuleFactoryFunc) Create

func (f ModuleFactoryFunc) Create() ModuleWithMeta

type ModuleWithMeta

type ModuleWithMeta interface {
	Module
	Unwrap() Module
	SetModule(m Module)
	ID() string
	Name() string
	SetName(name string)
	ShouldSkip() bool
	Dependencies() []string
	InputMappings() map[string]string
	OutDir() string
	ContainerSpec() *ContainerSpec
	UnmarshalHCL(body hcl.Body, ctx *hcl.EvalContext) hcl.Diagnostics
}

type Registration

type Registration interface {
	RegisterAt(registry *TypeRegistry)
}

type RegistrationFunc

type RegistrationFunc func(registry *TypeRegistry)

func (RegistrationFunc) RegisterAt

func (f RegistrationFunc) RegisterAt(registry *TypeRegistry)

type Repository

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

func (*Repository) Builds

func (s *Repository) Builds() map[string]ModuleWithMeta

func (*Repository) Module

func (s *Repository) Module(moduleType Category, moduleName string) ModuleWithMeta

func (*Repository) ModuleByID

func (s *Repository) ModuleByID(id string) ModuleWithMeta

func (*Repository) ModulesByCategory

func (s *Repository) ModulesByCategory(moduleType Category) map[string]ModuleWithMeta

func (*Repository) RegisterModules

func (s *Repository) RegisterModules(modules ...ModuleWithMeta)

func (*Repository) Tasks

func (s *Repository) Tasks() map[string]ModuleWithMeta

func (*Repository) Tools

func (s *Repository) Tools() map[string]ModuleWithMeta

type StateEncoder

type StateEncoder[T any] interface {
	Get(ctx context.Context, key string) (val T, ok bool, meta state.Metadata, err error)
	Set(ctx context.Context, key string, val T) error
}

type TestExecutionContext

type TestExecutionContext struct {
	context.Context
	TB              testing.TB
	StateStore      state.Store
	TestWorkingDir  string
	OutputDirectory string
}

func (TestExecutionContext) BinariesDir

func (t TestExecutionContext) BinariesDir() string

func (TestExecutionContext) GetState

func (t TestExecutionContext) GetState(ctx context.Context, key string) ([]byte, state.Metadata, error)

func (TestExecutionContext) Logger

func (t TestExecutionContext) Logger() *slog.Logger

func (TestExecutionContext) Name

func (t TestExecutionContext) Name() string

func (TestExecutionContext) OutDir

func (t TestExecutionContext) OutDir() string

func (TestExecutionContext) SetState

func (t TestExecutionContext) SetState(ctx context.Context, key string, value []byte) error

func (TestExecutionContext) StdErr

func (t TestExecutionContext) StdErr() io.Writer

func (TestExecutionContext) StdOut

func (t TestExecutionContext) StdOut() io.Writer

func (TestExecutionContext) WorkingDir

func (t TestExecutionContext) WorkingDir() string

type ToolModule

type ToolModule interface {
	Module
	BinaryNamer
}

type TypeRegistry

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

func NewRegistry

func NewRegistry(registrations ...Registration) *TypeRegistry

func (*TypeRegistry) Create

func (r *TypeRegistry) Create(moduleCategory Category, moduleType string) (ModuleWithMeta, error)

func (*TypeRegistry) CreateFromHCL

func (r *TypeRegistry) CreateFromHCL(
	moduleCategory Category,
	moduleType string,
	body hcl.Body,
	hclCtx *hcl.EvalContext,
	diagsWriter hcl.DiagnosticWriter,
) (ModuleWithMeta, error)

func (*TypeRegistry) Inventory

func (r *TypeRegistry) Inventory() (inventory map[Category][]string)

func (*TypeRegistry) RegisterModule

func (r *TypeRegistry) RegisterModule(factory Factory)

Directories

Path Synopsis
helpers
env

Jump to

Keyboard shortcuts

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