diff --git a/src/cloudforet/cost_analysis/connector/azure_cost_mgmt_connector.py b/src/cloudforet/cost_analysis/connector/azure_cost_mgmt_connector.py index f66ab53..53fc544 100644 --- a/src/cloudforet/cost_analysis/connector/azure_cost_mgmt_connector.py +++ b/src/cloudforet/cost_analysis/connector/azure_cost_mgmt_connector.py @@ -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" ) diff --git a/src/cloudforet/cost_analysis/main.py b/src/cloudforet/cost_analysis/main.py index 29175ad..33bd6a2 100644 --- a/src/cloudforet/cost_analysis/main.py +++ b/src/cloudforet/cost_analysis/main.py @@ -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") @@ -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