Skip to content

Commit

Permalink
Merge pull request #113 from whdalsrnt/master
Browse files Browse the repository at this point in the history
fix: fix type error
  • Loading branch information
whdalsrnt authored Nov 6, 2023
2 parents c29420c + 2c8b05e commit 90110c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)

Expand Down
12 changes: 5 additions & 7 deletions src/spaceone/cost_analysis/service/data_source_rule_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 90110c4

Please sign in to comment.