Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Resource when GetAttribute is present #439

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions pkg/generate/code/set_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,12 +955,14 @@ func SetResourceIdentifiers(
) string {
op := r.Ops.ReadOne
if op == nil {
if r.Ops.GetAttributes != nil {
// TODO(RedbackThomson): Support attribute maps for resource identifiers
return ""
switch {
case r.Ops.GetAttributes != nil:
// If single lookups can only be done with GetAttributes
op = r.Ops.GetAttributes
case r.Ops.ReadMany != nil:
// If single lookups can only be done using ReadMany
op = r.Ops.ReadMany
}
// If single lookups can only be done using ReadMany
op = r.Ops.ReadMany
}
inputShape := op.InputRef.Shape
if inputShape == nil {
Expand Down
43 changes: 43 additions & 0 deletions pkg/generate/code/set_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2971,6 +2971,49 @@ func TestSetResource_RDS_DBInstances_SetResourceIdentifiers(t *testing.T) {
)
}

func TestSetResource_SNS_Topics_SetResourceIdentifiers(t *testing.T) {
assert := assert.New(t)
require := require.New(t)

g := testutil.NewModelForService(t, "sns")

crd := testutil.GetCRDByName(t, g, "Topic")
require.NotNil(crd)

expected := `
if r.ko.Status.ACKResourceMetadata == nil {
r.ko.Status.ACKResourceMetadata = &ackv1alpha1.ResourceMetadata{}
}
r.ko.Status.ACKResourceMetadata.ARN = identifier.ARN
`
assert.Equal(
expected,
code.SetResourceIdentifiers(crd.Config(), crd, "identifier", "r.ko", 1),
)
}

func TestSetResource_SQS_Queues_SetResourceIdentifiers(t *testing.T) {
assert := assert.New(t)
require := require.New(t)

g := testutil.NewModelForService(t, "sqs")

crd := testutil.GetCRDByName(t, g, "Queue")
require.NotNil(crd)

expected := `
if identifier.NameOrID == "" {
return ackerrors.MissingNameIdentifier
}
r.ko.Status.QueueURL = &identifier.NameOrID

`
assert.Equal(
expected,
code.SetResourceIdentifiers(crd.Config(), crd, "identifier", "r.ko", 1),
)
}

func TestSetResource_RDS_DBSubnetGroup_SetResourceIdentifiers(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
Expand Down
1 change: 1 addition & 0 deletions pkg/testdata/models/apis/sns/0000-00-00/generator.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
resources:
Topic:
is_arn_primary_key: true
unpack_attributes_map:
set_attributes_single_attribute: true
fields:
Expand Down
3 changes: 3 additions & 0 deletions pkg/testdata/models/apis/sqs/0000-00-00/generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ resources:
QueueArn:
is_attribute: true
is_read_only: true
QueueUrl:
is_read_only: true
is_primary_key: true