validate

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package validate provides JSON Schema validation for Forge specifications.

Index

Constants

This section is empty.

Variables

View Source
var KnownAuthProviderSettings = map[string]map[string]bool{
	"http_verifier": {
		"url":         true,
		"default_org": true,
		"timeout":     true,
	},
	"static_token": {
		"token":     true,
		"token_env": true,
	},
	"oidc": {
		"issuer":         true,
		"audience":       true,
		"client_id":      true,
		"jwks_url":       true,
		"jwks_cache_ttl": true,
		"clock_skew":     true,
		"claim_map":      true,
	},
	"aws_sigv4": {
		"region":             true,
		"audience":           true,
		"allowed_principals": true,
		"allowed_accounts":   true,
		"identity_cache_ttl": true,
		"sts_endpoint":       true,
		"http_timeout":       true,
		"max_token_expires":  true,
		"clock_skew":         true,
	},
	"gcp_iap": {
		"audience":         true,
		"jwks_refresh_ttl": true,
		"http_timeout":     true,
	},
	"azure_ad": {
		"tenant_id":          true,
		"audience":           true,
		"allow_multi_tenant": true,
		"allowed_tenants":    true,
		"groups_mode":        true,
		"graph_timeout":      true,
		"jwks_cache_ttl":     true,
	},
}

KnownAuthProviderSettings is the closed set of YAML keys each provider type accepts. Mirrors the `yaml:` tags on each provider's Config struct; must be kept in sync when new fields are added. Internal-only struct fields (those carrying `yaml:"-"`) are intentionally absent — they can only be set by another Go package, not via forge.yaml or the Web UI's create-payload.

Two callers consume this map:

  1. ValidateAuthConfig emits a *warning* per unknown key during `forge validate`, so a typo like `aud:` instead of `audience:` gets surfaced loudly.

  2. The Web UI handler (forge-ui handlers_create.go) filters its incoming Settings map through FilterKnownSettings before forwarding to scaffold — closing the exploit chain where a malicious POST `{"settings": {"audience": "x", "evil": "y"}}` would otherwise drop `evil:` into forge.yaml verbatim.

Functions

func FilterKnownSettings

func FilterKnownSettings(providerType string, settings map[string]any) map[string]any

FilterKnownSettings returns a copy of settings with any keys not in the whitelist for providerType dropped. Use this at the boundary between untrusted input (Web UI POST) and persistence (forge.yaml scaffold) so unknown keys never reach disk.

For unknown providerType (returns nil from the whitelist lookup), the input is passed through unchanged — let the ValidateAuthConfig "unknown type" error catch that case instead.

func ValidateAgentSpec

func ValidateAgentSpec(jsonData []byte) ([]string, error)

ValidateAgentSpec validates raw JSON bytes against the AgentSpec v1.0 schema. It returns a slice of validation error descriptions and an error if schema compilation fails.

func ValidateAuthConfig

func ValidateAuthConfig(cfg types.AuthConfig, r *ValidationResult)

ValidateAuthConfig adds errors and warnings for a forge.yaml auth: block. Empty AuthConfig is valid (legacy --auth-url path remains the fallback).

func ValidateMCPConfig

func ValidateMCPConfig(cfg types.MCPConfig, r *ValidationResult)

ValidateMCPConfig adds errors and warnings for a forge.yaml mcp: block. Empty MCPConfig is valid — agents without MCP servers continue to work unchanged.

Types

type A2ACaps

type A2ACaps struct {
	Streaming         bool `json:"streaming"`
	PushNotifications bool `json:"push_notifications"`
}

A2ACaps represents agent capabilities as understood by Command.

type AgentDefinition

type AgentDefinition struct {
	Slug                 string            `json:"slug"`
	DisplayName          string            `json:"display_name"`
	Description          string            `json:"description,omitempty"`
	ContainerImage       string            `json:"container_image,omitempty"`
	Port                 int               `json:"port,omitempty"`
	EnvVars              map[string]string `json:"env_vars,omitempty"`
	Tools                []ImportedTool    `json:"tools,omitempty"`
	ModelProvider        string            `json:"model_provider,omitempty"`
	ModelName            string            `json:"model_name,omitempty"`
	Capabilities         *A2ACaps          `json:"capabilities,omitempty"`
	Guardrails           []string          `json:"guardrails,omitempty"`
	ToolInterfaceVersion string            `json:"tool_interface_version,omitempty"`
	SkillsSpecVersion    string            `json:"skills_spec_version,omitempty"`
	EgressProfile        string            `json:"egress_profile,omitempty"`
	EgressMode           string            `json:"egress_mode,omitempty"`
	Skills               []string          `json:"skills,omitempty"`
}

AgentDefinition represents what Command's import API produces from an AgentSpec.

type ImportSimResult

type ImportSimResult struct {
	Definition     *AgentDefinition `json:"agent_definition"`
	ImportWarnings []string         `json:"import_warnings"`
}

ImportSimResult holds the simulated import output.

func SimulateImport

func SimulateImport(spec *agentspec.AgentSpec) *ImportSimResult

SimulateImport simulates what Command's POST /api/v1/agents/import would produce from the given AgentSpec.

type ImportedTool

type ImportedTool struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	HasSchema   bool   `json:"has_schema"`
	Category    string `json:"category,omitempty"`
	SkillOrigin string `json:"skill_origin,omitempty"`
}

ImportedTool represents a tool as imported by Command.

type ValidationResult

type ValidationResult struct {
	Errors   []string
	Warnings []string
}

ValidationResult holds errors and warnings from config validation.

func ValidateCommandCompat

func ValidateCommandCompat(spec *agentspec.AgentSpec) *ValidationResult

ValidateCommandCompat checks an AgentSpec against Command platform import requirements. It returns errors for hard incompatibilities and warnings for missing optional fields.

func ValidateForgeConfig

func ValidateForgeConfig(cfg *types.ForgeConfig) *ValidationResult

ValidateForgeConfig checks a ForgeConfig for errors and warnings.

func (*ValidationResult) IsValid

func (r *ValidationResult) IsValid() bool

IsValid returns true if there are no validation errors.

Jump to

Keyboard shortcuts

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