Skip to content

Commit

Permalink
feat: add get secret data logic at get_data api
Browse files Browse the repository at this point in the history
Signed-off-by: ImMin5 <[email protected]>
  • Loading branch information
ImMin5 committed Oct 30, 2024
1 parent 0dcce6c commit 6b74ea9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,12 @@ def _get_access_token():
raise ERROR_INVALID_TOKEN(token=e)

@staticmethod
def _check_secret_data(secret_data):
def _check_secret_data(secret_data: dict):
if (
"billing_account_id" not in secret_data
and "subscription_id" not in secret_data
):
_LOGGER.debug(secret_data)
raise ERROR_REQUIRED_PARAMETER(
key="secret_data.billing_account_id or secret_data.subscription_id"
)
Expand Down
13 changes: 8 additions & 5 deletions src/cloudforet/cost_analysis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,7 @@ def cost_get_data(params: dict) -> Generator[dict, None, None]:
secret_data = params.pop("secret_data")

params["schema"] = params.pop("schema_name", None)
params["secret_data"] = __get_secret_data_with_tenant_id(
secret_data, task_options.get("billing_tenant_id")
)

params["secret_data"] = __get_secret_data(secret_data, task_options)
is_benefit_job = task_options.get("is_benefit_job", False)
cost_metric = options.get("cost_metric", "ActualCost")

Expand Down Expand Up @@ -190,13 +187,19 @@ def __remove_duplicate_list_of_dict(changed: list) -> list:
return unique_list


def __get_secret_data_with_tenant_id(secret_data: dict, tenant_id: str = None) -> dict:
def __get_secret_data(secret_data: dict, task_options: dict) -> dict:
secrets = secret_data.get("secrets", [secret_data])
if len(secrets) == 1:
return secrets[0]

tenant_id = task_options.get(
"billing_tenant_id",
)

for _secret_data in secrets:
if _secret_data["tenant_id"] == tenant_id:
secret_data = _secret_data
elif _secret_data.get("subscription_id") == task_options.get("subscription_id"):
secret_data = _secret_data

return secret_data

0 comments on commit 6b74ea9

Please sign in to comment.