Skip to content

Commit

Permalink
Merge pull request #841 from gooddata/snapshot-master-69354ebc-to-rel…
Browse files Browse the repository at this point in the history
…/dev

[bot] Merge master/69354ebc into rel/dev
  • Loading branch information
yenkins-admin authored Oct 14, 2024
2 parents 3115503 + 69354eb commit 3a943f1
Show file tree
Hide file tree
Showing 9 changed files with 658 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/content/en/latest/administration/users/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ See [Manage Users and UserGroups](https://www.gooddata.com/docs/cloud/manage-dep
* [get_user](./get_user/)
* [delete_user](./delete_user/)
* [list_users](./list_users/)
* [create_user_api_token](./create_user_api_token/)
* [get_user_api_token](./get_user_api_token/)
* [delete_user_api_token](./delete_user_api_token/)
* [list_user_api_tokens](./list_user_api_tokens/)


### Declarative Methods
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: "create_user_api_token"
linkTitle: "create_user_api_token"
weight: 10
no_list: true
superheading: "catalog_user."
---



``create_user_api_token(user_id: str, api_token_id: str)``

Create a new user api token.

{{% parameters-block title="Parameters"%}}
{{< parameter p_name="user_id" p_type="string" >}}
User identification string. e.g. "admin"
{{< /parameter >}}
{{< parameter p_name="api_token_id" p_type="string" >}}
API token identification string. e.g. "admin_token"
{{< /parameter >}}
{{% /parameters-block %}}

{{% parameters-block title="Returns" %}}
{{< parameter p_type="CatalogApiToken" >}}
Instance of CatalogApiToken holding the information about API token (its id, and bearer token).
{{< /parameter >}}
{{% /parameters-block %}}

## Example

```python
sdk.catalog_user.create_user_api_token(user_id="admin", api_token_id="admin_token")
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: "delete_user_api_token"
linkTitle: "delete_user_api_token"
weight: 10
no_list: true
superheading: "catalog_user."
---



``delete_user_api_token(user_id: str, api_token_id: str)``

Delete user api token.

{{% parameters-block title="Parameters"%}}
{{< parameter p_name="user_id" p_type="string" >}}
User identification string. e.g. "admin"
{{< /parameter >}}
{{< parameter p_name="api_token_id" p_type="string" >}}
API token identification string. e.g. "admin_token"
{{< /parameter >}}
{{% /parameters-block %}}

{{% parameters-block title="Returns" None="yes" %}}
{{% /parameters-block %}}

## Example

```python
sdk.catalog_user.delete_user_api_token(user_id="admin", api_token_id="admin_token")
```
34 changes: 34 additions & 0 deletions docs/content/en/latest/administration/users/get_user_api_token.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: "get_user_api_token"
linkTitle: "get_user_api_token"
weight: 10
no_list: true
superheading: "catalog_user."
---



``get_user_api_token(user_id: str, api_token_id: str)``

Get user api token.

{{% parameters-block title="Parameters"%}}
{{< parameter p_name="user_id" p_type="string" >}}
User identification string. e.g. "admin"
{{< /parameter >}}
{{< parameter p_name="api_token_id" p_type="string" >}}
API token identification string. e.g. "admin_token"
{{< /parameter >}}
{{% /parameters-block %}}

{{% parameters-block title="Returns" %}}
{{< parameter p_type="CatalogApiToken" >}}
Instance of CatalogApiToken holding the information about API token.
Note that the bearer token is not returned. It will always be None.
{{< /parameter >}}
{{% /parameters-block %}}
## Example

```python
sdk.catalog_user.get_user_api_token(user_id="admin", api_token_id="admin_token")
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: "list_user_api_tokens"
linkTitle: "list_user_api_tokens"
weight: 10
no_list: true
superheading: "catalog_user."
---



``list_user_api_tokens(user_id: str)``

List all user API tokens.

{{% parameters-block title="Parameters"%}}
{{< parameter p_name="user_id" p_type="string" >}}
User identification string. e.g. "admin"
{{< /parameter >}}
{{% /parameters-block %}}

{{% parameters-block title="Returns" %}}
{{< parameter p_type="list[CatalogApiToken]" >}}
List of CatalogApiToken instances holding the information about users API tokens.
Note that the bearer token is not returned. It will always be None.
{{< /parameter >}}
{{% /parameters-block %}}

## Example

```python
sdk.catalog_user.list_user_api_tokens(user_id="admin")
```
12 changes: 12 additions & 0 deletions gooddata-sdk/gooddata_sdk/catalog/user/entity_model/api_token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# (C) 2024 GoodData Corporation
from typing import Optional

from attrs import define

from gooddata_sdk.catalog.base import Base


@define(auto_attribs=True, kw_only=True)
class CatalogApiToken(Base):
id: str
bearer_token: Optional[str] = None
26 changes: 26 additions & 0 deletions gooddata-sdk/gooddata_sdk/catalog/user/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
from pathlib import Path

from gooddata_api_client.exceptions import NotFoundException
from gooddata_api_client.model.json_api_api_token_in import JsonApiApiTokenIn
from gooddata_api_client.model.json_api_api_token_in_document import JsonApiApiTokenInDocument

from gooddata_sdk.catalog.catalog_service_base import CatalogServiceBase
from gooddata_sdk.catalog.user.declarative_model.user import CatalogDeclarativeUsers
from gooddata_sdk.catalog.user.declarative_model.user_and_user_groups import CatalogDeclarativeUsersUserGroups
from gooddata_sdk.catalog.user.declarative_model.user_group import CatalogDeclarativeUserGroups
from gooddata_sdk.catalog.user.entity_model.api_token import CatalogApiToken
from gooddata_sdk.catalog.user.entity_model.user import CatalogUser, CatalogUserDocument
from gooddata_sdk.catalog.user.entity_model.user_group import CatalogUserGroup, CatalogUserGroupDocument
from gooddata_sdk.catalog.user.management_model.management import (
Expand Down Expand Up @@ -391,3 +394,26 @@ def assign_permissions_bulk(self, permissions_assignment: CatalogPermissionsAssi

def revoke_permissions_bulk(self, permissions_assignment: CatalogPermissionsAssignment) -> None:
self._user_management_api.revoke_permissions(permissions_assignment.to_api())

def list_user_api_tokens(self, user_id: str) -> list[CatalogApiToken]:
get_api_tokens = functools.partial(
self._entities_api.get_all_entities_api_tokens,
user_id,
_check_return_type=False,
)
api_tokens = load_all_entities(get_api_tokens)
return [CatalogApiToken(id=v["id"]) for v in api_tokens.data]

def create_user_api_token(self, user_id: str, api_token_id: str) -> CatalogApiToken:
document = JsonApiApiTokenInDocument(data=JsonApiApiTokenIn(id=api_token_id, type="apiToken"))
api_token = self._entities_api.create_entity_api_tokens(user_id, document, _check_return_type=False)
v = api_token.data
return CatalogApiToken(id=v["id"], bearer_token=v.get("attributes", {}).get("bearerToken"))

def get_user_api_token(self, user_id: str, api_token_id: str) -> CatalogApiToken:
api_token = self._entities_api.get_entity_api_tokens(user_id, api_token_id, _check_return_type=False)
v = api_token.data
return CatalogApiToken(id=v["id"])

def delete_user_api_token(self, user_id: str, api_token_id: str) -> None:
self._entities_api.delete_entity_api_tokens(user_id, api_token_id)
Loading

0 comments on commit 3a943f1

Please sign in to comment.