Skip to content

Commit

Permalink
Merge pull request #140 from whdalsrnt/master
Browse files Browse the repository at this point in the history
fix: fix authentication bug in worker
  • Loading branch information
whdalsrnt authored Jan 11, 2024
2 parents 82b511e + 5c7b55e commit 574b61e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def initialize(self, endpoint):
if static_endpoint:
endpoint = static_endpoint

self.client = self.locator.get_connector("SpaceConnector", endpoint=endpoint, token="NO_TOKEN")
self.client = self.locator.get_connector(
"SpaceConnector", endpoint=endpoint, token="NO_TOKEN"
)

self.secret_data = self.config.get("secret_data")
self.options = self.config.get("options")
Expand All @@ -46,13 +48,13 @@ def verify(self, options, secret_data, schema, domain_id):
self.client.dispatch("DataSource.verify", params)

def get_tasks(
self,
options: dict,
secret_data: dict,
schema: str,
domain_id: str,
start: str = None,
last_synchronized_at: str = None,
self,
options: dict,
secret_data: dict,
schema: str,
domain_id: str,
start: str = None,
last_synchronized_at: str = None,
):
params = {
"options": self.options or options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,41 @@


class DataSourceSyncScheduler(HourlyScheduler):

def __init__(self, queue, interval, minute=':00'):
def __init__(self, queue, interval, minute=":00"):
super().__init__(queue, interval, minute)
self.locator = Locator()
self._init_config()
self._create_metadata()

def _init_config(self):
self._token = get_token('TOKEN')
self._data_source_sync_hour = config.get_global('DATA_SOURCE_SYNC_HOUR', 16)

def _create_metadata(self):
self._metadata = {
'token': self._token,
'service': 'cost_analysis',
'resource': 'Job',
'verb': 'create_jobs_by_data_source'
}
self._token = get_token("TOKEN")
self._data_source_sync_hour = config.get_global("DATA_SOURCE_SYNC_HOUR", 16)

def create_task(self):
if datetime.utcnow().hour == self._data_source_sync_hour:
stp = {
'name': 'data_source_sync_schedule',
'version': 'v1',
'executionEngine': 'BaseWorker',
'stages': [{
'locator': 'SERVICE',
'name': 'JobService',
'metadata': self._metadata,
'method': 'create_jobs_by_data_source',
'params': {
'params': {}
"name": "data_source_sync_schedule",
"version": "v1",
"executionEngine": "BaseWorker",
"stages": [
{
"locator": "SERVICE",
"name": "JobService",
"metadata": {"token": self._token},
"method": "create_jobs_by_data_source",
"params": {"params": {}},
}
}]
],
}

print(f'{utils.datetime_to_iso8601(datetime.now())} [INFO] [create_task] create_jobs_by_data_source => START')
print(
f"{utils.datetime_to_iso8601(datetime.now())} [INFO] [create_task] create_jobs_by_data_source => START"
)
return [stp]
else:
print(f'{utils.datetime_to_iso8601(datetime.now())} [INFO] [create_task] create_jobs_by_data_source => SKIP')
print(f'{utils.datetime_to_iso8601(datetime.now())} [INFO] [create_task] data_source_sync_time: {self._data_source_sync_hour} hour (UTC)')
print(
f"{utils.datetime_to_iso8601(datetime.now())} [INFO] [create_task] create_jobs_by_data_source => SKIP"
)
print(
f"{utils.datetime_to_iso8601(datetime.now())} [INFO] [create_task] data_source_sync_time: {self._data_source_sync_hour} hour (UTC)"
)
return []
2 changes: 1 addition & 1 deletion src/spaceone/cost_analysis/manager/identity_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_workspace(self, workspace_id: str, domain_id: str) -> str:
_LOGGER.error(f"[get_project_name] API Error: {e}")
return workspace_id

def list_service_accounts(self, query: dict, domain_id: str = None) -> dict:
def list_service_accounts(self, query: dict, domain_id: str) -> dict:
if self.token_type == "SYSTEM_TOKEN":
return self.identity_conn.dispatch(
"ServiceAccount.list", {"query": query}, x_domain_id=domain_id
Expand Down
6 changes: 3 additions & 3 deletions src/spaceone/cost_analysis/manager/job_task_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def list_job_tasks(self, query={}):
def stat_job_tasks(self, query):
return self.job_task_model.stat(**query)

@staticmethod
def push_job_task(params):
def push_job_task(self, params):
token = self.transaction.meta.get("token")
task = {
"name": "sync_data_source",
"version": "v1",
Expand All @@ -70,7 +70,7 @@ def push_job_task(params):
{
"locator": "SERVICE",
"name": "JobService",
"metadata": {},
"metadata": {"token": token},
"method": "get_cost_data",
"params": {"params": params},
}
Expand Down

0 comments on commit 574b61e

Please sign in to comment.