Documentation
¶
Overview ¶
Package registry provides access to CloudFormation Resource Provider Schemas.
These are JSON Schema Draft-07 documents published per-resource by AWS at https://schema.cloudformation.{region}.amazonaws.com/CloudformationSchema.zip. They contain all property constraints (pattern, minLength, maxLength, minimum, maximum, enum, prefixItems, etc.) for all 900+ resource types.
Index ¶
- Constants
- func FallbackSchemas() map[string]*ResourceSchema
- func FetchRegistrySchemas(opts *FetchOptions) (map[string]*ResourceSchema, error)
- func Parse(schema *ResourceSchema) (*types.SchemaParseResult, error)
- func RegistryURLForRegion(region string) string
- type Constraint
- type ConstraintType
- type FetchOptions
- type Handler
- type Manager
- type Options
- type ResourceSchema
- type SchemaProperty
- type TaggingInfo
Constants ¶
const DefaultRegistryURL = "https://schema.cloudformation.us-east-1.amazonaws.com/CloudformationSchema.zip"
DefaultRegistryURL is the URL for the CloudFormation Registry Schema ZIP.
Variables ¶
This section is empty.
Functions ¶
func FallbackSchemas ¶ added in v1.3.0
func FallbackSchemas() map[string]*ResourceSchema
FallbackSchemas returns hand-authored stub schemas for well-known resource types that may be missing from the CloudFormation Registry Schema ZIP. These provide basic property definitions for common resources.
func FetchRegistrySchemas ¶
func FetchRegistrySchemas(opts *FetchOptions) (map[string]*ResourceSchema, error)
FetchRegistrySchemas downloads the registry schema ZIP, extracts individual JSON files, parses typeName from each, and returns a map of type name to schema.
func Parse ¶ added in v1.3.0
func Parse(schema *ResourceSchema) (*types.SchemaParseResult, error)
Parse converts a ResourceSchema into a SchemaParseResult. It resolves $ref pointers, classifies property types, extracts read-only properties, lifts definitions into property types, and extracts enums.
func RegistryURLForRegion ¶
RegistryURLForRegion returns the registry schema URL for the given AWS region.
Types ¶
type Constraint ¶ added in v1.3.0
type Constraint struct {
// Name is an identifier for the constraint (e.g. "IfThen_0", "DependentRequired_KeyName").
Name string
// Type is the constraint category.
Type ConstraintType
// Condition holds the conditional part of the constraint (for if/then) as raw JSON.
Condition json.RawMessage
// Requirement holds the requirement part of the constraint as raw JSON.
Requirement json.RawMessage
}
Constraint represents a typed cross-property constraint.
func ExtractConstraints ¶ added in v1.3.0
func ExtractConstraints(schema *ResourceSchema) []Constraint
ExtractConstraints walks the schema's Extensions and AllOf fields to extract all cross-property constraints as typed Constraint objects.
type ConstraintType ¶ added in v1.3.0
type ConstraintType string
ConstraintType represents the category of cross-property constraint.
const ( // ConstraintIfThen represents an if/then conditional constraint. ConstraintIfThen ConstraintType = "if_then" // ConstraintDependentExcluded represents a dependentRequired constraint. ConstraintDependentExcluded ConstraintType = "dependent_required" // ConstraintRequiredOr represents a requiredOr constraint (at least one). ConstraintRequiredOr ConstraintType = "required_or" // ConstraintRequiredXor represents a requiredXor constraint (exactly one). ConstraintRequiredXor ConstraintType = "required_xor" )
type FetchOptions ¶
type FetchOptions struct {
// Region is the AWS region. Defaults to "us-east-1".
Region string
// URL overrides the download URL. If set, Region is ignored.
URL string
// Force re-download even if cached.
Force bool
// CacheDir is the directory to cache the downloaded schemas.
// Defaults to system temp dir.
CacheDir string
// MaxAge is the maximum age of the cached schemas before re-downloading.
// If zero, the cache never expires (unless Force is true).
MaxAge time.Duration
// Quiet suppresses progress output.
Quiet bool
}
FetchOptions configures how registry schemas are fetched.
type Handler ¶
type Handler struct {
Permissions []string `json:"permissions,omitempty"`
}
Handler describes a CRUD handler and its required permissions.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager provides thread-safe access to CloudFormation Registry Schemas. It lazily loads schemas on first access and caches them.
func DefaultManager ¶
func DefaultManager() *Manager
DefaultManager returns a shared Manager that uses embedded schemas.
func NewManager ¶
NewManager creates a new registry Manager with the given options. If opts.UseEmbed is not explicitly set (zero value), it defaults to true.
func (*Manager) GetResourceSchema ¶
func (m *Manager) GetResourceSchema(typeName string) (*ResourceSchema, error)
GetResourceSchema returns the registry schema for a CloudFormation resource type. Returns nil if the resource type is not found.
func (*Manager) GetResourceSchemaWithFallback ¶ added in v1.3.0
func (m *Manager) GetResourceSchemaWithFallback(typeName string) (*ResourceSchema, error)
GetResourceSchemaWithFallback returns the registry schema for a CloudFormation resource type. If the resource type is not found in the registry, it checks the fallback schemas. Returns nil if the resource type is not found in either location.
func (*Manager) HasResourceSchema ¶
HasResourceSchema returns true if a registry schema exists for the resource type.
func (*Manager) ResourceTypeNames ¶
ResourceTypeNames returns sorted list of all resource type names.
type Options ¶
type Options struct {
// Region is the AWS region for fetching schemas. Defaults to "us-east-1".
Region string
// CacheDir is the directory for caching downloaded schemas.
CacheDir string
// UseEmbed loads schemas from the embedded filesystem (default true).
// Set to false to force downloading from AWS.
UseEmbed bool
}
Options configures the registry Manager.
type ResourceSchema ¶
type ResourceSchema struct {
// TypeName is the CloudFormation resource type (e.g. "AWS::Lambda::Function").
TypeName string `json:"typeName"`
// Description of the resource type.
Description string `json:"description,omitempty"`
// Properties maps property names to their schema definitions.
Properties map[string]*SchemaProperty `json:"properties,omitempty"`
// Definitions contains reusable sub-schemas referenced via $ref.
Definitions map[string]*SchemaProperty `json:"definitions,omitempty"`
// Required lists property names that must be present.
Required []string `json:"required,omitempty"`
// ReadOnlyProperties lists JSON pointer paths to read-only properties (e.g. "/properties/Arn").
ReadOnlyProperties []string `json:"readOnlyProperties,omitempty"`
// CreateOnlyProperties lists JSON pointer paths to create-only (immutable) properties.
CreateOnlyProperties []string `json:"createOnlyProperties,omitempty"`
// WriteOnlyProperties lists JSON pointer paths to write-only properties.
WriteOnlyProperties []string `json:"writeOnlyProperties,omitempty"`
// PrimaryIdentifier lists JSON pointer paths that form the primary key.
PrimaryIdentifier []string `json:"primaryIdentifier,omitempty"`
// AdditionalIdentifiers lists alternative identifier sets.
AdditionalIdentifiers [][]string `json:"additionalIdentifiers,omitempty"`
// DependentRequired maps a property to other properties that must also be present.
DependentRequired map[string][]string `json:"dependentRequired,omitempty"`
// OneOf defines sets where exactly one sub-schema must match.
OneOf []*SchemaProperty `json:"oneOf,omitempty"`
// AnyOf defines sets where at least one sub-schema must match.
AnyOf []*SchemaProperty `json:"anyOf,omitempty"`
// AllOf defines sets where all sub-schemas must match.
AllOf []*SchemaProperty `json:"allOf,omitempty"`
// Tagging describes the resource's tagging support.
Tagging *TaggingInfo `json:"tagging,omitempty"`
// Handlers describes the CRUD handlers for the resource.
Handlers map[string]*Handler `json:"handlers,omitempty"`
// AdditionalProperties controls whether extra properties are allowed.
// In top-level schemas this is typically false.
AdditionalProperties any `json:"additionalProperties,omitempty"`
// SourceUrl is the URL to the resource type's source code.
SourceUrl string `json:"sourceUrl,omitempty"`
// DocumentationUrl is the URL to the resource type's documentation.
DocumentationUrl string `json:"documentationUrl,omitempty"`
// Extensions contains embedded extension schema fragments for this resource type.
Extensions []*SchemaProperty `json:"-"`
}
ResourceSchema is the top-level schema for a CloudFormation resource type. It corresponds to a single JSON file from the registry schema ZIP.
func (*ResourceSchema) ResolveProperty ¶
func (rs *ResourceSchema) ResolveProperty(path string) *SchemaProperty
ResolveProperty resolves a dot-separated property path (e.g. "Code.S3Bucket") through nested properties, following $ref pointers as needed. Returns nil if the path cannot be resolved.
type SchemaProperty ¶
type SchemaProperty struct {
// Type is the JSON Schema type. Can be a string ("string") or array (["string", "null"]).
Type any `json:"type,omitempty"`
// Ref is a JSON Schema $ref pointer (e.g. "#/definitions/Tag").
Ref string `json:"$ref,omitempty"`
// Description of the property.
Description string `json:"description,omitempty"`
// Pattern is a regex the string value must match.
Pattern string `json:"pattern,omitempty"`
// MinLength is the minimum string length.
MinLength *int `json:"minLength,omitempty"`
// MaxLength is the maximum string length.
MaxLength *int `json:"maxLength,omitempty"`
// Minimum is the minimum numeric value (inclusive).
Minimum *float64 `json:"minimum,omitempty"`
// Maximum is the maximum numeric value (inclusive).
Maximum *float64 `json:"maximum,omitempty"`
// ExclusiveMinimum is the exclusive minimum numeric value.
ExclusiveMinimum *float64 `json:"exclusiveMinimum,omitempty"`
// ExclusiveMaximum is the exclusive maximum numeric value.
ExclusiveMaximum *float64 `json:"exclusiveMaximum,omitempty"`
// Enum lists allowed values.
Enum []any `json:"enum,omitempty"`
// Const specifies a single allowed value.
Const any `json:"const,omitempty"`
// Default specifies the default value.
Default any `json:"default,omitempty"`
// Format specifies a semantic format (e.g. "uri", "date-time").
Format string `json:"format,omitempty"`
// MinItems is the minimum array length.
MinItems *int `json:"minItems,omitempty"`
// MaxItems is the maximum array length.
MaxItems *int `json:"maxItems,omitempty"`
// UniqueItems requires array items to be unique.
UniqueItems bool `json:"uniqueItems,omitempty"`
// Items is the schema for array items.
Items *SchemaProperty `json:"items,omitempty"`
// PrefixItems defines ordered schemas for the first N array elements.
PrefixItems []*SchemaProperty `json:"prefixItems,omitempty"`
// Properties maps nested property names to their schemas (for object types).
Properties map[string]*SchemaProperty `json:"properties,omitempty"`
// Required lists required nested property names.
Required []string `json:"required,omitempty"`
// AdditionalProperties controls extra properties. Can be bool or a sub-schema.
AdditionalProperties any `json:"additionalProperties,omitempty"`
// InsertionOrder indicates whether array item order matters.
InsertionOrder *bool `json:"insertionOrder,omitempty"`
// ReadOnly indicates the property is read-only.
ReadOnly bool `json:"readOnly,omitempty"`
// OneOf defines sets where exactly one sub-schema must match.
OneOf []*SchemaProperty `json:"oneOf,omitempty"`
// AnyOf defines sets where at least one sub-schema must match.
AnyOf []*SchemaProperty `json:"anyOf,omitempty"`
// AllOf defines sets where all sub-schemas must match.
AllOf []*SchemaProperty `json:"allOf,omitempty"`
// Not defines a sub-schema that must not match.
Not *SchemaProperty `json:"not,omitempty"`
// Definitions can appear in sub-schemas too (rare).
Definitions map[string]*SchemaProperty `json:"definitions,omitempty"`
// DependentRequired maps a property to others that must be present with it.
DependentRequired map[string][]string `json:"dependentRequired,omitempty"`
// If defines the condition for conditional schema evaluation.
If *SchemaProperty `json:"if,omitempty"`
// Then defines the schema to apply if the "if" condition is satisfied.
Then *SchemaProperty `json:"then,omitempty"`
// Else defines the schema to apply if the "if" condition is not satisfied.
Else *SchemaProperty `json:"else,omitempty"`
// RequiredOr is a cfn-lint custom keyword for "at least one of" validation.
RequiredOr []string `json:"requiredOr,omitempty"`
// RequiredXor is a cfn-lint custom keyword for "exactly one of" validation.
RequiredXor []string `json:"requiredXor,omitempty"`
// UniqueKeys is a cfn-lint custom keyword for specifying unique key combinations.
UniqueKeys [][]string `json:"uniqueKeys,omitempty"`
// PropertyNames defines a schema that all property names must match.
PropertyNames *SchemaProperty `json:"propertyNames,omitempty"`
}
SchemaProperty defines a single property in a registry schema. It maps JSON Schema Draft-07 fields plus CloudFormation extensions.
func (*SchemaProperty) GetPropertyType ¶
func (sp *SchemaProperty) GetPropertyType() []string
GetPropertyType normalizes the Type field to a string slice. JSON Schema allows type to be "string" or ["string", "null"].
type TaggingInfo ¶
type TaggingInfo struct {
Taggable bool `json:"taggable"`
TagOnCreate bool `json:"tagOnCreate"`
TagUpdatable bool `json:"tagUpdatable"`
CloudFormationSystemTags bool `json:"cloudFormationSystemTags"`
TagProperty string `json:"tagProperty,omitempty"`
Permissions []string `json:"permissions,omitempty"`
}
TaggingInfo describes a resource's tagging support.