config

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Default = Config{
	PrefixConfig: PrefixConfig{
		SpecField:   ".Spec",
		StatusField: ".Status",
	},
	IncludeACKMetadata:             true,
	SetManyOutputNotFoundErrReturn: "return nil, ackerr.NotFound",
}

Functions

This section is empty.

Types

type CompareConfig

type CompareConfig struct {
	// Ignore is a list of field paths to ignore when comparing two objects
	Ignore []string `json:"ignore"`
}

CompareConfig informs instruct the code generator on how to compare two different two objects of the same type

type Config

type Config struct {
	// Resources contains generator instructions for individual CRDs within an
	// API
	Resources map[string]ResourceConfig `json:"resources"`
	// CRDs to ignore. ACK generator would skip these resources.
	Ignore IgnoreSpec `json:"ignore"`
	// Contains generator instructions for individual API operations.
	Operations map[string]OperationConfig `json:"operations"`
	// PrefixConfig contains the prefixes to access certain fields in the generated
	// Go code.
	PrefixConfig PrefixConfig `json:"prefix_config,omitempty"`
	// IncludeACKMetadata lets you specify whether ACK Metadata should be included
	// in the status. Default is true.
	IncludeACKMetadata bool `json:"include_ack_metadata,omitempty"`
	// SetManyOutputNotFoundErrReturn is the return statement when generated
	// SetManyOutput function fails with NotFound error.
	// Default is "return nil, ackerr.NotFound"
	SetManyOutputNotFoundErrReturn string `json:"set_many_output_notfound_err_return,omitempty"`
}

Config represents instructions to the ACK code generator for a particular AWS service API

func New

func New(
	configPath string,
	defaultConfig Config,
) (Config, error)

New returns a new Config object given a supplied path to a config file

func (*Config) GetCompareIgnoredFields

func (c *Config) GetCompareIgnoredFields(resName string) []string

GetCompareIgnoredFields returns the list of field path to ignore when comparing two differnt objects

func (*Config) IsIgnoredOperation

func (c *Config) IsIgnoredOperation(operation *awssdkmodel.Operation) bool

IsIgnoredOperation returns true if Operation Name is configured to be ignored in generator config for the AWS service

func (*Config) IsIgnoredResource

func (c *Config) IsIgnoredResource(resourceName string) bool

IsIgnoredResource returns true if Operation Name is configured to be ignored in generator config for the AWS service

func (*Config) IsIgnoredShape

func (c *Config) IsIgnoredShape(shapeName string) bool

IsIgnoredShape returns true if the supplied shape name should be ignored by the code generator, false otherwise

func (*Config) ListOpMatchFieldNames

func (c *Config) ListOpMatchFieldNames(
	resName string,
) []string

ListOpMatchFieldNames returns a slice of strings representing the field names in the List operation's Output shape's element Shape that we should check a corresponding value in the target Spec exists.

func (*Config) OverrideValues

func (c *Config) OverrideValues(operationName string) (map[string]string, bool)

OverrideValues gives list of member values to override.

func (*Config) ResourceInputFieldRename

func (c *Config) ResourceInputFieldRename(
	resName string,
	opID string,
	origFieldName string,
) (string, bool)

ResourceInputFieldRename returns the renamed field for a Resource, a supplied Operation ID and original field name and whether or not a renamed override field name was found

func (*Config) SetAttributesSingleAttribute

func (c *Config) SetAttributesSingleAttribute(resourceName string) bool

SetAttributesSingleAttribute returns true if the supplied resource name has a SetAttributes operation that only actually changes a single attribute at a time. See: SNS SetTopicAttributes API call, which is entirely different from the SNS SetPlatformApplicationAttributes API call, which sets multiple attributes at once. :shrug:

func (*Config) SpecFieldConfigs

func (c *Config) SpecFieldConfigs(resourceName string) ([]*SpecFieldConfig, bool)

SpecFieldConfigs gives map of operation and their MemberFields to add to spec.

func (*Config) UnpacksAttributesMap

func (c *Config) UnpacksAttributesMap(resourceName string) bool

