@@ -69,69 +69,78 @@ func processDeployment(
6969 }
7070}
7171
72+ func getDirectDeploymentVariableValue (value DirectDeploymentVariableValue ) (api.DirectDeploymentVariableValue , error ) {
73+ directValue := api.DirectDeploymentVariableValue {
74+ IsDefault : value .IsDefault ,
75+ Sensitive : value .Sensitive ,
76+ ResourceSelector : value .ResourceSelector ,
77+ Value : & api.DirectDeploymentVariableValue_Value {},
78+ }
79+
80+ valueData , err := json .Marshal (value .Value )
81+ if err != nil {
82+ return api.DirectDeploymentVariableValue {}, err
83+ }
84+ if err := directValue .Value .UnmarshalJSON (valueData ); err != nil {
85+ return api.DirectDeploymentVariableValue {}, err
86+ }
87+ return directValue , nil
88+ }
89+
90+ func getReferenceDeploymentVariableValue (value ReferenceDeploymentVariableValue ) (api.ReferenceDeploymentVariableValue , error ) {
91+ referenceValue := api.ReferenceDeploymentVariableValue {
92+ IsDefault : value .IsDefault ,
93+ ResourceSelector : value .ResourceSelector ,
94+ Path : value .Path ,
95+ Reference : value .Reference ,
96+ }
97+
98+ if value .DefaultValue != nil {
99+ referenceValue .DefaultValue = & api.ReferenceDeploymentVariableValue_DefaultValue {}
100+ valueData , err := json .Marshal (value .DefaultValue )
101+ if err != nil {
102+ return api.ReferenceDeploymentVariableValue {}, err
103+ }
104+ if err := referenceValue .DefaultValue .UnmarshalJSON (valueData ); err != nil {
105+ return api.ReferenceDeploymentVariableValue {}, err
106+ }
107+ }
108+
109+ return referenceValue , nil
110+ }
111+
72112func upsertDeploymentVariable (
73113 ctx context.Context ,
74114 client * api.ClientWithResponses ,
75115 deploymentID uuid.UUID ,
76116 variable DeploymentVariable ,
77117) {
78- vars := []api.VariableValue {}
79- for _ , value := range variable .Values {
80- if value .Value != nil {
81- directValue := api.DeploymentVariableDirectValue {}
82- directValue .Default = value .Default
83- directValue .Sensitive = value .Sensitive
84- directValue .ValueType = "direct"
85- directValue .ResourceSelector = value .ResourceSelector
86-
87- directValue .Value = api.DeploymentVariableDirectValue_Value {}
88- valueData , err := json .Marshal (* value .Value )
89- if err != nil {
90- log .Error ("Failed to marshal direct value" , "error" , err )
91- continue
92- }
93- directValue .Value .UnmarshalJSON (valueData )
94-
95- var varDirect api.VariableValue
96- varDirect .FromDeploymentVariableDirectValue (directValue )
97- vars = append (vars , varDirect )
118+ directValues := []api.DirectDeploymentVariableValue {}
119+ for _ , value := range variable .DirectValues {
120+ directValue , err := getDirectDeploymentVariableValue (value )
121+ if err != nil {
122+ log .Error ("Failed to get direct deployment variable value" , "error" , err )
98123 continue
99124 }
125+ directValues = append (directValues , directValue )
126+ }
100127
101- if value .Reference != nil && value .Path != nil {
102- referenceValue := api.DeploymentVariableReferenceValue {}
103- referenceValue .Default = value .Default
104- referenceValue .Reference = * value .Reference
105- referenceValue .Path = * value .Path
106- referenceValue .ResourceSelector = value .ResourceSelector
107- referenceValue .ValueType = "reference"
108-
109- if value .DefaultValue != nil {
110- referenceValue .DefaultValue = & api.DeploymentVariableReferenceValue_DefaultValue {}
111- valueData , err := json .Marshal (* value .DefaultValue )
112- if err != nil {
113- log .Error ("Failed to marshal default value" , "error" , err )
114- continue
115- }
116- referenceValue .DefaultValue .UnmarshalJSON (valueData )
117- }
118-
119- varReference := api.VariableValue {}
120- varReference .FromDeploymentVariableReferenceValue (referenceValue )
121- vars = append (vars , varReference )
128+ referenceValues := []api.ReferenceDeploymentVariableValue {}
129+ for _ , value := range variable .ReferenceValues {
130+ referenceValue , err := getReferenceDeploymentVariableValue (value )
131+ if err != nil {
132+ log .Error ("Failed to get reference deployment variable value" , "error" , err )
122133 continue
123134 }
124-
125- log .Error ("Unsupported variable value type" , "type" , variable .Values )
135+ referenceValues = append (referenceValues , referenceValue )
126136 }
127137
128- log .Info ("Creating deployment variable" , "key" , variable .Key , "values" , len (vars ))
129-
130138 body := api.CreateDeploymentVariableJSONRequestBody {
131- Key : variable .Key ,
132- Description : variable .Description ,
133- Values : & vars ,
134- Config : variable .Config ,
139+ Key : variable .Key ,
140+ Description : variable .Description ,
141+ DirectValues : & directValues ,
142+ ReferenceValues : & referenceValues ,
143+ Config : variable .Config ,
135144 }
136145
137146 _ , err := client .CreateDeploymentVariableWithResponse (ctx , deploymentID , body )
0 commit comments