Skip to content

Commit

Permalink
feat: change grpc_method of analyze API
Browse files Browse the repository at this point in the history
  • Loading branch information
whdalsrnt committed Sep 4, 2023
1 parent 3481b1f commit 8e01bab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 50 deletions.
39 changes: 2 additions & 37 deletions src/cloudforet/console_api_v2/interface/rest/cost_analysis/cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,54 +48,19 @@ async def get(self, request: Request):
@router.post('/list', openapi_extra=CostQuery.meta(), response_model=CostsInfo)
@exception_handler
async def list(self, request: Request):
"""
## Description
Gets a list of all Costs. You can use a query to get a filtered list of Costs.
<br>
| Key | Description | Type | Required |
|------------------------|---------------------------------------------------------------|--------|----------|
| **cost_id** | Cost id | string | |
| **original_currency** | Original currency like USD | string | |
| **provider** | CSP code like aws, azure and google_cloud | string | |
| **region_code** | Unique region code by each CSP | string | |
| **region_key** | {provider}.{region_code} format value | string | |
| **category** | Category value | string | |
| **product** | Product value | string | |
| **account** | Unique ID to identify your account from CSP | string | |
| **usage_type** | Usage type | string | |
| **resource_group** | Resource group value | string | |
| **resource** | Resource value | string | |
| **service_account_id** | Service account id | string | |
| **project_id** | Project id | string | |
| **project_group_id** | Project group id | string | |
| **data_source_id** | Data source id | string | |
| **query** | Query option for detail search | object | |
| **domain_id** | Unique id by each domain (extracted automatically from token) | string | |
"""
params, metadata = await self.parse_request(request, self.token.credentials)

with self.locator.get_service(ProxyService, metadata) as proxy_service:
params['grpc_method'] = 'cost_analysis.Cost.list'
return proxy_service.dispatch_api(params)

@router.post('/analyze', openapi_extra=CostAnalyzeV2Query.meta(), response_model=CostAnalyzeInfo)
@router.post('/analyze', openapi_extra=CostAnalyzeQuery.meta(), response_model=CostAnalyzeInfo)
@exception_handler
async def analyze(self, request: Request):
"""
## Description
Gets the Cost information of specific products.
<br>
| Key | Description | Type | Required |
|---------------|---------------------------------------------------------------|--------|----------|
| **query** | Query option for detail search | object |*True* |
| **domain_id** | Unique id by each domain (extracted automatically from token) | string | |
"""
params, metadata = await self.parse_request(request, self.token.credentials)

with self.locator.get_service(ProxyService, metadata) as proxy_service:
params['grpc_method'] = 'cost_analysis.Cost.analyze_v2'
params['grpc_method'] = 'cost_analysis.Cost.analyze'
return proxy_service.dispatch_api(params)

@router.post('/stat', openapi_extra=CostStatQuery.meta())
Expand Down
18 changes: 5 additions & 13 deletions src/cloudforet/console_api_v2/model/cost_analysis/cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@ class GetCostRequest(BaseAPIModel):

class CostQuery(BaseAPIModel):
cost_id: Union[str, None] = Field(None)
original_currency: Union[str, None] = Field(None)
provider: Union[str, None] = Field(None)
region_code: Union[str, None] = Field(None)
region_key: Union[str, None] = Field(None)
category: Union[str, None] = Field(None)
product: Union[str, None] = Field(None)
account: Union[str, None] = Field(None)
usage_type: Union[str, None] = Field(None)
resource_group: Union[str, None] = Field(None)
resource: Union[str, None] = Field(None)
service_account_id: Union[str, None] = Field(None)
project_id: Union[str, None] = Field(None)
Expand All @@ -38,35 +34,31 @@ class CostQuery(BaseAPIModel):

class CostInfo(BaseAPIModel):
cost_id: Union[str, None] = Field(None)
usd_cost: Union[str, None] = Field(None)
original_currency: Union[str, None] = Field(None)
original_cost: Union[float, None] = Field(None)
cost: Union[float, None] = Field(None)
usage_quantity: Union[float, None] = Field(None)
usage_unit: Union[str, None] = Field(None)
provider: Union[str, None] = Field(None)
region_code: Union[str, None] = Field(None)
region_key: Union[str, None] = Field(None)
category: Union[str, None] = Field(None)
product: Union[str, None] = Field(None)
account: Union[str, None] = Field(None)
usage_type: Union[str, None] = Field(None)
resource_group: Union[str, None] = Field(None)
resource: Union[str, None] = Field(None)
tags: Union[dict, None] = Field(None)
additional_info: Union[dict, None] = Field(None)
service_account_id: Union[str, None] = Field(None)
project_id: Union[str, None] = Field(None)
data_source_id: Union[str, None] = Field(None)
domain_id: Union[str, None] = Field(None)
billed_at: Union[datetime, None] = Field(None)
created_at: Union[datetime, None] = Field(None)
billed_date: Union[str, None] = Field(None)


class CostsInfo(BaseAPIModel):
results: Union[List[CostInfo], None] = Field(None)
total_count: Union[int, None] = Field(None)


class CostAnalyzeV2Query(BaseAPIModel):
class CostAnalyzeQuery(BaseAPIModel):
data_source_id: Union[str, None] = Field(None)
query: dict = Field(None)
domain_id: Union[str, None] = Field(None)

Expand Down

0 comments on commit 8e01bab

Please sign in to comment.