ports

package
v0.4.5-alpha Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package ports defines interfaces for infrastructure dependencies. These are the "ports" in hexagonal architecture - abstractions that the application layer depends on but doesn't implement.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthProvider

type AuthProvider interface {
	// GetCredentials returns username and password for a registry.
	GetCredentials(ctx context.Context, registry string) (username, password string, err error)
}

AuthProvider retrieves authentication credentials for registries.

type CapabilityAnalyzer

type CapabilityAnalyzer interface {
	ExtractCapabilities(profile entities.ProfileReader) map[string]*sdkEntities.GrantSet
}

CapabilityAnalyzer extracts specific capability requirements from profiles. This allows the orchestrator to be tested with mock analyzers.

type CapabilityCollector

type CapabilityCollector interface {
	CollectRequiredCapabilities(ctx context.Context, profile entities.ProfileReader, runtime PluginRuntime, pluginDir string) (map[string]*sdkEntities.GrantSet, error)
}

CapabilityCollector collects required capabilities from plugins.

type CapabilityGatekeeperPort

type CapabilityGatekeeperPort interface {
	GrantCapabilities(
		required *sdkEntities.GrantSet,
		capabilityInfo map[string]CapabilityInfo,
		trustAll bool,
	) (*sdkEntities.GrantSet, error)
}

CapabilityGatekeeperPort grants capabilities based on security policy. Named with "Port" suffix to avoid collision with the concrete CapabilityGatekeeper type.

type CapabilityGranter

type CapabilityGranter interface {
	GrantCapabilities(ctx context.Context, required map[string]*sdkEntities.GrantSet, trustAll bool) (map[string]*sdkEntities.GrantSet, error)
}

CapabilityGranter grants capabilities (interactively or automatically).

type CapabilityInfo

type CapabilityInfo struct {
	PluginName     string
	IsProfileBased bool
	IsBroad        bool
}

CapabilityInfo contains metadata about a capability request.

type Closer

type Closer interface {
	io.Closer
}

Closer is a common interface for resources that need cleanup.

type DataRedactor

type DataRedactor interface {
	Redact(input string) string
}

DataRedactor scrubs sensitive information from output. Placed here as it's often used with execution/security components.

type EmbeddedPluginSource

type EmbeddedPluginSource interface {
	// Get returns the file path to an embedded plugin.
	// Returns empty string if not found.
	Get(name string) string

	// List returns names of all embedded plugins.
	List() []string
}

EmbeddedPluginSource provides access to built-in WASM plugins.

type EngineFactory

type EngineFactory interface {
	CreateEngine(ctx context.Context, profile entities.ProfileReader, grantedCaps map[string]*sdkEntities.GrantSet, pluginDir string, filters dto.FilterOptions, execution dto.ExecutionOptions, skipSchemaValidation bool) (ExecutionEngine, error)
}

EngineFactory creates execution engines with capabilities.

type ExecutionEngine

type ExecutionEngine interface {
	Execute(ctx context.Context, profile entities.ProfileReader) (*execution.ExecutionResult, error)
	Close(ctx context.Context) error
}

ExecutionEngine executes profiles and returns results.

type FetchOptions

type FetchOptions struct {
	// Headers contains custom HTTP headers (e.g., Authorization).
	Headers map[string]string

	// MaxSize limits the response body size in bytes.
	// Default: 10MB if zero.
	MaxSize int64

	// Timeout for the fetch operation.
	// Default: 30s if zero.
	Timeout time.Duration

	// MaxRetries for transient failures (429, 5xx).
	// Default: 3 if zero.
	MaxRetries int

	// Insecure allows invalid TLS certificates when true.
	Insecure bool

	// AllowPrivateNetwork permits fetching from private IP ranges.
	// Default: false (blocked with warning).
	AllowPrivateNetwork bool
}

FetchOptions configures profile fetching behavior.

func DefaultFetchOptions

func DefaultFetchOptions() FetchOptions

