5
5
from python_json_config import ConfigBuilder , config_node
6
6
from mergedeep import merge
7
7
8
+ # The ConfigMap - Mapping between runtime environment variable keys and JSON Config keys. Will need to append 'INPUT_' when looking to map within GitHub Actions environment
8
9
ConfigKeyValuePair = {
9
- 'input_type ' : 'input.type' ,
10
- 'input_format ' : 'input.format' ,
11
- 'jira_cloud_url ' : 'jira.cloud_url' ,
12
- 'jira_project_key ' : 'jira.project_key' ,
13
- 'jira_auth_email ' : 'jira.auth_email' ,
14
- 'jira_api_token ' : 'jira.api_token' ,
15
- 'jira_default_issue_labels ' : 'jira.default_issue_labels' ,
16
- 'jira_use_atlassian_document_format ' : 'jira.use_atlassian_document_format' ,
17
- 'jira_create_sub_tasks ' : 'jira.create_sub_tasks'
10
+ 'INPUT_TYPE ' : 'input.type' ,
11
+ 'INPUT_FORMAT ' : 'input.format' ,
12
+ 'JIRA_CLOUD_URL ' : 'jira.cloud_url' ,
13
+ 'JIRA_PROJECT_KEY ' : 'jira.project_key' ,
14
+ 'JIRA_AUTH_EMAIL ' : 'jira.auth_email' ,
15
+ 'JIRA_API_TOKEN ' : 'jira.api_token' ,
16
+ 'JIRA_DEFAULT_ISSUE_LABELS ' : 'jira.default_issue_labels' ,
17
+ 'JIRA_USE_ATLASSIAN_DOCUMENT_FORMAT ' : 'jira.use_atlassian_document_format' ,
18
+ 'JIRA_CREATE_SUB_TASKS ' : 'jira.create_sub_tasks'
18
19
}
19
20
20
21
# SARIF - class to handle Static Analysis Results Interchange Format (SARIF)
@@ -102,8 +103,8 @@ def load_config_file(self) -> dict:
102
103
local_directory = getcwd ()
103
104
if 'GITHUB_ACTIONS' in environ .keys ():
104
105
105
- # self.logger.debug(" Running inside GitHub Actions" )
106
- local_directory = environ .get (" GITHUB_WORKSPACE" )
106
+ # self.logger.debug(' Running inside GitHub Actions' )
107
+ local_directory = environ .get (' GITHUB_WORKSPACE' )
107
108
108
109
for file in listdir (local_directory ):
109
110
if file == 'config.json' :
@@ -142,11 +143,11 @@ def load_config_file(self) -> dict:
142
143
# self.builder.validate_field_type('config.jira.use_atlassian_document_format', bool)
143
144
# self.builder.validate_field_type('config.jira.create_sub_tasks', bool)
144
145
145
- self .logger .debug (" Config from the config.json file - " + str (self .config ))
146
+ self .logger .debug (' Config from the config.json file - ' + str (self .config ))
146
147
return self .config .to_dict () if isinstance (self .config , config_node .Config ) else self .config
147
148
148
149
except Exception as e :
149
- self .logger .error (" Error loading config.json file: " + str (traceback .print_tb (e .__traceback__ )))
150
+ self .logger .error (' Error loading config.json file: ' + str (traceback .print_tb (e .__traceback__ )))
150
151
151
152
# Load the config.json file from environment variables instead if running inside GitHub Actions. Environment variables override config.json values to enable CI workflows.
152
153
def load_config_env (self ) -> dict :
@@ -159,49 +160,66 @@ def load_config_env(self) -> dict:
159
160
if config_key in environ .keys ():
160
161
temp_list .append (config_value )
161
162
163
+ self .logger .debug ('ConfigMap JSON key values found within environment variables - ' + str (temp_list ))
164
+
162
165
unique_parent_list = []
163
166
for item in temp_list :
164
167
if item .split ('.' )[0 ] not in unique_parent_list :
165
168
unique_parent_list .append (item .split ('.' )[0 ])
166
169
170
+ self .logger .debug ('Parent config attributes found within environment variables - ' + str (unique_parent_list ))
171
+
167
172
for parent_item in unique_parent_list :
168
173
169
174
temp_config_dict = {}
170
- for list_item in [x for x in temp_list if re .match (parent_item + ".*" , x )]:
175
+ for list_item in [x for x in temp_list if re .match (parent_item + '.*' , x )]:
176
+
177
+ if 'GITHUB_ACTIONS' in environ .keys ():
178
+ if environ ['GITHUB_ACTIONS' ]:
179
+ list_item = 'INPUT_' + list_item
180
+
181
+ self .logger .debug ('Config `' + str (list_item ) + '` within parent `' + str (parent_item ) + '` - ' + str (environ [list_item .replace ('.' , '_' ).upper ()]))
182
+
171
183
item_path = list_item .split ('.' )
172
184
for item in reversed (item_path ):
173
- # temp_config_dict.update({item: environ[list_item.replace('.', '_')]})
185
+ # temp_config_dict.update({item: environ[list_item.replace('.', '_').upper() ]})
174
186
# break
175
- if list_item == "jira.default_issue_labels" :
176
- temp_config_dict .update ({item : environ [list_item .replace ('.' , '_' )].split ("," )})
187
+ if list_item == 'jira.default_issue_labels' :
188
+ temp_config_dict .update ({
189
+ item : environ [list_item .replace ('.' , '_' ).upper ()].split (',' )
190
+ })
177
191
else :
178
192
if list_item in ['jira.use_atlassian_document_format' , 'jira.create_sub_tasks' ]:
179
- temp_config_dict .update ({item : self .get_boolean (environ [list_item .replace ('.' , '_' )])})
193
+ temp_config_dict .update ({
194
+ item : self .get_boolean (environ [list_item .replace ('.' , '_' ).upper ()])
195
+ })
180
196
else :
181
- temp_config_dict .update ({item : environ [list_item .replace ('.' , '_' )]})
197
+ temp_config_dict .update ({
198
+ item : environ [list_item .replace ('.' , '_' ).upper ()]
199
+ })
182
200
break
183
201
config .update ({list_item .split ('.' )[0 ]: temp_config_dict })
184
- self .logger .debug (" Config from environment variables - " + str (config ))
202
+ self .logger .debug (' Config from environment variables - ' + str (config ))
185
203
return config
186
204
187
205
except Exception as e :
188
- self .logger .error (" Error loading environment variables: " + str (traceback .print_tb (e .__traceback__ )))
206
+ self .logger .error (' Error loading environment variables: ' + str (traceback .print_tb (e .__traceback__ )))
189
207
190
- # self.input_type = self.check_if_env_var_exists(env_key=" input_type" , existing_value=self.input_type)
191
- # self.input_format = self.check_if_env_var_exists(env_key=" input_format" , existing_value=self.input_format)
192
- # self.jira_cloud_url = self.check_if_env_var_exists(env_key=" jira_cloud_url" , existing_value=self.jira_cloud_url)
193
- # self.jira_project_key = self.check_if_env_var_exists(env_key=" jira_project_key" , existing_value=self.jira_project_key)
194
- # self.auth_email = self.check_if_env_var_exists(env_key=" jira_auth_email" , existing_value=self.auth_email)
195
- # self.api_token = self.check_if_env_var_exists(env_key=" jira_api_token" , existing_value=self.api_token)
196
- # self.default_issue_labels = self.check_if_env_var_exists(env_key=" jira_default_issue_labels" , existing_value=self.default_issue_labels)
197
- # self.use_atlassian_document_format = self.check_if_env_var_exists(env_key=" jira_use_atlassian_document_format" , existing_value=self.use_atlassian_document_format)
198
- # self.create_sub_tasks = self.check_if_env_var_exists(env_key=" jira_create_sub_tasks" , existing_value=self.create_sub_tasks)
208
+ # self.input_type = self.check_if_env_var_exists(env_key=' input_type' , existing_value=self.input_type)
209
+ # self.input_format = self.check_if_env_var_exists(env_key=' input_format' , existing_value=self.input_format)
210
+ # self.jira_cloud_url = self.check_if_env_var_exists(env_key=' jira_cloud_url' , existing_value=self.jira_cloud_url)
211
+ # self.jira_project_key = self.check_if_env_var_exists(env_key=' jira_project_key' , existing_value=self.jira_project_key)
212
+ # self.auth_email = self.check_if_env_var_exists(env_key=' jira_auth_email' , existing_value=self.auth_email)
213
+ # self.api_token = self.check_if_env_var_exists(env_key=' jira_api_token' , existing_value=self.api_token)
214
+ # self.default_issue_labels = self.check_if_env_var_exists(env_key=' jira_default_issue_labels' , existing_value=self.default_issue_labels)
215
+ # self.use_atlassian_document_format = self.check_if_env_var_exists(env_key=' jira_use_atlassian_document_format' , existing_value=self.use_atlassian_document_format)
216
+ # self.create_sub_tasks = self.check_if_env_var_exists(env_key=' jira_create_sub_tasks' , existing_value=self.create_sub_tasks)
199
217
200
218
def get_combined_config (self , config_file : dict , config_env : dict ) -> dict :
201
219
202
220
try :
203
221
# merged_config = config_env | config_file
204
- # self.logger.debug(" Final Config Object - " + str(merged_config))
222
+ # self.logger.debug(' Final Config Object - ' + str(merged_config))
205
223
# return merged_config
206
224
207
225
# for k in set(config_file.keys()).union(config_env.keys()):
@@ -221,5 +239,5 @@ def get_combined_config(self, config_file: dict, config_env: dict) -> dict:
221
239
return merge (config_file , config_env )
222
240
223
241
except Exception as e :
224
- self .logger .error (" Error merging config: " + str (traceback .print_tb (e .__traceback__ )))
242
+ self .logger .error (' Error merging config: ' + str (traceback .print_tb (e .__traceback__ )))
225
243
0 commit comments