You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2019/08/21 18:07:57 UTC

[GitHub] [incubator-superset] robdiciuccio commented on a change in pull request #8047: [database] Improve connection URI validation

robdiciuccio commented on a change in pull request #8047: [database] Improve connection URI validation
URL: https://github.com/apache/incubator-superset/pull/8047#discussion_r316326062
 
 

 ##########
 File path: superset/views/database/__init__.py
 ##########
 @@ -16,17 +16,38 @@
 # under the License.
 # pylint: disable=C,R,W
 import inspect
+from typing import Type
 
-from flask import Markup
+from flask import current_app, Markup
 from flask_babel import lazy_gettext as _
+from marshmallow import ValidationError
 from sqlalchemy import MetaData
+from sqlalchemy.engine.url import make_url
+from sqlalchemy.exc import ArgumentError
 
 from superset import security_manager
 from superset.exceptions import SupersetException
 from superset.utils import core as utils
 from superset.views.base import SupersetFilter
 
 
+def sqlalchemy_uri_validator(
+    uri: str, exception: Type[ValidationError] = ValidationError
+) -> None:
+    """
+    Check if a user has submitted a valid SQLAlchemy URI
+    """
+    try:
+        url = make_url(uri.strip())
+    except ArgumentError:
+        raise exception(_("Invalid connnection string could not parse rfc1738 URL"))
 
 Review comment:
   Will this error message be displayed to the user? If so, I suggest making it a bit more user-friendly to those who don't know what RFCs are.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org