model

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: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ConflictingNameSuffix is appended to type names when they overlap with
	// well-known common struct names for things like a CRD itself, or its
	// Spec/Status subfield struct type name.
	ConflictingNameSuffix = "_SDK"
)

Variables

View Source
var (
	ErrInvalidVersionDirectory = errors.New(
		"expected to find only directories in api model directory but found non-directory",
	)
	ErrNoValidVersionDirectory = errors.New(
		"no valid version directories found",
	)
	ErrServiceNotFound = errors.New(
		"no such service",
	)
)
View Source
var (
	ErrNilShapePointer = errors.New("found nil Shape pointer")
)

Functions

This section is empty.

Types

type Attr

type Attr struct {
	Names  names.Names
	GoType string
	Shape  *awssdkmodel.Shape
}

func NewAttr

func NewAttr(
	names names.Names,
	goType string,
	shape *awssdkmodel.Shape,
) *Attr

type CRD

type CRD struct {
	Names  names.Names
	Kind   string
	Plural string
	Ops    CRDOps
	// SpecFields is a map, keyed by the **original SDK member name** of
	// CRDField objects representing those fields in the CRD's Spec struct
	// field.
	SpecFields map[string]*CRDField
	// StatusFields is a map, keyed by the **original SDK member name** of
	// CRDField objects representing those fields in the CRD's Status struct
	// field. Note that there are no fields in StatusFields that are also in
	// SpecFields.
	StatusFields map[string]*CRDField
	// TypeImports is a map, keyed by an import string, with the map value
	// being the import alias
	TypeImports map[string]string
	// contains filtered or unexported fields
}

CRD describes a single top-level resource in an AWS service API

func NewCRD

func NewCRD(
	sdkAPI *SDKAPI,
	genCfg *ackgenconfig.Config,
	crdNames names.Names,
	crdOps CRDOps,
) *CRD

NewCRD returns a pointer to a new `ackmodel.CRD` struct that describes a single top-level resource in an AWS service API

func (*CRD) AddSpecField

func (r *CRD) AddSpecField(
	memberNames names.Names,
	shapeRef *awssdkmodel.ShapeRef,
)

AddSpecField adds a new CRDField of a given name and shape into the Spec field of a CRD

func (*CRD) AddStatusField

func (r *CRD) AddStatusField(
	memberNames names.Names,
	shapeRef *awssdkmodel.ShapeRef,
)

AddStatusField adds a new CRDField of a given name and shape into the Status field of a CRD

func (*CRD) AddTypeImport

func (r *CRD) AddTypeImport(
	packagePath string,
	alias string,
)

AddTypeImport adds an entry in the CRD's TypeImports map for an import line and optional alias

func (*CRD) CompareIgnoredFields

func (r *CRD) CompareIgnoredFields() []string

CompareIgnoredFields returns the list of fields compare logic should ignore

func (*CRD) CustomUpdateMethodName

func (r *CRD) CustomUpdateMethodName() string

CustomUpdateMethodName returns the name of the custom resourceManager method for updating the resource state, if any has been specified in the generator config

func (*CRD) ExceptionCode

func (r *CRD) ExceptionCode(httpStatusCode int) string

ExceptionCode returns the name of the resource's Exception code for the Exception having the exception code. If the generator config has instructions for overriding the name of an exception code for a resource for a particular HTTP status code, we return that, otherwise we look through the API model definitions looking for a match

func (*CRD) GetCustomImplementation

func (r *CRD) GetCustomImplementation(

	op *awssdkmodel.Operation,
) string

GetCustomImplementation returns custom implementation method name for the supplied operation as specified in generator config

func (*CRD) GoCodeGetAttributesSetInput

func (r *CRD) GoCodeGetAttributesSetInput(

	sourceVarName string,

	targetVarName string,

	indentLevel int,
) string

GoCodeGetAttributesSetInput returns the Go code that sets the Input shape for a resource's GetAttributes operation.

As an example, for the GetTopicAttributes SNS API call, the returned code looks like this:

res.SetTopicArn(string(*r.ko.Status.ACKResourceMetadata.ARN))

For the SQS API's GetQueueAttributes call, the returned code looks like this:

res.SetQueueUrl(*r.ko.Status.QueueURL)

You will note the difference due to the special handling of the ARN fields.

func (*CRD) GoCodeGetAttributesSetOutput

func (r *CRD) GoCodeGetAttributesSetOutput(

	sourceVarName string,

	targetVarName string,

	indentLevel int,
) string

GoCodeGetAttributesSetOutput returns the Go code that sets the Status fields from the Output shape returned from a resource's GetAttributes operation.