DefaultFetchOptions returns sensible defaults for fetch operations.

type FetchResult

type FetchResult struct {
	// ContentHash is the SHA256 digest of the content.
	ContentHash values.Digest

	// ETag is the HTTP ETag header value for cache validation.
	ETag string

	// ContentType is the response Content-Type header.
	ContentType string

	// FinalURL is the URL after any redirects.
	FinalURL string

	// Content is the raw profile YAML content.
	Content []byte

	// RedirectCount is the number of redirects followed.
	RedirectCount int
}

FetchResult contains the result of a profile fetch operation.

type GrantStore

type GrantStore interface {
	Load() (*sdkEntities.GrantSet, error)
	Save(grants *sdkEntities.GrantSet) error
	ConfigPath() string
}

GrantStore persists and retrieves granted capabilities.

type IntegrityVerifier

type IntegrityVerifier interface {
	// VerifySignature checks the signature of a plugin in the registry.
	VerifySignature(ctx context.Context, ref values.PluginReference) (*SignatureResult, error)

	// Sign signs a plugin artifact (for publishing).
	Sign(ctx context.Context, ref values.PluginReference) error
}

IntegrityVerifier verifies cryptographic signatures on plugin artifacts.

type LockfileRepository

type LockfileRepository interface {
	// Load reads a lockfile from the given path.
	// Returns nil, nil if lockfile doesn't exist.
	Load(ctx context.Context, path string) (*entities.Lockfile, error)

	// Save writes a lockfile to the given path.
	Save(ctx context.Context, lockfile *entities.Lockfile, path string) error

	// Exists checks if a lockfile exists at the given path.
	Exists(ctx context.Context, path string) (bool, error)
}

LockfileRepository handles lockfile persistence. This is a PORT - abstracts file system or other storage.

SOLID: Interface Segregation - focused only on lockfile I/O

type OutputFormatter

type OutputFormatter interface {
	Format(result *execution.ExecutionResult) error
}

OutputFormatter formats execution results.

type OutputFormatterFactory

type OutputFormatterFactory interface {
	// Create returns a formatter for the given format name.
	// options is implementation-specific (typically output.FactoryOptions).
	// Returns error if format is unknown.
	Create(format string, writer io.Writer, options interface{}) (OutputFormatter, error)

	// SupportedFormats returns list of available format names.
	SupportedFormats() []string
}

OutputFormatterFactory creates formatters by name. The options parameter is implementation-specific (e.g., output.FactoryOptions).

type OutputWriter

type OutputWriter interface {
	Write(ctx context.Context, data []byte, dest string) error
}

OutputWriter writes formatted output to destination.

type Plugin

type Plugin interface {
	// Describe returns plugin metadata including declared capabilities.
	Describe(ctx context.Context) (*PluginInfo, error)
}

Plugin represents a loaded WASM plugin that can be inspected and executed. This interface abstracts the concrete wasm.Plugin implementation.

type PluginDigester

type PluginDigester interface {
	// DigestBytes computes SHA-256 of raw bytes.
	DigestBytes(data []byte) string

	// DigestFile computes SHA-256 of a file.
	DigestFile(ctx context.Context, path string) (string, error)
}

PluginDigester computes digests for plugins. Separate from VersionResolver per Interface Segregation.

type PluginDirectoryResolver

type PluginDirectoryResolver interface {
	ResolvePluginDir(ctx context.Context) (string, error)
}

PluginDirectoryResolver resolves the plugin directory path.

type PluginInfo

type PluginInfo struct {
	Capabilities *sdkEntities.GrantSet
	Name         string
	Version      string
	Description  string
}

PluginInfo contains metadata about a plugin. This is the application-layer representation of plugin metadata.

type PluginRegistry