UnpacksAttributesMap returns true if the underlying API has Get{Resource}Attributes/Set{Resource}Attributes API calls that map real, schema'd fields to a raw `map[string]*string` for this resource (see SNS and SQS APIs)

type ExceptionsConfig

type ExceptionsConfig struct {
	// Codes is a map of HTTP status code to the name of the Exception shape
	// that corresponds to that HTTP status code for this resource
	Codes map[int]string `json:"codes"`
	// Set of aws exception codes that are terminal exceptions for this resource
	TerminalCodes []string `json:"terminal_codes"`
}

ExceptionsConfig contains instructions to the code generator about how to handle the exceptions for the operations on a resource. These instructions are necessary for those APIs where the API models do not contain any information about the HTTP status codes a particular exception has (or, like the EC2 API, where the API model has no information at all about error responses for any operation)

type FieldConfig

type FieldConfig struct {
	// IsReadOnly indicates the field's value can not be set by a Kubernetes
	// user; in other words, the field should go in the CR's Status struct
	IsReadOnly bool `json:"is_read_only"`
	// ContainsOwnerAccountID indicates the field contains the AWS Account ID
	// that owns the resource. This is a special field that we direct to
	// storage in the common `Status.ACKResourceMetadata.OwnerAccountID` field.
	ContainsOwnerAccountID bool `json:"contains_owner_account_id"`
}

FieldConfig contains instructions to the code generator about how to interpret the value of an Attribute and how to map it to a CRD's Spec or Status field

type GetAttributesInputConfig

type GetAttributesInputConfig struct {
	// Overrides is a map of structures instructing the code generator how to
	// handle the override of a particular field in the Input shape for the
	// GetAttributes operation. The map keys are the names of the field in the
	// Input shape to override.
	Overrides map[string]*MemberConstructorConfig `json:"overrides"`
}

GetAttributesInputConfig is used to instruct the code generator how to handle the GetAttributes API operation's Input shape.

type IgnoreSpec

type IgnoreSpec struct {
	// Set of operation IDs/names that should be ignored by the
	// generator when constructing SDK linkage
	Operations []string `json:"operations"`
	// Set of resource names that should be ignored by the
	// generator
	ResourceNames []string `json:"resource_names"`
	// Set of shapes to ignore when constructing API type definitions and
	// associated SDK code for structs that have these shapes as members
	ShapeNames []string `json:"shape_names"`
}

IgnoreSpec represents instructions to the ACK code generator to ignore operations, resources on an AWS service API

type ListOperationConfig

type ListOperationConfig struct {
	// MatchFields lists the names of fields in the Shape of the
	// list element in the List Operation's Output shape.
	MatchFields []string `json:"match_fields"`
}

ListOperationConfig contains instructions for the code generator to handle List operations for service APIs that have no built-in filtering ability and whose List Operation always returns all objects.

type MemberConstructorConfig

type MemberConstructorConfig struct {
	// Values contains the value or values of the member to always set the
	// member to. If the member's type is a []string, the member is set to the
	// Values list. If the type is a string, the member's value is set to the
	// first list element in the Values list.
	Values []string `json:"values"`
}

MemberConstructorConfig contains override instructions for how to handle the construction of a particular member for a Shape in the API.

type OperationConfig

type OperationConfig struct {
	CustomImplementation string            `json:"custom_implementation,omitempty"`
	OverrideValues       map[string]string `json:"override_values"`
	// SetOutputCustomMethodName provides the name of the custom method on the
	// `resourceManager` struct that will set fields on a `resource` struct
	// depending on the output of the operation.
	SetOutputCustomMethodName string `json:"set_output_custom_method_name,omitempty"`
	// Override for resource name in case of heuristic failure
	// An example of this is correcting stutter when the resource logic doesn't properly determine the resource name
	ResourceName string `json:"resource_name"`
	// Override for operation type in case of heuristic failure
	// An example of this is `Put...` or `Register...` API operations not being correctly classified as `Create` op type
	OperationType string `json:"operation_type"`
}

OperationConfig represents instructions to the ACK code generator to specify the overriding values for API operation parameters and its custom implementation.

