mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
feat(bigquery): Custom message when Service Account doesnt have the correct Roles and Permissions (#21838)
This commit is contained in:
committed by
GitHub
parent
059e53a39f
commit
203b289021
@@ -75,10 +75,12 @@ from superset.databases.schemas import (
|
||||
from superset.databases.utils import get_table_metadata
|
||||
from superset.db_engine_specs import get_available_engine_specs
|
||||
from superset.errors import ErrorLevel, SupersetError, SupersetErrorType
|
||||
from superset.exceptions import SupersetErrorsException
|
||||
from superset.extensions import security_manager
|
||||
from superset.models.core import Database
|
||||
from superset.superset_typing import FlaskResponse
|
||||
from superset.utils.core import error_msg_from_exception, parse_js_uri_path_item
|
||||
from superset.views.base import json_errors_response
|
||||
from superset.views.base_api import (
|
||||
BaseSupersetModelRestApi,
|
||||
requires_form_data,
|
||||
@@ -224,7 +226,7 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
|
||||
log_to_statsd=False,
|
||||
)
|
||||
@requires_json
|
||||
def post(self) -> Response:
|
||||
def post(self) -> FlaskResponse:
|
||||
"""Creates a new Database
|
||||
---
|
||||
post:
|
||||
@@ -281,6 +283,8 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
|
||||
return self.response_422(message=ex.normalized_messages())
|
||||
except DatabaseConnectionFailedError as ex:
|
||||
return self.response_422(message=str(ex))
|
||||
except SupersetErrorsException as ex:
|
||||
return json_errors_response(errors=ex.errors, status=ex.status)
|
||||
except DatabaseCreateFailedError as ex:
|
||||
logger.error(
|
||||
"Error creating model %s: %s",
|
||||
|
||||
@@ -31,6 +31,7 @@ from superset.databases.commands.exceptions import (
|
||||
)
|
||||
from superset.databases.commands.test_connection import TestConnectionDatabaseCommand
|
||||
from superset.databases.dao import DatabaseDAO
|
||||
from superset.exceptions import SupersetErrorsException
|
||||
from superset.extensions import db, event_logger, security_manager
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -46,6 +47,13 @@ class CreateDatabaseCommand(BaseCommand):
|
||||
try:
|
||||
# Test connection before starting create transaction
|
||||
TestConnectionDatabaseCommand(self._properties).run()
|
||||
except SupersetErrorsException as ex:
|
||||
event_logger.log_with_context(
|
||||
action=f"db_creation_failed.{ex.__class__.__name__}",
|
||||
engine=self._properties.get("sqlalchemy_uri", "").split(":")[0],
|
||||
)
|
||||
# So we can show the original message
|
||||
raise ex
|
||||
except Exception as ex:
|
||||
event_logger.log_with_context(
|
||||
action=f"db_creation_failed.{ex.__class__.__name__}",
|
||||
|
||||
@@ -29,13 +29,16 @@ from superset.commands.base import BaseCommand
|
||||
from superset.databases.commands.exceptions import (
|
||||
DatabaseSecurityUnsafeError,
|
||||
DatabaseTestConnectionDriverError,
|
||||
DatabaseTestConnectionFailedError,
|
||||
DatabaseTestConnectionUnexpectedError,
|
||||
)
|
||||
from superset.databases.dao import DatabaseDAO
|
||||
from superset.databases.utils import make_url_safe
|
||||
from superset.errors import ErrorLevel, SupersetErrorType
|
||||
from superset.exceptions import SupersetSecurityException, SupersetTimeoutException
|
||||
from superset.exceptions import (
|
||||
SupersetErrorsException,
|
||||
SupersetSecurityException,
|
||||
SupersetTimeoutException,
|
||||
)
|
||||
from superset.extensions import event_logger
|
||||
from superset.models.core import Database
|
||||
|
||||
@@ -49,6 +52,7 @@ class TestConnectionDatabaseCommand(BaseCommand):
|
||||
|
||||
def run(self) -> None: # pylint: disable=too-many-statements
|
||||
self.validate()
|
||||
ex_str = ""
|
||||
uri = self._properties.get("sqlalchemy_uri", "")
|
||||
if self._model and uri == self._model.safe_sqlalchemy_uri():
|
||||
uri = self._model.sqlalchemy_uri_decrypted
|
||||
@@ -117,10 +121,13 @@ class TestConnectionDatabaseCommand(BaseCommand):
|
||||
level=ErrorLevel.ERROR,
|
||||
extra={"sqlalchemy_uri": database.sqlalchemy_uri},
|
||||
) from ex
|
||||
except Exception: # pylint: disable=broad-except
|
||||
except Exception as ex: # pylint: disable=broad-except
|
||||
alive = False
|
||||
# So we stop losing the original message if any
|
||||
ex_str = str(ex)
|
||||
|
||||
if not alive:
|
||||
raise DBAPIError(None, None, None)
|
||||
raise DBAPIError(ex_str or None, None, None)
|
||||
|
||||
# Log succesful connection test with engine
|
||||
event_logger.log_with_context(
|
||||
@@ -145,7 +152,7 @@ class TestConnectionDatabaseCommand(BaseCommand):
|
||||
)
|
||||
# check for custom errors (wrong username, wrong password, etc)
|
||||
errors = database.db_engine_spec.extract_errors(ex, context)
|
||||
raise DatabaseTestConnectionFailedError(errors) from ex
|
||||
raise SupersetErrorsException(errors) from ex
|
||||
except SupersetSecurityException as ex:
|
||||
event_logger.log_with_context(
|
||||
action=f"test_connection_error.{ex.__class__.__name__}",
|
||||
|
||||
Reference in New Issue
Block a user