schema

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2016 License: MIT Imports: 8 Imported by: 26

Documentation

Index

Constants

View Source
const (
	LongID  bool = true
	ShortID      = false
)

Variables

View Source
var ARN = FuncType{
	Description: "ARN",

	Fn: func(value interface{}, ctx PropertyContext) (reporting.ValidateResult, reporting.Reports) {
		if result, errs := ValueString.Validate(value, ctx); result == reporting.ValidateAbort || errs != nil {
			return reporting.ValidateOK, errs
		}

		return reporting.ValidateOK, nil
	},
}
View Source
var AllocationID = newResourceID("EipAllocationID", "eipalloc", ShortID)
View Source
var AvailabilityZone = EnumValue{
	Description: "Availability Zone",

	Options: []string{
		"ap-northeast-1a",
		"ap-northeast-1b",
		"ap-northeast-1c",
		"ap-northeast-2a",
		"ap-northeast-2c",
		"ap-southeast-1a",
		"ap-southeast-1b",
		"ap-southeast-2a",
		"ap-southeast-2b",
		"eu-central-1a",
		"eu-central-1b",
		"eu-west-1a",
		"eu-west-1b",
		"eu-west-1c",
		"sa-east-1a",
		"sa-east-1b",
		"sa-east-1c",
		"us-east-1a",
		"us-east-1b",
		"us-east-1c",
		"us-east-1d",
		"us-east-1e",
		"us-west-1a",
		"us-west-1c",
		"us-west-2a",
		"us-west-2b",
		"us-west-2c",
	},
}
View Source
var CIDR = ConstrainedString(
	"CIDR",
	func(value string, ctx PropertyContext) reporting.Reports {
		if ok, _ := regexp.MatchString(cidrPattern, value); !ok {
			return reporting.Reports{reporting.NewFailure(ctx, "Cidr %s is invalid", value)}
		}

		return nil
	},
)
View Source
var HostedZoneID = ConstrainedString(
	"HostedZoneID",

	func(value string, ctx PropertyContext) reporting.Reports {

		return nil
	},
)
View Source
var IPAddress = ConstrainedString(
	"IPAddress",
	func(value string, ctx PropertyContext) reporting.Reports {
		if !ipAddressRegex.MatchString(value) {
			return reporting.Reports{
				reporting.NewFailure(ctx, "Value '%s' is not a valid IPv4 address", value),
			}
		}

		return nil
	},
)
View Source
var ImageID = newResourceID("AMI", "ami", ShortID)
View Source
var InstanceID = newResourceID("InstanceID", "i", LongID)
View Source
var InternetGatewayID = newResourceID("InternetGatewayID", "igw", ShortID)
View Source
var KeyName = ConstrainedString(
	"KeyName",
	func(value string, ctx PropertyContext) reporting.Reports {

		return nil
	},
)
View Source
var NatGatewayID = newResourceID("NatGatewayID", "nat", LongID)
View Source
var NetworkAclID = newResourceID("NetworkAclID", "acl", ShortID)
View Source
var NetworkInterfaceID = newResourceID("NetworkInterfaceID", "eni", ShortID)
View Source
var Period = ConstrainedString(
	"Period",
	func(value string, ctx PropertyContext) reporting.Reports {
		num, err := strconv.Atoi(value)
		if err != nil {
			return reporting.Reports{reporting.NewFailure(ctx, "Period is not a number: %s", value)}
		}

		if num == 0 || num%60 != 0 {
			return reporting.Reports{reporting.NewFailure(ctx, "Period is not a multiple of 60: %s", value)}
		}

		return nil
	},
)
View Source
var RouteTableID = newResourceID("RouteTableID", "rtb", ShortID)
View Source
var SecurityGroupID = newResourceID("SecurityGroupID", "sg", ShortID)
View Source
var SecurityGroupName = ConstrainedString(
	"SecurityGroupName",
	func(value string, ctx PropertyContext) reporting.Reports {

		return nil
	},
)
View Source
var SnapshotID = newResourceID("SnapshotID", "vol", LongID)
View Source
var SubnetID = newResourceID("SubnetID", "subnet", ShortID)

SupportedFunctionsAll deliberately excludes Condition, because it isn't valid anywhere except nested in other conditions (and they cater for it explicitly)

