Skip to content

Commit

Permalink
Merge pull request #398 from JKlucka/jklu/nas-5360-new
Browse files Browse the repository at this point in the history
NAS-5360 Enforcing api-token permission python sdk update

Reviewed-by: Jan Kadlec
             https://github.com/hkad98
  • Loading branch information
gdgate authored Oct 30, 2023
2 parents 87aecc7 + f9e5ae4 commit d705310
Show file tree
Hide file tree
Showing 13 changed files with 806 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gooddata-api-client/docs/ActionsApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ with gooddata_api_client.ApiClient() as api_client:
workspace_id = "/6bUUGjjNSwg0_bs" # str | Workspace identifier
elements_request = ElementsRequest(
complement_filter=False,
data_sampling_percentage=100.0,
data_sampling_percentage=100,
exact_filter=[
"exact_filter_example",
],
Expand Down
2 changes: 1 addition & 1 deletion gooddata-api-client/docs/ComputationApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ with gooddata_api_client.ApiClient() as api_client:
workspace_id = "/6bUUGjjNSwg0_bs" # str | Workspace identifier
elements_request = ElementsRequest(
complement_filter=False,
data_sampling_percentage=100.0,
data_sampling_percentage=100,
exact_filter=[
"exact_filter_example",
],
Expand Down
2 changes: 1 addition & 1 deletion gooddata-api-client/docs/ElementsRequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**label** | **str** | Requested label. |
**complement_filter** | **bool** | Inverse filters: * ```false``` - return items matching ```patternFilter``` and ```exactFilter``` * ```true``` - return items not matching ```patternFilter``` and ```exactFilter``` | [optional] if omitted the server will use the default value of False
**data_sampling_percentage** | **float** | Specifies percentage of source table data scanned during the computation. This field is deprecated and is no longer used during the elements computation. | [optional] if omitted the server will use the default value of 100.0
**data_sampling_percentage** | **float** | Specifies percentage of source table data scanned during the computation. This field is deprecated and is no longer used during the elements computation. | [optional] if omitted the server will use the default value of 100
**exact_filter** | **[str, none_type]** | Return only items, whose ```label``` title exactly matches one of ```filter```. | [optional]
**exclude_primary_label** | **bool** | Excludes items from the result that differ only by primary label * ```false``` - return items with distinct primary label * ```true``` - return items with distinct requested label | [optional] if omitted the server will use the default value of False
**filter_by** | [**FilterBy**](FilterBy.md) | | [optional]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def _from_openapi_data(cls, label, *args, **kwargs): # noqa: E501
through its discriminator because we passed in
_visited_composed_classes = (Animal,)
complement_filter (bool): Inverse filters: * ```false``` - return items matching ```patternFilter``` and ```exactFilter``` * ```true``` - return items not matching ```patternFilter``` and ```exactFilter```. [optional] if omitted the server will use the default value of False # noqa: E501
data_sampling_percentage (float): Specifies percentage of source table data scanned during the computation. This field is deprecated and is no longer used during the elements computation.. [optional] if omitted the server will use the default value of 100.0 # noqa: E501
data_sampling_percentage (float): Specifies percentage of source table data scanned during the computation. This field is deprecated and is no longer used during the elements computation.. [optional] if omitted the server will use the default value of 100 # noqa: E501
exact_filter ([str, none_type]): Return only items, whose ```label``` title exactly matches one of ```filter```.. [optional] # noqa: E501
exclude_primary_label (bool): Excludes items from the result that differ only by primary label * ```false``` - return items with distinct primary label * ```true``` - return items with distinct requested label. [optional] if omitted the server will use the default value of False # noqa: E501
filter_by (FilterBy): [optional] # noqa: E501
Expand Down Expand Up @@ -264,7 +264,7 @@ def __init__(self, label, *args, **kwargs): # noqa: E501
through its discriminator because we passed in
_visited_composed_classes = (Animal,)
complement_filter (bool): Inverse filters: * ```false``` - return items matching ```patternFilter``` and ```exactFilter``` * ```true``` - return items not matching ```patternFilter``` and ```exactFilter```. [optional] if omitted the server will use the default value of False # noqa: E501
data_sampling_percentage (float): Specifies percentage of source table data scanned during the computation. This field is deprecated and is no longer used during the elements computation.. [optional] if omitted the server will use the default value of 100.0 # noqa: E501
data_sampling_percentage (float): Specifies percentage of source table data scanned during the computation. This field is deprecated and is no longer used during the elements computation.. [optional] if omitted the server will use the default value of 100 # noqa: E501
exact_filter ([str, none_type]): Return only items, whose ```label``` title exactly matches one of ```filter```.. [optional] # noqa: E501
exclude_primary_label (bool): Excludes items from the result that differ only by primary label * ```false``` - return items with distinct primary label * ```true``` - return items with distinct requested label. [optional] if omitted the server will use the default value of False # noqa: E501
filter_by (FilterBy): [optional] # noqa: E501
Expand Down
2 changes: 2 additions & 0 deletions gooddata-sdk/gooddata_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@
CatalogDeclarativeDashboardPermissionsForAssignee,
CatalogDeclarativeDashboardPermissionsForAssigneeRule,
CatalogDeclarativeDataSourcePermission,
CatalogDeclarativeOrganizationPermission,
CatalogDeclarativeSingleWorkspacePermission,
CatalogDeclarativeWorkspaceHierarchyPermission,
CatalogDeclarativeWorkspacePermissions,
CatalogOrganizationPermissionAssignment,
)
from gooddata_sdk.catalog.rule import CatalogAssigneeRule
from gooddata_sdk.catalog.user.declarative_model.user import CatalogDeclarativeUser, CatalogDeclarativeUsers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
DeclarativeAnalyticalDashboardPermissionForAssigneeRule,
)
from gooddata_api_client.model.declarative_data_source_permission import DeclarativeDataSourcePermission
from gooddata_api_client.model.declarative_organization_permission import DeclarativeOrganizationPermission
from gooddata_api_client.model.declarative_single_workspace_permission import DeclarativeSingleWorkspacePermission
from gooddata_api_client.model.declarative_workspace_hierarchy_permission import DeclarativeWorkspaceHierarchyPermission
from gooddata_api_client.model.declarative_workspace_permissions import DeclarativeWorkspacePermissions
from gooddata_api_client.model.organization_permission_assignment import OrganizationPermissionAssignment
from gooddata_sdk.catalog.base import Base, value_in_allowed
from gooddata_sdk.catalog.identifier import CatalogAssigneeIdentifier
from gooddata_sdk.catalog.rule import CatalogAssigneeRule
Expand Down Expand Up @@ -78,3 +80,23 @@ class CatalogDeclarativeDashboardPermissionsForAssigneeRule(Base):
@staticmethod
def client_class() -> Type[DeclarativeAnalyticalDashboardPermissionForAssigneeRule]:
return DeclarativeAnalyticalDashboardPermissionForAssigneeRule


