Skip to content

Commit 0b7de94

Browse files
authored
Merge pull request #14 from ImMin5/master
Add filter condition at task_changed
2 parents 95ce4d5 + 59e6cc2 commit 0b7de94

File tree

2 files changed

+46
-50
lines changed

2 files changed

+46
-50
lines changed

src/plugin/connector/spaceone_connector.py

+42-49
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from spaceone.core.connector import BaseConnector
88
from spaceone.core.error import *
99

10-
__all__ = ['SpaceONEConnector']
10+
__all__ = ["SpaceONEConnector"]
1111

1212
_LOGGER = logging.getLogger(__name__)
1313

@@ -22,96 +22,89 @@ def __init__(self, *args, **kwargs):
2222
self.endpoint = None
2323

2424
def init_client(self, options: dict, secret_data: dict, schema: str = None) -> None:
25-
self._check_secret_data(secret_data)
26-
spaceone_endpoint = secret_data['spaceone_endpoint']
27-
self.token = secret_data['spaceone_client_secret']
28-
29-
if spaceone_endpoint.startswith('http') or spaceone_endpoint.startswith('https'):
30-
self.protocol = 'http'
25+
task_type = options.get("task_type", "identity")
26+
self._check_secret_data(secret_data, task_type)
27+
spaceone_endpoint = secret_data["spaceone_endpoint"]
28+
self.token = secret_data["spaceone_client_secret"]
29+
30+
if spaceone_endpoint.startswith("http") or spaceone_endpoint.startswith(
31+
"https"
32+
):
33+
self.protocol = "http"
3134
self.endpoint = spaceone_endpoint
32-
elif spaceone_endpoint.startswith('grpc') or spaceone_endpoint.startswith('grpc+ssl'):
33-
self.protocol = 'grpc'
34-
self.grpc_client: SpaceConnector = SpaceConnector(endpoint=spaceone_endpoint, token=self.token)
35+
elif spaceone_endpoint.startswith("grpc") or spaceone_endpoint.startswith(
36+
"grpc+ssl"
37+
):
38+
self.protocol = "grpc"
39+
self.grpc_client: SpaceConnector = SpaceConnector(
40+
endpoint=spaceone_endpoint, token=self.token
41+
)
3542

3643
def verify_plugin(self, domain_id: str) -> None:
37-
method = 'Project.list'
44+
method = "Project.list"
3845
params = {
39-
"query": {
40-
"filter": [
41-
{"k": "tags.domain_id", "v": domain_id, "o": "eq"}
42-
]
43-
}
46+
"query": {"filter": [{"k": "tags.domain_id", "v": domain_id, "o": "eq"}]}
4447
}
4548
self.dispatch(method, params)
4649

4750
def list_projects(self, domain_id: str):
4851
params = {
49-
'query': {
50-
'filter': [
51-
{'k': 'tags.domain_id', 'v': domain_id, 'o': 'eq'}
52-
]
53-
}
52+
"query": {"filter": [{"k": "tags.domain_id", "v": domain_id, "o": "eq"}]}
5453
}
5554

56-
return self.dispatch('Project.list', params)
55+
return self.dispatch("Project.list", params)
5756

5857
def get_service_account(self, service_account_id):
59-
params = {
60-
'service_account_id': service_account_id
61-
}
58+
params = {"service_account_id": service_account_id}
6259

63-
return self.dispatch('ServiceAccount.get', params)
60+
return self.dispatch("ServiceAccount.get", params)
6461

6562
def update_service_account(self, service_account_id, tags):
66-
params = {
67-
'service_account_id': service_account_id,
68-
'tags': tags
69-
}
63+
params = {"service_account_id": service_account_id, "tags": tags}
7064

71-
return self.dispatch('ServiceAccount.update', params)
65+
return self.dispatch("ServiceAccount.update", params)
7266

7367
def list_service_accounts(self, project_id: str):
74-
params = {
75-
'provider': 'aws',
76-
'project_id': project_id
77-
}
68+
params = {"provider": "aws", "project_id": project_id}
7869

79-
return self.dispatch('ServiceAccount.list', params)
70+
return self.dispatch("ServiceAccount.list", params)
8071

8172
def _get_metadata(self):
82-
return ('token', self.token),
73+
return (("token", self.token),)
8374

8475
def dispatch(self, method: str = None, params: dict = None, **kwargs):
85-
if self.protocol == 'grpc':
76+
if self.protocol == "grpc":
8677
return self.grpc_client.dispatch(method, params, **kwargs)
8778
else:
8879
return self.request(method, params, **kwargs)
8980

9081
def request(self, method, params, **kwargs):
9182
method = self._convert_method_to_snake_case(method)
92-
url = f'{self.endpoint}/{method}'
83+
url = f"{self.endpoint}/{method}"
9384

9485
headers = self._make_request_header(self.token, **kwargs)
9586
response = requests.post(url, json=params, headers=headers)
9687

9788
if response.status_code >= 400:
98-
raise requests.HTTPError(f'HTTP {response.status_code} Error: {response.json()["detail"]}')
89+
raise requests.HTTPError(
90+
f'HTTP {response.status_code} Error: {response.json()["detail"]}'
91+
)
9992

10093
response = response.json()
10194
return response
10295

10396
@staticmethod
10497
def _convert_method_to_snake_case(method):
105-
method = re.sub(r'(?<!^)(?=[A-Z])', '_', method)
106-
method = method.replace('.', '/').replace('_', '-').lower()
98+
method = re.sub(r"(?<!^)(?=[A-Z])", "_", method)
99+
method = method.replace(".", "/").replace("_", "-").lower()
107100
return method
108101

109102
@staticmethod
110103
def _make_request_header(token, **kwargs):
111104
access_token = token
112105
headers = {
113-
'Authorization': f'Bearer {access_token}',
114-
'Content-Type': 'application/json',
106+
"Authorization": f"Bearer {access_token}",
107+
"Content-Type": "application/json",
115108
}
116109
return headers
117110

@@ -120,9 +113,9 @@ def _change_message(message):
120113
return MessageToDict(message, preserving_proto_field_name=True)
121114

122115
@staticmethod
123-
def _check_secret_data(secret_data: dict):
124-
if 'spaceone_endpoint' not in secret_data:
125-
raise ERROR_REQUIRED_PARAMETER(key='secret_data.spaceone_endpoint')
116+
def _check_secret_data(secret_data: dict, task_type: str):
117+
if "spaceone_endpoint" not in secret_data:
118+
raise ERROR_REQUIRED_PARAMETER(key="secret_data.spaceone_endpoint")
126119

127-
if 'spaceone_client_secret' not in secret_data:
128-
raise ERROR_REQUIRED_PARAMETER(key='secret_data.spaceone_client_secret')
120+
if "spaceone_client_secret" not in secret_data:
121+
raise ERROR_REQUIRED_PARAMETER(key="secret_data.spaceone_client_secret")

src/plugin/manager/job_manager.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ def get_tasks_directory_type(
135135
"is_sync": "true",
136136
"task_type": "directory",
137137
}
138-
task_changed = {"start": start_month}
138+
task_changed = {
139+
"start": start_month,
140+
"filter": {"additional_info.Account ID": account_id},
141+
}
139142
tasks.append({"task_options": task_options, "task_changed": task_changed})
140143

141144
changed.append({"start": start_month})

0 commit comments

Comments
 (0)