Skip to content

Commit e0eac49

Browse files
authored
check for nil Name field in attr APIs (#415)
The code which builds the input shapes for the GET_ATTRIBUTES and SET_ATTRIBUTES operations for attribute-based APIs was checking for a Name or ID field in order to set the value for ARN fields in the input shapes. However, some resources, like SNS' Subscription resources, do not have a Name or ID field. This resulted in nil pointer dereferencing and panics when building the controller for SNS Subscriptions. This patch simply double-checks that the `*string` returned from the `CRD.SpecIdentifierField()` method is not nil before adding in the Go code that constructs an ARN from a Name or ID field. Signed-off-by: Jay Pipes <[email protected]>
1 parent d0f3d78 commit e0eac49

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

pkg/generate/code/set_sdk.go

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -438,14 +438,18 @@ func SetSDKGetAttributes(
438438
"%s\t%s.Set%s(string(*%s.Status.ACKResourceMetadata.ARN))\n",
439439
indent, targetVarName, memberName, sourceVarName,
440440
)
441-
out += fmt.Sprintf(
442-
"%s} else {\n", indent,
443-
)
444-
nameField := *r.SpecIdentifierField()
445-
out += fmt.Sprintf(
446-
"%s\t%s.Set%s(rm.ARNFromName(*%s.Spec.%s))\n",
447-
indent, targetVarName, memberName, sourceVarName, nameField,
448-
)
441+
nameField := r.SpecIdentifierField()
442+
if nameField != nil {
443+
// There is no name or ID field for the resource, so don't try
444+
// to set an ARN from a name. Example: Subscription from SNS...
445+
out += fmt.Sprintf(
446+
"%s} else {\n", indent,
447+
)
448+
out += fmt.Sprintf(
449+
"%s\t%s.Set%s(rm.ARNFromName(*%s.Spec.%s))\n",
450+
indent, targetVarName, memberName, sourceVarName, *nameField,
451+
)
452+
}
449453
out += fmt.Sprintf(
450454
"%s}\n", indent,
451455
)
@@ -617,14 +621,18 @@ func SetSDKSetAttributes(
617621
"%s\t%s.Set%s(string(*%s.Status.ACKResourceMetadata.ARN))\n",
618622
indent, targetVarName, memberName, sourceVarName,
619623
)
620-
out += fmt.Sprintf(
621-
"%s} else {\n", indent,
622-
)
623-
nameField := *r.SpecIdentifierField()
624-
out += fmt.Sprintf(
625-
"%s\t%s.Set%s(rm.ARNFromName(*%s.Spec.%s))\n",
626-
indent, targetVarName, memberName, sourceVarName, nameField,
627-
)
624+
nameField := r.SpecIdentifierField()
625+
if nameField != nil {
626+
// There is no name or ID field for the resource, so don't try
627+
// to set an ARN from a name. Example: Subscription from SNS...
628+
out += fmt.Sprintf(
629+
"%s} else {\n", indent,
630+
)
631+
out += fmt.Sprintf(
632+
"%s\t%s.Set%s(rm.ARNFromName(*%s.Spec.%s))\n",
633+
indent, targetVarName, memberName, sourceVarName, *nameField,
634+
)
635+
}
628636
out += fmt.Sprintf(
629637
"%s}\n", indent,
630638
)

0 commit comments

Comments
 (0)