-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
197 additions
and
630 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
|
||
spaceone-core | ||
spaceone-api | ||
schematics | ||
requests | ||
boto3 | ||
pyarrow | ||
pandas | ||
|
||
spaceone-cost-analysis |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
from typing import Generator | ||
from spaceone.cost_analysis.plugin.data_source.lib.server import DataSourcePluginServer | ||
from .manager.data_source_manager import DataSourceManager | ||
from .manager.job_manager import JobManager | ||
from .manager.cost_manager import CostManager | ||
|
||
app = DataSourcePluginServer() | ||
|
||
|
||
@app.route('DataSource.init') | ||
def data_source_init(params: dict) -> dict: | ||
""" init plugin by options | ||
Args: | ||
params (DataSourceInitRequest): { | ||
'options': 'dict', # Required | ||
'domain_id': 'str' # Required | ||
} | ||
Returns: | ||
PluginResponse: { | ||
'metadata': 'dict' | ||
} | ||
""" | ||
options = params['options'] | ||
|
||
data_source_mgr = DataSourceManager() | ||
return data_source_mgr.init_response(options) | ||
|
||
|
||
@app.route('DataSource.verify') | ||
def data_source_verify(params: dict) -> None: | ||
""" Verifying data source plugin | ||
Args: | ||
params (CollectorVerifyRequest): { | ||
'options': 'dict', # Required | ||
'secret_data': 'dict', # Required | ||
'schema': 'str', | ||
'domain_id': 'str' | ||
} | ||
Returns: | ||
None | ||
""" | ||
|
||
options = params['options'] | ||
secret_data = params['secret_data'] | ||
schema = params.get('schema') | ||
|
||
data_source_mgr = DataSourceManager() | ||
data_source_mgr.verify_plugin(options, secret_data, schema) | ||
|
||
|
||
@app.route('Job.get_tasks') | ||
def job_get_tasks(params: dict) -> dict: | ||
""" Get job tasks | ||
Args: | ||
params (JobGetTaskRequest): { | ||
'options': 'dict', # Required | ||
'secret_data': 'dict', # Required | ||
'schema': 'str', | ||
'start': 'str', | ||
'last_synchronized_at': 'datetime', | ||
'domain_id': 'str' | ||
} | ||
Returns: | ||
TasksResponse: { | ||
'tasks': 'list', | ||
'changed': 'list' | ||
} | ||
""" | ||
|
||
domain_id = params['domain_id'] | ||
options = params['options'] | ||
secret_data = params['secret_data'] | ||
schema = params.get('schema') | ||
start = params.get('start') | ||
last_synchronized_at = params.get('last_synchronized_at') | ||
|
||
job_mgr = JobManager() | ||
return job_mgr.get_tasks(domain_id, options, secret_data, schema, start, last_synchronized_at) | ||
|
||
|
||
@app.route('Cost.get_data') | ||
def cost_get_data(params: dict) -> Generator[dict, None, None]: | ||
""" Get external cost data | ||
Args: | ||
params (CostGetDataRequest): { | ||
'options': 'dict', # Required | ||
'secret_data': 'dict', # Required | ||
'schema': 'str', | ||
'task_options': 'dict', | ||
'domain_id': 'str' | ||
} | ||
Returns: | ||
Generator[ResourceResponse, None, None] | ||
{ | ||
'cost': 'float', | ||
'usage_quantity': 'float', | ||
'usage_unit': 'str', | ||
'provider': 'str', | ||
'region_code': 'str', | ||
'product': 'str', | ||
'usage_type': 'str', | ||
'resource': 'str', | ||
'tags': 'dict' | ||
'additional_info': 'dict' | ||
'data': 'dict' | ||
'billed_date': 'str' | ||
} | ||
""" | ||
|
||
options = params['options'] | ||
secret_data = params['secret_data'] | ||
|
||
task_options = params.get('task_options', {}) | ||
schema = params.get('schema') | ||
|
||
cost_mgr = CostManager() | ||
return cost_mgr.get_data(options, secret_data, task_options, schema) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import logging | ||
|
||
from spaceone.core.manager import BaseManager | ||
from ..connector.aws_s3_connector import AWSS3Connector | ||
from ..connector.spaceone_connector import SpaceONEConnector | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class DataSourceManager(BaseManager): | ||
|
||
@staticmethod | ||
def init_response(options: dict) -> dict: | ||
return { | ||
'metadata': { | ||
'currency': 'USD', | ||
'supported_secret_types': ['MANUAL'], | ||
'data_source_rules': [ | ||
{ | ||
'name': 'match_service_account', | ||
'conditions_policy': 'ALWAYS', | ||
'actions': { | ||
'match_service_account': { | ||
'source': 'additional_info.Account ID', | ||
'target': 'data.account_id' | ||
} | ||
}, | ||
'options': { | ||
'stop_processing': True | ||
} | ||
} | ||
] | ||
} | ||
} | ||
|
||
@staticmethod | ||
def verify_plugin(options: dict, secret_data: dict, schema: str = None) -> None: | ||
space_connector = SpaceONEConnector() | ||
space_connector.init_client(options, secret_data, schema) | ||
space_connector.verify_plugin() | ||
|
||
aws_s3_connector = AWSS3Connector() | ||
aws_s3_connector.create_session(options, secret_data, schema) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.