type OperationRenamesConfig

type OperationRenamesConfig struct {
	// InputFields is a map of Input shape fields to renamed field name.
	InputFields map[string]string `json:"input_fields"`
	// OutputFields is a map of Output shape fields to renamed field name.
	OutputFields map[string]string `json:"output_fields"`
}

OperationRenamesConfig contains instructions to the code generator on how to rename fields in an Operation's input and output payload shapes

type PrefixConfig

type PrefixConfig struct {
	// SpecField stores the string prefix to use for information that will be
	// sent to AWS. Defaults to `.Spec`
	SpecField string `json:"spec_field,omitempty"`
	// StatusField stores the string prefix to use for information fetched from
	// AWS. Defaults to `.Status`
	StatusField string `json:"status_field,omitempty"`
}

type RenamesConfig

type RenamesConfig struct {
	// Operations is a map, keyed by Operation ID, of instructions on how to
	// handle renamed fields in Input and Output shapes.
	Operations map[string]*OperationRenamesConfig `json:"operations"`
}

RenamesConfig contains instructions to the code generator how to rename fields in various Operation payloads

type ResourceConfig

type ResourceConfig struct {
	// NameField is the name of the Member of the Create Input shape that
	// represents the name/string identifier field for the resource. If this
	// isn't set, then the generator will look for a field called "Name" or
	// "{Resource}Name" or "{Resource}Id" because, well, because we can never
	// have nice things.
	NameField *string `json:"name_field,omitempty"`
	// UnpackAttributeMapConfig contains instructions for converting a raw
	// `map[string]*string` into real fields on a CRD's Spec or Status object
	UnpackAttributesMapConfig *UnpackAttributesMapConfig `json:"unpack_attributes_map,omitempty"`
	// Exceptions identifies the exception codes for the resource. Some API
	// model files don't contain the ErrorInfo struct that contains the
	// HTTPStatusCode attribute that we usually look for to identify 404 Not
	// Found and other common error types for primary resources, and thus we
	// need these instructions.
	Exceptions *ExceptionsConfig `json:"exceptions,omitempty"`

	// Renames identifies fields in Operations that should be renamed.
	Renames *RenamesConfig `json:"renames,omitempty"`
	// ListOperation contains instructions for the code generator to generate
	// Go code that filters the results of a List operation looking for a
	// singular object. Certain AWS services (e.g. S3's ListBuckets API) have
	// absolutely no way to pass a filter to the operation. Instead, the List
	// operation always returns ALL objects of that type.
	//
	// The ListOperationConfig object enables us to inject some custom code to
	// filter the results of these List operations from within the generated
	// code in sdk.go's sdkFind().
	ListOperation *ListOperationConfig `json:"list_operation,omitempty"`
	// UpdateOperation contains instructions for the code generator to generate
	// Go code for the update operation for the resource. For some APIs, the
	// way that a resource's attributes are updated after creation is, well,
	// very odd. Some APIs have separate API calls for each attribute or set of
	// related attributes of the resource. For example, the ECR API has
	// separate API calls for PutImageScanningConfiguration,
	// PutImageTagMutability, PutLifecyclePolicy and SetRepositoryPolicy. FOr
	// these APIs, we basically need to revert to custom code because there's
	// very little consistency to the APIs that we can use to instruct the code
	// generator :(
	UpdateOperation *UpdateOperationConfig `json:"update_operation,omitempty"`
	// UpdateConditionsCustomMethodName provides the name of the custom method on the
	// `resourceManager` struct that will set Conditions on a `resource` struct
	// depending on the status of the resource.
	UpdateConditionsCustomMethodName string `json:"update_conditions_custom_method_name,omitempty"`

	// SpecFields is a list of instructions about additional Spec fields
	// on this Resource
	SpecFields []*SpecFieldConfig `json:"spec_fields"`
	// Compare contains instructions for the code generation to generate custom
	// comparison logic.
	Compare *CompareConfig `json:"compare,omitempty"`
}

ResourceConfig represents instructions to the ACK code generator for a particular CRD/resource on an AWS service API

type SpecFieldConfig

