schema

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2023 License: Apache-2.0 Imports: 3 Imported by: 2

README

types/resource/schema

The types/resource/schema package contains interfaces that allow callers to understand the schema of a resource

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field interface {
	// Type returns the underlying type of the field.
	Type() FieldType
	// ElementType returns the type of the list's elements.
	//
	// If Type is FieldTypeList, the ElementType() method is guaranteed to
	// return the type of the list element. If Type is not FieldTypeList,
	// ElementType is guaranteed to be FieldTypeNil.
	ElementType() FieldType
	// ValueType returns the type of the map's values.
	//
	// If Type is FieldTypeMap, the ValueType() method is guaranteed to return
	// the type of the map values. If Type is not FieldTypeMap, ValueType will
	// always return FieldTypeNil
	ValueType() FieldType
	// KeyType returns the type of the map's keys.
	//
	// If Type is FieldTypeMap, the KeyType() method is guaranteed to return
	// the type of the map keys. If Type is not FieldTypeMap, KeyType will
	// always return FieldTypeNil
	KeyType() FieldType
	// MemberFields returns a map, keyed by member field name, of nested Fields
	// when this Field has a Type of FieldTypeStruct. Returns nil when Type is
	// not FieldTypeStruct.
	MemberFields() map[string]Field
	// IsRequired returns true if the field is required to be set by the user
	IsRequired() bool
	// IsReadOnly returns true if the field is not settable by the user
	IsReadOnly() bool
	// IsImmutable returns true if the field cannot be changed once set
	IsImmutable() bool
	// IsLateInitialized returns true if the field is "late initialized"
	// with a service-side default value
	IsLateInitialized() bool
	// IsSecret returns true if the field contains secret information
	IsSecret() bool
	// References returns the Kind for a referred type if the field contains a
	// reference to another resource, or nil otherwise.
	//
	// For example, consider a Resource `rds.aws/DBInstance` with a field
	// `Subnets`. This field contains EC2 VPC Subnet identifiers. The Type() of
	// this field would be FieldTypeList. The ElementType() of this field would
	// be FieldTypeString. The References() of this field would return a Kind
	// containing "ec2.aws/Subnet".
	References() Kind
}

Field has methods that return information about a field in a resource.

type FieldType

type FieldType int

FieldType indicates the underlying Go builtin type for a Field.

const (
	// FieldTypeUnknown is a placeholder for an unknown field type
	FieldTypeUnknown FieldType = iota
	// FieldTypeNil is a placeholder for a nil type
	FieldTypeNil
	// FieldTypeInt is for integer types
	FieldTypeInt
	// FieldTypeBool is for boolean types
	FieldTypeBool
	// FieldTypeFloat is for float/double types
	FieldTypeFloat
	// FieldTypeTime is for time.Time types
	FieldTypeTime
	// FieldTypeString is for string types
	FieldTypeString
	// FieldTypeList is for list/slice types
	FieldTypeList
	// FieldTypeMap is for map[string]interface{} types
	FieldTypeMap
	// FieldTypeStruct is for (nested) struct types
	FieldTypeStruct
)

func StringToFieldType

func StringToFieldType(s string) FieldType

StringToFieldType converts a string into the associated FieldType. Uses case-insensitive matching.

func (FieldType) EnumString added in v0.0.3

func (t FieldType) EnumString() string

EnumString returns the stringified field type enum name, mainly useful for templates.

func (*FieldType) MarshalJSON added in v0.0.5

func (t *FieldType) MarshalJSON() ([]byte, error)

MarshalJSON converts the integer representation of the field type into a string.

func (FieldType) String added in v0.0.2

func (t FieldType) String() string

String returns the stringified field type

func (*FieldType) UnmarshalJSON added in v0.0.5

func (t *FieldType) UnmarshalJSON(data []byte) error

UnmarshalJSON converts the string representation into the enum/integer representation of the field type

type Identifiers

type Identifiers interface {
	// Fields returns an ordered slice of slices of Fields that contain values
	// that can be used to uniquely identify the resource.
	//
	// The returned slice is sorted by efficiency of fetch operation. For
	// example, assume an S3 Bucket resource. It may be identified by ARN or by
	// Bucket Location in addition to the Bucket's Name field, which happens to
	// be globally-unique, so the returned value from Fields() would be:
	//
	// [][]Field{
	//   {Field("ARN")},
	//   {Field("Location")},
	//   {Field("Name")},
	// }
	//
	// For something like an RDS DBInstance, the DB instance's ARN is a
	// globally unique identifier, but the instance's DBInstanceIdentifier
	// field is only unique when coupled with the customer's AWS Account and
	// Region. So, the returned value from Fields() would be:
	//
	// [][]Field{
	//   {Field("ARN")},
	//   {Field("DBInstanceIdentifier"), Field("CloudAccountID"), Field("CloudRegion")},
	// }
	Fields() [][]Field
}

Identifiers returns information about a resource's identifying fields and those fields' values.

type Kind

type Kind interface {
	// Service returns the name of the cloud service this resource is
	// associated with.
	//
	// For AWS resources, the string returned matches the service package name
	// in aws-sdk-go.
	Service() string
	// Name returns the camel-cased name of the resource (i.e. the Kind, in Kubernetes
	// speak).
	//
	// Note that the combination of Service and Name is a unique identifier for
	// this type of Resource.
	Name() string
	// PluralName returns camel-cased name of the pluralized resource.
	//
	// Note that the combination of Service and PluralName is a unique identifier for
	// this type of Resource.
	PluralName() string
}

Kind describes the type/kind of a Resource. It is similar to a GroupKind in Kubernetes.

type Schema

type Schema interface {
	Kind
	// Field returns a Field at a given field path, or nil if there is no Field
	// at that path.
	Field(*fieldpath.Path) Field
	// Fields returns a map, keyed by field path string, of Fields that
	// describe the resource's member fields.
	Fields() map[string]Field
	// Identifiers returns information about a resource's identifying fields
	// and those fields' values.
	Identifiers() Identifiers
}

Schema contains methods that returns information about a resource's schema.

Jump to

Keyboard shortcuts

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