@@ -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))
@@ -252,6 +235,17 @@ func SetSDK(
252
235
}
253
236
sourceAdaptedVarName += "." + f .Names .Camel
254
237
238
+ if r .IsSecretField (memberName ) {
239
+ out += setSDKForSecret (
240
+ cfg , r ,
241
+ memberName ,
242
+ targetVarName ,
243
+ sourceAdaptedVarName ,
244
+ indentLevel ,
245
+ )
246
+ continue
247
+ }
248
+
255
249
memberShapeRef , _ := inputShape .MemberRefs [memberName ]
256
250
memberShape := memberShapeRef .Shape
257
251
@@ -777,6 +771,66 @@ func setSDKForContainer(
777
771
}
778
772
}
779
773
774
+ // setSDKForSecret returns a string of Go code that sets a target variable to
775
+ // the value of a Secret when the type of the source variable is a
776
+ // SecretKeyReference.
777
+ //
778
+ // The Go code output from this function looks like this:
779
+ //
780
+ // if ko.Spec.MasterUserPassword != nil {
781
+ // tmpSecret, err := rm.rr.SecretValueFromReference(ctx, ko.Spec.MasterUserPassword)
782
+ // if err != nil {
783
+ // return nil, err
784
+ // }
785
+ // if tmpSecret != "" {
786
+ // res.SetMasterUserPassword(tmpSecret)
787
+ // }
788
+ // }
789
+ func setSDKForSecret (
790
+ cfg * ackgenconfig.Config ,
791
+ r * model.CRD ,
792
+ // The name of the SDK Shape field we're setting
793
+ targetFieldName string ,
794
+ // The variable name that we want to set a value on
795
+ targetVarName string ,
796
+ // The CR field that we access our source value from
797
+ sourceVarName string ,
798
+ indentLevel int ,
799
+ ) string {
800
+ out := ""
801
+ indent := strings .Repeat ("\t " , indentLevel )
802
+ secVar := "tmpSecret"
803
+
804
+ // if ko.Spec.MasterUserPassword != nil {
805
+ out += fmt .Sprintf (
806
+ "%sif %s != nil {\n " ,
807
+ indent , sourceVarName ,
808
+ )
809
+ // tmpSecret, err := rm.rr.SecretValueFromReference(ctx, ko.Spec.MasterUserPassword)
810
+ out += fmt .Sprintf (
811
+ "%s\t %s, err := rm.rr.SecretValueFromReference(ctx, %s)\n " ,
812
+ indent , secVar , sourceVarName ,
813
+ )
814
+ // if err != nil {
815
+ // return nil, err
816
+ // }
817
+ out += fmt .Sprintf ("%s\t if err != nil {\n " , indent )
818
+ out += fmt .Sprintf ("%s\t \t return nil, err\n " , indent )
819
+ out += fmt .Sprintf ("%s\t }\n " , indent )
820
+ // if tmpSecret != "" {
821
+ // res.SetMasterUserPassword(tmpSecret)
822
+ // }
823
+ out += fmt .Sprintf ("%s\t if tmpSecret != \" \" {\n " , indent )
824
+ out += fmt .Sprintf (
825
+ "%s\t \t %s.Set%s(%s)\n " ,
826
+ indent , targetVarName , targetFieldName , secVar ,
827
+ )
828
+ out += fmt .Sprintf ("%s\t }\n " , indent )
829
+ // }
830
+ out += fmt .Sprintf ("%s}\n " , indent )
831
+ return out
832
+ }
833
+
780
834
// setSDKForStruct returns a string of Go code that sets a target variable
781
835
// value to a source variable when the type of the source variable is a struct.
782
836
func setSDKForStruct (
0 commit comments