type SpecFieldConfig struct {
	// OperationID refers to the ID of the API Operation where we will
	// determine the field's Go type.
	OperationID string `json:"operation_id,omitempty"`
	// MemberName refers to the name of the member of the
	// Input shape in the Operation identified by OperaitonID that
	// we will take as our additional spec field.
	MemberName string `json:"member_name"`
}

SpecFieldConfig instructs the code generator how to handle an additional field in the Resource's SpecFields collection. This additional field can source its value from a shape in a different API Operation.

type UnpackAttributesMapConfig

type UnpackAttributesMapConfig struct {
	// Fields contains a map, keyed by the original Attribute Key, of
	// FieldConfig instructions for Attributes that should be
	// considered actual CRD fields.
	//
	// Some fields are ReadWrite -- i.e. the Kubernetes user has the ability to
	// set/update these fields on their CR -- and therefore go in the Spec
	// struct of the CR
	//
	// Other fields are ReadeOnly -- i.e. the Kubernetes user cannot update the
	// value of these fields.
	//
	// Note that any Attribute keys *not* listed here will be **excluded** from
	// the representation of the CR's Status struct. If there is an Attribute
	// -- e.g. an SNS Topic's `SubscriptionsDeleted` attribute -- that has
	// information that is constantly changing and does not represent
	// information to the ACK service controller that is useful for determining
	// observed versus desired state -- then do NOT list that attribute here.
	Fields map[string]FieldConfig `json:"fields"`
	// SetAttributesSingleAttribute indicates that the SetAttributes API call
	// doesn't actually set multiple attributes but rather must be called
	// multiple times, once for each attribute that needs to change. See SNS
	// SetTopicAttributes API call, which can be compared to the "normal" SNS
	// SetPlatformApplicationAttributes API call which accepts multiple
	// attributes and replaces the supplied attributes map key/values...
	SetAttributesSingleAttribute bool `json:"set_attributes_single_attribute"`
	// GetAttributesInput instructs the code generator how to handle the
	// GetAttributes input shape
	GetAttributesInput *GetAttributesInputConfig `json:"get_attributes_input,omitempty"`
}

UnpackAttributesMapConfig informs the code generator that the API follows a pattern or using an "Attributes" `map[string]*string` that contains real, schema'd fields of the primary resource, and that those fields should be "unpacked" from the raw map and into CRD's Spec and Status struct fields.

AWS Simple Notification Service (SNS) and AWS Simple Queue Service (SQS) are examples of APIs that use this pattern. For instance, the SNS CreateTopic API accepts a parameter called "Attributes" that can contain one of four keys:

  • DeliveryPolicy – The policy that defines how Amazon SNS retries failed deliveries to HTTP/S endpoints.
  • DisplayName – The display name to use for a topic with SMS subscriptions
  • Policy – The policy that defines who can access your topic.
  • KmsMasterKeyId - The ID of an AWS-managed customer master key (CMK) for Amazon SNS or a custom CMK.

The `CreateTopic` API call **returns** only a single field: the TopicARN. But there is a separate `GetTopicAttributes` call that needs to be made that returns the above attributes (that are ReadWrite) along with a set of key/values that are ReadOnly:

  • Owner – The AWS account ID of the topic's owner.
  • SubscriptionsConfirmed – The number of confirmed subscriptions for the topic.
  • SubscriptionsDeleted – The number of deleted subscriptions for the topic.
  • SubscriptionsPending – The number of subscriptions pending confirmation for the topic.
  • TopicArn – The topic's ARN.
  • EffectiveDeliveryPolicy – The JSON serialization of the effective delivery policy, taking system defaults into account.

This structure instructs the code generator about the above real, schema'd fields that are masquerading as raw key/value pairs.

type UpdateOperationConfig

type UpdateOperationConfig struct {
	// CustomMethodName is a string for the method name to replace the
	// sdkUpdate() method implementation for this resource
	CustomMethodName string `json:"custom_method_name"`
}

UpdateOperationConfig contains instructions for the code generator to handle Update operations for service APIs that have resources that have difficult-to-standardize update operations.

Jump to

Keyboard shortcuts

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