Fixed mode test connection (#14693)

This commit is contained in:
Onkar Ravgan 2024-01-12 18:29:12 +05:30 committed by GitHub
parent 156dc29687
commit f1049d55c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 27 deletions

View File

@ -74,23 +74,18 @@ class ModeApiClient:
Returns:
dict
"""
try:
all_reports = []
response_collections = self.client.get(f"/{workspace_name}/{COLLECTIONS}")
collections = response_collections[EMBEDDED]["spaces"]
for collection in collections:
response_reports = self.get_all_reports_for_collection(
workspace_name=workspace_name,
collection_token=collection.get(TOKEN),
)
all_reports = []
response_collections = self.client.get(f"/{workspace_name}/{COLLECTIONS}")
collections = response_collections[EMBEDDED]["spaces"]
for collection in collections:
response_reports = self.get_all_reports_for_collection(
workspace_name=workspace_name,
collection_token=collection.get(TOKEN),
)
if response_reports:
reports = response_reports[EMBEDDED][REPORTS]
all_reports.extend(reports)
return all_reports
except Exception as exc: # pylint: disable=broad-except
logger.debug(traceback.format_exc())
logger.warning(f"Error fetching all reports: {exc}")
return None
return all_reports
def get_all_reports_for_collection(
self, workspace_name: str, collection_token: str
@ -180,11 +175,3 @@ class ModeApiClient:
logger.warning(f"Error fetching all data sources: {exc}")
return None
def get_user_account(self) -> dict:
"""Method to fetch account details
Returns:
dict
"""
response = self.client.get("/account")
return response

View File

@ -12,6 +12,7 @@
"""
Source connection handler
"""
from functools import partial
from typing import Optional
from metadata.generated.schema.entity.automations.workflow import (
@ -43,7 +44,11 @@ def test_connection(
of a metadata workflow or during an Automation Workflow
"""
test_fn = {"CheckAccess": client.get_user_account}
test_fn = {
"CheckDashboards": partial(
client.fetch_all_reports, service_connection.workspaceName
)
}
test_connection_steps(
metadata=metadata,

View File

@ -4,9 +4,9 @@
"description": "This Test Connection validates the access against the server and basic metadata extraction of dashboards and charts.",
"steps": [
{
"name": "CheckAccess",
"description": "Validate that the API is accessible with the given credentials",
"errorMessage": "Failed to connect to mode, please validate the credentials",
"name": "CheckDashboards",
"description": "Validate that the Dashboards(Reports) API is accessible with the given credentials",
"errorMessage": "Failed to connect to mode to get the dashboards, please validate the credentials",
"shortCircuit": true,
"mandatory": true
}