As an example, for the GetTopicAttributes SNS API call, the returned code looks like this:

if ko.Status.ACKResourceMetadata == nil {
    ko.Status.ACKResourceMetadata = &ackv1alpha1.ResourceMetadata{}
}

ko.Status.EffectiveDeliveryPolicy = resp.Attributes["EffectiveDeliveryPolicy"] ko.Status.ACKResourceMetadata.OwnerAccountID = ackv1alpha1.AWSAccountID(resp.Attributes["Owner"]) ko.Status.ACKResourceMetadata.ARN = ackv1alpha1.AWSResourceName(resp.Attributes["TopicArn"])

func (*CRD) GoCodeRequiredFieldsMissingFromShape

func (r *CRD) GoCodeRequiredFieldsMissingFromShape(
	opType OpType,
	koVarName string,
	indentLevel int,
) string

GoCodeRequiredFieldsMissingFromShape returns Go code that contains a condition checking that the required fields in the supplied Shape have a non-nil value in the corresponding CR's Spec or Status substruct.

Sample Output:

return r.ko.Spec.APIID == nil || r.ko.Status.RouteID != nil

func (*CRD) GoCodeSetAttributesSetInput

func (r *CRD) GoCodeSetAttributesSetInput(

	sourceVarName string,

	targetVarName string,

	indentLevel int,
) string

GoCodeSetAttributesSetInput returns the Go code that sets the Input shape for a resource's SetAttributes operation.

Unfortunately, the AWS SetAttributes API operations (even within the *same* API) are inconsistent regarding whether the SetAttributes sets a batch of attributes or a single attribute. We need to construct the method differently depending on this behaviour. For example, the SNS SetTopicAttributes API call actually only allows the caller to set a single attribute, which needs to be specified in an AttributeName and AttributeValue field in the Input shape. On the other hand, the SNS SetPlatformApplicationAttributes API call's Input shape has an Attributes field which is a map[string]string containing all the attribute key/value pairs to replace. Your guess is as good as mine as to why these APIs are different.

The returned code looks something like this:

attrMap := map[string]*string{}

if r.ko.Spec.DeliveryPolicy != nil {
    attrMap["DeliveryPolicy"] = r.ko.Spec.DeliveryPolicy
}
if r.ko.Spec.DisplayName != nil {
    attrMap["DisplayName"} = r.ko.Spec.DisplayName
}
if r.ko.Spec.KMSMasterKeyID != nil {
    attrMap["KmsMasterKeyId"] = r.ko.Spec.KMSMasterKeyID
}
if r.ko.Spec.Policy != nil {
    attrMap["Policy"] = r.ko.Spec.Policy
}

res.SetAttributes(attrMap)

func (*CRD) GoCodeSetInput

func (r *CRD) GoCodeSetInput(

	opType OpType,

	sourceVarName string,

	targetVarName string,

	indentLevel int,
) string

GoCodeSetInput returns the Go code that sets an input shape's member fields from a CRD's fields.

Assume a CRD called Repository that looks like this pseudo-schema:

.Status

.Authors ([]*string)
.ImageData
  .Location (*string)
  .Tag (*string)
.Name (*string)

And assume an SDK Shape CreateRepositoryInput that looks like this pseudo-schema:

.Repository

.Authors ([]*string)
.ImageData
  .Location (*string)
  .Tag (*string)
.Name

This function is called from a template that generates the Go code that represents linkage between the Kubernetes objects (CRs) and the aws-sdk-go (SDK) objects. If we call this function with the following parameters:

opType:			OpTypeCreate
sourceVarName:	ko
targetVarName:	res
indentLevel:	1

Then this function should output something like this:

  field1 := []*string{}
  for _, elem0 := range r.ko.Spec.Authors {
      elem0 := &string{*elem0}
      field0 = append(field0, elem0)
  }
  res.Authors = field1
  field1 := &svcsdk.ImageData{}
  field1.SetLocation(*r.ko.Spec.ImageData.Location)
  field1.SetTag(*r.ko.Spec.ImageData.Tag)
  res.ImageData = field1
	 res.SetName(*r.ko.Spec.Name)

Note that for scalar fields, we use the SetXXX methods that are on all aws-sdk-go SDK structs

func (*CRD) GoCodeSetOutput

func (r *CRD) GoCodeSetOutput(

	opType OpType,

	sourceVarName string,

	targetVarName string,

	indentLevel int,

	performSpecUpdate bool,
) string

GoCodeSetOutput returns the Go code that sets a CRD's field value to the value of an output shape's member fields. Status fields are always updated. Update of Spec fields depends on 'performSpecUpdate' parameter

