Skip to content

Commit

Permalink
Merge pull request #298 from ImMin5/master
Browse files Browse the repository at this point in the history
Modify reset data source account option
  • Loading branch information
ImMin5 authored Oct 14, 2024
2 parents 20c3977 + 59a70b8 commit 2abf6af
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class DataSourceAccountUpdateRequest(BaseModel):
class DataSourceAccountResetRequest(BaseModel):
data_source_id: str
account_id: Union[str, None] = None
reset_sync: Union[bool, None] = None
workspace_id: Union[str, None] = None
domain_id: str

Expand Down
28 changes: 11 additions & 17 deletions src/spaceone/cost_analysis/service/data_source_account_service.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import logging
from datetime import datetime
from typing import Union

from spaceone.core.service import *
from spaceone.core.error import ERROR_PERMISSION_DENIED

from spaceone.cost_analysis.manager import DataSourceManager
from spaceone.cost_analysis.manager.data_source_account_manager import (
DataSourceAccountManager,
Expand Down Expand Up @@ -99,6 +96,7 @@ def reset(self, params: DataSourceAccountResetRequest) -> None:
params (dict): {
'data_source_id': 'str', # required
'account_id': 'str', # optional
'reset_sync': 'bool', # required
'workspace_id': 'str', # injected from auth
'domain_id': 'str' # injected from auth
}
Expand All @@ -107,19 +105,13 @@ def reset(self, params: DataSourceAccountResetRequest) -> None:
"""
data_source_id = params.data_source_id
account_id = params.account_id
reset_sync = params.reset_sync
workspace_id = params.workspace_id
domain_id = params.domain_id

# Check if the data source exists
role_type = self.transaction.get_meta("authorization.role_type")
if role_type != "DOMAIN_ADMIN":
data_source_vo = self.data_source_mgr.get_data_source(
data_source_id, domain_id, workspace_id
)
else:
data_source_vo = self.data_source_mgr.get_data_source(
data_source_id, domain_id
)
data_source_vo = self.data_source_mgr.get_data_source(
data_source_id, domain_id, workspace_id
)

conditions = {
"data_source_id": data_source_id,
Expand All @@ -133,14 +125,16 @@ def reset(self, params: DataSourceAccountResetRequest) -> None:
data_source_account_vos = (
self.data_source_account_mgr.filter_data_source_accounts(**conditions)
)

for data_source_account_vo in data_source_account_vos:
update_params = {
"is_sync": False,
"updated_at": datetime.utcnow(),
}
update_params = {}

if data_source_vo.resource_group == "DOMAIN":
update_params["workspace_id"] = None
if reset_sync:
update_params["is_linked"] = False

if update_params:
self.data_source_account_mgr.update_data_source_account_by_vo(
update_params, data_source_account_vo
)
Expand Down

0 comments on commit 2abf6af

Please sign in to comment.