crafter

package
v0.95.3 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAttestationStateNotLoaded = errors.New("crafting state not loaded")
View Source
var ErrRunnerContextNotFound = errors.New("the runner environment doesn't match the required runner type")

Functions

func LoadSchema

func LoadSchema(pathOrURI string) (*schemaapi.CraftingSchema, error)

Types

type CommitRemote added in v0.25.0

type CommitRemote struct {
	Name, URL string
}

type Crafter

type Crafter struct {
	Logger        *zerolog.Logger
	CraftingState *VersionedCraftingState
	Runner        SupportedRunner
	// contains filtered or unexported fields
}

func NewCrafter

func NewCrafter(stateManager StateManager, opts ...NewOpt) (*Crafter, error)

Create a completely new crafter

func (*Crafter) AddMaterialContactFreeWithAutoDetectedKind added in v0.95.3

func (c *Crafter) AddMaterialContactFreeWithAutoDetectedKind(ctx context.Context, attestationID, name, value string, casBackend *casclient.CASBackend, runtimeAnnotations map[string]string) (schemaapi.CraftingSchema_Material_MaterialType, error)

AddMaterialContactFreeWithAutoDetectedKind adds a material to the crafting state checking the incoming material matches any of the supported types in validation order. If the material is not found it will return an error.

func (*Crafter) AddMaterialContractFree added in v0.89.0

func (c *Crafter) AddMaterialContractFree(ctx context.Context, attestationID, kind, name, value string, casBackend *casclient.CASBackend, runtimeAnnotations map[string]string) error

AddMaterialContractFree adds a material to the crafting state without checking the contract schema. This is useful for adding materials that are not defined in the schema. The name of the material is automatically calculated to conform the API contract if not provided.

func (*Crafter) AddMaterialFromContract added in v0.89.0

func (c *Crafter) AddMaterialFromContract(ctx context.Context, attestationID, key, value string, casBackend *casclient.CASBackend, runtimeAnnotations map[string]string) error

AddMaterialFromContract adds a material to the crafting state checking the incoming materials is in the schema and has not been set yet

func (*Crafter) AlreadyInitialized

func (c *Crafter) AlreadyInitialized(ctx context.Context, stateID string) (bool, error)

func (*Crafter) Init

func (c *Crafter) Init(ctx context.Context, opts *InitOpts) error

Initialize the crafter with a remote or local schema

func (*Crafter) IsMaterialInContract added in v0.95.3

func (c *Crafter) IsMaterialInContract(key string) bool

IsMaterialInContract checks if the material is in the contract schema

func (*Crafter) LoadCraftingState

func (c *Crafter) LoadCraftingState(ctx context.Context, attestationID string) error

func (*Crafter) Reset

func (c *Crafter) Reset(ctx context.Context, stateID string) error

Reset removes the current crafting state

func (*Crafter) ResolveEnvVars

func (c *Crafter) ResolveEnvVars(ctx context.Context, attestationID string) error

ResolveEnvVars will iterate on the env vars in the allow list and resolve them from the system context strict indicates if it should fail if any env variable can not be found

func (*Crafter) ValidateAttestation

func (c *Crafter) ValidateAttestation() error

type HeadCommit added in v0.25.0

type HeadCommit struct {
	// hash of the commit
	Hash string
	// When did the commit happen
	Date time.Time
	// Author of the commit
	AuthorEmail, AuthorName string
	// Commit Message
	Message string
	Remotes []*CommitRemote
}

type InitOpts

type InitOpts struct {
	// Control plane workflow metadata
	WfInfo *api.WorkflowMetadata
	// already marshaled schema
	SchemaV1 *schemaapi.CraftingSchema
	// do not record, upload or push attestation
	DryRun bool
	// Identifier of the attestation state
	AttestationID string
	Runner        SupportedRunner
}

type NewOpt

type NewOpt func(c *Crafter) error

func WithLogger

func WithLogger(l *zerolog.Logger) NewOpt

func WithOCIAuth added in v0.65.0

func WithOCIAuth(server, username, password string) NewOpt

func WithWorkingDirPath added in v0.20.0

func WithWorkingDirPath(path string) NewOpt

type RunnerM added in v0.65.0

type StateManager added in v0.60.0

type StateManager interface {
	// Check if the state is already initialized
	Initialized(ctx context.Context, key string) (bool, error)
	// Write the state to the manager backend
	Write(ctx context.Context, key string, state *VersionedCraftingState) error
	// Read the state from the manager backend
	Read(ctx context.Context, key string, state *VersionedCraftingState) error
	// Reset/Delete the state
	Reset(ctx context.Context, key string) error
	// String returns a string representation of the state manager
	Info(ctx context.Context, key string) string
}

StateManager is an interface for managing the state of the crafting process

type SupportedRunner added in v0.65.0

type SupportedRunner interface {
	// Whether the attestation is happening in this environment
	CheckEnv() bool

	// List the env variables registered
	ListEnvVars() []*runners.EnvVarDefinition

	// Return the list of env vars associated with this runner already resolved
	ResolveEnvVars() (map[string]string, []*error)

	// uri to the running job/workload
	RunURI() string

	// ID returns the runner type
	ID() schemaapi.CraftingSchema_Runner_RunnerType
}

func DiscoverAndEnforceRunner added in v0.65.0

func DiscoverAndEnforceRunner(enforcedRunnerType schemaapi.CraftingSchema_Runner_RunnerType, dryRun bool, logger zerolog.Logger) (SupportedRunner, error)

func DiscoverRunner added in v0.88.0

func DiscoverRunner(logger zerolog.Logger) SupportedRunner

DiscoverRunner the runner environment This method does a simple check to see which runner is available in the environment by iterating over the different runners and performing duck-typing checks If more than one runner is detected, we default to generic since its an incongruent result

func NewRunner

Load a specific runner

type VersionedCraftingState added in v0.94.3

type VersionedCraftingState struct {
	*api.CraftingState
	// This digest is used to verify the integrity of the state during updates
	UpdateCheckSum string
}

Directories

Path Synopsis
api

Jump to

Keyboard shortcuts

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