Skip to content

Commit

Permalink
Merge pull request #59 from whdalsrnt/master
Browse files Browse the repository at this point in the history
Refactor Cost Analysis API
  • Loading branch information
whdalsrnt authored Sep 4, 2023
2 parents f47671b + 8e01bab commit 9480cfd
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 422 deletions.
41 changes: 3 additions & 38 deletions src/cloudforet/console_api_v2/conf/router_conf.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
ROUTER = [
{
'router_path': 'cloudforet.console_api_v2.interface.rest.extension.resource:router',
'router_options': {
'prefix': '/console-api/extension/resource',
'tags': ['console-api > extension > resource']
}
},
{
'router_path': 'cloudforet.console_api_v2.interface.rest.identity.domain:router',
'router_options': {
Expand Down Expand Up @@ -245,10 +238,10 @@
}
},
{
'router_path': 'cloudforet.console_api_v2.interface.rest.cost_analysis.exchange_rate:router',
'router_path': 'cloudforet.console_api_v2.interface.rest.cost_analysis.data_source_rule:router',
'router_options': {
'prefix': '/cost-analysis/exchange-rate',
'tags': ['cost-analysis > exchange-rate'],
'prefix': '/cost-analysis/data-source-rule',
'tags': ['cost-analysis > data-source-rule'],
}
},
{
Expand All @@ -258,13 +251,6 @@
'tags': ['cost-analysis > cost'],
}
},
{
'router_path': 'cloudforet.console_api_v2.interface.rest.cost_analysis.data_source_rule:router',
'router_options': {
'prefix': '/cost-analysis/data-source-rule',
'tags': ['cost-analysis > data-source-rule'],
}
},
{
'router_path': 'cloudforet.console_api_v2.interface.rest.cost_analysis.budget:router',
'router_options': {
Expand All @@ -279,34 +265,13 @@
'tags': ['cost-analysis > budget-usage'],
}
},
{
'router_path': 'cloudforet.console_api_v2.interface.rest.cost_analysis.public_dashboard:router',
'router_options': {
'prefix': '/cost-analysis/public-dashboard',
'tags': ['cost-analysis > public-dashboard'],
}
},
{
'router_path': 'cloudforet.console_api_v2.interface.rest.cost_analysis.user_dashboard:router',
'router_options': {
'prefix': '/cost-analysis/user-dashboard',
'tags': ['cost-analysis > user-dashboard'],
}
},
{
'router_path': 'cloudforet.console_api_v2.interface.rest.cost_analysis.cost_query_set:router',
'router_options': {
'prefix': '/cost-analysis/cost-query-set',
'tags': ['cost-analysis > cost-query-set']
}
},
{
'router_path': 'cloudforet.console_api_v2.interface.rest.cost_analysis.custom_widget:router',
'router_options': {
'prefix': '/cost-analysis/custom-widget',
'tags': ['cost-analysis > custom-widget']
}
},
{
'router_path': 'cloudforet.console_api_v2.interface.rest.cost_analysis.job:router',
'router_options': {
Expand Down
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

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 9480cfd

Please sign in to comment.