@@ -165,7 +165,6 @@ func SetSDK(
165
165
}
166
166
167
167
opConfig , override := cfg .OverrideValues (op .Name )
168
- fieldConfigs := cfg .ResourceFields (r .Names .Original )
169
168
for memberIndex , memberName := range inputShape .MemberNames () {
170
169
if r .UnpacksAttributesMap () && memberName == "Attributes" {
171
170
continue
@@ -190,22 +189,6 @@ func SetSDK(
190
189
}
191
190
}
192
191
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
-
209
192
if r .IsPrimaryARNField (memberName ) {
210
193
// if ko.Status.ACKResourceMetadata != nil && ko.Status.ACKResourceMetadata.ARN != nil {
211
194
// res.SetTopicArn(string(*ko.Status.ACKResourceMetadata.ARN))
@@ -243,14 +226,26 @@ func SetSDK(
243
226
if found {
244
227
sourceAdaptedVarName += cfg .PrefixConfig .SpecField
245
228
} else {
246
- f , found = r .StatusFields [memberName ]
229
+ f , found = r .StatusFields [renamedName ]
247
230
if ! found {
248
231
// TODO(jaypipes): check generator config for exceptions?
249
232
continue
250
233
}
251
234
sourceAdaptedVarName += cfg .PrefixConfig .StatusField
252
235
}
253
236
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
+ }
254
249
255
250
memberShapeRef , _ := inputShape .MemberRefs [memberName ]
256
251
memberShape := memberShapeRef .Shape
@@ -327,6 +322,7 @@ func SetSDK(
327
322
cfg , r ,
328
323
memberName ,
329
324
memberVarName ,
325
+ sourceFieldPath ,
330
326
sourceAdaptedVarName ,
331
327
memberShapeRef ,
332
328
indentLevel + 1 ,
@@ -336,6 +332,7 @@ func SetSDK(
336
332
memberName ,
337
333
targetVarName ,
338
334
inputShape .Type ,
335
+ sourceFieldPath ,
339
336
memberVarName ,
340
337
memberShapeRef ,
341
338
indentLevel + 1 ,
@@ -347,6 +344,7 @@ func SetSDK(
347
344
memberName ,
348
345
targetVarName ,
349
346
inputShape .Type ,
347
+ sourceFieldPath ,
350
348
sourceAdaptedVarName ,
351
349
memberShapeRef ,
352
350
indentLevel + 1 ,
@@ -514,6 +512,7 @@ func SetSDKGetAttributes(
514
512
memberName ,
515
513
targetVarName ,
516
514
inputShape .Type ,
515
+ cleanMemberName ,
517
516
sourceVarPath ,
518
517
field .ShapeRef ,
519
518
indentLevel + 1 ,
@@ -708,6 +707,7 @@ func SetSDKSetAttributes(
708
707
memberName ,
709
708
targetVarName ,
710
709
inputShape .Type ,
710
+ cleanMemberName ,
711
711
sourceVarPath ,
712
712
field .ShapeRef ,
713
713
indentLevel + 1 ,
@@ -730,6 +730,8 @@ func setSDKForContainer(
730
730
targetFieldName string ,
731
731
// The variable name that we want to set a value to
732
732
targetVarName string ,
733
+ // The path to the field that we access our source value from
734
+ sourceFieldPath string ,
733
735
// The struct or struct field that we access our source value from
734
736
sourceVarName string ,
735
737
// ShapeRef of the target struct field
@@ -743,6 +745,7 @@ func setSDKForContainer(
743
745
targetFieldName ,
744
746
targetVarName ,
745
747
targetShapeRef ,
748
+ sourceFieldPath ,
746
749
sourceVarName ,
747
750
indentLevel ,
748
751
)
@@ -752,6 +755,7 @@ func setSDKForContainer(
752
755
targetFieldName ,
753
756
targetVarName ,
754
757
targetShapeRef ,
758
+ sourceFieldPath ,
755
759
sourceVarName ,
756
760
indentLevel ,
757
761
)
@@ -761,6 +765,7 @@ func setSDKForContainer(
761
765
targetFieldName ,
762
766
targetVarName ,
763
767
targetShapeRef ,
768
+ sourceFieldPath ,
764
769
sourceVarName ,
765
770
indentLevel ,
766
771
)
@@ -770,13 +775,74 @@ func setSDKForContainer(
770
775
targetFieldName ,
771
776
targetVarName ,
772
777
targetShapeRef .Shape .Type ,
778
+ sourceFieldPath ,
773
779
sourceVarName ,
774
780
targetShapeRef ,
775
781
indentLevel ,
776
782
)
777
783
}
778
784
}
779
785
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
+
780
846
// setSDKForStruct returns a string of Go code that sets a target variable
781
847
// value to a source variable when the type of the source variable is a struct.
782
848
func setSDKForStruct (
@@ -788,6 +854,8 @@ func setSDKForStruct(
788
854
targetVarName string ,
789
855
// Shape Ref of the target struct field
790
856
targetShapeRef * awssdkmodel.ShapeRef ,
857
+ // The path to the field that we access our source value from
858
+ sourceFieldPath string ,
791
859
// The struct or struct field that we access our source value from
792
860
sourceVarName string ,
793
861
indentLevel int ,
@@ -801,14 +869,28 @@ func setSDKForStruct(
801
869
memberShape := memberShapeRef .Shape
802
870
cleanMemberNames := names .New (memberName )
803
871
cleanMemberName := cleanMemberNames .Camel
804
- memberVarName := fmt .Sprintf ("%sf%d" , targetVarName , memberIndex )
805
872
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
+ }
806
884
out += fmt .Sprintf (
807
885
"%sif %s != nil {\n " , indent , sourceAdaptedVarName ,
808
886
)
809
887
switch memberShape .Type {
810
888
case "list" , "structure" , "map" :
811
889
{
890
+ memberVarName := fmt .Sprintf (
891
+ "%sf%d" ,
892
+ targetVarName , memberIndex ,
893
+ )
812
894
out += varEmptyConstructorSDKType (
813
895
cfg , r ,
814
896
memberVarName ,
@@ -819,6 +901,7 @@ func setSDKForStruct(
819
901
cfg , r ,
820
902
memberName ,
821
903
memberVarName ,
904
+ memberFieldPath ,
822
905
sourceAdaptedVarName ,
823
906
memberShapeRef ,
824
907
indentLevel + 1 ,
@@ -828,6 +911,7 @@ func setSDKForStruct(
828
911
memberName ,
829
912
targetVarName ,
830
913
targetShape .Type ,
914
+ memberFieldPath ,
831
915
memberVarName ,
832
916
memberShapeRef ,
833
917
indentLevel + 1 ,
@@ -839,6 +923,7 @@ func setSDKForStruct(
839
923
memberName ,
840
924
targetVarName ,
841
925
targetShape .Type ,
926
+ memberFieldPath ,
842
927
sourceAdaptedVarName ,
843
928
memberShapeRef ,
844
929
indentLevel + 1 ,
@@ -862,6 +947,8 @@ func setSDKForSlice(
862
947
targetVarName string ,
863
948
// Shape Ref of the target struct field
864
949
targetShapeRef * awssdkmodel.ShapeRef ,
950
+ // The path to the field that we access our source value from
951
+ sourceFieldPath string ,
865
952
// The struct or struct field that we access our source value from
866
953
sourceVarName string ,
867
954
indentLevel int ,
@@ -894,6 +981,7 @@ func setSDKForSlice(
894
981
cfg , r ,
895
982
containerFieldName ,
896
983
elemVarName ,
984
+ sourceFieldPath + "." ,
897
985
iterVarName ,
898
986
& targetShape .MemberRef ,
899
987
indentLevel + 1 ,
@@ -922,6 +1010,8 @@ func setSDKForMap(
922
1010
targetVarName string ,
923
1011
// Shape Ref of the target struct field
924
1012
targetShapeRef * awssdkmodel.ShapeRef ,
1013
+ // The path to the field that we access our source value from
1014
+ sourceFieldPath string ,
925
1015
// The struct or struct field that we access our source value from
926
1016
sourceVarName string ,
927
1017
indentLevel int ,
@@ -955,6 +1045,7 @@ func setSDKForMap(
955
1045
cfg , r ,
956
1046
containerFieldName ,
957
1047
valVarName ,
1048
+ sourceFieldPath + "." ,
958
1049
valIterVarName ,
959
1050
& targetShape .ValueRef ,
960
1051
indentLevel + 1 ,
@@ -1063,6 +1154,8 @@ func setSDKForScalar(
1063
1154
targetVarName string ,
1064
1155
// The type of shape of the target variable
1065
1156
targetVarType string ,
1157
+ // The path to the field that we access our source value from
1158
+ sourceFieldPath string ,
1066
1159
// The struct or struct field that we access our source value from
1067
1160
sourceVarName string ,
1068
1161
shapeRef * awssdkmodel.ShapeRef ,
0 commit comments