Skip to content

Commit

Permalink
feat: add analyze api for DataSourceAccount (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
ImMin5 committed May 14, 2024
1 parent e2ba7b8 commit 6c302c8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"DataSourceAccountResetRequest",
"DataSourceAccountGetRequest",
"DataSourceAccountSearchQueryRequest",
"DataSourceAnalyzeQueryRequest",
"DataSourceAccountStatQueryRequest",
]

Expand All @@ -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
Expand Down
23 changes: 23 additions & 0 deletions src/spaceone/cost_analysis/service/data_source_account_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down

0 comments on commit 6c302c8

Please sign in to comment.