Skip to content

Commit a748628

Browse files
Merge pull request #1233 from gooddata/snapshot-master-81da27bd-to-rel/dev
[bot] Merge master/81da27bd into rel/dev
2 parents ef14430 + 81da27b commit a748628

File tree

2 files changed

+27
-59
lines changed

2 files changed

+27
-59
lines changed

packages/gooddata-pipelines/src/gooddata_pipelines/api/gooddata_sdk.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,6 @@ def check_workspace_exists(self, workspace_id: str) -> bool:
5252
except Exception:
5353
return False
5454

55-
def get_workspace(self, workspace_id: str, **_: str) -> CatalogWorkspace:
56-
"""
57-
Calls GoodData Python SDK to retrieve a workspace by its ID.
58-
59-
Args:
60-
workspace_id (str): The ID of the workspace to retrieve.
61-
Returns:
62-
CatalogWorkspace: The workspace object retrieved from the SDK.
63-
Raises:
64-
GoodDataApiException: If the workspace cannot be retrieved, an exception
65-
is raised with additional context information.
66-
"""
67-
return self._sdk.catalog_workspace.get_workspace(workspace_id)
68-
6955
def delete_panther_workspace(self, workspace_id: str) -> None:
7056
"""
7157
Calls GoodData Python SDK to delete a workspace by its ID.
@@ -184,20 +170,6 @@ def put_declarative_permissions(
184170
workspace_id, ws_permissions
185171
)
186172

187-
def get_user(self, user_id: str, **_: str) -> CatalogUser:
188-
"""
189-
Calls GoodData Python SDK to retrieve a user by its ID.
190-
191-
Args:
192-
user_id (str): The ID of the user to retrieve.
193-
Returns:
194-
CatalogUser: The user object retrieved from the SDK.
195-
Raises:
196-
GoodDataApiException: If the user cannot be retrieved, an exception
197-
is raised with additional context information.
198-
"""
199-
return self._sdk.catalog_user.get_user(user_id)
200-
201173
def create_or_update_user(self, user: CatalogUser, **_: str) -> None:
202174
"""
203175
Calls GoodData Python SDK to create or update a user.
@@ -226,20 +198,6 @@ def delete_user(self, user_id: str, **_: str) -> None:
226198
"""
227199
return self._sdk.catalog_user.delete_user(user_id)
228200

229-
def get_user_group(self, user_group_id: str, **_: str) -> CatalogUserGroup:
230-
"""
231-
Calls GoodData Python SDK to retrieve a user group by its ID.
232-
233-
Args:
234-
user_group_id (str): The ID of the user group to retrieve.
235-
Returns:
236-
CatalogUserGroup: The user group object retrieved from the SDK.
237-
Raises:
238-
GoodDataApiException: If the user group cannot be retrieved, an exception
239-
is raised with additional context information.
240-
"""
241-
return self._sdk.catalog_user.get_user_group(user_group_id)
242-
243201
def list_user_groups(self) -> list[CatalogUserGroup]:
244202
"""
245203
Calls GoodData Python SDK to retrieve all user groups.

packages/gooddata-pipelines/src/gooddata_pipelines/provisioning/entities/users/permissions.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
from typing import TypeVar
66

7-
from gooddata_pipelines.api.exceptions import GoodDataApiException
7+
from gooddata_api_client.exceptions import NotFoundException # type: ignore
8+
89
from gooddata_pipelines.provisioning.entities.users.models.permissions import (
910
EntityType,
1011
PermissionDeclaration,
@@ -14,7 +15,6 @@
1415
WSPermissionsDeclarations,
1516
)
1617
from gooddata_pipelines.provisioning.provisioning import Provisioning
17-
from gooddata_pipelines.provisioning.utils.exceptions import BaseUserException
1818

1919
# Type variable for permission models (PermissionIncrementalLoad or PermissionFullLoad)
2020
PermissionModel = TypeVar(
@@ -109,20 +109,32 @@ def _check_user_group_exists(self, ug_id: str) -> None:
109109

110110
def _validate_permission(
111111
self, permission: PermissionFullLoad | PermissionIncrementalLoad
112-
) -> None:
113-
"""Validates if the permission is correctly defined."""
114-
if permission.entity_type == EntityType.user:
115-
self._api.get_user(
116-
permission.entity_id, error_message="User not found"
112+
) -> bool:
113+
"""Validates that all entities referenced in the permission exist.
114+
115+
Raises:
116+
RuntimeError: If an unexpected error is encountered.
117+
"""
118+
all_entities_exist = True
119+
try:
120+
if permission.entity_type == EntityType.user:
121+
self._api._sdk.catalog_user.get_user(permission.entity_id)
122+
else:
123+
self._api._sdk.catalog_user.get_user_group(permission.entity_id)
124+
125+
self._api._sdk.catalog_workspace.get_workspace(
126+
permission.workspace_id
117127
)
118-
else:
119-
self._api.get_user_group(
120-
permission.entity_id, error_message="User group not found"
128+
129+
except NotFoundException:
130+
all_entities_exist = False
131+
132+
except Exception as e:
133+
raise RuntimeError(
134+
f"Failed to validate permission: {e.__class__.__name__}: {e}"
121135
)
122136

123-
self._api.get_workspace(
124-
permission.workspace_id, error_message="Workspace not found"
125-
)
137+
return all_entities_exist
126138

127139
def _filter_invalid_permissions(
128140
self,
@@ -132,11 +144,9 @@ def _filter_invalid_permissions(
132144
valid_permissions: list[PermissionModel] = []
133145

134146
for permission in permissions:
135-
try:
136-
self._validate_permission(permission)
137-
except (BaseUserException, GoodDataApiException) as e:
147+
if not self._validate_permission(permission):
138148
self.logger.error(
139-
f"Skipping {permission}. Error: {e.error_message} "
149+
f"Skipping {permission}. Error: Permission references non-existent entities."
140150
+ f"Context: {permission.__dict__}"
141151
)
142152
continue

0 commit comments

Comments
 (0)