diff --git a/src/spaceone/cost_analysis/interface/grpc/data_source_account.py b/src/spaceone/cost_analysis/interface/grpc/data_source_account.py index 42c86073..5b722fb0 100644 --- a/src/spaceone/cost_analysis/interface/grpc/data_source_account.py +++ b/src/spaceone/cost_analysis/interface/grpc/data_source_account.py @@ -43,6 +43,12 @@ def list(self, request, context): response: dict = data_source_account_svc.list(params) return self.dict_to_message(response) + def analyze(self, request, context): + params, metadata = self.parse_request(request, context) + data_source_account_svc = DataSourceAccountService(metadata) + response: dict = data_source_account_svc.analyze(params) + return self.dict_to_message(response) + def stat(self, request, context): params, metadata = self.parse_request(request, context) data_source_account_svc = DataSourceAccountService(metadata) diff --git a/src/spaceone/cost_analysis/manager/data_source_account_manager.py b/src/spaceone/cost_analysis/manager/data_source_account_manager.py index 9efbc5f0..cf0947fa 100644 --- a/src/spaceone/cost_analysis/manager/data_source_account_manager.py +++ b/src/spaceone/cost_analysis/manager/data_source_account_manager.py @@ -80,6 +80,9 @@ def list_data_source_accounts(self, query: dict) -> Tuple[QuerySet, int]: def filter_data_source_accounts(self, **conditions) -> QuerySet: return self.data_source_account_model.filter(**conditions) + def analyze_data_source_accounts(self, query: dict) -> dict: + return self.data_source_account_model.analyze(**query) + def stat_data_source_accounts(self, query: dict) -> dict: return self.data_source_account_model.stat(**query) diff --git a/src/spaceone/cost_analysis/model/data_source_account/request.py b/src/spaceone/cost_analysis/model/data_source_account/request.py index 4db218a5..b9d7f639 100644 --- a/src/spaceone/cost_analysis/model/data_source_account/request.py +++ b/src/spaceone/cost_analysis/model/data_source_account/request.py @@ -6,6 +6,7 @@ "DataSourceAccountResetRequest", "DataSourceAccountGetRequest", "DataSourceAccountSearchQueryRequest", + "DataSourceAnalyzeQueryRequest", "DataSourceAccountStatQueryRequest", ] @@ -31,6 +32,14 @@ class DataSourceAccountGetRequest(BaseModel): domain_id: str +class DataSourceAnalyzeQueryRequest(BaseModel): + query: dict + data_source_id: Union[str, None] = None + account_id: Union[str, None] = None + workspace_id: Union[str, None] = None + domain_id: str + + class DataSourceAccountSearchQueryRequest(BaseModel): query: Union[dict, None] = None data_source_id: Union[str, None] = None diff --git a/src/spaceone/cost_analysis/service/data_source_account_service.py b/src/spaceone/cost_analysis/service/data_source_account_service.py index e2443040..011645f7 100644 --- a/src/spaceone/cost_analysis/service/data_source_account_service.py +++ b/src/spaceone/cost_analysis/service/data_source_account_service.py @@ -232,6 +232,29 @@ def list( results=data_source_accounts_info, total_count=total_count ) + @transaction( + permission="cost-analysis:DataSourceAccount.read", + role_types=["DOMAIN_ADMIN", "WORKSPACE_OWNER"], + ) + @append_query_filter(["data_source_id", "account_id", "workspace_id", "domain_id"]) + @convert_model + def analyze(self, params: DataSourceAnalyzeQueryRequest) -> dict: + """Analyze data source account + Args: + params (dict): { + 'query': 'dict', + 'data_source_id': 'str', # required + 'account_id': 'str', # required + 'workspace_id': 'str', # injected from auth + 'domain_id': 'str' # injected from auth + } + Returns: + dict + """ + + query = params.query or {} + return self.data_source_account_mgr.analyze_data_source_accounts(query) + @transaction( permission="cost-analysis:DataSourceAccount.read", role_types=["DOMAIN_ADMIN", "WORKSPACE_OWNER"],