Documentation
¶
Overview ¶
Package ports defines interfaces for infrastructure operations. These ports enable dependency inversion - domain logic depends on abstractions, and infrastructure adapters implement these interfaces.
Index ¶
- type CapabilityRegistry
- type CapabilityValidator
- type CommandRequest
- type CommandResult
- type CommandRunner
- type ConfigProvider
- type DNSResolver
- type DenialHandler
- type Extractor
- type ExtractorRegistry
- type GrantStore
- type HTTPClient
- type HTTPRequest
- type HTTPResponse
- type MXRecord
- type ManifestParser
- type Policy
- type Prompter
- type SMTPClient
- type SMTPConnectResult
- type TCPConnection
- type TCPDialer
- type TemplateEngine
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CapabilityRegistry ¶
type CapabilityRegistry interface {
// Register adds a schema generated from a Go struct.
Register(kind string, model interface{}) error
// GetSchema retrieves the JSON Schema for a capability type.
GetSchema(kind string) (string, bool)
// List returns all registered capability type names.
List() []string
}
CapabilityRegistry manages JSON schemas for capability types.
type CapabilityValidator ¶
type CapabilityValidator interface {
// Validate checks the manifest capabilities against registered schemas.
Validate(manifest *entities.PluginManifest) (*entities.ValidationResult, error)
}
CapabilityValidator validates capability configurations against schemas.
type CommandRequest ¶
type CommandRequest struct {
Command string
Args []string
Dir string
Env []string
Timeout int // milliseconds
}
CommandRequest holds parameters for command execution.
type CommandResult ¶
type CommandResult struct {
Stdout string
Stderr string
ExitCode int
DurationMs int64
IsTimeout bool
}
CommandResult represents the result of a command execution.
type CommandRunner ¶
type CommandRunner interface {
// Run executes a command and returns the result.
Run(ctx context.Context, req CommandRequest) (*CommandResult, error)
}
CommandRunner defines the interface for command execution. Infrastructure adapters implement this to provide exec functionality.
type ConfigProvider ¶
type ConfigProvider interface {
// GetConfig returns the configuration map for a plugin.
GetConfig(pluginName string) (map[string]interface{}, error)
}
ConfigProvider supplies configuration values for template resolution.
type DNSResolver ¶
type DNSResolver interface {
// LookupHost resolves IP addresses for a given hostname.
// Returns A and AAAA records as string slices.
LookupHost(ctx context.Context, host string) ([]string, error)
// LookupCNAME returns the canonical name for the given host.
LookupCNAME(ctx context.Context, host string) (string, error)
// LookupMX returns MX records for the given domain.
LookupMX(ctx context.Context, domain string) ([]MXRecord, error)
// LookupTXT returns TXT records for the given domain.
LookupTXT(ctx context.Context, domain string) ([]string, error)
// LookupNS returns NS records (nameservers) for the given domain.
LookupNS(ctx context.Context, domain string) ([]string, error)
}
DNSResolver defines the interface for DNS resolution operations. Infrastructure adapters (e.g., WASM host functions) implement this interface.
type DenialHandler ¶
type DenialHandler interface {
// OnDenial is called when a capability request is denied.
// kind: "network", "fs", "env", "exec", "kv"
// request: the denied request (type depends on kind)
// reason: human-readable denial reason
OnDenial(kind string, request interface{}, reason string)
}
DenialHandler is called when a policy check denies a request. Implementations can log, collect metrics, or take other actions.
type Extractor ¶
type Extractor interface {
// Extract returns capabilities needed based on the plugin's config.
// Returns a GrantSet representing what the plugin needs.
Extract(config map[string]interface{}) (*entities.GrantSet, error)
}
Extractor analyzes plugin configuration and returns required capabilities.
type ExtractorRegistry ¶
type ExtractorRegistry interface {
Register(pluginName string, extractor Extractor)
Get(pluginName string) (Extractor, bool)
}
ExtractorRegistry manages extractors by plugin name.
type GrantStore ¶
type GrantStore interface {
// Load retrieves all granted capabilities.
// Returns empty GrantSet (not error) if no grants exist.
Load() (*entities.GrantSet, error)
// Save persists the granted capabilities.
Save(grants *entities.GrantSet) error
// ConfigPath returns the path to the backing store (for user messaging).
ConfigPath() string
}
GrantStore provides persistence for capability grants.
type HTTPClient ¶
type HTTPClient interface {
// Do executes an HTTP request and returns the response.
Do(ctx context.Context, req HTTPRequest) (*HTTPResponse, error)
// Get performs an HTTP GET request.
Get(ctx context.Context, url string) (*HTTPResponse, error)
// Post performs an HTTP POST request.
Post(ctx context.Context, url string, contentType string, body []byte) (*HTTPResponse, error)
}
HTTPClient defines the interface for HTTP operations. Infrastructure adapters implement this to provide HTTP functionality.
type HTTPRequest ¶
type HTTPRequest struct {
Method string
URL string
Headers map[string]string
Body []byte
Timeout int // milliseconds
}
HTTPRequest represents an HTTP request.
type HTTPResponse ¶
HTTPResponse represents an HTTP response.
type ManifestParser ¶
type ManifestParser interface {
// Parse unmarshals YAML bytes into a PluginManifest struct.
Parse(data []byte) (*entities.PluginManifest, error)
}
ManifestParser parses raw YAML bytes into a PluginManifest.
type Policy ¶
type Policy interface {
CheckNetwork(req entities.NetworkRequest, grants *entities.GrantSet) bool
CheckFileSystem(req entities.FileSystemRequest, grants *entities.GrantSet) bool
CheckEnvironment(req entities.EnvironmentRequest, grants *entities.GrantSet) bool
CheckExec(req entities.ExecCapabilityRequest, grants *entities.GrantSet) bool
CheckKeyValue(req entities.KeyValueRequest, grants *entities.GrantSet) bool
}
Policy enforces capability grants against runtime requests.
type Prompter ¶
type Prompter interface {
// IsInteractive returns true if running in an interactive terminal.
IsInteractive() bool
// PromptForCapability asks the user to grant a capability.
// Returns: granted (allow this time), always (persist to store), error.
PromptForCapability(req entities.CapabilityRequest) (granted bool, always bool, err error)
// PromptForCapabilities prompts for multiple capabilities at once.
// Returns the GrantSet of approved capabilities.
PromptForCapabilities(reqs []entities.CapabilityRequest) (*entities.GrantSet, error)
// FormatNonInteractiveError creates a helpful error for non-interactive mode.
FormatNonInteractiveError(missing *entities.GrantSet) error
}
Prompter handles interactive capability authorization.
type SMTPClient ¶
type SMTPClient interface {
// Connect establishes an SMTP connection to the given host and port.
Connect(ctx context.Context, host, port string, timeout time.Duration, useTLS, useStartTLS bool) (*SMTPConnectResult, error)
}
SMTPClient defines the interface for SMTP connection operations. Infrastructure adapters implement this to provide SMTP functionality.
type SMTPConnectResult ¶
type SMTPConnectResult struct {
Banner string
TLSVersion string
ResponseTime time.Duration
Connected bool
TLSEnabled bool
}
SMTPConnectResult represents the result of an SMTP connection attempt.
type TCPConnection ¶
type TCPConnection interface {
// Close closes the connection.
Close() error
// RemoteAddr returns the remote address.
RemoteAddr() string
// IsConnected returns true if the connection is established.
IsConnected() bool
}
TCPConnection represents an established TCP connection.
type TCPDialer ¶
type TCPDialer interface {
// Dial establishes a TCP connection to the given address.
Dial(ctx context.Context, address string) (TCPConnection, error)
// DialWithTimeout establishes a TCP connection with a timeout.
DialWithTimeout(ctx context.Context, address string, timeoutMs int) (TCPConnection, error)
}
TCPDialer defines the interface for TCP connection operations. Infrastructure adapters implement this to provide TCP functionality.
type TemplateEngine ¶
type TemplateEngine interface {
// Render processes the raw manifest bytes with the provided config.
// Returns resolved bytes with all template placeholders replaced.
Render(raw []byte, config map[string]interface{}) ([]byte, error)
}
TemplateEngine renders templates with configuration values.