@@ -39,17 +39,32 @@ class SubprocessRunError(Exception):
3939# Function to apply vars for a group or a project (gorp)
4040def apply_vars_gorp (gorp_kind , yaml_dict , gorp , gorp_dict , variables_clean_all_before_set , logger ):
4141
42+ # Expand defaults gorp_dict to gorp_dict_variables_pre0
43+ gorp_dict_variables_pre0 = []
44+ for var in gorp_dict ["variables" ]:
45+ if "variable_type" not in var :
46+ var ["variable_type" ] = "env_var"
47+ if "protected" not in var :
48+ var ["protected" ] = False
49+ if "masked" not in var :
50+ var ["masked" ] = False
51+ if "raw" not in var :
52+ var ["raw" ] = False
53+ if "environment_scope" not in var :
54+ var ["environment_scope" ] = "*"
55+ gorp_dict_variables_pre0 .append (var )
56+
4257 # Expand quick key_values sets, pre1 before expanding environment_scope
4358 gorp_dict_variables_pre1 = []
44- for var in gorp_dict [ "variables" ] :
59+ for var in gorp_dict_variables_pre0 :
4560 if "key_values" in var :
4661 for k , v in var ["key_values" ].items ():
4762 gorp_dict_variables_pre1 .append (
4863 {
4964 "variable_type" : var ["variable_type" ],
5065 "protected" : var ["protected" ],
5166 "masked" : var ["masked" ],
52- "raw" : var ["raw" ] if "raw" in var else False ,
67+ "raw" : var ["raw" ],
5368 "environment_scope" : var ["environment_scope" ],
5469 "key" : k ,
5570 "value" : v
@@ -68,7 +83,7 @@ def apply_vars_gorp(gorp_kind, yaml_dict, gorp, gorp_dict, variables_clean_all_b
6883 "variable_type" : var ["variable_type" ],
6984 "protected" : var ["protected" ],
7085 "masked" : var ["masked" ],
71- "raw" : var ["raw" ] if "raw" in var else False ,
86+ "raw" : var ["raw" ],
7287 "environment_scope" : env_scope ,
7388 "key" : var ["key" ],
7489 "value" : var ["value" ]
@@ -87,17 +102,32 @@ def apply_vars_gorp(gorp_kind, yaml_dict, gorp, gorp_dict, variables_clean_all_b
87102 if var_file_dict is None :
88103 raise Exception ("Config file error or missing: {0}" .format (var_file ))
89104
105+ # Expand defaults in var_file_dict to var_file_dict_expanded_pre0
106+ var_file_dict_expanded_pre0 = []
107+ for var in var_file_dict :
108+ if "variable_type" not in var :
109+ var ["variable_type" ] = "env_var"
110+ if "protected" not in var :
111+ var ["protected" ] = False
112+ if "masked" not in var :
113+ var ["masked" ] = False
114+ if "raw" not in var :
115+ var ["raw" ] = False
116+ if "environment_scope" not in var :
117+ var ["environment_scope" ] = "*"
118+ var_file_dict_expanded_pre0 .append (var )
119+
90120 # Expand quick key_values sets in variables from file, pre1 before expanding environment_scope
91121 var_file_dict_expanded_pre1 = []
92- for var in var_file_dict :
122+ for var in var_file_dict_expanded_pre0 :
93123 if "key_values" in var :
94124 for k , v in var ["key_values" ].items ():
95125 var_file_dict_expanded_pre1 .append (
96126 {
97127 "variable_type" : var ["variable_type" ],
98128 "protected" : var ["protected" ],
99129 "masked" : var ["masked" ],
100- "raw" : var ["raw" ] if "raw" in var else False ,
130+ "raw" : var ["raw" ],
101131 "environment_scope" : var ["environment_scope" ],
102132 "key" : k ,
103133 "value" : v
@@ -116,7 +146,7 @@ def apply_vars_gorp(gorp_kind, yaml_dict, gorp, gorp_dict, variables_clean_all_b
116146 "variable_type" : var ["variable_type" ],
117147 "protected" : var ["protected" ],
118148 "masked" : var ["masked" ],
119- "raw" : var ["raw" ] if "raw" in var else False ,
149+ "raw" : var ["raw" ],
120150 "environment_scope" : env_scope ,
121151 "key" : var ["key" ],
122152 "value" : var ["value" ]
@@ -157,7 +187,7 @@ def apply_vars_gorp(gorp_kind, yaml_dict, gorp, gorp_dict, variables_clean_all_b
157187 or
158188 gorp_var .masked != var ["masked" ]
159189 or
160- gorp_var .raw != ( var ["raw" ] if "raw" in var else False )
190+ gorp_var .raw != var ["raw" ]
161191 ):
162192 print ("changed: {scope} / {var}:" .format (scope = var ["environment_scope" ], var = var ["key" ]))
163193 # Print old -> new
@@ -169,15 +199,15 @@ def apply_vars_gorp(gorp_kind, yaml_dict, gorp, gorp_dict, variables_clean_all_b
169199 print (" protected: {old} -> {new}" .format (old = gorp_var .protected , new = var ["protected" ]))
170200 if gorp_var .masked != var ["masked" ]:
171201 print (" masked: {old} -> {new}" .format (old = gorp_var .masked , new = var ["masked" ]))
172- if gorp_var .raw != ( var ["raw" ] if "raw" in var else False ) :
173- print (" raw: {old} -> {new}" .format (old = gorp_var .raw , new = var ["raw" ] if "raw" in var else False ))
202+ if gorp_var .raw != var ["raw" ]:
203+ print (" raw: {old} -> {new}" .format (old = gorp_var .raw , new = var ["raw" ]))
174204 if not var_found :
175205 print ("new: {scope} / {var}" .format (scope = var ["environment_scope" ], var = var ["key" ]))
176206 print (" value: {value}" .format (value = var ["value" ]))
177207 print (" variable_type: {variable_type}" .format (variable_type = var ["variable_type" ]))
178208 print (" protected: {protected}" .format (protected = var ["protected" ]))
179209 print (" masked: {masked}" .format (masked = var ["masked" ]))
180- print (" raw: {raw}" .format (raw = var ["raw" ] if "raw" in var else False ))
210+ print (" raw: {raw}" .format (raw = var ["raw" ]))
181211
182212 # Check vars to delete
183213 for gorp_var in old_gorp_variables :
@@ -264,7 +294,7 @@ def create_var(var):
264294 "variable_type" : var ["variable_type" ],
265295 "protected" : var ["protected" ],
266296 "masked" : var ["masked" ],
267- "raw" : var ["raw" ] if "raw" in var else False ,
297+ "raw" : var ["raw" ],
268298 "environment_scope" : var ["environment_scope" ]
269299 }
270300 executor .submit (create_var , var_dict )
@@ -289,7 +319,7 @@ def create_var(var):
289319 or
290320 gorp_var .masked != var ["masked" ]
291321 or
292- gorp_var .raw != ( var ["raw" ] if "raw" in var else False )
322+ gorp_var .raw != var ["raw" ]
293323 ):
294324 # gorp_var.delete()
295325 # There is a bug (at least at python-gitlab 2.5.0):
@@ -352,7 +382,7 @@ def create_var(var):
352382 "variable_type" : var ["variable_type" ],
353383 "protected" : var ["protected" ],
354384 "masked" : var ["masked" ],
355- "raw" : var ["raw" ] if "raw" in var else False ,
385+ "raw" : var ["raw" ],
356386 "environment_scope" : var ["environment_scope" ]
357387 }
358388 try :
0 commit comments