@@ -141,8 +141,36 @@ def get_sc_product_id(product_id):
141
141
except Exception as e :
142
142
log .error (f"Error getting product ID from SC: { e } " )
143
143
return False
144
-
144
+ # This method is to find the values defined for allowlist in values*.yaml files under helm_deploy folder of each project.
145
+ # This methods read all the values files under helm_deploy folder and create a dictionary object of allowlist for each environment
146
+ # including the default values.
147
+ def fetch_values_for_allowlist_key (yaml_data , key ):
148
+ values = {}
149
+ if isinstance (yaml_data , dict ):
150
+ if key in yaml_data :
151
+ values .update (yaml_data [key ])
152
+ for k , v in yaml_data .items ():
153
+ if isinstance (v , dict ) or isinstance (v , list ):
154
+ child_values = fetch_values_for_allowlist_key (v , key )
155
+ if child_values :
156
+ values .update ({k : child_values })
157
+ elif isinstance (yaml_data , list ):
158
+ for item in yaml_data :
159
+ child_values = fetch_values_for_allowlist_key (item , key )
160
+ if child_values :
161
+ values .update (child_values )
162
+ return values
163
+
164
+ # This method read the value stored in dictionary passed to it checks if the ip allow list is present or not and returns boolean
165
+
166
+ def is_ipallowList_enabled (yaml_data ):
167
+ ip_allow_list_enabled = False
168
+ if len (yaml_data ) != 0 :
169
+ ip_allow_list_enabled = True
170
+ return ip_allow_list_enabled
145
171
def process_repo (** component ):
172
+
173
+ allow_list_key = "allowlist"
146
174
c_name = component ["attributes" ]["name" ]
147
175
c_id = component ["id" ]
148
176
github_repo = component ["attributes" ]["github_repo" ]
@@ -175,6 +203,10 @@ def process_repo(**component):
175
203
teams_write = []
176
204
teams_admin = []
177
205
teams_maintain = []
206
+ #variables used for implemenmtation of findind IP allowlist in helm values files
207
+ ip_allow_list_data = {}
208
+ ip_allow_list = {}
209
+ ip_allow_list_default = {}
178
210
179
211
try :
180
212
branch_protection = default_branch .get_protection ()
@@ -249,8 +281,17 @@ def process_repo(**component):
249
281
if file .name .startswith ('values-' ):
250
282
env = re .match ('values-([a-z0-9-]+)\\ .y[a]?ml' , file .name )[1 ]
251
283
helm_environments .append (env )
284
+
285
+ # HEAT-223 Start : Read and collate data for IPallowlist from all environment specific values.yaml files.
286
+ ip_allow_list [file ] = fetch_values_for_allowlist_key (get_file_yaml (repo , f"{ monorepo_dir_suffix } helm_deploy/{ file .name } " ), allow_list_key )
287
+ ip_allow_list_data .update ({file .name : ip_allow_list [file ]})
288
+ # HEAT-223 End : Read and collate data for IPallowlist from all environment specific values.yaml files.
289
+
252
290
helm_default_values = get_file_yaml (repo , f"{ monorepo_dir_suffix } helm_deploy/{ c_name } /values.yaml" )
253
291
if helm_default_values :
292
+
293
+ ip_allow_list_default = fetch_values_for_allowlist_key (helm_default_values , allow_list_key )
294
+
254
295
# Try to get the container image
255
296
try :
256
297
container_image = helm_default_values ['image' ]['repository' ]
@@ -323,12 +364,30 @@ def process_repo(**component):
323
364
if 'circleci_project_k8s_namespace' in p :
324
365
dev_namespace = p ['circleci_project_k8s_namespace' ]
325
366
e = {'namespace' : dev_namespace , 'type' : 'dev' }
367
+ allow_list_values_for_prj_ns = {}
326
368
if 'dev' in helm_envs :
327
369
dev_url = f"https://{ helm_envs ['dev' ]['host' ]} "
328
370
e .update ({'name' : 'dev' , 'type' : 'dev' , 'url' : dev_url })
371
+
372
+ try :
373
+ ip_allow_list_env = ip_allow_list_data ['values-dev.yaml' ]
374
+ allow_list_values_for_prj_ns .update ({'values-dev.yaml' : ip_allow_list_env , 'values.yaml' :ip_allow_list_default })
375
+ except KeyError :
376
+ pass
377
+
378
+ e .update ({'ip_allow_list' : allow_list_values_for_prj_ns , 'ip_allow_list_enabled' : is_ipallowList_enabled (allow_list_values_for_prj_ns )})
379
+
329
380
elif 'development' in helm_envs :
330
381
dev_url = f"https://{ helm_envs ['development' ]['host' ]} "
331
382
e .update ({'name' : 'development' , 'type' : 'dev' , 'url' : dev_url })
383
+
384
+ try :
385
+ ip_allow_list_env = ip_allow_list_data ['values-development.yaml' ]
386
+ allow_list_values_for_prj_ns .update ({'values-development.yaml' : ip_allow_list_env , 'values.yaml' :ip_allow_list_default })
387
+ except KeyError :
388
+ pass
389
+ e .update ({'ip_allow_list' : allow_list_values_for_prj_ns , 'ip_allow_list_enabled' : is_ipallowList_enabled (allow_list_values_for_prj_ns )})
390
+
332
391
else :
333
392
dev_url = False
334
393
@@ -361,6 +420,7 @@ def process_repo(**component):
361
420
if 'circleci_context_k8s_namespaces' in p :
362
421
for c in p ['circleci_context_k8s_namespaces' ]:
363
422
e = {}
423
+ allow_list_values = {}
364
424
env_name = c ['env_name' ]
365
425
env_type = c ['env_type' ]
366
426
@@ -369,24 +429,80 @@ def process_repo(**component):
369
429
if env_name in helm_envs :
370
430
env_url = f"https://{ helm_envs [env_name ]['host' ]} "
371
431
e .update ({'name' : env_name , 'url' : env_url })
432
+ try :
433
+ ip_allow_list_env = ip_allow_list_data [f'values-{ env_name } .yaml' ]
434
+ allow_list_values .update ({f'values-{ env_name } .yaml' : ip_allow_list_env , 'values.yaml' :ip_allow_list_default })
435
+ except KeyError :
436
+ pass
437
+
438
+ e .update ({'ip_allow_list' : allow_list_values , 'ip_allow_list_enabled' : is_ipallowList_enabled (allow_list_values )})
439
+
372
440
elif 'developement' in helm_envs :
373
441
env_url = f"https://{ helm_envs ['developement' ]['host' ]} "
374
442
e .update ({'type' : 'dev' , 'name' : 'developement' , 'url' : env_url })
443
+ try :
444
+ ip_allow_list_env = ip_allow_list_data [f'values-{ env_name } .yaml' ]
445
+ allow_list_values .update ({f'values-{ env_name } .yaml' : ip_allow_list_env , 'values.yaml' :ip_allow_list_default })
446
+ except KeyError :
447
+ pass
448
+
449
+ e .update ({'ip_allow_list' : allow_list_values , 'ip_allow_list_enabled' : is_ipallowList_enabled (allow_list_values )})
450
+
375
451
elif 'test' in helm_envs :
376
452
env_url = f"https://{ helm_envs ['test' ]['host' ]} "
377
453
e .update ({'type' : 'test' , 'name' : 'test' , 'url' : env_url })
454
+ try :
455
+ ip_allow_list_env = ip_allow_list_data ['values-test.yaml' ]
456
+ allow_list_values .update ({'values-test.yaml' : ip_allow_list_env , 'values.yaml' :ip_allow_list_default })
457
+ except KeyError :
458
+ pass
459
+
460
+ e .update ({'ip_allow_list' : allow_list_values , 'ip_allow_list_enabled' : is_ipallowList_enabled (allow_list_values )})
461
+
378
462
elif 'testing' in helm_envs :
379
463
env_url = f"https://{ helm_envs ['testing' ]['host' ]} "
380
464
e .update ({'type' : 'test' , 'name' : 'testing' , 'url' : env_url })
465
+ try :
466
+ ip_allow_list_env = ip_allow_list_data ['values-testing.yaml' ]
467
+ allow_list_values .update ({'values-testing.yaml' : ip_allow_list_env , 'values.yaml' :ip_allow_list_default })
468
+ except KeyError :
469
+ pass
470
+
471
+ e .update ({'ip_allow_list' : allow_list_values , 'ip_allow_list_enabled' : is_ipallowList_enabled (allow_list_values )})
472
+
381
473
elif 'staging' in helm_envs :
382
474
env_url = f"https://{ helm_envs ['staging' ]['host' ]} "
383
475
e .update ({'type' : 'stage' , 'name' : 'staging' , 'url' : env_url })
476
+ try :
477
+ ip_allow_list_env = ip_allow_list_data ['values-staging.yaml' ]
478
+ allow_list_values .update ({'values-staging.yaml' : ip_allow_list_env , 'values.yaml' :ip_allow_list_default })
479
+ except KeyError :
480
+ pass
481
+
482
+ e .update ({'ip_allow_list' : allow_list_values , 'ip_allow_list_enabled' : is_ipallowList_enabled (allow_list_values )})
483
+
384
484
elif 'qa' in helm_envs :
385
485
env_url = f"https://{ helm_envs ['qa' ]['host' ]} "
386
486
e .update ({'type' : 'preprod' , 'name' : 'qa' , 'url' : env_url })
487
+ try :
488
+ ip_allow_list_env = ip_allow_list_data ['values-qa.yaml' ]
489
+ allow_list_values .update ({'values-qa.yaml' : ip_allow_list_env , 'values.yaml' :ip_allow_list_default })
490
+ except KeyError :
491
+ pass
492
+
493
+ e .update ({'ip_allow_list' : allow_list_values , 'ip_allow_list_enabled' : is_ipallowList_enabled (allow_list_values )})
494
+
387
495
elif 'production' in helm_envs :
388
496
env_url = f"https://{ helm_envs ['production' ]['host' ]} "
389
497
e .update ({'type' : 'prod' , 'name' : 'production' , 'url' : env_url })
498
+ try :
499
+ ip_allow_list_env = ip_allow_list_data ['values-production.yaml' ]
500
+ allow_list_values .update ({'values-production.yaml' : ip_allow_list_env , 'values.yaml' :ip_allow_list_default })
501
+ except KeyError :
502
+ pass
503
+
504
+ e .update ({'ip_allow_list' : allow_list_values , 'ip_allow_list_enabled' : is_ipallowList_enabled (allow_list_values )})
505
+
390
506
else :
391
507
env_url = False
392
508
0 commit comments