code

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckExceptionMessagePrefix

func CheckExceptionMessagePrefix(
	cfg *ackgenconfig.Config,
	r *model.CRD,
	httpStatusCode int,
) string

CheckExceptionMessagePrefix returns Go code that contains a condition to check if the message_prefix specified for a particular HTTP status code in generator config is a prefix for the exception message returned by AWS API. If message_prefix field was not specified for this HTTP code in generator config, we return an empty string

Sample Output:

&& strings.HasPrefix(awsErr.Message(), "Could not find model")

func CheckRequiredFieldsMissingFromShape

func CheckRequiredFieldsMissingFromShape(
	r *model.CRD,
	opType model.OpType,
	koVarName string,
	indentLevel int,
) string

CheckRequiredFieldsMissingFromShape 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 ListMemberNameInReadManyOutput

func ListMemberNameInReadManyOutput(
	r *model.CRD,
) string

func SetResource

func SetResource(
	cfg *ackgenconfig.Config,
	r *model.CRD,

	opType model.OpType,

	sourceVarName string,

	targetVarName string,

	indentLevel int,

	performSpecUpdate bool,
) string

SetResource 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 {
    var elem0 string
    elem0 = *iter
    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 SetResourceGetAttributes

func SetResourceGetAttributes(
	cfg *ackgenconfig.Config,
	r *model.CRD,

	sourceVarName string,

	targetVarName string,

	indentLevel int,
) string

SetResourceGetAttributes 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 SetSDK

func SetSDK(
	cfg *ackgenconfig.Config,
	r *model.CRD,

	opType model.OpType,

	sourceVarName string,

	targetVarName string,

	indentLevel int,
) string

SetSDK returns the Go code that sets an SDK 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 SetSDKGetAttributes

func SetSDKGetAttributes(
	cfg *ackgenconfig.Config,
	r *model.CRD,

	sourceVarName string,

	targetVarName string,

	indentLevel int,
) string

SetSDKGetAttributes 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 SetSDKSetAttributes

func SetSDKSetAttributes(
	cfg *ackgenconfig.Config,
	r *model.CRD,

	sourceVarName string,

	targetVarName string,

	indentLevel int,
) string

SetSDKSetAttributes 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)

Types

This section is empty.

Jump to

Keyboard shortcuts

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