@@ -165,7 +165,6 @@ func SetSDK(
165165 }
166166
167167 opConfig , override := cfg .OverrideValues (op .Name )
168- fieldConfigs := cfg .ResourceFields (r .Names .Original )
169168 for memberIndex , memberName := range inputShape .MemberNames () {
170169 if r .UnpacksAttributesMap () && memberName == "Attributes" {
171170 continue
@@ -190,22 +189,6 @@ func SetSDK(
190189 }
191190 }
192191
193- fc , ok := fieldConfigs [memberName ]
194- if ok && fc .IsSecret {
195- out += fmt .Sprintf ("%sif %s.Spec.%s != nil {\n " , indent , sourceVarName , memberName )
196- out += fmt .Sprintf ("%s%stmpSecret, err := rm.rr.SecretValueFromReference(ctx, %s.Spec.%s)\n " , indent ,
197- indent , sourceVarName , memberName )
198- out += fmt .Sprintf ("%s%sif err != nil {\n " , indent , indent )
199- out += fmt .Sprintf ("%s%s%sreturn nil, err\n " , indent , indent , indent )
200- out += fmt .Sprintf ("%s%s}\n " , indent , indent )
201- out += fmt .Sprintf ("%s%sif tmpSecret != \" \" {\n " , indent , indent )
202- out += fmt .Sprintf ("%s%s%s%s.Set%s(%s)\n " , indent , indent , indent ,
203- targetVarName , memberName , "tmpSecret" )
204- out += fmt .Sprintf ("%s%s}\n " , indent , indent )
205- out += fmt .Sprintf ("%s}\n " , indent )
206- continue
207- }
208-
209192 if r .IsPrimaryARNField (memberName ) {
210193 // if ko.Status.ACKResourceMetadata != nil && ko.Status.ACKResourceMetadata.ARN != nil {
211194 // res.SetTopicArn(string(*ko.Status.ACKResourceMetadata.ARN))
@@ -243,14 +226,26 @@ func SetSDK(
243226 if found {
244227 sourceAdaptedVarName += cfg .PrefixConfig .SpecField
245228 } else {
246- f , found = r .StatusFields [memberName ]
229+ f , found = r .StatusFields [renamedName ]
247230 if ! found {
248231 // TODO(jaypipes): check generator config for exceptions?
249232 continue
250233 }
251234 sourceAdaptedVarName += cfg .PrefixConfig .StatusField
252235 }
253236 sourceAdaptedVarName += "." + f .Names .Camel
237+ sourceFieldPath := f .Names .Camel
238+
239+ if r .IsSecretField (memberName ) {
240+ out += setSDKForSecret (
241+ cfg , r ,
242+ memberName ,
243+ targetVarName ,
244+ sourceAdaptedVarName ,
245+ indentLevel ,
246+ )
247+ continue
248+ }
254249
255250 memberShapeRef , _ := inputShape .MemberRefs [memberName ]
256251 memberShape := memberShapeRef .Shape
@@ -327,6 +322,7 @@ func SetSDK(
327322 cfg , r ,
328323 memberName ,
329324 memberVarName ,
325+ sourceFieldPath ,
330326 sourceAdaptedVarName ,
331327 memberShapeRef ,
332328 indentLevel + 1 ,
@@ -336,6 +332,7 @@ func SetSDK(
336332 memberName ,
337333 targetVarName ,
338334 inputShape .Type ,
335+ sourceFieldPath ,
339336 memberVarName ,
340337 memberShapeRef ,
341338 indentLevel + 1 ,
@@ -347,6 +344,7 @@ func SetSDK(
347344 memberName ,
348345 targetVarName ,
349346 inputShape .Type ,
347+ sourceFieldPath ,
350348 sourceAdaptedVarName ,
351349 memberShapeRef ,
352350 indentLevel + 1 ,
@@ -514,6 +512,7 @@ func SetSDKGetAttributes(
514512 memberName ,
515513 targetVarName ,
516514 inputShape .Type ,
515+ cleanMemberName ,
517516 sourceVarPath ,
518517 field .ShapeRef ,
519518 indentLevel + 1 ,
@@ -708,6 +707,7 @@ func SetSDKSetAttributes(
708707 memberName ,
709708 targetVarName ,
710709 inputShape .Type ,
710+ cleanMemberName ,
711711 sourceVarPath ,
712712 field .ShapeRef ,
713713 indentLevel + 1 ,
@@ -730,6 +730,8 @@ func setSDKForContainer(
730730 targetFieldName string ,
731731 // The variable name that we want to set a value to
732732 targetVarName string ,
733+ // The path to the field that we access our source value from
734+ sourceFieldPath string ,
733735 // The struct or struct field that we access our source value from
734736 sourceVarName string ,
735737 // ShapeRef of the target struct field
@@ -743,6 +745,7 @@ func setSDKForContainer(
743745 targetFieldName ,
744746 targetVarName ,
745747 targetShapeRef ,
748+ sourceFieldPath ,
746749 sourceVarName ,
747750 indentLevel ,
748751 )
@@ -752,6 +755,7 @@ func setSDKForContainer(
752755 targetFieldName ,
753756 targetVarName ,
754757 targetShapeRef ,
758+ sourceFieldPath ,
755759 sourceVarName ,
756760 indentLevel ,
757761 )
@@ -761,6 +765,7 @@ func setSDKForContainer(
761765 targetFieldName ,
762766 targetVarName ,
763767 targetShapeRef ,
768+ sourceFieldPath ,
764769 sourceVarName ,
765770 indentLevel ,
766771 )
@@ -770,13 +775,74 @@ func setSDKForContainer(
770775 targetFieldName ,
771776 targetVarName ,
772777 targetShapeRef .Shape .Type ,
778+ sourceFieldPath ,
773779 sourceVarName ,
774780 targetShapeRef ,
775781 indentLevel ,
776782 )
777783 }
778784}
779785
786+ // setSDKForSecret returns a string of Go code that sets a target variable to
787+ // the value of a Secret when the type of the source variable is a
788+ // SecretKeyReference.
789+ //
790+ // The Go code output from this function looks like this:
791+ //
792+ // if ko.Spec.MasterUserPassword != nil {
793+ // tmpSecret, err := rm.rr.SecretValueFromReference(ctx, ko.Spec.MasterUserPassword)
794+ // if err != nil {
795+ // return nil, err
796+ // }
797+ // if tmpSecret != "" {
798+ // res.SetMasterUserPassword(tmpSecret)
799+ // }
800+ // }
801+ func setSDKForSecret (
802+ cfg * ackgenconfig.Config ,
803+ r * model.CRD ,
804+ // The name of the SDK Shape field we're setting
805+ targetFieldName string ,
806+ // The variable name that we want to set a value on
807+ targetVarName string ,
808+ // The CR field that we access our source value from
809+ sourceVarName string ,
810+ indentLevel int ,
811+ ) string {
812+ out := ""
813+ indent := strings .Repeat ("\t " , indentLevel )
814+ secVar := "tmpSecret"
815+
816+ // if ko.Spec.MasterUserPassword != nil {
817+ out += fmt .Sprintf (
818+ "%sif %s != nil {\n " ,
819+ indent , sourceVarName ,
820+ )
821+ // tmpSecret, err := rm.rr.SecretValueFromReference(ctx, ko.Spec.MasterUserPassword)
822+ out += fmt .Sprintf (
823+ "%s\t %s, err := rm.rr.SecretValueFromReference(ctx, %s)\n " ,
824+ indent , secVar , sourceVarName ,
825+ )
826+ // if err != nil {
827+ // return nil, err
828+ // }
829+ out += fmt .Sprintf ("%s\t if err != nil {\n " , indent )
830+ out += fmt .Sprintf ("%s\t \t return nil, err\n " , indent )
831+ out += fmt .Sprintf ("%s\t }\n " , indent )
832+ // if tmpSecret != "" {
833+ // res.SetMasterUserPassword(tmpSecret)
834+ // }
835+ out += fmt .Sprintf ("%s\t if tmpSecret != \" \" {\n " , indent )
836+ out += fmt .Sprintf (
837+ "%s\t \t %s.Set%s(%s)\n " ,
838+ indent , targetVarName , targetFieldName , secVar ,
839+ )
840+ out += fmt .Sprintf ("%s\t }\n " , indent )
841+ // }
842+ out += fmt .Sprintf ("%s}\n " , indent )
843+ return out
844+ }
845+
780846// setSDKForStruct returns a string of Go code that sets a target variable
781847// value to a source variable when the type of the source variable is a struct.
782848func setSDKForStruct (
@@ -788,6 +854,8 @@ func setSDKForStruct(
788854 targetVarName string ,
789855 // Shape Ref of the target struct field
790856 targetShapeRef * awssdkmodel.ShapeRef ,
857+ // The path to the field that we access our source value from
858+ sourceFieldPath string ,
791859 // The struct or struct field that we access our source value from
792860 sourceVarName string ,
793861 indentLevel int ,
@@ -801,14 +869,28 @@ func setSDKForStruct(
801869 memberShape := memberShapeRef .Shape
802870 cleanMemberNames := names .New (memberName )
803871 cleanMemberName := cleanMemberNames .Camel
804- memberVarName := fmt .Sprintf ("%sf%d" , targetVarName , memberIndex )
805872 sourceAdaptedVarName := sourceVarName + "." + cleanMemberName
873+ memberFieldPath := sourceFieldPath + "." + cleanMemberName
874+ if r .IsSecretField (memberFieldPath ) {
875+ out += setSDKForSecret (
876+ cfg , r ,
877+ memberName ,
878+ targetVarName ,
879+ sourceAdaptedVarName ,
880+ indentLevel ,
881+ )
882+ continue
883+ }
806884 out += fmt .Sprintf (
807885 "%sif %s != nil {\n " , indent , sourceAdaptedVarName ,
808886 )
809887 switch memberShape .Type {
810888 case "list" , "structure" , "map" :
811889 {
890+ memberVarName := fmt .Sprintf (
891+ "%sf%d" ,
892+ targetVarName , memberIndex ,
893+ )
812894 out += varEmptyConstructorSDKType (
813895 cfg , r ,
814896 memberVarName ,
@@ -819,6 +901,7 @@ func setSDKForStruct(
819901 cfg , r ,
820902 memberName ,
821903 memberVarName ,
904+ memberFieldPath ,
822905 sourceAdaptedVarName ,
823906 memberShapeRef ,
824907 indentLevel + 1 ,
@@ -828,6 +911,7 @@ func setSDKForStruct(
828911 memberName ,
829912 targetVarName ,
830913 targetShape .Type ,
914+ memberFieldPath ,
831915 memberVarName ,
832916 memberShapeRef ,
833917 indentLevel + 1 ,
@@ -839,6 +923,7 @@ func setSDKForStruct(
839923 memberName ,
840924 targetVarName ,
841925 targetShape .Type ,
926+ memberFieldPath ,
842927 sourceAdaptedVarName ,
843928 memberShapeRef ,
844929 indentLevel + 1 ,
@@ -862,6 +947,8 @@ func setSDKForSlice(
862947 targetVarName string ,
863948 // Shape Ref of the target struct field
864949 targetShapeRef * awssdkmodel.ShapeRef ,
950+ // The path to the field that we access our source value from
951+ sourceFieldPath string ,
865952 // The struct or struct field that we access our source value from
866953 sourceVarName string ,
867954 indentLevel int ,
@@ -894,6 +981,7 @@ func setSDKForSlice(
894981 cfg , r ,
895982 containerFieldName ,
896983 elemVarName ,
984+ sourceFieldPath + "." ,
897985 iterVarName ,
898986 & targetShape .MemberRef ,
899987 indentLevel + 1 ,
@@ -922,6 +1010,8 @@ func setSDKForMap(
9221010 targetVarName string ,
9231011 // Shape Ref of the target struct field
9241012 targetShapeRef * awssdkmodel.ShapeRef ,
1013+ // The path to the field that we access our source value from
1014+ sourceFieldPath string ,
9251015 // The struct or struct field that we access our source value from
9261016 sourceVarName string ,
9271017 indentLevel int ,
@@ -955,6 +1045,7 @@ func setSDKForMap(
9551045 cfg , r ,
9561046 containerFieldName ,
9571047 valVarName ,
1048+ sourceFieldPath + "." ,
9581049 valIterVarName ,
9591050 & targetShape .ValueRef ,
9601051 indentLevel + 1 ,
@@ -1063,6 +1154,8 @@ func setSDKForScalar(
10631154 targetVarName string ,
10641155 // The type of shape of the target variable
10651156 targetVarType string ,
1157+ // The path to the field that we access our source value from
1158+ sourceFieldPath string ,
10661159 // The struct or struct field that we access our source value from
10671160 sourceVarName string ,
10681161 shapeRef * awssdkmodel.ShapeRef ,
0 commit comments