Skip to content

Commit 440b484

Browse files
authored
only call SetAttributes() when attrMap not empty (#442)
For SQS's `CreateQueue` API, if you pass an empty map to the `CreateQueueInput.SetAttributes()` method, everything succeeds however the service will return the following cryptic error message: `MalformedInput: End of list found where not expected` This patch updates the generated code for attribute-based APIs to only call `SetAttributes()` on the input shape when there are attributes to set. Issue aws-controllers-k8s/community#1695 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent a4bd77b commit 440b484

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

pkg/generate/code/set_sdk.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ func SetSDK(
137137
// attrMap["DisplayName"} = r.ko.Spec.DisplayName
138138
// attrMap["KmsMasterKeyId"] = r.ko.Spec.KMSMasterKeyID
139139
// attrMap["Policy"] = r.ko.Spec.Policy
140-
// res.SetAttributes(attrMap)
140+
// if len(attrMap) > 0 {
141+
// res.SetAttributes(attrMap)
142+
// }
141143
fieldConfigs := cfg.GetFieldConfigs(r.Names.Original)
142144
out += fmt.Sprintf("%sattrMap := map[string]*string{}\n", indent)
143145
sortedAttrFieldNames := []string{}
@@ -165,7 +167,13 @@ func SetSDK(
165167
)
166168
}
167169
}
168-
out += fmt.Sprintf("%s%s.SetAttributes(attrMap)\n", indent, targetVarName)
170+
out += fmt.Sprintf(
171+
"%sif len(attrMap) > 0 {\n", indent,
172+
)
173+
out += fmt.Sprintf("\t%s%s.SetAttributes(attrMap)\n", indent, targetVarName)
174+
out += fmt.Sprintf(
175+
"%s}\n", indent,
176+
)
169177
}
170178

171179
opConfig, override := cfg.GetOverrideValues(op.ExportedName)

pkg/generate/code/set_sdk_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,7 +1779,9 @@ func TestSetSDK_SNS_Topic_Create(t *testing.T) {
17791779
if r.ko.Spec.Policy != nil {
17801780
attrMap["Policy"] = r.ko.Spec.Policy
17811781
}
1782-
res.SetAttributes(attrMap)
1782+
if len(attrMap) > 0 {
1783+
res.SetAttributes(attrMap)
1784+
}
17831785
if r.ko.Spec.Name != nil {
17841786
res.SetName(*r.ko.Spec.Name)
17851787
}
@@ -1874,7 +1876,9 @@ func TestSetSDK_SQS_Queue_Create(t *testing.T) {
18741876
if r.ko.Spec.VisibilityTimeout != nil {
18751877
attrMap["VisibilityTimeout"] = r.ko.Spec.VisibilityTimeout
18761878
}
1877-
res.SetAttributes(attrMap)
1879+
if len(attrMap) > 0 {
1880+
res.SetAttributes(attrMap)
1881+
}
18781882
if r.ko.Spec.QueueName != nil {
18791883
res.SetQueueName(*r.ko.Spec.QueueName)
18801884
}

0 commit comments

Comments
 (0)