View Source
var Timestamp = ConstrainedString(
	"Timestamp",
	func(value string, ctx PropertyContext) reporting.Reports {
		if ok, _ := regexp.MatchString(cidrPattern, value); !ok {
			return reporting.Reports{reporting.NewFailure(ctx, "Timestamp %s is invalid", value)}
		}

		return nil
	},
)
View Source
var VolumeID = newResourceID("VolumeID", "vol", LongID)
View Source
var VpcID = newResourceID("VpcID", "vpc", ShortID)
View Source
var VpcPeeringConnectionID = newResourceID("VpcPeeringConnectionID", "pcx", ShortID)
View Source
var VpnConnectionID = newResourceID("VpnConnectionID", "vpn", ShortID)
View Source
var VpnGatewayID = newResourceID("VpnGatewayID", "vgw", ShortID)

Functions

func TemplateValidate

func TemplateValidate(template *parse.Template, definitions ResourceDefinitions, options ValidationOptions) (bool, reporting.Reports)

func ValidateIntrinsicFunctions added in v0.2.0

func ValidateIntrinsicFunctions(value parse.IntrinsicFunction, ctx PropertyContext, supportedFunctions SupportedFunctions) (reporting.ValidateResult, reporting.Reports)

Types

type ArrayPropertyType added in v0.2.0

type ArrayPropertyType struct {
	PropertyType
}

func (ArrayPropertyType) CoercibleTo added in v0.2.0

func (pt ArrayPropertyType) CoercibleTo(to PropertyType) Coercion

func (ArrayPropertyType) Describe added in v0.2.0

func (pt ArrayPropertyType) Describe() string

func (ArrayPropertyType) Same added in v0.2.0

func (pt ArrayPropertyType) Same(to PropertyType) bool

func (ArrayPropertyType) Unwrap added in v0.2.0

func (apt ArrayPropertyType) Unwrap() PropertyType

type Coercion

type Coercion string
const (
	CoercionNever        Coercion = "never"
	CoercionAlways       Coercion = "always"
	CoercionBegrudgingly Coercion = "begrudgingly"
)

type Context

type Context interface {
	Options() ValidationOptions
	Definitions() ResourceDefinitions
	Path() []string
	Template() *parse.Template
}

func ContextAdd

func ContextAdd(ctx Context, path ...string) Context

func NewInitialContext

func NewInitialContext(template *parse.Template, definitions ResourceDefinitions, options ValidationOptions) Context

type EnumValue

type EnumValue struct {
	Description string
	Options     []string
}

func (EnumValue) CoercibleTo

func (from EnumValue) CoercibleTo(to PropertyType) Coercion

func (EnumValue) Describe

func (enum EnumValue) Describe() string

func (EnumValue) IsArray added in v0.2.0

func (EnumValue) IsArray() bool

func (EnumValue) PropertyDefault

func (EnumValue) PropertyDefault(string) (interface{}, bool)

func (EnumValue) Same added in v0.2.0

func (from EnumValue) Same(to PropertyType) bool

func (EnumValue) Validate

func (enum EnumValue) Validate(value interface{}, ctx PropertyContext) (reporting.ValidateResult, reporting.Reports)

type FuncType

type FuncType struct {
	Description string
	Fn          func(value interface{}, ctx PropertyContext) (reporting.ValidateResult, reporting.Reports)
	CoercibleFn func(PropertyType) Coercion
}
var JSON FuncType

func (FuncType) CoercibleTo

func (from FuncType) CoercibleTo(to PropertyType) Coercion

func (FuncType) Describe

func (ft FuncType) Describe() string

func (FuncType) IsArray added in v0.2.0

func (FuncType) IsArray() bool

func (FuncType) PropertyDefault

func (FuncType) PropertyDefault(string) (interface{}, bool)

func (FuncType) Same added in v0.2.0

func (from FuncType) Same(to PropertyType) bool

func (FuncType) String

func (ft FuncType) String() string

func (FuncType) Validate

func (ft FuncType) Validate(value interface{}, ctx PropertyContext) (reporting.ValidateResult, reporting.Reports)

type IntrinsicFunctionValidate added in v0.2.0

type IntrinsicFunctionValidate func(value parse.IntrinsicFunction, ctx PropertyContext) reporting.Reports

type NestedResource

type NestedResource struct {
	Description string
	Properties  ValidatableProperties
}

func (NestedResource) AwsType added in v0.2.0

func (res NestedResource) AwsType() string

func (NestedResource) CoercibleTo

func (NestedResource) CoercibleTo(PropertyType) Coercion

func (NestedResource) Describe

func (res NestedResource) Describe() string

