Skip to content

Commit

Permalink
Merge pull request #75 from whdalsrnt/master
Browse files Browse the repository at this point in the history
feat: add plugin_id for data source compatibility
  • Loading branch information
whdalsrnt authored Jun 30, 2024
2 parents d5c1679 + 546b266 commit 5ba20c8
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/spaceone/dashboard/manager/cost_analysis_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ def __init__(self, *args, **kwargs):

def analyze_cost(self, params: dict) -> dict:
return self.cost_analysis_conn.dispatch("Cost.analyze", params)

def list_data_sources(self, params: dict) -> dict:
return self.cost_analysis_conn.dispatch("DataSource.list", params)
3 changes: 3 additions & 0 deletions src/spaceone/dashboard/manager/inventory_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ def __init__(self, *args, **kwargs):

def analyze_metric_data(self, params: dict) -> dict:
return self.inventory_conn.dispatch("MetricData.analyze", params)

def list_metrics(self, params: dict) -> dict:
return self.inventory_conn.dispatch("Metric.list", params)
25 changes: 25 additions & 0 deletions src/spaceone/dashboard/service/private_data_table_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from spaceone.dashboard.manager.data_table_manager.data_transformation_manager import (
DataTransformationManager,
)
from spaceone.dashboard.manager.cost_analysis_manager import CostAnalysisManager
from spaceone.dashboard.model.private_data_table.request import *
from spaceone.dashboard.model.private_data_table.response import *
from spaceone.dashboard.model.private_data_table.database import PrivateDataTable
Expand Down Expand Up @@ -74,6 +75,13 @@ def add_data_table(self, params_dict: dict) -> dict:
user_id,
)

if source_type == "COST":
if plugin_id := options.get("COST", {}).get("plugin_id"):
data_source_id = self._get_data_source_id_from_plugin_id(plugin_id)
options["COST"]["data_source_id"] = data_source_id
params_dict["options"] = options
del params_dict["options"]["COST"]["plugin_id"]

ds_mgr = DataSourceManager(
"PRIVATE",
source_type,
Expand All @@ -99,6 +107,23 @@ def add_data_table(self, params_dict: dict) -> dict:

return pri_data_table_vo.to_dict()

@staticmethod
def _get_data_source_id_from_plugin_id(plugin_id: str) -> str:
cost_mgr = CostAnalysisManager()
params = {
"query": {
"filter": [{"k": "plugin_info.plugin_id", "v": plugin_id, "o": "eq"}],
}
}
data_sources_info = cost_mgr.list_data_sources(params)
if data_sources_info.get("total_count", 0) == 0:
raise ERROR_INVALID_PARAMETER(
key="options.COST.plugin_id",
reason=f"Invalid plugin_id: {plugin_id}",
)
data_source_info = data_sources_info.get("results")[0]
return data_source_info.get("data_source_id")

@transaction(
permission="dashboard:PrivateDataTable.write",
role_types=["USER"],
Expand Down
25 changes: 25 additions & 0 deletions src/spaceone/dashboard/service/public_data_table_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from spaceone.dashboard.manager.data_table_manager.data_transformation_manager import (
DataTransformationManager,
)
from spaceone.dashboard.manager.cost_analysis_manager import CostAnalysisManager
from spaceone.dashboard.model.public_data_table.request import *
from spaceone.dashboard.model.public_data_table.response import *
from spaceone.dashboard.model.public_data_table.database import PublicDataTable
Expand Down Expand Up @@ -75,6 +76,13 @@ def add_data_table(self, params_dict: dict) -> dict:
user_projects,
)

if source_type == "COST":
if plugin_id := options.get("COST", {}).get("plugin_id"):
data_source_id = self._get_data_source_id_from_plugin_id(plugin_id)
options["COST"]["data_source_id"] = data_source_id
params_dict["options"] = options
del params_dict["options"]["COST"]["plugin_id"]

ds_mgr = DataSourceManager(
"PUBLIC",
source_type,
Expand Down Expand Up @@ -103,6 +111,23 @@ def add_data_table(self, params_dict: dict) -> dict:

return pub_data_table_vo.to_dict()

@staticmethod
def _get_data_source_id_from_plugin_id(plugin_id: str) -> str:
cost_mgr = CostAnalysisManager()
params = {
"query": {
"filter": [{"k": "plugin_info.plugin_id", "v": plugin_id, "o": "eq"}],
}
}
data_sources_info = cost_mgr.list_data_sources(params)
if data_sources_info.get("total_count", 0) == 0:
raise ERROR_INVALID_PARAMETER(
key="options.COST.plugin_id",
reason=f"Invalid plugin_id: {plugin_id}",
)
data_source_info = data_sources_info.get("results")[0]
return data_source_info.get("data_source_id")

@transaction(
permission="dashboard:PublicDataTable.write",
role_types=["DOMAIN_ADMIN", "WORKSPACE_OWNER", "WORKSPACE_MEMBER"],
Expand Down

0 comments on commit 5ba20c8

Please sign in to comment.