model

package
v0.0.0-...-9dcacef Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	// Path is a "field path" that indicates where the field's value can be
	// found within the Resource.
	Path *fieldpath.Path `json:"-"` // ignored in JSON as map keys are paths
	// Config contains the configuration options for this field
	Config *config.FieldConfig `json:"-"`
	// Definition contains metadata about the field's type
	Definition *FieldDefinition
}

Field represents a single field in the Resource's Schema.

func NewField

func NewField(
	path *fieldpath.Path,
	cfg *config.FieldConfig,
	def *FieldDefinition,
) *Field

NewField returns an initialized Field from a field path, configuration and FieldDefinition. We normalize each part of the supplied field path, so for example, "RegistryId" becomes "RegistryID" and "EncryptionConfig.KmsKeyId" becomes "EncryptionConfig.KMSKeyID".

func (*Field) Names

func (f *Field) Names() names.Names

Names returns the set of normalized name variations for the field

type FieldDefinition

type FieldDefinition struct {
	// Type is the underlying type of the field.
	Type schema.FieldType `json:"type"`
	// ElementType is 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 schema.FieldType `json:"element_type,omitempty"`
	// ValueType is 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 schema.FieldType `json:"value_type,omitempty"`
	// KeyType is 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 schema.FieldType `json:"key_type,omitempty"`
	// MemberFieldDefinitions is a map, keyed by member field name, of nested
	// FieldDefinitions when this Field has a Type of FieldTypeStruct. Returns
	// nil when Type is not FieldTypeStruct.
	MemberFieldDefinitions map[string]*FieldDefinition `json:"member_field_definitions,omitempty"`
	// IsRequired is true if the field is required to be set by the user
	IsRequired bool `json:"is_required,omitempty"`
	// IsReadOnly is true if the field is not settable by the user
	IsReadOnly bool `json:"is_read_only,omitempty"`
	// IsImmutable is true if the field cannot be changed once set
	IsImmutable bool `json:"is_immutable,omitempty"`
	// IsLateInitialized is true if the field is "late initialized"
	// with a service-side default value
	IsLateInitialized bool `json:"is_late_initialized,omitempty"`
	// IsSecret is true if the field contains secret information
	IsSecret bool `json:"is_secret,omitempty"`
	// References contains 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 `json:"references,omitempty"`
}

FieldDefinition represents a type of Field in a Resource's Schema. Note that multiple Fields can have the same FieldDefinition but will never have the same FieldDefinition *and* Path.

type Kind

type Kind struct {
	// CloudProvider contains the short name of the cloud provider exposing
	// this type of Resource
	CloudProvider string
	// ServiceName contains the short name of the service exposing this type of
	// Resource
	Service string
	// Name contains the camel-cased name of the resource (i.e. the Kind, in
	// Kubernetes speak).
	//
	// Note that the combination of CloudProvider, Service and Name is a unique
	// identifier for this type of Resource.
	Name string
	// PluralName contains the camel-cased name of the pluralized resource.
	//
	// Note that the combination of CloudProvider, Service and PluralName is a
	// unique identifier for this type of Resource.
	PluralName string
}

Kind describes a provider-specific, service-specific type of Resource

func NewKind

func NewKind(
	cloudProvider string,
	service string,
	name string,
) Kind

NewKind returns a new Kind that describes the type of a single top-level resource in a cloud service API

type ResourceDefinition

type ResourceDefinition struct {
	// Config contains the resource-specific configuration options
	Config *config.ResourceConfig `json:"-"`
	// Kind is the type of Resource
	Kind Kind
	// Fields is a map, keyed by the **field path**, of Field objects
	// representing a field in the Resource.
	Fields map[string]*Field
}

ResourceDefinition describes a single top-level resource in a cloud service API

func NewResourceDefinition

func NewResourceDefinition(
	cfg *config.ResourceConfig,
	kind Kind,
) *ResourceDefinition

NewResourceDefinition returns a pointer to a new ResourceDefinition that describes a single top-level resource in a cloud service API. Add fields to the ResourceDefinition by calling the AddField method.

func (*ResourceDefinition) AddField

func (d *ResourceDefinition) AddField(f *Field)

AddField adds a new Field to the resource definition at the supplied field path

func (*ResourceDefinition) GetField

func (d *ResourceDefinition) GetField(path *fieldpath.Path) *Field

GetField returns a Field given a field path. The search is case-insensitive

func (*ResourceDefinition) GetFieldPaths

func (d *ResourceDefinition) GetFieldPaths() []*fieldpath.Path

FieldPaths returns a sorted list of field paths for this resource.

Jump to

Keyboard shortcuts

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