Assume a CRD called Repository that looks like this pseudo-schema:

.Status

.Authors ([]*string)
.ImageData
  .Location (*string)
  .Tag (*string)
.Name (*string)

And assume an SDK Shape CreateRepositoryOutput that looks like this pseudo-schema:

.Repository

.Authors ([]*string)
.ImageData
  .Location (*string)
  .Tag (*string)
.Name

This function is called from a template that generates the Go code that represents linkage between the Kubernetes objects (CRs) and the aws-sdk-go (SDK) objects. If we call this function with the following parameters:

opType:			OpTypeCreate
sourceVarName:	resp
targetVarName:	ko.Status
indentLevel:	1

Then this function should output something like this:

field0 := []*string{}
for _, iter0 := range resp.Authors {
    elem0 := &string{*iter0}
    field0 = append(field0, elem0)
}
ko.Status.Authors = field0
field1 := &svcapitypes.ImageData{}
field1.Location = resp.ImageData.Location
field1.Tag = resp.ImageData.Tag
ko.Status.ImageData = field1
ko.Status.Name = resp.Name

func (*CRD) HasShapeAsMember

func (r *CRD) HasShapeAsMember(toFind string) bool

HasShapeAsMember returns true if the supplied Shape name appears in *any* payload shape of *any* Operation for the resource. It recurses down through the resource's Operation Input and Output shapes and their member shapes looking for a shape with the supplied name

func (*CRD) InputFieldRename

func (r *CRD) InputFieldRename(
	opID string,
	origFieldName string,
) (string, bool)

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

func (*CRD) IsPrimaryARNField

func (r *CRD) IsPrimaryARNField(fieldName string) bool

IsPrimaryARNField returns true if the supplied field name is likely the resource's ARN identifier field.

func (*CRD) NameField

func (r *CRD) NameField() string

NameField returns the name of the "Name" or string identifier field in the Spec

func (*CRD) SetAttributesSingleAttribute

func (r *CRD) SetAttributesSingleAttribute() 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 (*CRD) SetOutputCustomMethodName

func (r *CRD) SetOutputCustomMethodName(

	op *awssdkmodel.Operation,
) *string

SetOutputCustomMethodName returns custom set output operation as *string for given operation on custom resource, if specified in generator config

func (*CRD) SpecFieldNames

func (r *CRD) SpecFieldNames() []string

SpecFieldNames returns a sorted slice of field names for the Spec fields

func (*CRD) TerminalExceptionCodes

func (r *CRD) TerminalExceptionCodes() []string

TerminalExceptionCodes returns terminal exception codes as []string for custom resource, if specified in generator config

func (*CRD) UnpackAttributes

func (r *CRD) UnpackAttributes()

UnpackAttributes grabs instructions about fields that are represented in the AWS API as a `map[string]*string` but are actually real, schema'd fields and adds CRDField definitions for those fields.

func (*CRD) UnpacksAttributesMap

func (r *CRD) UnpacksAttributesMap() 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)

func (*CRD) UpdateConditionsCustomMethodName

func (r *CRD) UpdateConditionsCustomMethodName() string

UpdateConditionsCustomMethodName returns custom update conditions operation as *string for custom resource, if specified in generator config

type CRDField

type CRDField struct {
	CRD               *CRD
	Names             names.Names
	GoType            string
	GoTypeElem        string
	GoTypeWithPkgName string
	ShapeRef          *awssdkmodel.ShapeRef
	FieldConfig       *ackgenconfig.FieldConfig
}

CRDField represents a single field in the CRD's Spec or Status objects

func (*CRDField) IsRequired

func (crdField *CRDField) IsRequired() bool

IsRequired return if the shape is marked as required in AWS SDK Private model we use this to append kubebuilder:validation:Required markers to validate using the CRD validation schema

type CRDOps

type CRDOps struct {
	Create        *awssdkmodel.Operation
	ReadOne       *awssdkmodel.Operation
	ReadMany      *awssdkmodel.Operation
	Update        *awssdkmodel.Operation
	Delete        *awssdkmodel.Operation
	GetAttributes *awssdkmodel.Operation
	SetAttributes *awssdkmodel.Operation
}

func (CRDOps) IterOps

func (ops CRDOps) IterOps() []*awssdkmodel.Operation

type EnumDef

type EnumDef struct {
	Names  names.Names
	Values []EnumValue
}

EnumDef is the definition of an enumeration type for a field present in either a CRD or a TypeDef

func NewEnumDef

func NewEnumDef(names names.Names, values []string) (*EnumDef, error)

NewEnumDef returns a pointer to an `ackmodel.EnumDef` struct representing a constrained string value field

type EnumValue

