Skip to content

Commit

Permalink
Merge pull request #48 from stat-kwon/master
Browse files Browse the repository at this point in the history
Add type mapper in cost manager
  • Loading branch information
stat-kwon authored Sep 2, 2024
2 parents 5c8747d + e3c8ee9 commit f318a82
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/cloudforet/cost_analysis/manager/cost_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.default_vars = None
self.field_mapper = None
self.type_mapper = None

def get_data(self, options, secret_data, schema, task_options):
if "default_vars" in options:
Expand All @@ -25,6 +26,9 @@ def get_data(self, options, secret_data, schema, task_options):
if "field_mapper" in options:
self.field_mapper = options["field_mapper"]

if "type_mapper" in options:
self.type_mapper = options["type_mapper"]

if "base_url" in task_options:
base_url = task_options["base_url"]
http_file_connector = self.locator.get_connector(HTTPFileConnector)
Expand Down Expand Up @@ -53,6 +57,9 @@ def _make_cost_data(self, results):
if self.field_mapper:
self._set_default_vars(result)

if self.type_mapper:
self._set_type_mapper(result)

self._create_billed_date(result)

if not self._convert_cost_and_usage_quantity_types(result):
Expand Down Expand Up @@ -199,3 +206,16 @@ def _check_required_fields(result):
for field in _REQUIRED_FIELDS:
if field not in result:
raise ERROR_REQUIRED_PARAMETER(key=field)

def _set_type_mapper(self, result):
# Not Implemented
if "additional_info" in self.type_mapper:
if (
"Account ID" in self.type_mapper["additional_info"]
and "additional_info" in result
and "Account ID" in result.get("additional_info", {})
):
account_id = result["additional_info"]["Account ID"]
if isinstance(account_id, int) or isinstance(account_id, float):
result["additional_info"]["Account ID"] = str(account_id).zfill(12)
return result

0 comments on commit f318a82

Please sign in to comment.