Skip to content

Commit

Permalink
feat: remove account connect policy metadata
Browse files Browse the repository at this point in the history
Signed-off-by: ImMin5 <[email protected]>
  • Loading branch information
ImMin5 committed May 2, 2024
1 parent d48b5e1 commit 7a65725
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

_LOGGER = logging.getLogger(__name__)

_PAGE_SIZE = 5000
_PAGE_SIZE = 6000


class AzureCostMgmtConnector(BaseConnector):
Expand Down
14 changes: 10 additions & 4 deletions src/cloudforet/cost_analysis/manager/cost_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ def _make_cost_data(
if not billed_date:
continue

if self._skip_cost_data_rule(result):
continue

data = self._make_data_info(result, billed_date, options, tenant_id)
costs_data.append(data)

Expand Down Expand Up @@ -222,9 +225,6 @@ def _get_additional_info(self, result: dict, options: dict, tenant_id: str = Non
if result.get("productname"):
additional_info["Product Name"] = result["productname"]

if result.get("unitprice") != "" and result.get("unitprice"):
additional_info["Unit Price"] = result["unitprice"]

if result.get("customername") != "" and result.get("customername"):
additional_info["Customer Name"] = result["customername"]

Expand All @@ -243,7 +243,7 @@ def _get_cost_from_result_with_options(self, result: dict, options: dict) -> flo
cost = self._convert_str_to_float_format(
result.get("costinbillingcurrency", 0.0)
)
if options.get("pay_as_you_go", False) and result.get("chargetype") == "Usage":
if options.get("pay_as_you_go", False):
cost = self.get_pay_as_you_go_cost(result, cost)

return cost
Expand Down Expand Up @@ -470,3 +470,9 @@ def _check_task_options(task_options):
raise ERROR_REQUIRED_PARAMETER(key="task_options.subscription_id")
elif task_options["collect_scope"] == "customer_tenants":
raise ERROR_REQUIRED_PARAMETER(key="task_options.customer_tenants")

@staticmethod
def _skip_cost_data_rule(result: dict) -> bool:
if result.get("customertenentname") and not result.get("customertenantid"):
return True
return False
7 changes: 2 additions & 5 deletions src/cloudforet/cost_analysis/manager/data_source_manager.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import logging

from spaceone.core.manager import BaseManager
from cloudforet.cost_analysis.model.data_source_model import (
PluginMetadata,
DEFAULT_ACCOUNT_CONNECT_POLICES,
)
from cloudforet.cost_analysis.model.data_source_model import PluginMetadata
from cloudforet.cost_analysis.connector.azure_cost_mgmt_connector import (
AzureCostMgmtConnector,
)
Expand All @@ -28,7 +25,7 @@ def init_response(options):

if options.get("use_account_routing"):
plugin_metadata.use_account_routing = True
plugin_metadata.account_connect_polices = DEFAULT_ACCOUNT_CONNECT_POLICES
plugin_metadata.account_match_key = "additional_info.Tenant Id"

plugin_metadata.validate()
return {"metadata": plugin_metadata.to_primitive()}
Expand Down
36 changes: 1 addition & 35 deletions src/cloudforet/cost_analysis/model/data_source_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,16 @@
}
]

DEFAULT_ACCOUNT_CONNECT_POLICES = [
{
"name": "connect_account_to_workspace",
"polices": {
"connect_account_to_workspace": {
"operator": "in",
"source": "account_id",
"target": "references",
}
},
},
{
"name": "connect_cost_to_account",
"polices": {
"connect_cost_to_account": {
"operator": "eq",
"source": "additional_info.Tenant Id",
"target": "account_id",
}
},
},
]


class MatchServiceAccount(Model):
source = StringType(required=True)
target = StringType(required=True)


class ConnectResource(Model):
operator = StringType(choices=["in", "eq"], default=["eq"])
source = StringType(required=True)
target = StringType(required=True)


class Actions(Model):
match_service_account = ModelType(MatchServiceAccount)


class Polices(Model):
connect_account_to_workspace = ModelType(ConnectResource)
connect_cost_to_account = ModelType(ConnectResource)


class Options(Model):
stop_processing = BooleanType(default=False)

Expand Down Expand Up @@ -92,8 +58,8 @@ class PluginMetadata(Model):
data_source_rules = ListType(
ModelType(DataSourceRule), default=_DEFAULT_DATA_SOURCE_RULES
)
account_connect_polices = ListType(ModelType(AccountMatchPolicy), default=[])
supported_secret_types = ListType(StringType, default=["MANUAL"])
currency = StringType(default="KRW")
use_account_routing = BooleanType(default=False)
alias = DictType(StringType, default={})
account_match_key = StringType(default=None)

0 comments on commit 7a65725

Please sign in to comment.