Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function for 'settings' domain config for set 'default unified cost config' #10

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/spaceone/config/conf/global_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,17 @@

# System Token Settings
TOKEN = ""

# Default Domain Unified Cost Configuration
DEFAULT_UNIFIED_COST_CONFIG = {

"run_hour": 0,
"aggregation_day": 15,
"is_last_day": False,
"exchange_source": "Yahoo Finance!",
"exchange_date": 15,
"is_exchange_last_day": False,
"exchange_rate_mode": "AUTO",
# "custom_exchange_rate": {},
"currency": "KRW",
}
16 changes: 15 additions & 1 deletion src/spaceone/config/service/domain_config_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from spaceone.core.service import *

from spaceone.core import config
from spaceone.config.manager.domain_config_manager import DomainConfigManager
from spaceone.config.model import DomainConfig

Expand Down Expand Up @@ -117,10 +118,15 @@ def get(self, params: dict) -> DomainConfig:
domain_config_vo (object)
"""

return self.domain_config_mgr.get_domain_config(
domain_config_vo = self.domain_config_mgr.get_domain_config(
params["name"], params["domain_id"]
)

if domain_config_vo.name == "settings":
domain_config_vo = self._get_config_vo_with_default_unified_cost_config(domain_config_vo)

return domain_config_vo

@transaction(permission="config:DomainConfig.read", role_types=["DOMAIN_ADMIN"])
@check_required(["domain_id"])
@append_query_filter(["name", "domain_id"])
Expand Down Expand Up @@ -162,3 +168,11 @@ def stat(self, params: dict) -> dict:

query = params.get("query", {})
return self.domain_config_mgr.state_domain_configs(query)

def _get_config_vo_with_default_unified_cost_config(self, domain_config_vo) -> DomainConfig:
domain_config_data: dict = domain_config_vo.data
if not domain_config_data.get("unified_cost_config", {}):
domain_config_data["unified_cost_config"] = config.get_global("DEFAULT_UNIFIED_COST_CONFIG", {})
domain_config_vo = self.domain_config_mgr.update_domain_config_by_vo({"data": domain_config_data},
domain_config_vo)
return domain_config_vo
Loading