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