Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: [3.12]

steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions supersetapiclient/assets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Assets."""

import json
from pathlib import Path
from typing import Union
Expand Down
1 change: 1 addition & 0 deletions supersetapiclient/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Base classes."""

import dataclasses
import logging

Expand Down
1 change: 1 addition & 0 deletions supersetapiclient/charts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Charts."""

from dataclasses import dataclass, field
from typing import List, Optional

Expand Down
25 changes: 8 additions & 17 deletions supersetapiclient/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A Superset REST Api Client."""

import getpass
import logging

Expand All @@ -15,12 +16,12 @@
from supersetapiclient.assets import Assets
from supersetapiclient.base import raise_for_status
from supersetapiclient.charts import Charts
from supersetapiclient.css_templates import CssTemplates
from supersetapiclient.dashboards import Dashboards
from supersetapiclient.databases import Databases
from supersetapiclient.datasets import Datasets
from supersetapiclient.exceptions import QueryLimitReached
from supersetapiclient.saved_queries import SavedQueries
from supersetapiclient.css_templates import CssTemplates

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -54,18 +55,17 @@ def __init__(
self.provider = provider
if not verify:
self.http_adapter_cls = NoVerifyHTTPAdapter

self.firstname = firstname
self.lastname = lastname

# Related Objects
self.assets = self.assets_cls(self)
self.dashboards = self.dashboards_cls(self)
self.charts = self.charts_cls(self)
self.css_templates = self.css_templates_cls(self)
self.datasets = self.datasets_cls(self)
self.databases = self.databases_cls(self)
self.saved_queries = self.saved_queries_cls(self)
self.css_templates = self.css_templates_cls(self)

@cached_property
def _token(self):
Expand Down Expand Up @@ -210,7 +210,7 @@ def login_endpoint(self) -> str:
@property
def refresh_endpoint(self) -> str:
return self.join_urls(self.base_url, "security/refresh")

@property
def guest_token_endpoint(self) -> str:
return self.join_urls(self.base_url, "security/guest_token/")
Expand All @@ -227,8 +227,8 @@ def csrf_token(self, session) -> str:
)
raise_for_status(csrf_response) # Check CSRF Token went well
return csrf_response.json().get("result")
def guest_token(self, uuid: str) -> dict:

def guest_token(self, uuid: str) -> str:
"""Retrieve a guest token from the Superset API.

:param uuid: The UUID of the resource (e.g., dashboard).
Expand All @@ -237,18 +237,9 @@ def guest_token(self, uuid: str) -> dict:
"""
# Construct the request body
request_body = {
"resources": [
{
"id": uuid,
"type": "dashboard"
}
],
"resources": [{"id": uuid, "type": "dashboard"}],
"rls": [],
"user": {
"first_name": self.firstname,
"last_name": self.lastname,
"username": self.username
}
"user": {"first_name": self.firstname, "last_name": self.lastname, "username": self.username},
}

response = self.post(self.guest_token_endpoint, json=request_body)
Expand Down
3 changes: 2 additions & 1 deletion supersetapiclient/css_templates.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""CSS Templates."""

from dataclasses import dataclass
from typing import Optional

from supersetapiclient.base import Object, ObjectFactories, default_string, raise_for_status
from supersetapiclient.base import Object, ObjectFactories, default_string


@dataclass
Expand Down
16 changes: 9 additions & 7 deletions supersetapiclient/dashboards.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Dashboards."""

from dataclasses import dataclass, field
from typing import List, Optional

Expand All @@ -8,7 +9,7 @@
@dataclass
class DashboardEmbed(Object):
allowed_domains: List[str] = field(default_factory=list)
uuid:str = None
uuid: str = None


@dataclass
Expand Down Expand Up @@ -51,11 +52,11 @@ def get_charts(self) -> List[int]:
c = self._parent.client.charts.find_one(slice_name=slice_name)
charts.append(c)
return charts

def get_embed(self) -> DashboardEmbed:
"""Get the dashboard's embedded configuration"""
client = self._parent.client
embed_dashboard_url = client.join_urls(self.base_url,"embedded")
embed_dashboard_url = client.join_urls(self.base_url, "embedded")
response = client.get(embed_dashboard_url)
if response.status_code == 404:
return None
Expand All @@ -64,18 +65,19 @@ def get_embed(self) -> DashboardEmbed:
def create_embed(self, allowed_domains: List[str]) -> DashboardEmbed:
"""Set a dashboard's embedded configuration"""
client = self._parent.client
embed_dashboard_url = client.join_urls(self.base_url,"embedded")
response = client.post(embed_dashboard_url, json={ "allowed_domains": allowed_domains })
embed_dashboard_url = client.join_urls(self.base_url, "embedded")
response = client.post(embed_dashboard_url, json={"allowed_domains": allowed_domains})
raise_for_status(response)
return DashboardEmbed().from_json(response.json().get("result"))

def copy_dashboard(self, dashboard_payload: dict) -> None:
"""Copy the dashboard with the given payload"""
client = self._parent.client
copy_dashboard_url = client.join_urls(self.base_url,"copy")
copy_dashboard_url = client.join_urls(self.base_url, "copy")
response = client.post(copy_dashboard_url, json=dashboard_payload)
raise_for_status(response)


class Dashboards(ObjectFactories):
endpoint = "dashboard/"
base_object = Dashboard
1 change: 1 addition & 0 deletions supersetapiclient/databases.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Databases."""

from dataclasses import dataclass
from typing import Optional

Expand Down
1 change: 1 addition & 0 deletions supersetapiclient/datasets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Dashboards."""

from dataclasses import dataclass, field
from typing import Optional

Expand Down
1 change: 1 addition & 0 deletions supersetapiclient/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Custom Exception."""

import json

from requests import HTTPError
Expand Down
1 change: 1 addition & 0 deletions supersetapiclient/saved_queries.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Saved queries."""

from dataclasses import dataclass
from typing import Optional

Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Fixture and superset app for testing."""

import json
import os
from pathlib import Path
Expand Down
1 change: 1 addition & 0 deletions tests/superset_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
allow running queries through the API. Standard Superset only has /superset/sql_json/
which is only accessible via a browser.
"""

import logging
from typing import Optional, cast

Expand Down