diff --git a/src/spaceone/cost_analysis/manager/data_source_rule_manager.py b/src/spaceone/cost_analysis/manager/data_source_rule_manager.py index aa2f1175..271e4cf1 100644 --- a/src/spaceone/cost_analysis/manager/data_source_rule_manager.py +++ b/src/spaceone/cost_analysis/manager/data_source_rule_manager.py @@ -88,10 +88,10 @@ def _apply_data_source_rule_to_cost_data(self, cost_data, data_source_rule_vos, def _change_cost_data_with_actions(self, cost_data, actions, domain_id): for action, value in actions.items(): - if action == 'change_project': + if action == 'change_project' and value: cost_data['project_id'] = value - elif action == 'match_project': + elif action == 'match_project' and value: source = value['source'] target_key = value.get('target', 'project_id') target_value = utils.get_dict_value(cost_data, source) @@ -100,7 +100,7 @@ def _change_cost_data_with_actions(self, cost_data, actions, domain_id): if project_info: cost_data['project_id'] = project_info['project_id'] - elif action == 'match_service_account': + elif action == 'match_service_account' and value: source = value['source'] target_key = value.get('target', 'service_account_id') target_value = utils.get_dict_value(cost_data, source) @@ -110,7 +110,7 @@ def _change_cost_data_with_actions(self, cost_data, actions, domain_id): cost_data['service_account_id'] = service_account_info['service_account_id'] cost_data['project_id'] = service_account_info.get('project_info', {}).get('project_id') - if action == 'add_additional_info': + if action == 'add_additional_info' and value: cost_data['additional_info'] = cost_data.get('additional_info', {}) cost_data['additional_info'].update(value) diff --git a/src/spaceone/cost_analysis/service/data_source_rule_service.py b/src/spaceone/cost_analysis/service/data_source_rule_service.py index e80409f2..84711050 100644 --- a/src/spaceone/cost_analysis/service/data_source_rule_service.py +++ b/src/spaceone/cost_analysis/service/data_source_rule_service.py @@ -296,18 +296,16 @@ def _check_conditions(conditions): f'({" | ".join(_SUPPORTED_CONDITION_OPERATORS)})') def _check_actions(self, actions, domain_id): - if 'change_project' in actions: - project_id = actions['change_project'] - + if project_id := actions.get('change_project'): identity_mgr: IdentityManager = self.locator.get_manager('IdentityManager') identity_mgr.get_project(project_id, domain_id) - if 'match_project' in actions: - if 'source' not in actions['match_project']: + if match_project := actions.get('match_project'): + if 'source' not in match_project: raise ERROR_REQUIRED_PARAMETER(key='actions.match_project.source') - if 'match_service_account' in actions: - if 'source' not in actions['match_service_account']: + if match_service_account := actions.get('match_service_account'): + if 'source' not in match_service_account: raise ERROR_REQUIRED_PARAMETER(key='actions.match_service_account.source') def _get_highest_order(self, data_source_id, rule_type, domain_id):