type PluginRegistry interface {
	// Pull downloads a plugin artifact from the registry.
	Pull(ctx context.Context, ref values.PluginReference) (*dto.PluginArtifactDTO, error)

	// Push uploads a plugin artifact to the registry.
	Push(ctx context.Context, artifact *dto.PluginArtifactDTO) error

	// Resolve resolves a reference to its content digest.
	Resolve(ctx context.Context, ref values.PluginReference) (values.Digest, error)
}

PluginRegistry provides access to remote OCI registries.

type PluginRepository

type PluginRepository interface {
	// Find retrieves a cached plugin by reference.
	Find(ctx context.Context, ref values.PluginReference) (*entities.Plugin, string, error)

	// Store persists a plugin with its WASM binary.
	// Returns the path to the stored WASM file.
	Store(ctx context.Context, plugin *entities.Plugin, wasm io.Reader) (string, error)

	// List returns all cached plugins.
	List(ctx context.Context) ([]*entities.Plugin, error)

	// Prune removes old versions, keeping only the specified number.
	Prune(ctx context.Context, keepVersions int) error

	// Delete removes a specific plugin from cache.
	Delete(ctx context.Context, ref values.PluginReference) error
}

PluginRepository manages persistent storage of cached plugins. Implements Repository pattern for Plugin aggregate.

type PluginRuntime

type PluginRuntime interface {
	// LoadPlugin compiles and caches a plugin from WASM bytes.
	LoadPlugin(ctx context.Context, name string, wasmBytes []byte) (Plugin, error)

	// Close releases runtime resources.
	Close(ctx context.Context) error
}

PluginRuntime abstracts the WASM runtime for plugin loading and management. This interface allows the application layer to work with plugins without depending on concrete infrastructure types like wasm.Runtime.

type PluginRuntimeFactory

type PluginRuntimeFactory interface {
	// NewRuntime creates a new plugin runtime with optional configuration.
	// Accepts functional options for capabilities, redaction, memory limits, and caching.
	NewRuntime(ctx context.Context, opts ...RuntimeOption) (PluginRuntime, error)
}

PluginRuntimeFactory creates runtime instances. This allows the application layer to create runtimes without importing infrastructure.

type ProfileAuthProvider

type ProfileAuthProvider interface {
	// GetAuthHeader returns the Authorization header value for the given URL.
	// Returns empty string if no auth is configured for this URL.
	GetAuthHeader(ctx context.Context, url string) (string, error)
}

ProfileAuthProvider retrieves authentication headers for remote profile fetching. Supports header-based authentication (Bearer, Basic, custom headers).

type ProfileCacheRepository

type ProfileCacheRepository interface {
	// Find retrieves a cached profile by reference.
	// Returns nil if not found.
	Find(ctx context.Context, ref values.ProfileReference) (*entities.ProfileCacheEntry, error)

	// Store persists a profile cache entry.
	Store(ctx context.Context, entry *entities.ProfileCacheEntry) error

	// List returns all cached profiles.
	List(ctx context.Context) ([]*entities.ProfileCacheEntry, error)

	// Delete removes a specific profile from cache.
	Delete(ctx context.Context, ref values.ProfileReference) error

	// Prune removes profiles older than the specified duration.
	// Returns the number of entries removed.
	Prune(ctx context.Context, maxAge time.Duration) (int, error)
}

ProfileCacheRepository manages persistent storage of cached remote profiles. Implements Repository pattern for ProfileCacheEntry aggregate.

type ProfileFetcher

type ProfileFetcher interface {
	// Fetch retrieves profile content from the given reference.
	// Returns the fetch result containing content, hash, and metadata.
	Fetch(ctx context.Context, ref values.ProfileReference, opts FetchOptions) (*FetchResult, error)
}

ProfileFetcher fetches remote profile content from HTTPS URLs or OCI registries.

type ProfileLoader

