Skip to content

Commit

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

[bot] Merge master/1e7d9537 into rel/dev
  • Loading branch information
yenkins-admin authored Oct 16, 2024
2 parents 68c794f + 1e7d953 commit 13e406e
Show file tree
Hide file tree
Showing 19 changed files with 1,315 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: "Notification channels"
linkTitle: "Notification channels"
weight: 50
no_list: true
---

Manage notification channels.

Note that currently only Webhook is supported in Python SDK due to an issue in the generated API client.

### Declarative Methods

* [get_declarative_notification_channels](./get_declarative_notification_channels/)
* [put_declarative_notification_channels](./put_declarative_notification_channels/)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
title: "get_declarative_notification_channels"
linkTitle: "get_declarative_notification_channels..."
weight: 190
no_list: true
superheading: "catalog_organization."
---



``get_declarative_notification_channels()``

Get all declarative notification channels in the current organization.

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

{{% parameters-block title="Returns" %}}
{{< parameter p_type="list[CatalogDeclarativeNotificationChannel]" >}}
List of declarative notification channels.
{{< /parameter >}}
{{% /parameters-block %}}

## Example

```python
sdk.catalog_organization.get_declarative_notification_channels()
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: "put_declarative_notification_channels"
linkTitle: "put_declarative_notification_channels..."
weight: 190
no_list: true
superheading: "catalog_organization."
---



``put_declarative_notification_channels(notification_channels: list[CatalogDeclarativeNotificationChannel])``

Put declarative notification channels in the current organization.

{{% parameters-block title="Parameters"%}}
{{< parameter p_name="notification_channels" p_type="list[CatalogDeclarativeNotificationChannel]" >}}
List of declarative notification channels.
{{< /parameter >}}
{{% /parameters-block %}}

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

## Example

```python
from gooddata_sdk import CatalogDeclarativeNotificationChannel, CatalogWebhook

notification_channels = [CatalogDeclarativeNotificationChannel(
id="webhook", name="Webhook", destination=CatalogWebhook(url="https://webhook.site", token="123")
)]
sdk.catalog_organization.put_declarative_notification_channels()
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ weight: 110
superheading: "catalog_workspace_content."
---

``get_declarative_analytics_model(workspace_id: str)``
``get_declarative_analytics_model(workspace_id: str, exclude: Optional[list[str]])``

Gets an analytics model layout.

Expand All @@ -14,6 +14,10 @@ Gets an analytics model layout.
{{< parameter p_name="workspace_id" p_type="string" >}}
Workspace identification string e.g. "demo"
{{< /parameter >}}
{{< parameter p_name="exclude" p_type="Optional[list[str]]" >}}
Defines properties which should not be included in the payload.
E.g.: ["ACTIVITY_INFO"]
{{< /parameter >}}
{{% /parameters-block %}}

{{% parameters-block title="Returns" %}}
Expand Down
2 changes: 2 additions & 0 deletions docs/content/en/latest/workspace/workspaces/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Manage workspaces. Entity and Declarative methods are supported.
* [store_declarative_workspaces](./store_declarative_workspaces/)
* [load_declarative_workspaces](./load_declarative_workspaces/)
* [load_and_put_declarative_workspaces](./load_and_put_declarative_workspaces/)
* [get_declarative_automations](./get_declarative_automations/)
* [put_declarative_automations](./put_declarative_automations/)


## Example
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
title: "get_declarative_automations"
linkTitle: "get_declarative_automations"
weight: 50
superheading: "catalog_workspace."
---

``get_declarative_automations(workspace_id: str)``

Gets the layout of all workspaces and their hierarchy.

{{% parameters-block title="Parameters" %}}
{{< parameter p_name="workspace_id" p_type="string" >}}
Workspace identification string e.g. "demo"
{{< /parameter >}}
{{% /parameters-block %}}

{{% parameters-block title="Returns" %}}
{{< parameter p_type="list[CatalogDeclarativeAutomation]" >}}
Retrieve a list of declarative automations.
{{< /parameter >}}
{{% /parameters-block %}}

## Example

```python
declarative_automations = sdk.catalog_workspace.get_declarative_automations(workspace_id="demo")
```
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@ superheading: "catalog_workspace."
---


``get_declarative_workspace(workspace_id: str, exclude: Optional[list[str]])``

``get_declarative_workspace(workspace_id: str)``
Get all workspaces in the current organization in a declarative form.
This method combines
`sdk.catalog_workspace_content.get_declarative_ldm` and `sdk.catalog_workspace_content.get_declarative_analytics_model`
methods and returns a declarative workspace object.

Gets all workspaces in the current organization in a declarative form.

