mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-01 21:23:10 +00:00
parent
b3617a8f8b
commit
1bc2cc1d71
@ -67,15 +67,27 @@ class ModeApiClient:
|
|||||||
)
|
)
|
||||||
self.client = REST(client_config)
|
self.client = REST(client_config)
|
||||||
|
|
||||||
def fetch_all_reports(self, workspace_name: str) -> Optional[list]:
|
def fetch_all_reports(
|
||||||
|
self, workspace_name: str, filter: Optional[str] = "all"
|
||||||
|
) -> Optional[list]:
|
||||||
"""Method to fetch all reports for Mode
|
"""Method to fetch all reports for Mode
|
||||||
Args:
|
Args:
|
||||||
workspace_name:
|
workspace_name:
|
||||||
|
filter:
|
||||||
Returns:
|
Returns:
|
||||||
dict
|
dict
|
||||||
"""
|
"""
|
||||||
|
if filter not in ["custom", "all"]:
|
||||||
|
logger.warning(
|
||||||
|
"Invalid value for filter. Should be one of ['custom', 'all']"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
all_reports = []
|
all_reports = []
|
||||||
response_collections = self.client.get(f"/{workspace_name}/{COLLECTIONS}")
|
filter_param = f"?filter={filter}"
|
||||||
|
response_collections = self.client.get(
|
||||||
|
f"/{workspace_name}/{COLLECTIONS}{filter_param}"
|
||||||
|
)
|
||||||
collections = response_collections[EMBEDDED]["spaces"]
|
collections = response_collections[EMBEDDED]["spaces"]
|
||||||
for collection in collections:
|
for collection in collections:
|
||||||
response_reports = self.get_all_reports_for_collection(
|
response_reports = self.get_all_reports_for_collection(
|
||||||
@ -175,3 +187,19 @@ class ModeApiClient:
|
|||||||
logger.warning(f"Error fetching all data sources: {exc}")
|
logger.warning(f"Error fetching all data sources: {exc}")
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_workspace(self, workspace_name: str) -> Optional[dict]:
|
||||||
|
"""Method to get info about a workspace
|
||||||
|
Args:
|
||||||
|
workspace_name:
|
||||||
|
Returns:
|
||||||
|
dict
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
response = self.client.get(f"/{workspace_name}")
|
||||||
|
return response.json()
|
||||||
|
except Exception as exc: # pylint: disable=broad-except
|
||||||
|
logger.debug(traceback.format_exc())
|
||||||
|
logger.warning(f"Error testing workspace connection: {exc}")
|
||||||
|
|
||||||
|
return None
|
||||||
|
@ -51,7 +51,7 @@ def test_connection(
|
|||||||
|
|
||||||
test_fn = {
|
test_fn = {
|
||||||
"CheckDashboards": partial(
|
"CheckDashboards": partial(
|
||||||
client.fetch_all_reports, service_connection.workspaceName
|
client.get_workspace, service_connection.workspaceName
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,6 +62,7 @@ class ModeSource(DashboardServiceSource):
|
|||||||
):
|
):
|
||||||
super().__init__(config, metadata)
|
super().__init__(config, metadata)
|
||||||
self.workspace_name = config.serviceConnection.root.config.workspaceName
|
self.workspace_name = config.serviceConnection.root.config.workspaceName
|
||||||
|
self.filter_query_param = config.serviceConnection.root.config.filterQueryParam
|
||||||
self.data_sources = self.client.get_all_data_sources(self.workspace_name)
|
self.data_sources = self.client.get_all_data_sources(self.workspace_name)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -80,7 +81,9 @@ class ModeSource(DashboardServiceSource):
|
|||||||
"""
|
"""
|
||||||
Get List of all dashboards
|
Get List of all dashboards
|
||||||
"""
|
"""
|
||||||
return self.client.fetch_all_reports(self.workspace_name)
|
# If filter param field was empty, we will default to passing "all" to the API
|
||||||
|
filter_param = "all" if not self.filter_query_param else self.filter_query_param
|
||||||
|
return self.client.fetch_all_reports(self.workspace_name, filter_param)
|
||||||
|
|
||||||
def get_dashboard_name(self, dashboard: dict) -> str:
|
def get_dashboard_name(self, dashboard: dict) -> str:
|
||||||
"""
|
"""
|
||||||
|
@ -44,6 +44,11 @@
|
|||||||
"description": "Mode Workspace Name",
|
"description": "Mode Workspace Name",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"filterQueryParam": {
|
||||||
|
"title": "Filter Query Param",
|
||||||
|
"description": "Filter query parameter for some of the Mode API calls",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"supportsMetadataExtraction": {
|
"supportsMetadataExtraction": {
|
||||||
"title": "Supports Metadata Extraction",
|
"title": "Supports Metadata Extraction",
|
||||||
"$ref": "../connectionBasicType.json#/definitions/supportsMetadataExtraction"
|
"$ref": "../connectionBasicType.json#/definitions/supportsMetadataExtraction"
|
||||||
|
@ -42,3 +42,14 @@ $$section
|
|||||||
|
|
||||||
Name of the Mode workspace.
|
Name of the Mode workspace.
|
||||||
$$
|
$$
|
||||||
|
|
||||||
|
$$section
|
||||||
|
### Filter Query Param $(id="filterQueryParam")
|
||||||
|
|
||||||
|
This value is the `filter` query parameter that is passed to the Mode API. Different API
|
||||||
|
calls use different types of acceptable values. Currently this parameter is only implemented
|
||||||
|
to [list all collections](https://mode.com/developer/api-reference/management/collections/#listCollections).
|
||||||
|
The valid values that is currently supported are: `all`
|
||||||
|
and `custom`. If this field is left empty, `all` will be used.
|
||||||
|
|
||||||
|
$$
|
Loading…
x
Reference in New Issue
Block a user