type ProfileLoader interface {
	LoadProfile(path string) (*entities.Profile, error)
	// LoadProfileWithCLIVars loads a profile and merges CLI variables before substitution.
	// CLI variables override profile variables at the same path.
	LoadProfileWithCLIVars(path string, cliVars map[string]interface{}) (*entities.Profile, error)
	// LoadProfileWithOptions loads a profile with CLI variables and remote fetch options.
	// remoteOpts configures behavior for remote profile fetching (refresh, timeout, etc.).
	LoadProfileWithOptions(path string, cliVars map[string]interface{}, remoteOpts RemoteLoadOptions) (*entities.Profile, error)
}

ProfileLoader loads profiles from storage.

type ProfileTrustChecker

type ProfileTrustChecker interface {
	// RequiresTrust returns true if the profile path requires trust verification.
	RequiresTrust(path string) bool

	// IsTrusted returns true if the URL matches a trusted source pattern.
	IsTrusted(url string) bool

	// PromptForTrust prompts the user to trust a remote profile.
	// Returns true if trusted, false if denied, or error for non-interactive mode.
	PromptForTrust(
		ctx context.Context,
		url string,
		requiredCaps map[string]*sdkEntities.GrantSet,
		trustFlag bool,
	) (bool, error)
}

ProfileTrustChecker verifies trust for remote profile sources.

type ProfileValidator

type ProfileValidator interface {
	Validate(profile *entities.Profile) error
	ValidateWithSchemas(ctx context.Context, profile *entities.Profile, runtime PluginRuntime) error
}

ProfileValidator validates profile structure and schemas.

type Prompter

type Prompter interface {
	IsInteractive() bool
	PromptForCapability(req sdkEntities.CapabilityRequest) (granted bool, always bool, err error)
	PromptForCapabilities(reqs []sdkEntities.CapabilityRequest) (*sdkEntities.GrantSet, error)
	FormatNonInteractiveError(missing *sdkEntities.GrantSet) error
}

Prompter handles interactive capability authorization.

type RemoteLoadOptions

type RemoteLoadOptions struct {
	// Refresh forces cache bypass for remote profiles.
	Refresh bool
	// AllowPrivateNetwork permits fetching from private IPs.
	AllowPrivateNetwork bool
	// Insecure skips TLS validation for remote profiles.
	Insecure bool
	// Timeout for remote fetch operations.
	Timeout time.Duration
}

RemoteLoadOptions configures remote profile loading behavior.

type RuntimeOption

type RuntimeOption any

RuntimeOption configures runtime creation. This type alias allows the application layer to pass options without importing infrastructure.

type SecretResolver

type SecretResolver interface {
	// Resolve returns the secret value by name.
	// The resolved value is automatically tracked for redaction.
	Resolve(name string) (string, error)
}

SecretResolver resolves named secrets for profile interpolation. Implementations automatically track resolved values for redaction.

type SensitiveValueProvider

type SensitiveValueProvider interface {
	// Track registers a sensitive value to be protected (redacted).
	Track(value string)

	// AllValues returns all tracked sensitive values.
	AllValues() []string
}

SensitiveValueProvider tracks and provides all sensitive values for protection. This is a PORT - the application defines what it needs, infrastructure provides it.

type SignatureResult

type SignatureResult struct {
	SignedAt        time.Time
	Signer          string
	TransparencyLog string
	Certificate     []byte
	Verified        bool
}

SignatureResult contains signature verification details.

type SystemConfigProvider

type SystemConfigProvider interface {
	LoadConfig(ctx context.Context, path string) (*system.Config, error)
}

SystemConfigProvider loads system configuration.

type VersionResolver

type VersionResolver interface {
	// Resolve converts a version constraint to an exact version.
	// Examples:
	//   "@1.0"   -> "1.0.x" (latest 1.0.x)
	//   "^1.2.0" -> "1.x.x >= 1.2.0"
	//   "~1.2.3" -> "1.2.x >= 1.2.3"
	Resolve(constraint string, available []string) (string, error)
}

VersionResolver resolves semver version constraints to exact versions. This is a PORT - application defines what it needs, infrastructure provides how.

SOLID: Interface Segregation - focused only on version resolution

Jump to

Keyboard shortcuts

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