@@ -236,17 +236,6 @@ func SetSDK(
236
236
sourceAdaptedVarName += "." + f .Names .Camel
237
237
sourceFieldPath := f .Names .Camel
238
238
239
- if r .IsSecretField (memberName ) {
240
- out += setSDKForSecret (
241
- cfg , r ,
242
- memberName ,
243
- targetVarName ,
244
- sourceAdaptedVarName ,
245
- indentLevel ,
246
- )
247
- continue
248
- }
249
-
250
239
memberShapeRef , _ := inputShape .MemberRefs [memberName ]
251
240
memberShape := memberShapeRef .Shape
252
241
@@ -339,16 +328,26 @@ func SetSDK(
339
328
)
340
329
}
341
330
default :
342
- out += setSDKForScalar (
343
- cfg , r ,
344
- memberName ,
345
- targetVarName ,
346
- inputShape .Type ,
347
- sourceFieldPath ,
348
- sourceAdaptedVarName ,
349
- memberShapeRef ,
350
- indentLevel + 1 ,
351
- )
331
+ if r .IsSecretField (memberName ) {
332
+ out += setSDKForSecret (
333
+ cfg , r ,
334
+ memberName ,
335
+ targetVarName ,
336
+ sourceAdaptedVarName ,
337
+ indentLevel ,
338
+ )
339
+ } else {
340
+ out += setSDKForScalar (
341
+ cfg , r ,
342
+ memberName ,
343
+ targetVarName ,
344
+ inputShape .Type ,
345
+ sourceFieldPath ,
346
+ sourceAdaptedVarName ,
347
+ memberShapeRef ,
348
+ indentLevel + 1 ,
349
+ )
350
+ }
352
351
}
353
352
out += fmt .Sprintf (
354
353
"%s}\n " , indent ,
@@ -770,6 +769,25 @@ func setSDKForContainer(
770
769
indentLevel ,
771
770
)
772
771
default :
772
+ if r .IsSecretField (sourceFieldPath ) {
773
+ indent := strings .Repeat ("\t " , indentLevel )
774
+ // if ko.Spec.MasterUserPassword != nil {
775
+ out := fmt .Sprintf (
776
+ "%sif %s != nil {\n " ,
777
+ indent , sourceVarName ,
778
+ )
779
+ out += setSDKForSecret (
780
+ cfg , r ,
781
+ "" ,
782
+ targetVarName ,
783
+ sourceVarName ,
784
+ indentLevel ,
785
+ )
786
+ // }
787
+ out += fmt .Sprintf ("%s}\n " , indent )
788
+ return out
789
+ }
790
+
773
791
return setSDKForScalar (
774
792
cfg , r ,
775
793
targetFieldName ,
@@ -789,15 +807,27 @@ func setSDKForContainer(
789
807
//
790
808
// The Go code output from this function looks like this:
791
809
//
792
- // if ko.Spec.MasterUserPassword != nil {
793
810
// tmpSecret, err := rm.rr.SecretValueFromReference(ctx, ko.Spec.MasterUserPassword)
794
811
// if err != nil {
795
812
// return nil, err
796
813
// }
797
814
// if tmpSecret != "" {
798
815
// res.SetMasterUserPassword(tmpSecret)
799
816
// }
800
- // }
817
+ //
818
+ // or:
819
+ //
820
+ // tmpSecret, err := rm.rr.SecretValueFromReference(ctx, f3iter)
821
+ // if err != nil {
822
+ // return nil, err
823
+ // }
824
+ // if tmpSecret != "" {
825
+ // f3elem = tmpSecret
826
+ // }
827
+ //
828
+ // The second case is used when the SecretKeyReference field
829
+ // is a slice of `[]*string` in the original AWS API Input shape.
830
+
801
831
func setSDKForSecret (
802
832
cfg * ackgenconfig.Config ,
803
833
r * model.CRD ,
@@ -809,15 +839,11 @@ func setSDKForSecret(
809
839
sourceVarName string ,
810
840
indentLevel int ,
811
841
) string {
842
+
812
843
out := ""
813
844
indent := strings .Repeat ("\t " , indentLevel )
814
845
secVar := "tmpSecret"
815
846
816
- // if ko.Spec.MasterUserPassword != nil {
817
- out += fmt .Sprintf (
818
- "%sif %s != nil {\n " ,
819
- indent , sourceVarName ,
820
- )
821
847
// tmpSecret, err := rm.rr.SecretValueFromReference(ctx, ko.Spec.MasterUserPassword)
822
848
out += fmt .Sprintf (
823
849
"%s\t %s, err := rm.rr.SecretValueFromReference(ctx, %s)\n " ,
@@ -833,13 +859,18 @@ func setSDKForSecret(
833
859
// res.SetMasterUserPassword(tmpSecret)
834
860
// }
835
861
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
- )
862
+ if targetFieldName == "" {
863
+ out += fmt .Sprintf (
864
+ "%s\t \t %s = %s\n " ,
865
+ indent , targetVarName , secVar ,
866
+ )
867
+ } else {
868
+ out += fmt .Sprintf (
869
+ "%s\t \t %s.Set%s(%s)\n " ,
870
+ indent , targetVarName , targetFieldName , secVar ,
871
+ )
872
+ }
840
873
out += fmt .Sprintf ("%s\t }\n " , indent )
841
- // }
842
- out += fmt .Sprintf ("%s}\n " , indent )
843
874
return out
844
875
}
845
876
@@ -871,16 +902,7 @@ func setSDKForStruct(
871
902
cleanMemberName := cleanMemberNames .Camel
872
903
sourceAdaptedVarName := sourceVarName + "." + cleanMemberName
873
904
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
- }
905
+
884
906
out += fmt .Sprintf (
885
907
"%sif %s != nil {\n " , indent , sourceAdaptedVarName ,
886
908
)
@@ -918,16 +940,26 @@ func setSDKForStruct(
918
940
)
919
941
}
920
942
default :
921
- out += setSDKForScalar (
922
- cfg , r ,
923
- memberName ,
924
- targetVarName ,
925
- targetShape .Type ,
926
- memberFieldPath ,
927
- sourceAdaptedVarName ,
928
- memberShapeRef ,
929
- indentLevel + 1 ,
930
- )
943
+ if r .IsSecretField (memberFieldPath ) {
944
+ out += setSDKForSecret (
945
+ cfg , r ,
946
+ memberName ,
947
+ targetVarName ,
948
+ sourceAdaptedVarName ,
949
+ indentLevel ,
950
+ )
951
+ } else {
952
+ out += setSDKForScalar (
953
+ cfg , r ,
954
+ memberName ,
955
+ targetVarName ,
956
+ targetShape .Type ,
957
+ memberFieldPath ,
958
+ sourceAdaptedVarName ,
959
+ memberShapeRef ,
960
+ indentLevel + 1 ,
961
+ )
962
+ }
931
963
}
932
964
out += fmt .Sprintf (
933
965
"%s}\n " , indent ,
@@ -974,14 +1006,16 @@ func setSDKForSlice(
974
1006
//
975
1007
// f0elem.SetMyField(*f0iter)
976
1008
containerFieldName := ""
1009
+ sourceAttributePath := sourceFieldPath
977
1010
if targetShape .MemberRef .Shape .Type == "structure" {
978
1011
containerFieldName = targetFieldName
1012
+ sourceAttributePath = sourceFieldPath + "."
979
1013
}
980
1014
out += setSDKForContainer (
981
1015
cfg , r ,
982
1016
containerFieldName ,
983
1017
elemVarName ,
984
- sourceFieldPath + "." ,
1018
+ sourceAttributePath ,
985
1019
iterVarName ,
986
1020
& targetShape .MemberRef ,
987
1021
indentLevel + 1 ,
0 commit comments