gcp-platforms-auto 0.8.1__tar.gz → 0.8.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gcp_platforms_auto
3
- Version: 0.8.1
3
+ Version: 0.8.3
4
4
  Summary: A brief description of your package
5
5
  Author-email: ofir4858 <ofirshasha10@gmail.com>
6
6
  License: MIT
@@ -13,7 +13,6 @@ Requires-Dist: requests
13
13
  Requires-Dist: pyjwt
14
14
  Requires-Dist: google-cloud-logging
15
15
  Requires-Dist: google-cloud-asset
16
- Requires-Dist: google-cloud-resource-manager
17
16
  Requires-Dist: gitpython
18
17
  Requires-Dist: sqlalchemy
19
18
  Requires-Dist: pg8000
@@ -1,8 +1,9 @@
1
1
  """IAM access management utilities for GCP."""
2
2
 
3
3
  import logging
4
+ import os
4
5
  import google.cloud.logging
5
- from google.cloud import asset_v1, resourcemanager_v3
6
+ from google.cloud import asset_v1
6
7
  from typing import Optional
7
8
 
8
9
  # Initialize Google Cloud Logging
@@ -106,47 +107,39 @@ def check_user_has_role_in_project(
106
107
  raise
107
108
 
108
109
 
109
- def _get_all_folders_recursive(parent: str, folders_client) -> list:
110
- """
111
- Recursively get all folders under a parent (organization or folder).
112
-
113
- Args:
114
- parent: Parent resource (e.g., 'organizations/123' or 'folders/456')
115
- folders_client: FoldersClient instance
116
-
117
- Returns:
118
- list: List of all folder resource names
119
- """
120
- all_folders = []
121
-
122
- try:
123
- request = resourcemanager_v3.ListFoldersRequest(parent=parent)
124
- folders = folders_client.list_folders(request=request)
125
-
126
- for folder in folders:
127
- folder_name = folder.name # Format: folders/123
128
- all_folders.append(folder_name)
129
- logger.info(f"Found folder: {folder_name}")
130
-
131
- # Recursively get subfolders
132
- subfolders = _get_all_folders_recursive(folder_name, folders_client)
133
- all_folders.extend(subfolders)
134
-
135
- except Exception as e:
136
- logger.warning(f"Error listing folders under {parent}: {e}")
137
-
138
- return all_folders
110
+ def _get_all_service_projects(base_paths, prefix):
111
+ service_projects = []
112
+
113
+ for path in base_paths:
114
+ logger.info(f"[INFO] Searching for projects under: {path}")
115
+
116
+ for root, _, _ in os.walk(path):
117
+ if root == path:
118
+ continue
119
+
120
+ for _, _, projects in os.walk(root):
121
+ for project in projects:
122
+ if not project.endswith(".yaml"):
123
+ continue
124
+ if project.startswith(prefix):
125
+ service_projects.append(project.split('.')[0])
126
+ else:
127
+ service_projects.append(f"{prefix}-{project.split('.')[0]}")
128
+
129
+ return list(set(service_projects))
139
130
 
140
131
 
141
132
  def get_projects_with_role(
142
133
  user_email: str,
143
134
  organization_id: str,
144
135
  role: str = "roles/owner",
145
- expand_groups: bool = True
136
+ expand_groups: bool = True,
137
+ project_prefix: Optional[str] = None,
138
+ projects_base_paths: Optional[list] = []
146
139
  ) -> list:
147
140
  """
148
141
  Get all projects where a user or service account has a specific role.
149
- Searches recursively through all folders in the organization.
142
+ Searches for all service projects in the organization.
150
143
 
151
144
  Args:
152
145
  user_email: Email of the user or service account to check
@@ -168,27 +161,12 @@ def get_projects_with_role(
168
161
  logger.info(f"Fetching all projects in organization {organization_id} (including folders)")
169
162
 
170
163
  try:
171
- # Initialize clients
172
- projects_client = resourcemanager_v3.ProjectsClient()
173
- folders_client = resourcemanager_v3.FoldersClient()
174
-
175
- # Get all folders recursively
176
- org_parent = f"organizations/{organization_id}"
177
- all_folders = _get_all_folders_recursive(org_parent, folders_client)
178
- logger.info(f"Found {len(all_folders)} folder(s) in organization")
179
-
180
- # Create list of all parents to search (organization + all folders)
181
- parents_to_search = [org_parent] + all_folders
182
-
183
- # Collect all projects from all parents
184
- all_projects = []
185
- for parent in parents_to_search:
186
- request = resourcemanager_v3.ListProjectsRequest(parent=parent)
187
- projects = projects_client.list_projects(request=request)
188
- for project in projects:
189
- all_projects.append(project.project_id)
164
+ all_projects = _get_all_service_projects(
165
+ base_paths=projects_base_paths,
166
+ prefix=project_prefix
167
+ )
190
168
 
191
- logger.info(f"Found {len(all_projects)} total project(s) across organization and folders")
169
+ logger.info(f"Found {len(all_projects)} total service project(s) across organization {organization_id}")
192
170
 
193
171
  # Filter projects where user has the specified role
194
172
  matching_projects = []
@@ -1,7 +1,6 @@
1
1
  import logging
2
2
  from pydantic import (
3
3
  BaseModel,
4
- ValueError,
5
4
  field_validator,
6
5
  )
7
6
  from google.cloud import logging as cloud_logging
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gcp_platforms_auto
3
- Version: 0.8.1
3
+ Version: 0.8.3
4
4
  Summary: A brief description of your package
5
5
  Author-email: ofir4858 <ofirshasha10@gmail.com>
6
6
  License: MIT
@@ -13,7 +13,6 @@ Requires-Dist: requests
13
13
  Requires-Dist: pyjwt
14
14
  Requires-Dist: google-cloud-logging
15
15
  Requires-Dist: google-cloud-asset
16
- Requires-Dist: google-cloud-resource-manager
17
16
  Requires-Dist: gitpython
18
17
  Requires-Dist: sqlalchemy
19
18
  Requires-Dist: pg8000
@@ -2,7 +2,6 @@ requests
2
2
  pyjwt
3
3
  google-cloud-logging
4
4
  google-cloud-asset
5
- google-cloud-resource-manager
6
5
  gitpython
7
6
  sqlalchemy
8
7
  pg8000
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "gcp_platforms_auto"
7
- version = "0.8.1"
7
+ version = "0.8.3"
8
8
  description = "A brief description of your package"
9
9
  readme = "README.md"
10
10
  authors = [
@@ -16,7 +16,6 @@ dependencies = [
16
16
  "pyjwt",
17
17
  "google-cloud-logging",
18
18
  "google-cloud-asset",
19
- "google-cloud-resource-manager",
20
19
  "gitpython",
21
20
  "sqlalchemy",
22
21
  "pg8000",