-
Notifications
You must be signed in to change notification settings - Fork 14.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: "Impersonate user" setting on Datasource #3404
Conversation
Current solution works for sync queries but doesn't for async. It says
Which makes sense. My first idea would be to pass it as a parameter to |
659c87d
to
ddd7c66
Compare
Coverage increased (+0.02%) to 69.137% when pulling ddd7c66e200c6f666fa7ce0d7a1a0493e6b8ff92 on dmigo:master into 3dfdde1 on apache:master. |
Coverage increased (+0.02%) to 69.137% when pulling ddd7c66e200c6f666fa7ce0d7a1a0493e6b8ff92 on dmigo:master into 3dfdde1 on apache:master. |
Coverage increased (+0.02%) to 69.137% when pulling 018017d11bf9ee0ccf53aa0f71643493ee86445c on dmigo:master into 3dfdde1 on apache:master. |
Coverage increased (+0.02%) to 69.137% when pulling fa9b606e9cb7edac1c35d30af34c46e70b57d9d5 on dmigo:master into 3dfdde1 on apache:master. |
1 similar comment
Coverage increased (+0.02%) to 69.137% when pulling fa9b606e9cb7edac1c35d30af34c46e70b57d9d5 on dmigo:master into 3dfdde1 on apache:master. |
Coverage decreased (-0.001%) to 69.117% when pulling 0945f55877fa883e366fbfa7005af9b179aa527a on dmigo:master into 3dfdde1 on apache:master. |
Coverage decreased (-0.001%) to 69.117% when pulling a62f02e3cb3474a43122ec09fabd4e02773a17cc on dmigo:master into 147c12d on apache:master. |
Coverage decreased (-0.001%) to 69.111% when pulling b92e03d155397bdf406e2e7f564c47c7ef074b80 on dmigo:master into 7c1b56f on apache:master. |
Coverage decreased (-0.001%) to 69.118% when pulling 95f1b0d7c5e8ee12bb7c06ad4e01e380b2301b5a on dmigo:master into 3c0e85e on apache:master. |
1 similar comment
Coverage decreased (-0.001%) to 69.118% when pulling 95f1b0d7c5e8ee12bb7c06ad4e01e380b2301b5a on dmigo:master into 3c0e85e on apache:master. |
Coverage decreased (-0.001%) to 69.153% when pulling 31e78051a88597ce651e7de2332de138980b1d07 on dmigo:master into fdee06b on apache:master. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor change request, otherwise looks good.
Took me a moment to understand why you're passing the username around, and then I understood that in the async context the user isn't authenticated.
Good work!
superset/models/core.py
Outdated
extra = self.get_extra() | ||
uri = make_url(self.sqlalchemy_uri_decrypted) | ||
params = extra.get('engine_params', {}) | ||
if nullpool: | ||
params['poolclass'] = NullPool | ||
uri = self.db_engine_spec.adjust_database_uri(uri, schema) | ||
if self.impersonate_user: | ||
uri.username = user_name if user_name != None else g.user.username |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer user_name if user_name else g.user.username
as it accounts for empty strings and it's more pythonesque
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done! 👍
3 similar comments
* Add "Impersonate user" setting to Datasource * Add tests * Use g.user.username for all the sync cases * use uri.username instead of uri.user * Small refactoring
Is there anything in the docs about this? Seems like it sets the DB user in the connection string to the superset user name, but I don't understand how the password for that DB user is set? |
* Add "Impersonate user" setting to Datasource * Add tests * Use g.user.username for all the sync cases * use uri.username instead of uri.user * Small refactoring
Implements #2148
All the code that makes difference is covered, I don't really think it would make sense to add any more tests as a part of the current PR.