workflowpkg

package
v0.11.3 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: EUPL-1.2 Imports: 17 Imported by: 0

Documentation

Overview

Package workflowpkg provides workflow pack installation, removal, and discovery. It mirrors the pluginmgr pattern: atomic temp+rename installs, per-pack state.json, and pkg/registry for all transport operations (download, checksum, extraction).

Index

Constants

View Source
const ManifestFileName = "manifest.yaml"
View Source
const MaxManifestSize = 1 << 20

MaxManifestSize caps manifest.yaml reads at 1MB to prevent OOM from malicious packs.

Variables

This section is empty.

Functions

func SourceDataFromPackSource

func SourceDataFromPackSource(source *PackSource) (map[string]any, error)

SourceDataFromPackSource converts a PackSource to a map[string]any for persistence.

Types

type Manifest

type Manifest struct {
	Name        string            `yaml:"name"`
	Version     string            `yaml:"version"`
	Description string            `yaml:"description"`
	Author      string            `yaml:"author"`
	License     string            `yaml:"license"`
	AWFVersion  string            `yaml:"awf_version"`
	Workflows   []string          `yaml:"workflows"`
	Plugins     map[string]string `yaml:"plugins"`
}

Manifest is the parsed content of a workflow pack's manifest.yaml file.

func ParseManifest

func ParseManifest(data []byte) (*Manifest, error)

ParseManifest parses manifest.yaml bytes into a Manifest.

func (*Manifest) Validate

func (m *Manifest) Validate(packDir string) error

Validate checks manifest fields against spec rules:

  • name matches ^[a-z][a-z0-9-]*$
  • version is valid semver
  • awf_version is a valid semver constraint
  • every entry in workflows has a corresponding .yaml file in packDir/workflows/

type PackDiscovererAdapter

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

PackDiscovererAdapter implements ports.PackDiscoverer using PackLoader. It scans multiple directories in priority order, deduplicating by pack name. The first directory in the list wins when the same pack name appears in multiple directories.

func NewPackDiscovererAdapter

func NewPackDiscovererAdapter(dirs []string) *PackDiscovererAdapter

NewPackDiscovererAdapter creates a PackDiscovererAdapter scanning the given directories in priority order (first directory wins for duplicate pack names).

func (*PackDiscovererAdapter) DiscoverWorkflows

func (a *PackDiscovererAdapter) DiscoverWorkflows(ctx context.Context) ([]workflow.WorkflowEntry, error)

DiscoverWorkflows returns WorkflowEntry items for all enabled packs found across the configured directories. Disabled packs and packs without a readable manifest are silently skipped. The returned slice may be nil when no enabled packs are found.

func (*PackDiscovererAdapter) LoadWorkflow

func (a *PackDiscovererAdapter) LoadWorkflow(ctx context.Context, packName, workflowName string) (*workflow.Workflow, error)

LoadWorkflow loads a single workflow from an installed pack by pack name and workflow name. It searches configured directories in priority order.

Both packName and workflowName are validated with the shared ValidateName rule before any filepath.Join — this is the central choke-point that prevents path traversal for all GetWorkflow-by-pack callers.

type PackInfo

type PackInfo struct {
	Name        string            // Pack name (lowercase, alphanumeric with dashes)
	Version     string            // Semver version
	Description string            // Human-readable description
	Author      string            // Author contact
	License     string            // License identifier
	Workflows   map[string]string // Workflow filename → path mapping
	Plugins     map[string]string // Plugin name → version requirement mapping
}

PackInfo holds metadata about an installed workflow pack, parsed from manifest.yaml.

type PackInstaller

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

PackInstaller handles downloading, verifying, extracting, and atomically installing workflow packs from GitHub releases. Delegates all transport to pkg/registry.

func NewPackInstaller

func NewPackInstaller(cliVersion string, optionalClient ...httpx.HTTPDoer) *PackInstaller

NewPackInstaller creates a new PackInstaller with the given CLI version and optional HTTP client.

func (*PackInstaller) Install

func (pi *PackInstaller) Install(ctx context.Context, url, checksum, targetDir string, force bool, source PackSource) error

Install downloads, verifies, extracts, and atomically installs a workflow pack.

url: download URL of the pack archive checksum: expected SHA-256 checksum (hex string) targetDir: final installation directory (workflow-packs/<name>/) force: if true, overwrites an existing pack source: source metadata written to state.json after installation

type PackLoader

type PackLoader struct{}

PackLoader discovers installed workflow packs from filesystem directories.

func NewPackLoader

func NewPackLoader() *PackLoader

NewPackLoader creates a new PackLoader.

func (*PackLoader) DiscoverPacks

func (l *PackLoader) DiscoverPacks(ctx context.Context, packsDir string) ([]PackInfo, error)

DiscoverPacks scans packsDir for installed workflow packs. Each subdirectory containing a manifest.yaml is considered a pack. Returns empty slice for nonexistent or empty directories. Skips subdirectories with invalid or missing manifests.

func (*PackLoader) LoadPackState

func (l *PackLoader) LoadPackState(packDir string) (*PackState, error)

LoadPackState reads state.json from packDir and returns the persisted PackState. Returns error for missing file or invalid JSON.

type PackSource

type PackSource struct {
	Repository  string // e.g., "owner/awf-workflow-example"
	Version     string // e.g., "1.0.0"
	InstalledAt time.Time
	UpdatedAt   time.Time
}

PackSource represents the origin and installation metadata of an external workflow pack. Serialized to PackState.SourceData for persistence.

func PackSourceFromSourceData

func PackSourceFromSourceData(data map[string]any) (*PackSource, error)

PackSourceFromSourceData converts persisted map[string]any back to PackSource. Returns error if data is nil, missing required fields, or type mismatches.

type PackState

type PackState struct {
	Name       string         `json:"name"`
	Enabled    bool           `json:"enabled"`
	SourceData map[string]any `json:"source_data"`
}

PackState represents the persisted state of an installed workflow pack. Stored in workflow-packs/<name>/state.json.

Jump to

Keyboard shortcuts

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