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

Removed data sharing mechanism to avoid concurrency issues #55

Merged
merged 1 commit into from
Aug 21, 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
1 change: 0 additions & 1 deletion src/plugin/manager/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

class ResourceManager(BaseManager):
service = None
common_data = {}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down
32 changes: 11 additions & 21 deletions src/plugin/manager/iam/permission_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,17 @@ def collect_cloud_services(
folders = self.rm_v3_connector.search_folders()
projects = self.rm_v3_connector.list_all_projects()

if ResourceManager.common_data.get("are_roles_synced"):
predefined_roles = ResourceManager.common_data["role_lists"][
"predefined_roles"
]
organization_roles = ResourceManager.common_data["role_lists"][
"organization_roles"
]
project_roles = ResourceManager.common_data["role_lists"]["project_roles"]

else:
predefined_roles = self.iam_connector.list_roles()
organization_roles = []
for organization in organizations:
organization_roles = self.iam_connector.list_organization_roles(
organization["name"]
)
project_roles = []
for project in projects:
project_roles = self.iam_connector.list_project_roles(
project["projectId"]
)
predefined_roles = self.iam_connector.list_roles()
organization_roles = []
for organization in organizations:
organization_roles = self.iam_connector.list_organization_roles(
organization["name"]
)
project_roles = []
for project in projects:
project_roles = self.iam_connector.list_project_roles(
project["projectId"]
)

self.role_id_to_info["predefined_roles"] = {role.get("name"): role for role in predefined_roles}
self.role_id_to_info["organization_roles"] = {role.get("name"): role for role in organization_roles}
Expand Down
19 changes: 2 additions & 17 deletions src/plugin/manager/iam/role_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ def __init__(self, *args, **kwargs):
self.metadata_path = "metadata/role.yaml"
self.iam_connector = None
self.rm_v3_connector = None
ResourceManager.common_data.update(
{
"role_lists": {
"organization_roles": [],
"project_roles": [],
"predefined_roles": [],
},
"are_roles_synced": False,
}
)

def collect_cloud_services(
self, options: dict, secret_data: dict, schema: str
Expand All @@ -42,10 +32,8 @@ def collect_cloud_services(
default_project_id = secret_data.get("project_id")

# Get all roles
ResourceManager.common_data["role_lists"]["predefined_roles"].extend(
self.iam_connector.list_roles()
)
for role in ResourceManager.common_data["role_lists"]["predefined_roles"]:
predefined_roles = self.iam_connector.list_roles()
for role in predefined_roles:
yield self.make_role_info(role, default_project_id, "PREDEFINED")

# get Organization roles
Expand All @@ -57,7 +45,6 @@ def collect_cloud_services(
projects = self.rm_v3_connector.list_all_projects()
for project in projects:
yield from self.collect_project_roles(project["projectId"])
ResourceManager.common_data["are_roles_synced"] = True

def collect_organization_roles(
self, organization: dict, default_project_id: str
Expand All @@ -66,15 +53,13 @@ def collect_organization_roles(
organization_name = organization.get("displayName")
location = f"organizations/{organization_name}"
roles = self.iam_connector.list_organization_roles(organization_id)
ResourceManager.common_data["role_lists"]["organization_roles"].extend(roles)
for role in roles:
yield self.make_role_info(
role, default_project_id, "ORGANIZATION", location
)

def collect_project_roles(self, project_id: str) -> Generator[dict, None, None]:
roles = self.iam_connector.list_project_roles(project_id)
ResourceManager.common_data["role_lists"]["project_roles"].extend(roles)
location = f"projects/{project_id}"
for role in roles:
yield self.make_role_info(role, project_id, "PROJECT", location)
Expand Down
Loading