Documentation
¶
Overview ¶
Package contract defines the core data model for Pacto v2.0 service contracts: the in-memory representation of a pacto.yaml and the types for service identity, interfaces, dependencies, configurations, policies, state, capabilities, and readiness. It also provides YAML parsing along with OCI-reference and semver-range helpers shared by the CLI, dashboard, and operator.
Index ¶
- Constants
- type Bundle
- type Capability
- type CapabilityBinding
- type Configuration
- type Contract
- type Dependency
- type Interface
- type OCIReference
- type Owner
- type OwnerContact
- type ParseError
- type Persistence
- type Policy
- type Range
- type Readiness
- type ReadinessClaim
- type ReadinessRevision
- type ReferenceRef
- type Service
- type State
- type ValidationError
- type ValidationWarning
Constants ¶
const ( StatusDone = "done" StatusPartial = "partial" StatusNotDone = "not-done" StatusDeferred = "deferred" )
Declared per-check completion status.
const ( CategoryArchitecture = "architecture" CategoryTesting = "testing" CategoryCodeQuality = "code-quality" CategoryObservability = "observability" CategorySecurity = "security" CategoryDocumentation = "documentation" CategoryInfrastructure = "infrastructure" CategoryCICD = "ci-cd" CategoryDeployment = "deployment" CategoryResilience = "resilience" CategoryBackupRecovery = "backup-recovery" CategoryIncidentResponse = "incident-response" CategoryCompliance = "compliance" CategoryOther = "other" )
Readiness check software-domain categories.
const ( EvidenceTypeURL = "url" EvidenceTypeDocument = "document" EvidenceTypeTicket = "ticket" EvidenceTypeReport = "report" EvidenceTypeArtifact = "artifact" EvidenceTypeIdentifier = "identifier" EvidenceTypeOther = "other" )
Evidence type constants for ReadinessCheck.Type. These classify the kind of evidence pointer, not the organizational requirement (which is the ID). "other" exists for forward compatibility.
const ( InterfaceTypeOpenAPI = "openapi" InterfaceTypeAsyncAPI = "asyncapi" InterfaceTypeGRPC = "grpc" )
InterfaceType constants.
const ( VisibilityPublic = "public" VisibilityInternal = "internal" )
Visibility constants.
const ( ReferenceKindPolicy = "policy" ReferenceKindConfig = "config" )
Reference kinds for ReferenceRef.Kind.
const ( WorkloadService = "service" WorkloadJob = "job" WorkloadScheduled = "scheduled" )
Workload type constants.
const ( StateStateless = "stateless" StateStateful = "stateful" StateHybrid = "hybrid" )
StateType constants.
const ( DataCriticalityLow = "low" DataCriticalityMedium = "medium" DataCriticalityHigh = "high" )
DataCriticality constants.
const ( ScopeLocal = "local" )
Scope constants.
const ( DurabilityEphemeral = "ephemeral" DurabilityPersistent = "persistent" )
Durability constants.
const ( CapabilityHealth = "health" CapabilityMetrics = "metrics" CapabilityExtension = "extension" )
CapabilityType constants.
const (
CapabilityBindingHTTP = "http"
)
CapabilityBindingType constants.
const (
PolicyTargetContract = "contract"
)
PolicyTarget constants.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bundle ¶
type Bundle struct {
Contract *Contract
RawYAML []byte // Original YAML bytes; populated for local reads.
FS fs.FS
}
Bundle represents a contract bundled with its referenced files.
type Capability ¶
type Capability struct {
Type string `yaml:"type" json:"type"`
Ref string `yaml:"ref,omitempty" json:"ref,omitempty"` // extension only
Binding *CapabilityBinding `yaml:"binding,omitempty" json:"binding,omitempty"` // standard types only
}
Capability describes a service capability. Standard types (health, metrics) may declare a binding to a declared interface; extension requires a namespaced ref (no binding).
func (Capability) AssertionKey ¶
func (cap Capability) AssertionKey() string
AssertionKey returns the canonical assertion identity for a capability: the namespaced ref for an extension, otherwise the standard type. This is the single identity rule used everywhere — Evidence Subject.Name, finding subjects, coverage counting, uniqueness validation and (in S6) collector / evaluator registration — so two distinct extensions never collapse to the same "extension" identity.
type CapabilityBinding ¶
type CapabilityBinding struct {
Type string `yaml:"type" json:"type"` // "http" (the only supported transport)
Interface string `yaml:"interface" json:"interface"` // declared interface providing the address/port anchor
Path string `yaml:"path,omitempty" json:"path,omitempty"` // relative to the resolved endpoint; must start with "/" (INV-6)
}
CapabilityBinding binds a standard capability endpoint (health/metrics) to a declared interface for probing. binding.type is a CLOSED set — only "http" is supported (an unknown transport fails structural validation). binding.interface names the declared interface that provides the ADDRESS/PORT anchor for the probe — the platform-neutral counterpart of the Kubernetes CR's spec.target.interfaceBindings[]; it does NOT claim the capability path is part of that interface's OpenAPI/AsyncAPI/gRPC specification. binding.path is relative to the resolved endpoint.
type Configuration ¶
type Configuration struct {
Name string `yaml:"name" json:"name"`
Schema string `yaml:"schema,omitempty" json:"schema,omitempty"`
Ref string `yaml:"ref,omitempty" json:"ref,omitempty"`
Values map[string]any `yaml:"values,omitempty" json:"values,omitempty"`
Required bool `yaml:"required" json:"required"` // MANDATORY in schema; true = confirmed absence is a violation
}
Configuration declares a named configuration scope. Each entry is an independent scope with no implicit merge semantics. Name is required and must be unique within the configurations array. Exactly one of Schema or Ref must be set. Values is only allowed with Schema.
type Contract ¶
type Contract struct {
PactoVersion string `yaml:"pactoVersion" json:"pactoVersion"`
Service Service `yaml:"service" json:"service"`
Interfaces []Interface `yaml:"interfaces,omitempty" json:"interfaces,omitempty"`
Configurations []Configuration `yaml:"configurations,omitempty" json:"configurations,omitempty"`
Dependencies []Dependency `yaml:"dependencies,omitempty" json:"dependencies,omitempty"`
State *State `yaml:"state,omitempty" json:"state,omitempty"`
Workload string `yaml:"workload,omitempty" json:"workload,omitempty"`
Capabilities []Capability `yaml:"capabilities,omitempty" json:"capabilities,omitempty"`
Policies []Policy `yaml:"policies,omitempty" json:"policies,omitempty"`
Readiness *Readiness `yaml:"readiness,omitempty" json:"readiness,omitempty"`
Metadata map[string]any `yaml:"metadata,omitempty" json:"metadata,omitempty"`
Extensions map[string]any `yaml:"extensions,omitempty" json:"extensions,omitempty"`
}
Contract is the root aggregate — the parsed in-memory representation of a pacto.yaml.
func Parse ¶
Parse deserializes a pacto.yaml from the given reader into a Contract. It enforces syntactic correctness (field types, unknown-field rejection) and a few required top-level fields (pactoVersion, service.name, service.version). Only pactoVersion "2.0" is supported; other versions are rejected. Deeper semantic validation is a separate concern handled by the validation engine.
func (*Contract) ReferenceRefs ¶
func (c *Contract) ReferenceRefs() []ReferenceRef
ReferenceRefs returns the contract's declared config/policy references in a stable order (policies first, then configurations), skipping entries that declare an inline schema rather than a ref (empty Ref). Both the lockfile builder and the demo lock generator resolve exactly this set.
type Dependency ¶
type Dependency struct {
Name string `yaml:"name" json:"name"`
Ref string `yaml:"ref" json:"ref"`
Required bool `yaml:"required" json:"required"`
Compatibility string `yaml:"compatibility" json:"compatibility"`
}
Dependency represents a named dependency on another service. Name is required and must be unique within the dependencies array.
type Interface ¶
type Interface struct {
Name string `yaml:"name" json:"name"`
Type string `yaml:"type" json:"type"`
Ref string `yaml:"ref" json:"ref"`
Visibility string `yaml:"visibility,omitempty" json:"visibility,omitempty"`
}
Interface describes a service interface declaration.
type OCIReference ¶
OCIReference represents a parsed OCI artifact reference.
func ParseOCIReference ¶
func ParseOCIReference(s string) (OCIReference, error)
ParseOCIReference parses an OCI reference string into its components. Accepted formats:
registry/repo registry/repo:tag registry/repo@sha256:<64 hex> registry/repo:tag@sha256:<64 hex>
Tags must match the OCI tag grammar and digests must be a well-formed sha256/sha512 digest; malformed tags or digests are rejected.
func (OCIReference) String ¶
func (r OCIReference) String() string
String returns the full OCI reference string.
type Owner ¶
type Owner struct {
Team string `yaml:"team,omitempty" json:"team,omitempty"`
DRI string `yaml:"dri,omitempty" json:"dri,omitempty"`
Contacts []OwnerContact `yaml:"contacts,omitempty" json:"contacts,omitempty"`
}
Owner is the structured, provider-neutral ownership block for a service.
func (Owner) DisplayString ¶
DisplayString returns the canonical human label: team, else DRI, else "".
func (Owner) MatchesFilter ¶
MatchesFilter reports whether the query matches team, DRI, or any contact value.
type OwnerContact ¶
type OwnerContact struct {
Type string `yaml:"type" json:"type"`
Value string `yaml:"value" json:"value"`
Purpose string `yaml:"purpose,omitempty" json:"purpose,omitempty"`
}
OwnerContact is a single ownership or escalation contact point.
type ParseError ¶
ParseError represents an error encountered during YAML parsing.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
Error returns a "parse error" message, including the path when set.
func (*ParseError) Unwrap ¶
func (e *ParseError) Unwrap() error
Unwrap returns the underlying cause, enabling errors.Is and errors.As.
type Persistence ¶
type Persistence struct {
Scope string `yaml:"scope" json:"scope"`
Durability string `yaml:"durability" json:"durability"`
}
Persistence represents the persistence requirements.
type Policy ¶
type Policy struct {
Name string `yaml:"name" json:"name"`
Schema string `yaml:"schema,omitempty" json:"schema,omitempty"`
Ref string `yaml:"ref,omitempty" json:"ref,omitempty"`
Target string `yaml:"target,omitempty" json:"target,omitempty"`
}
Policy declares a named policy constraint source. Each entry provides either a local JSON Schema file or a reference to an external contract. When resolving a ref, if the referenced contract declares its own policies[] entries, those schemas are used directly (supporting custom paths and multiple schemas). Otherwise, the fixed path policy/schema.json is used as a backward-compatible fallback. A policy schema validates the contract itself, enabling platform teams to enforce organizational standards. Schema and Ref are mutually exclusive. Name is required and must be unique within the policies array.
type Range ¶
type Range struct {
// contains filtered or unexported fields
}
Range represents a parsed semver constraint range.
func ParseRange ¶
ParseRange parses a semver range string (npm-style: ^, ~, exact, range).
type Readiness ¶
type Readiness struct {
// MinScore is the gate: the derived readiness score must be >= this value for
// the contract to be considered ready. It is on the same 0..100 scale as the
// score. Omitted means 100 (every weighted claim must be done); set lower to
// tolerate partial completion. Enforced by `pacto validate --readiness` and
// the operator.
MinScore *int `yaml:"minScore,omitempty" json:"minScore,omitempty"`
// Expires is the single assessment-level freshness boundary (YYYY-MM-DD).
// After this date every in-scope claim earns zero weight and the gate fails.
Expires string `yaml:"expires" json:"expires"`
// PartialCredit is the fraction of a claim's weight earned when its status is
// "partial". Omitted means 0.5.
PartialCredit *float64 `yaml:"partialCredit,omitempty" json:"partialCredit,omitempty"`
// History records the revision log of the readiness assessment.
History []ReadinessRevision `yaml:"history,omitempty" json:"history,omitempty"`
Claims []ReadinessClaim `yaml:"claims,omitempty" json:"claims,omitempty"`
}
Readiness declares operational readiness evidence for the service. It is an optional, provider-neutral section. Each claim declares its completion status (done/partial/not-done/deferred) and points at evidence (a dashboard, runbook, ticket, report, etc.) without Pacto verifying the target content. The whole assessment expires on a single date; once expired, every in-scope claim earns zero weight.
type ReadinessClaim ¶
type ReadinessClaim struct {
ID string `yaml:"id" json:"id"`
Type string `yaml:"type" json:"type"`
Category string `yaml:"category,omitempty" json:"category,omitempty"`
Status string `yaml:"status" json:"status"`
Evidence string `yaml:"evidence" json:"evidence"`
Weight int `yaml:"weight" json:"weight"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
}
ReadinessClaim is a single declared readiness requirement. ID identifies the organizational requirement (e.g. dashboard, runbook), Type classifies the evidence pointer, Category groups the claim into a software domain, Status declares its completion state, Evidence is the pointer itself, and Weight contributes to the readiness score. The service owner is declared at the contract level, so readiness claims deliberately carry no per-claim owner. A claim is a declared, unverified attestation.
type ReadinessRevision ¶
type ReadinessRevision struct {
Date string `yaml:"date" json:"date"`
Version string `yaml:"version" json:"version"`
Author string `yaml:"author" json:"author"`
Description string `yaml:"description" json:"description"`
}
ReadinessRevision is a single entry in the readiness revision history.
type ReferenceRef ¶
ReferenceRef is one declared config/policy reference: its kind ("policy" or "config"), declared name and the raw ref string from the declaring contract.
type Service ¶
type Service struct {
Name string `yaml:"name" json:"name"`
Version string `yaml:"version" json:"version"`
Owner Owner `yaml:"owner,omitempty" json:"owner,omitempty"`
}
Service holds service identification fields.
type State ¶
type State struct {
Type string `yaml:"type" json:"type"`
Persistence Persistence `yaml:"persistence" json:"persistence"`
DataCriticality string `yaml:"dataCriticality" json:"dataCriticality"`
}
State describes the state semantics of the service.
type ValidationError ¶
ValidationError represents a validation failure that makes a contract invalid.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error formats the failure as "[CODE] path: message".
type ValidationWarning ¶
ValidationWarning represents a validation concern that does not invalidate the contract.
func (*ValidationWarning) String ¶
func (w *ValidationWarning) String() string
String formats the warning as "[CODE] path: message".