func (NestedResource) IsArray added in v0.2.0

func (NestedResource) IsArray() bool

func (NestedResource) PropertyDefault added in v0.2.0

func (res NestedResource) PropertyDefault(name string) (interface{}, bool)

func (NestedResource) Same added in v0.2.0

func (res NestedResource) Same(to PropertyType) bool

func (NestedResource) Validate

func (res NestedResource) Validate(value interface{}, ctx PropertyContext) (reporting.ValidateResult, reporting.Reports)

TODO: This is all a bit hairy. We shouldn't need to be creating the

TemplateNestedResource here, ideally `self` should already refer to
one and value should already be a map[string]inteface{}

type Properties

type Properties map[string]Schema

func (Properties) PropertyDefault

func (p Properties) PropertyDefault(name string) (interface{}, bool)

func (Properties) Validate

func (p Properties) Validate(ctx ResourceContext) reporting.Reports

type PropertyContext

type PropertyContext interface {
	Options() ValidationOptions
	CurrentResource() constraints.CurrentResource
	Definitions() ResourceDefinitions
	Path() []string
	Property() Schema
	Template() *parse.Template
}

func NewPropertyContext

func NewPropertyContext(ctx ResourceContext, property Schema) PropertyContext

func PropertyContextAdd

func PropertyContextAdd(ctx PropertyContext, path ...string) PropertyContext

type PropertyDefaults

type PropertyDefaults interface {
	PropertyDefault(name string) (interface{}, bool)
}

type PropertyType

type PropertyType interface {
	// Describe returns a human-readable description of the type in AWS, which
	// could be the AWS Resource Type or just any arbitrary description.
	Describe() string

	// Same returns true when two PropertyTypes represent the same AWS type.
	Same(PropertyType) bool

	// Validate checks that the property is valid, including any built-in function
	// calls and stuff within the property.
	Validate(value interface{}, ctx PropertyContext) (reporting.ValidateResult, reporting.Reports)

	// CoercibleTo will return true for types which the value of this property can
	// be coerced into. e.g. A number can be coerced to a string
	// CoercionAlways means a type is always coercible to another
	// 	 e.g. all numbers are valid strings
	// CoercionNever means a type is never coercible to another
	//   e.g. a number is never a valid bool
	// CoercionBegrudgingly means a type can be coerced but results may vary
	//   e.g. a string can be coerced to a number, but only if it is numerically
	//        valid.
	//
	// CoerceAlways and CoercionBegrudgingly are equivalent right now, but in
	// future a warning may be issued for begrudging conversions.
	CoercibleTo(PropertyType) Coercion

	// PropertyDefault returns the default value for a property, if one is set.
	PropertyDefault(name string) (interface{}, bool)
}

func ConstrainedString added in v0.3.0

func ConstrainedString(description string, fn constrainedStringValidate) PropertyType

func Multiple added in v0.2.0

func Multiple(pt PropertyType) PropertyType

type RefTarget

type RefTarget interface {
	TargetType() PropertyType
}

type Resource

type Resource struct {
	AwsType      string
	Attributes   map[string]Schema
	Properties   ValidatableProperties
	ReturnValue  Schema
	ValidateFunc func(ResourceContext) (reporting.ValidateResult, reporting.Reports)
}

func NewUnrecognisedResource

func NewUnrecognisedResource(awsType string) Resource

func (Resource) PropertyDefault added in v0.2.0

func (rd Resource) PropertyDefault(name string) (interface{}, bool)

func (Resource) TargetType

func (rd Resource) TargetType() PropertyType

func (Resource) Validate

type ResourceContext

type ResourceContext interface {
	Options() ValidationOptions
	CurrentResource() constraints.CurrentResource
	Definitions() ResourceDefinitions
	Path() []string
	Template() *parse.Template
}

func NewResourceContext

func NewResourceContext(ctx Context, currentResource constraints.CurrentResource) ResourceContext

func ResourceContextAdd

func ResourceContextAdd(ctx ResourceContext, path ...string) ResourceContext

type ResourceDefinitions

type ResourceDefinitions interface {
	Lookup(awsType string) Resource
	LookupParameter(awsType string) Schema
}

func NewResourceDefinitions

func NewResourceDefinitions(definitions map[string]Resource) ResourceDefinitions

type ResourceWithDefinition

type ResourceWithDefinition struct {
	parse.TemplateResource
	PropertyDefaults
}

