Skip to content

Commit

Permalink
Merge pull request #394 from ImMin5/master
Browse files Browse the repository at this point in the history
Fix collector secret filter with workspace_id
  • Loading branch information
ImMin5 authored Sep 4, 2024
2 parents ae820cf + 5bb1fd3 commit 79eca66
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/spaceone/inventory/service/collector_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ def verify_plugin(self, params: dict) -> None:
collector_vo.provider,
domain_id,
params.get("secret_id"),
workspace_id,
)

if secret_ids:
Expand Down Expand Up @@ -459,7 +460,7 @@ def collect(self, params: dict) -> Job:

collector_id = params["collector_id"]
domain_id = params["domain_id"]
workspace_id = params.get("workspace_id")
workspace_id = params.get("workspace_id", None)

collector_vo = self.collector_mgr.get_collector(
collector_id, domain_id, workspace_id
Expand Down Expand Up @@ -492,6 +493,7 @@ def collect(self, params: dict) -> Job:
plugin_info,
secret_filter,
domain_id,
workspace_id,
)

duplicated_job_vos = job_mgr.get_duplicate_jobs(
Expand Down Expand Up @@ -579,6 +581,7 @@ def _get_tasks(
plugin_info: dict,
secret_filter: dict,
domain_id: str,
workspace_id: str = None,
) -> list:
secret_mgr: SecretManager = self.locator.get_manager(SecretManager)
collector_plugin_mgr: CollectorPluginManager = self.locator.get_manager(
Expand All @@ -591,6 +594,7 @@ def _get_tasks(
collector_provider,
domain_id,
params.get("secret_id"),
workspace_id,
)

for secret_id in secret_ids:
Expand Down Expand Up @@ -778,10 +782,15 @@ def _get_secret_ids_from_filter(
provider: str,
domain_id: str,
secret_id: str = None,
workspace_id: str = None,
) -> list:
secret_manager: SecretManager = self.locator.get_manager(SecretManager)

query = {"filter": self._make_secret_filter(secret_filter, provider, secret_id)}
query = {
"filter": self._make_secret_filter(
secret_filter, provider, secret_id, workspace_id
)
}
response = secret_manager.list_secrets(query, domain_id)

return [
Expand Down Expand Up @@ -852,13 +861,19 @@ def delete_collector_rules(self, collector_id: str, domain_id: str) -> None:

@staticmethod
def _make_secret_filter(
secret_filter: dict, provider: str, secret_id: str = None
secret_filter: dict,
provider: str,
secret_id: str = None,
workspace_id: str = None,
) -> list:
_filter = [{"k": "provider", "v": provider, "o": "eq"}]

if secret_id:
_filter.append({"k": "secret_id", "v": secret_id, "o": "eq"})

if workspace_id:
_filter.append({"k": "workspace_id", "v": workspace_id, "o": "eq"})

if secret_filter.get("state") == "ENABLED":
if secrets := secret_filter.get("secrets"):
_filter.append({"k": "secret_id", "v": secrets, "o": "in"})
Expand Down

0 comments on commit 79eca66

Please sign in to comment.