{{% parameters-block title="Parameters" None="yes" %}}
{{% parameters-block title="Parameters" %}}
{{< parameter p_name="workspace_id" p_type="string" >}}
Workspace identification string e.g. "demo"
{{< /parameter >}}
{{< parameter p_name="exclude" p_type="Optional[list[str]]" >}}
Defines properties which should not be included in the payload.
E.g.: ["ACTIVITY_INFO"]
{{< /parameter >}}
{{% /parameters-block %}}

{{% parameters-block title="Returns" %}}
Expand All @@ -20,7 +29,6 @@ Declarative Workspaces object including all the workspaces for given organizatio
{{< /parameter >}}
{{% /parameters-block %}}


## Example

```python
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: "put_declarative_automations"
linkTitle: "put_declarative_automations"
weight: 50
superheading: "catalog_workspace."
---

``put_declarative_automations(workspace_id: str, automations: list[CatalogDeclarativeAutomation])``

Set automations for the workspace.

{{% parameters-block title="Parameters" %}}
{{< parameter p_name="workspace_id" p_type="string" >}}
Workspace identification string e.g. "demo"
{{< /parameter >}}
{{< parameter p_name="automations" p_type="list[CatalogDeclarativeAutomation]" >}}
List of declarative automations.
{{< /parameter >}}
{{% /parameters-block %}}

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

## Example

```python
automations = [CatalogDeclarativeAutomation(id="schedule", ...)]
sdk.catalog_workspace.put_declarative_automations(workspace_id="demo", automations=automations)
```
10 changes: 10 additions & 0 deletions gooddata-sdk/gooddata_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
from gooddata_sdk.catalog.identifier import (
CatalogAssigneeIdentifier,
CatalogDatasetWorkspaceDataFilterIdentifier,
CatalogExportDefinitionIdentifier,
CatalogNotificationChannelIdentifier,
CatalogWorkspaceIdentifier,
)
from gooddata_sdk.catalog.organization.entity_model.directive import CatalogCspDirective
Expand All @@ -82,6 +84,10 @@
)
from gooddata_sdk.catalog.organization.entity_model.organization import CatalogOrganization
from gooddata_sdk.catalog.organization.entity_model.setting import CatalogOrganizationSetting
from gooddata_sdk.catalog.organization.layout.notification_channel import (
CatalogDeclarativeNotificationChannel,
CatalogWebhook,
)
from gooddata_sdk.catalog.organization.service import CatalogOrganizationService
from gooddata_sdk.catalog.permission.declarative_model.dashboard_assignees import (
CatalogAvailableAssignees,
Expand Down Expand Up @@ -139,6 +145,10 @@
CatalogDeclarativeExportDefinition,
CatalogDeclarativeExportDefinitionRequestPayload,
)
from gooddata_sdk.catalog.workspace.declarative_model.workspace.automation import (
CatalogAutomationSchedule,
CatalogDeclarativeAutomation,
)
from gooddata_sdk.catalog.workspace.declarative_model.workspace.logical_model.data_filter_references import (
CatalogDeclarativeWorkspaceDataFilterReferences,
)
Expand Down
23 changes: 23 additions & 0 deletions gooddata-sdk/gooddata_sdk/catalog/identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
import builtins

import attr
from attrs import define
from gooddata_api_client.model.assignee_identifier import AssigneeIdentifier
from gooddata_api_client.model.dataset_workspace_data_filter_identifier import DatasetWorkspaceDataFilterIdentifier
from gooddata_api_client.model.declarative_export_definition_identifier import DeclarativeExportDefinitionIdentifier
from gooddata_api_client.model.declarative_notification_channel_identifier import (
DeclarativeNotificationChannelIdentifier,
)
from gooddata_api_client.model.declarative_user_group_identifier import DeclarativeUserGroupIdentifier
from gooddata_api_client.model.declarative_user_identifier import DeclarativeUserIdentifier
from gooddata_api_client.model.grain_identifier import GrainIdentifier
Expand Down Expand Up @@ -91,3 +96,21 @@ class CatalogDatasetWorkspaceDataFilterIdentifier(Base):
@staticmethod
def client_class() -> builtins.type[DatasetWorkspaceDataFilterIdentifier]:
return DatasetWorkspaceDataFilterIdentifier


@define(auto_attribs=True, kw_only=True)
class CatalogExportDefinitionIdentifier(Base):
id: str

@staticmethod
def client_class() -> builtins.type[DeclarativeExportDefinitionIdentifier]:
return DeclarativeExportDefinitionIdentifier


@define(auto_attribs=True, kw_only=True)
class CatalogNotificationChannelIdentifier(Base):
id: str

@staticmethod
def client_class() -> builtins.type[DeclarativeNotificationChannelIdentifier]:
return DeclarativeNotificationChannelIdentifier
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# (C) 2024 GoodData Corporation
import builtins
from typing import Optional

from attrs import define, field
from gooddata_api_client.model.declarative_notification_channel import DeclarativeNotificationChannel
from gooddata_api_client.model.webhook import Webhook
from gooddata_sdk.catalog.base import Base

# TODO: there is an issue with generated client which causes these two classes to fail
# type in gooddata_api_client/model/declarative_notification_channel_destination.py contains only WEBHOOK as valid value
# @define(auto_attribs=True, kw_only=True)
# class CatalogDefaultSmtp(Base):
# from_email: Optional[str] = None
# from_email_name: Optional[str] = None
#
# @staticmethod
# def client_class() -> Type[DefaultSmtp]:
# return DefaultSmtp
#
#
# @define(auto_attribs=True, kw_only=True)
# class CatalogSmtp(Base):
# from_email: Optional[str] = None
# from_email_name: Optional[str] = None
# host: Optional[str] = None
# password: Optional[str] = None
# port: Optional[int] = None
# username: Optional[str] = None
#
# @staticmethod
# def client_class() -> Type[Smtp]:
# return Smtp


@define(auto_attribs=True, kw_only=True)
class CatalogWebhook(Base):
type: str = field(default="WEBHOOK", init=False)
url: Optional[str] = None
token: Optional[str] = field(default=None, eq=False)
has_token: Optional[bool] = field(default=None, eq=False)

@staticmethod
def client_class() -> builtins.type[Webhook]:
return Webhook


@define(auto_attribs=True, kw_only=True)
class CatalogDeclarativeNotificationChannel(Base):
id: str
name: Optional[str] = None
description: Optional[str] = None
destination_type: Optional[str] = None
custom_dashboard_url: Optional[str] = None
enable_multiple_recipients: Optional[bool] = None
# destination: Optional[Union[CatalogDefaultSmtp, CatalogSmtp, CatalogWebhook]] = None
destination: Optional[CatalogWebhook] = None

@staticmethod
def client_class() -> builtins.type[DeclarativeNotificationChannel]:
return DeclarativeNotificationChannel
35 changes: 35 additions & 0 deletions gooddata-sdk/gooddata_sdk/catalog/organization/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Optional

from gooddata_api_client.exceptions import NotFoundException
from gooddata_api_client.model.declarative_notification_channels import DeclarativeNotificationChannels
from gooddata_api_client.model.json_api_csp_directive_in_document import JsonApiCspDirectiveInDocument
from gooddata_api_client.model.json_api_organization_setting_in_document import JsonApiOrganizationSettingInDocument

Expand All @@ -13,6 +14,7 @@
from gooddata_sdk.catalog.organization.entity_model.jwk import CatalogJwk, CatalogJwkDocument
from gooddata_sdk.catalog.organization.entity_model.organization import CatalogOrganizationDocument
from gooddata_sdk.catalog.organization.entity_model.setting import CatalogOrganizationSetting
from gooddata_sdk.catalog.organization.layout.notification_channel import CatalogDeclarativeNotificationChannel
from gooddata_sdk.client import GoodDataApiClient
from gooddata_sdk.utils import load_all_entities

Expand All @@ -21,6 +23,8 @@ class CatalogOrganizationService(CatalogServiceBase):
def __init__(self, api_client: GoodDataApiClient) -> None:
super().__init__(api_client)

# Entities API

def update_oidc_parameters(
self,
oauth_issuer_location: Optional[str] = None,
Expand Down Expand Up @@ -319,3 +323,34 @@ def update_csp_directive(self, csp_directive: CatalogCspDirective) -> None:
self._entities_api.update_entity_csp_directives(csp_directive.id, csp_directive_document)
except NotFoundException:
raise ValueError(f"Can not update {csp_directive.id} csp directive. This csp directive does not exist.")

# Layout APIs

def get_declarative_notification_channels(self) -> list[CatalogDeclarativeNotificationChannel]:
"""
Get all declarative notification channels in the current organization.
Returns:
list[CatalogDeclarativeNotificationChannel]:
List of declarative notification channels.
"""
return [
CatalogDeclarativeNotificationChannel.from_api(nc)
for nc in self._layout_api.get_notification_channels_layout().notification_channels
]

def put_declarative_notification_channels(
self, notification_channels: list[CatalogDeclarativeNotificationChannel]
) -> None:
"""
Put declarative notification channels in the current organization.
Args:
notification_channels (list[CatalogDeclarativeNotificationChannel]):
List of declarative notification channels.
Returns:
None
"""
api_ncs = [nc.to_api() for nc in notification_channels]
self._layout_api.set_notification_channels(DeclarativeNotificationChannels(notification_channels=api_ncs))
Loading

0 comments on commit 13e406e

Please sign in to comment.