mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-10-28 17:23:28 +00:00
parent
6acb47a87a
commit
bf0ec44f4b
@ -85,18 +85,49 @@ class MetabaseClient:
|
||||
)
|
||||
self.client = REST(client_config)
|
||||
|
||||
def get_dashboards_list(self) -> List[MetabaseDashboard]:
|
||||
def get_dashboards_list(
|
||||
self, collections: List[MetabaseCollection]
|
||||
) -> List[MetabaseDashboard]:
|
||||
"""
|
||||
Get List of all dashboards
|
||||
"""
|
||||
try:
|
||||
resp_dashboards = self.client.get("/dashboard")
|
||||
dashboards = []
|
||||
for collection in collections or []:
|
||||
try:
|
||||
resp_dashboards = self.client.get(
|
||||
f"/collection/{collection.id}/items?models=dashboard"
|
||||
)
|
||||
if resp_dashboards:
|
||||
dashboard_list = MetabaseDashboardList(**resp_dashboards)
|
||||
dashboards.extend(dashboard_list.data)
|
||||
except Exception:
|
||||
logger.debug(traceback.format_exc())
|
||||
logger.warning("Failed to fetch the dashboard list")
|
||||
return dashboards
|
||||
|
||||
def get_dashboards_list_test_conn(
|
||||
self, collections: List[MetabaseCollection]
|
||||
) -> List[MetabaseDashboard]:
|
||||
"""
|
||||
Get List of all dashboards
|
||||
"""
|
||||
for collection in collections or []:
|
||||
resp_dashboards = self.client.get(
|
||||
f"/collection/{collection.id}/items?models=dashboard"
|
||||
)
|
||||
if resp_dashboards:
|
||||
dashboard_list = MetabaseDashboardList(dashboards=resp_dashboards)
|
||||
return dashboard_list.dashboards
|
||||
except Exception:
|
||||
logger.debug(traceback.format_exc())
|
||||
logger.warning("Failed to fetch the dashboard list")
|
||||
dashboard_list = MetabaseDashboardList(**resp_dashboards)
|
||||
return dashboard_list.data
|
||||
return []
|
||||
|
||||
def get_collections_list_test_conn(self) -> List[MetabaseCollection]:
|
||||
"""
|
||||
Get List of all collections
|
||||
"""
|
||||
resp_collections = self.client.get("/collection")
|
||||
if resp_collections:
|
||||
collection_list = MetabaseCollectionList(collections=resp_collections)
|
||||
return collection_list.collections
|
||||
return []
|
||||
|
||||
def get_collections_list(self) -> List[MetabaseCollection]:
|
||||
|
||||
@ -44,7 +44,8 @@ def test_connection(
|
||||
"""
|
||||
|
||||
def custom_executor():
|
||||
return client.get_dashboards_list()
|
||||
collections = client.get_collections_list_test_conn()
|
||||
return client.get_dashboards_list_test_conn(collections)
|
||||
|
||||
test_fn = {"GetDashboards": custom_executor}
|
||||
|
||||
|
||||
@ -94,7 +94,7 @@ class MetabaseSource(DashboardServiceSource):
|
||||
"""
|
||||
Get List of all dashboards
|
||||
"""
|
||||
return self.client.get_dashboards_list()
|
||||
return self.client.get_dashboards_list(self.collections)
|
||||
|
||||
def get_dashboard_name(self, dashboard: MetabaseDashboard) -> str:
|
||||
"""
|
||||
|
||||
@ -37,7 +37,7 @@ class MetabaseCollection(BaseModel):
|
||||
|
||||
|
||||
class MetabaseDashboardList(BaseModel):
|
||||
dashboards: Optional[List[MetabaseDashboard]]
|
||||
data: Optional[List[MetabaseDashboard]]
|
||||
|
||||
|
||||
class MetabaseCollectionList(BaseModel):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user