func (ResourceWithDefinition) AwsType added in v0.2.0

func (r ResourceWithDefinition) AwsType() string

func (ResourceWithDefinition) Id added in v0.2.0

func (ResourceWithDefinition) PropertyValueOrDefault

func (r ResourceWithDefinition) PropertyValueOrDefault(name string) (interface{}, bool)

type Schema

type Schema struct {
	// Conflicts is an array of property names which cannot also be specified when
	// this property is too.
	Conflicts constraints.Constraint

	// Default is the AWS default value for this property; this is used for
	// validations when the property isn't specified
	//
	// e.g. prop X must be set to false when prop Y is true, if prop Y unspecified
	// but has a Default of true then this validation can safely fail.
	Default interface{}

	// Deprecated indicates that this property has been deprecated and should no
	// longer be used (although may still work for an indeterimate amount of time)
	// Some properties are replaced by others, or separate resources.
	Deprecated deprecations.Deprecation

	// Required is set to true if this property must have a value in the template
	Required constraints.Constraint

	// Type is the type of the Value this property is expected to contain. For
	// example "String", "Number", "JSON", or nested resources such as Tags.
	Type PropertyType

	// ValidateFunc can be used to supply a custom validation function for a
	// property for applying further validation on top of basic type checks.
	//
	// e.g. prop X must be set to false when prop Y is true
	ValidateFunc ValidateFunc
}

A Schema defines the qualities and behaviour of a property.

func (Schema) TargetType

func (s Schema) TargetType() PropertyType

func (Schema) Validate

func (s Schema) Validate(value interface{}, ctx ResourceContext) (reporting.ValidateResult, reporting.Reports)

type SupportedFunctions added in v0.2.0

type SupportedFunctions map[parse.IntrinsicFunctionSignature]bool

type UnsupportedProperties added in v0.2.0

type UnsupportedProperties struct{}

UnsupportedProperties is a convinience type to give less intrusive errors for resource types we haven't implemented yet. People will get one "unsupported" warning per-resource, rather than lots of "unknown property" errors.

func (UnsupportedProperties) PropertyDefault added in v0.2.0

func (UnsupportedProperties) PropertyDefault(name string) (interface{}, bool)

func (UnsupportedProperties) Validate added in v0.2.0

type ValidatableProperties added in v0.2.0

type ValidatableProperties interface {
	PropertyDefault(string) (interface{}, bool)
	Validate(ResourceContext) reporting.Reports
	// contains filtered or unexported methods
}

ValidatableProperties is a wrapper around Properties to allow us to support undefined or unsupported properties

type ValidateFunc

type ValidateFunc func(interface{}, PropertyContext) (reporting.ValidateResult, reporting.Reports)

func FixedArrayValidate

func FixedArrayValidate(options ...[]string) ValidateFunc

TODO: fixme

func IntegerRangeValidate

func IntegerRangeValidate(start, end float64) ValidateFunc

func NumberOptions

func NumberOptions(numbers ...float64) ValidateFunc

func RegexpValidate

func RegexpValidate(pattern, message string) ValidateFunc

func SingleValueValidate

func SingleValueValidate(expected interface{}) ValidateFunc

func StringLengthValidate

func StringLengthValidate(min, max int) ValidateFunc

type ValidateOption added in v0.2.0

type ValidateOption int
const (
	OptionExperimentDisableObjectArrayCoercion ValidateOption = iota
)

func (ValidateOption) String added in v0.2.0

func (i ValidateOption) String() string

type ValidationOptions added in v0.2.0

type ValidationOptions map[ValidateOption]bool

type ValueType

type ValueType int
const (
	ValueUnknown ValueType = iota
	ValueString
	ValueBool
	ValueNumber
)

func (ValueType) CoercibleTo

func (from ValueType) CoercibleTo(to PropertyType) Coercion

TODO: This really feels like it can be simplified

func (ValueType) Describe

func (vt ValueType) Describe() string

func (ValueType) IsArray added in v0.2.0

func (t ValueType) IsArray() bool

func (ValueType) PropertyDefault

func (ValueType) PropertyDefault(string) (interface{}, bool)

func (ValueType) Same added in v0.2.0

func (from ValueType) Same(to PropertyType) bool

func (ValueType) String

func (i ValueType) String() string

func (ValueType) Validate

func (vt ValueType) Validate(value interface{}, ctx PropertyContext) (reporting.ValidateResult, reporting.Reports)

Jump to

Keyboard shortcuts

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