@attr.s(auto_attribs=True, kw_only=True)
class CatalogDeclarativeOrganizationPermission(Base):
name: str = attr.field(validator=value_in_allowed)
assignee: CatalogAssigneeIdentifier

@staticmethod
def client_class() -> Type[DeclarativeOrganizationPermission]:
return DeclarativeOrganizationPermission


@attr.s(auto_attribs=True, kw_only=True)
class CatalogOrganizationPermissionAssignment(Base):
assignee_identifier: CatalogAssigneeIdentifier
permissions: List[str] = attr.field(factory=list)

@staticmethod
def client_class() -> Type[OrganizationPermissionAssignment]:
return OrganizationPermissionAssignment
52 changes: 52 additions & 0 deletions gooddata-sdk/gooddata_sdk/catalog/permission/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
from gooddata_sdk import (
CatalogAvailableAssignees,
CatalogDashboardPermissions,
CatalogDeclarativeOrganizationPermission,
CatalogDeclarativeWorkspacePermissions,
CatalogOrganizationPermissionAssignment,
CatalogPermissionsForAssignee,
CatalogPermissionsForAssigneeRule,
GoodDataApiClient,
Expand Down Expand Up @@ -106,3 +108,53 @@ def manage_dashboard_permissions(
[permission.to_api() for permission in permissions_for_assignee],
_check_return_type=False,
)

def get_declarative_organization_permissions(self) -> List[CatalogDeclarativeOrganizationPermission]:
"""Get a list of all declarative organization permissions.
Args:
None
Returns:
[CatalogDeclarativeOrganizationPermission]:
List of all declarative organization permissions.
"""

catalog_list = []
organization_permissions = self._layout_api.get_organization_permissions()
for permission in organization_permissions:
catalog_list.append(CatalogDeclarativeOrganizationPermission.from_api(permission))
return catalog_list

def put_declarative_organization_permissions(
self, org_permissions: List[CatalogDeclarativeOrganizationPermission]
) -> None:
"""Put a list of all declarative organization permissions.
Args:
org_permissions([CatalogDeclarativeOrganizationPermission])
list of declarative organization permissions
Returns:
None
"""

declarative_organization_permissions = []
for catalog_permission in org_permissions:
declarative_organization_permissions.append(catalog_permission.to_api())
self._layout_api.set_organization_permissions(declarative_organization_permissions)

def manage_organization_permissions(
self, organization_permission_assignments: List[CatalogOrganizationPermissionAssignment]
) -> None:
"""Provide managing organization permissions for user and user groups.
Args:
organization_permission_assignments ([CatalogOrganizationPermissionAssignment]):
Object containing List of users and user group and desired organization permissions. Set empty list
permissions for user/user group means remove organization permissions.
Returns:
None
"""
permissions = [permission.to_api() for permission in organization_permission_assignments]
self._actions_api.manage_organization_permissions(permissions, _check_return_type=False)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"assignee": {
"id": "adminGroup",
"type": "userGroup"
},
"name": "MANAGE"
},
{
"assignee": {
"id": "adminGroup",
"type": "userGroup"
},
"name": "SELF_CREATE_TOKEN"
}
]
Loading

0 comments on commit d705310

Please sign in to comment.