mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-01 05:36:58 +00:00
* fix: get dashboard by id * fix: function param name id->dashboard_id | python checkstyle * refactor: used api version and rename get dashboard function * fix: used clean uri
This commit is contained in:
parent
c09c504178
commit
20f567b8da
@ -13,6 +13,7 @@ REST Auth & Client for Redash
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from metadata.ingestion.ometa.client import REST, ClientConfig
|
from metadata.ingestion.ometa.client import REST, ClientConfig
|
||||||
|
from metadata.utils.helpers import clean_uri
|
||||||
from metadata.utils.logger import utils_logger
|
from metadata.utils.logger import utils_logger
|
||||||
|
|
||||||
logger = utils_logger()
|
logger = utils_logger()
|
||||||
@ -28,8 +29,8 @@ class RedashApiClient:
|
|||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.config = config
|
self.config = config
|
||||||
client_config = ClientConfig(
|
client_config = ClientConfig(
|
||||||
base_url=str(config.hostPort),
|
base_url=clean_uri(config.hostPort),
|
||||||
api_version="",
|
api_version="api",
|
||||||
access_token=config.apiKey.get_secret_value(),
|
access_token=config.apiKey.get_secret_value(),
|
||||||
auth_header="Authorization",
|
auth_header="Authorization",
|
||||||
auth_token_mode="Key",
|
auth_token_mode="Key",
|
||||||
@ -41,16 +42,11 @@ class RedashApiClient:
|
|||||||
"""GET api/dashboards"""
|
"""GET api/dashboards"""
|
||||||
|
|
||||||
params_data = {"page": page, "page_size": page_size}
|
params_data = {"page": page, "page_size": page_size}
|
||||||
return self.client.get(path="api/dashboards", data=params_data)
|
return self.client.get(path="/dashboards", data=params_data)
|
||||||
|
|
||||||
def get_dashboard(self, slug):
|
def get_dashboard(self, dashboard_id: int):
|
||||||
"""GET api/dashboards/<slug>"""
|
"""GET api/dashboards/<id>"""
|
||||||
|
return self.client.get(f"/dashboards/{dashboard_id}")
|
||||||
# The API changed from redash v9 onwards
|
|
||||||
# legacy=true allows us to get the results in the old way
|
|
||||||
return self.client.get(
|
|
||||||
f"api/dashboards/{slug}?legacy=true",
|
|
||||||
)
|
|
||||||
|
|
||||||
def paginate(self, resource, page=1, page_size=25, **kwargs):
|
def paginate(self, resource, page=1, page_size=25, **kwargs):
|
||||||
"""Load all items of a paginated resource"""
|
"""Load all items of a paginated resource"""
|
||||||
|
@ -115,7 +115,7 @@ class RedashSource(DashboardServiceSource):
|
|||||||
return dashboard["name"]
|
return dashboard["name"]
|
||||||
|
|
||||||
def get_dashboard_details(self, dashboard: dict) -> dict:
|
def get_dashboard_details(self, dashboard: dict) -> dict:
|
||||||
return self.client.get_dashboard(dashboard["slug"])
|
return self.client.get_dashboard(dashboard["id"])
|
||||||
|
|
||||||
def get_owner_ref(self, dashboard_details) -> Optional[EntityReferenceList]:
|
def get_owner_ref(self, dashboard_details) -> Optional[EntityReferenceList]:
|
||||||
"""
|
"""
|
||||||
@ -160,9 +160,9 @@ class RedashSource(DashboardServiceSource):
|
|||||||
dashboard_request = CreateDashboardRequest(
|
dashboard_request = CreateDashboardRequest(
|
||||||
name=EntityName(str(dashboard_details["id"])),
|
name=EntityName(str(dashboard_details["id"])),
|
||||||
displayName=dashboard_details.get("name"),
|
displayName=dashboard_details.get("name"),
|
||||||
description=Markdown(dashboard_description)
|
description=(
|
||||||
if dashboard_description
|
Markdown(dashboard_description) if dashboard_description else None
|
||||||
else None,
|
),
|
||||||
charts=[
|
charts=[
|
||||||
FullyQualifiedEntityName(
|
FullyQualifiedEntityName(
|
||||||
fqn.build(
|
fqn.build(
|
||||||
@ -275,9 +275,11 @@ class RedashSource(DashboardServiceSource):
|
|||||||
yield Either(
|
yield Either(
|
||||||
right=CreateChartRequest(
|
right=CreateChartRequest(
|
||||||
name=EntityName(str(widgets["id"])),
|
name=EntityName(str(widgets["id"])),
|
||||||
displayName=chart_display_name
|
displayName=(
|
||||||
if visualization and visualization["query"]
|
chart_display_name
|
||||||
else "",
|
if visualization and visualization["query"]
|
||||||
|
else ""
|
||||||
|
),
|
||||||
chartType=get_standard_chart_type(
|
chartType=get_standard_chart_type(
|
||||||
visualization["type"] if visualization else ""
|
visualization["type"] if visualization else ""
|
||||||
),
|
),
|
||||||
@ -285,9 +287,11 @@ class RedashSource(DashboardServiceSource):
|
|||||||
self.context.get().dashboard_service
|
self.context.get().dashboard_service
|
||||||
),
|
),
|
||||||
sourceUrl=SourceUrl(self.get_dashboard_url(dashboard_details)),
|
sourceUrl=SourceUrl(self.get_dashboard_url(dashboard_details)),
|
||||||
description=Markdown(visualization["description"])
|
description=(
|
||||||
if visualization
|
Markdown(visualization["description"])
|
||||||
else None,
|
if visualization
|
||||||
|
else None
|
||||||
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user