Skip to content

Commit f318a82

Browse files
authored
Merge pull request #48 from stat-kwon/master
Add type mapper in cost manager
2 parents 5c8747d + e3c8ee9 commit f318a82

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/cloudforet/cost_analysis/manager/cost_manager.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def __init__(self, *args, **kwargs):
1717
super().__init__(*args, **kwargs)
1818
self.default_vars = None
1919
self.field_mapper = None
20+
self.type_mapper = None
2021

2122
def get_data(self, options, secret_data, schema, task_options):
2223
if "default_vars" in options:
@@ -25,6 +26,9 @@ def get_data(self, options, secret_data, schema, task_options):
2526
if "field_mapper" in options:
2627
self.field_mapper = options["field_mapper"]
2728

29+
if "type_mapper" in options:
30+
self.type_mapper = options["type_mapper"]
31+
2832
if "base_url" in task_options:
2933
base_url = task_options["base_url"]
3034
http_file_connector = self.locator.get_connector(HTTPFileConnector)
@@ -53,6 +57,9 @@ def _make_cost_data(self, results):
5357
if self.field_mapper:
5458
self._set_default_vars(result)
5559

60+
if self.type_mapper:
61+
self._set_type_mapper(result)
62+
5663
self._create_billed_date(result)
5764

5865
if not self._convert_cost_and_usage_quantity_types(result):
@@ -199,3 +206,16 @@ def _check_required_fields(result):
199206
for field in _REQUIRED_FIELDS:
200207
if field not in result:
201208
raise ERROR_REQUIRED_PARAMETER(key=field)
209+
210+
def _set_type_mapper(self, result):
211+
# Not Implemented
212+
if "additional_info" in self.type_mapper:
213+
if (
214+
"Account ID" in self.type_mapper["additional_info"]
215+
and "additional_info" in result
216+
and "Account ID" in result.get("additional_info", {})
217+
):
218+
account_id = result["additional_info"]["Account ID"]
219+
if isinstance(account_id, int) or isinstance(account_id, float):
220+
result["additional_info"]["Account ID"] = str(account_id).zfill(12)
221+
return result

0 commit comments

Comments
 (0)