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

 ##########
 File path: superset/db_engine_specs/mssql.py
 ##########
 @@ -76,3 +77,16 @@ 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:
+            url.query["conn_properties"] = "EXECUTE AS USER = 
'{}'".format(username)
 
 Review comment:
   You are right, `pymssql` is deprecated and this feature is limited to that 
adapter. I've analyzed first `pyodbc` but I didn't find a way to send SQL 
queries to the server upon the connection establishment. I added logic to check 
the driver being used and applied this logic only for `pymssql`. For other 
adapters I just don't know if we should raise an exception or just add the 
default behaviour, which is replacing the connection string username by the 
logged in user's. What do you think?

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to