type EnumValue struct {
	Original string
	Clean    string
}

type OpType

type OpType int
const (
	OpTypeUnknown OpType = iota
	OpTypeCreate
	OpTypeCreateBatch
	OpTypeDelete
	OpTypeReplace
	OpTypeUpdate
	OpTypeAddChild
	OpTypeAddChildren
	OpTypeRemoveChild
	OpTypeRemoveChildren
	OpTypeGet
	OpTypeList
	OpTypeGetAttributes
	OpTypeSetAttributes
)

func GetOpTypeAndResourceNameFromOpID

func GetOpTypeAndResourceNameFromOpID(opID string) (OpType, string)

GetOpTypeAndResourceNameFromOpID guesses the resource name and type of operation from the OperationID

func OpTypeFromString

func OpTypeFromString(s string) OpType

type OperationMap

type OperationMap map[OpType]map[string]*awssdkmodel.Operation

type SDKAPI

type SDKAPI struct {
	API *awssdkmodel.API
	// contains filtered or unexported fields
}

SDKAPI contains an API model for a single AWS service API

func (*SDKAPI) APIGroup

func (a *SDKAPI) APIGroup() string

APIGroup returns the normalized Kubernetes APIGroup for the AWS service API, e.g. "sns.services.k8s.aws"

func (*SDKAPI) CRDNames

func (a *SDKAPI) CRDNames(cfg *ackgenconfig.Config) []names.Names

CRDNames returns a slice of names structs for all top-level resources in the API

func (*SDKAPI) GetMemberShapeRef

func (a *SDKAPI) GetMemberShapeRef(operation string, memberName string) (*awssdkmodel.ShapeRef, bool)

Given an API operation and member of API operation, return shape reference associated with the member

func (*SDKAPI) GetOperationMap

func (a *SDKAPI) GetOperationMap(cfg *ackgenconfig.Config) *OperationMap

GetOperationMap returns a map, keyed by the operation type and operation ID/name, of aws-sdk-go private/model/api.Operation struct pointers

func (*SDKAPI) GetPayloads

func (a *SDKAPI) GetPayloads() []string

GetPayloads returns a slice of strings of Shape names representing input and output request/response payloads

func (*SDKAPI) GetServiceFullName

func (a *SDKAPI) GetServiceFullName() string

func (*SDKAPI) GetTypeRenames

func (a *SDKAPI) GetTypeRenames(cfg *ackgenconfig.Config) map[string]string

GetTypeRenames returns a map of original type name to renamed name (some type definition names conflict with generated names)

func (*SDKAPI) HasConflictingTypeName

func (a *SDKAPI) HasConflictingTypeName(typeName string, cfg *ackgenconfig.Config) bool

HasConflictingTypeName returns true if the supplied type name will conflict with any generated type in the service's API package

func (*SDKAPI) SDKAPIInterfaceTypeName

func (a *SDKAPI) SDKAPIInterfaceTypeName() string

SDKAPIInterfaceTypeName returns the name of the aws-sdk-go primary API interface type name.

func (*SDKAPI) ServiceID

func (a *SDKAPI) ServiceID() string

ServiceID returns the exact `metadata.serviceId` attribute for the AWS service APi's api-2.json file

func (*SDKAPI) ServiceIDClean

func (a *SDKAPI) ServiceIDClean() string

ServiceIDClean returns a lowercased, whitespace-stripped ServiceID

type SDKHelper

type SDKHelper struct {

	// Default is "services.k8s.aws"
	APIGroupSuffix string
	// contains filtered or unexported fields
}

SDKHelper is a helper struct that helps work with the aws-sdk-go models and API model loader

func NewSDKHelper

func NewSDKHelper(basePath string) *SDKHelper

NewSDKHelper returns a new SDKHelper object

func (*SDKHelper) API

func (h *SDKHelper) API(serviceAlias string) (*SDKAPI, error)

API returns the aws-sdk-go API model for a supplied service alias

func (*SDKHelper) APIVersion

func (h *SDKHelper) APIVersion(serviceAlias string) (string, error)

APIVersion returns the API version (e.h. "2012-10-03") for a service API

func (*SDKHelper) ModelAndDocsPath

func (h *SDKHelper) ModelAndDocsPath(
	serviceAlias string,
) (string, string, error)

ModelAndDocsPath returns two string paths to the supplied service alias' model and doc JSON files

type TypeDef

type TypeDef struct {
	Names names.Names
	Attrs map[string]*Attr
}

TypeDef is a Go type definition for structs that are member fields of the Spec or Status structs in Custom Resource Definitions (CRDs).

Jump to

Keyboard shortcuts

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