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 2020/04/06 10:27:55 UTC

[GitHub] [incubator-superset] villebro commented on a change in pull request #9405: Added support for impersonation on SQL Server databases using the pym…

villebro commented on a change in pull request #9405: Added support for impersonation on SQL Server databases using the pym…
URL: https://github.com/apache/incubator-superset/pull/9405#discussion_r403986473
 
 

 ##########
 File path: superset/db_engine_specs/mssql.py
 ##########
 @@ -76,3 +78,19 @@ def get_sqla_column_type(cls, type_: str) -> Optional[TypeEngine]:
             if regex.match(type_):
                 return sqla_type
         return None
+
+    @classmethod
+    def modify_url_for_impersonation(
+        cls, url: URL, impersonate_user: bool, username: Optional[str]
+    ) -> None:
+        """
+        Modify the SQL Alchemy URL object with the user to impersonate if applicable.
+        :param url: SQLAlchemy URL object
+        :param impersonate_user: Flag indicating if impersonation is enabled
+        :param username: Effective username
+        """
+        if impersonate_user and username is not None:
+            if url.get_dialect().driver == MSDialect_pymssql.driver:
+                url.query["conn_properties"] = f"EXECUTE AS USER = '{username}'"
+            else:
+                url.username = username
 
 Review comment:
   I would turn this around, ie. check if the driver is `MSDialect_pymssql`, then do the different logic, else call the original method `super(). modify_url_for_impersonation(url, impersonate_user, username)`.

----------------------------------------------------------------
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