Skip to content

Commit e69321e

Browse files
authored
Set Resource when GetAttribute is present (#439)
This change basically the SetResource function to continue when the `GetAttribute` operation is present. If the `ReadOne` operation is present then that is preferred. Issue aws-controllers-k8s/community#1778 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 74d5465 commit e69321e

File tree

4 files changed

+54
-5
lines changed

4 files changed

+54
-5
lines changed

pkg/generate/code/set_resource.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -955,12 +955,14 @@ func SetResourceIdentifiers(
955955
) string {
956956
op := r.Ops.ReadOne
957957
if op == nil {
958-
if r.Ops.GetAttributes != nil {
959-
// TODO(RedbackThomson): Support attribute maps for resource identifiers
960-
return ""
958+
switch {
959+
case r.Ops.GetAttributes != nil:
960+
// If single lookups can only be done with GetAttributes
961+
op = r.Ops.GetAttributes
962+
case r.Ops.ReadMany != nil:
963+
// If single lookups can only be done using ReadMany
964+
op = r.Ops.ReadMany
961965
}
962-
// If single lookups can only be done using ReadMany
963-
op = r.Ops.ReadMany
964966
}
965967
inputShape := op.InputRef.Shape
966968
if inputShape == nil {

pkg/generate/code/set_resource_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2971,6 +2971,49 @@ func TestSetResource_RDS_DBInstances_SetResourceIdentifiers(t *testing.T) {
29712971
)
29722972
}
29732973

2974+
func TestSetResource_SNS_Topics_SetResourceIdentifiers(t *testing.T) {
2975+
assert := assert.New(t)
2976+
require := require.New(t)
2977+
2978+
g := testutil.NewModelForService(t, "sns")
2979+
2980+
crd := testutil.GetCRDByName(t, g, "Topic")
2981+
require.NotNil(crd)
2982+
2983+
expected := `
2984+
if r.ko.Status.ACKResourceMetadata == nil {
2985+
r.ko.Status.ACKResourceMetadata = &ackv1alpha1.ResourceMetadata{}
2986+
}
2987+
r.ko.Status.ACKResourceMetadata.ARN = identifier.ARN
2988+
`
2989+
assert.Equal(
2990+
expected,
2991+
code.SetResourceIdentifiers(crd.Config(), crd, "identifier", "r.ko", 1),
2992+
)
2993+
}
2994+
2995+
func TestSetResource_SQS_Queues_SetResourceIdentifiers(t *testing.T) {
2996+
assert := assert.New(t)
2997+
require := require.New(t)
2998+
2999+
g := testutil.NewModelForService(t, "sqs")
3000+
3001+
crd := testutil.GetCRDByName(t, g, "Queue")
3002+
require.NotNil(crd)
3003+
3004+
expected := `
3005+
if identifier.NameOrID == "" {
3006+
return ackerrors.MissingNameIdentifier
3007+
}
3008+
r.ko.Status.QueueURL = &identifier.NameOrID
3009+
3010+
`
3011+
assert.Equal(
3012+
expected,
3013+
code.SetResourceIdentifiers(crd.Config(), crd, "identifier", "r.ko", 1),
3014+
)
3015+
}
3016+
29743017
func TestSetResource_RDS_DBSubnetGroup_SetResourceIdentifiers(t *testing.T) {
29753018
assert := assert.New(t)
29763019
require := require.New(t)

pkg/testdata/models/apis/sns/0000-00-00/generator.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
resources:
22
Topic:
3+
is_arn_primary_key: true
34
unpack_attributes_map:
45
set_attributes_single_attribute: true
56
fields:

pkg/testdata/models/apis/sqs/0000-00-00/generator.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ resources:
3838
QueueArn:
3939
is_attribute: true
4040
is_read_only: true
41+
QueueUrl:
42+
is_read_only: true
43+
is_primary_key: true

0 commit comments

Comments
 (0)