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/01/29 12:50:23 UTC

[GitHub] [incubator-superset] gbrian opened a new issue #9045: Allow environment variables for sqlalchemy uri

gbrian opened a new issue #9045: Allow environment variables for sqlalchemy uri
URL: https://github.com/apache/incubator-superset/issues/9045
 
 
   **Is your feature request related to a problem? Please describe.**
   When deploying to multiple environments we'll like to be able to switch database connection.
   Currently we have one script fixing database sqlalchemy uri
   
   **Describe the solution you'd like**
   Allow the use of environment variables as the value of `sqlalchemy_uri` property of `Database`
   
   **Describe alternatives you've considered**
   No idea
   
   **Additional context**
   We depoy using docker
   
   **Proposal**
   
       class Database(Model, AuditMixinNullable, ImportMixin):
       ....
       allow_env_for_uri = Column(Boolean, default=False)
       ....
       @property
       def expanded_sqlalchemy_uri(self):
           if self.allow_env_for_uri:
               return os.path.expandvars(self.sqlalchemy_uri)
           return self.sqlalchemy_uri
       
       @property
       def sqlalchemy_uri_decrypted(self):
           conn = sqla.engine.url.make_url(self.expanded_sqlalchemy_uri)
           if custom_password_store:
               conn.password = custom_password_store(conn)
           else:
               conn.password = self.password
           return str(conn)
   

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


[GitHub] [incubator-superset] willbarrett commented on issue #9045: Allow environment variables for sqlalchemy uri

Posted by GitBox <gi...@apache.org>.
willbarrett commented on issue #9045: Allow environment variables for sqlalchemy uri
URL: https://github.com/apache/incubator-superset/issues/9045#issuecomment-606856255
 
 
   @gbrian you are free to extend the Python configuration as described in [the documentation] https://superset.apache.org/installation.html#configuration - as the configuration is a Python file, it is possible to tell Superset to look for environment variables for any configuration option. I hope this approach will work for you!

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


[GitHub] [incubator-superset] stale[bot] commented on issue #9045: Allow environment variables for sqlalchemy uri

Posted by GitBox <gi...@apache.org>.
stale[bot] commented on issue #9045: Allow environment variables for sqlalchemy uri
URL: https://github.com/apache/incubator-superset/issues/9045#issuecomment-605632689
 
 
   This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue `.pinned` to prevent stale bot from closing the issue.
   

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


[GitHub] [incubator-superset] stale[bot] commented on issue #9045: Allow environment variables for sqlalchemy uri

Posted by GitBox <gi...@apache.org>.
stale[bot] commented on issue #9045:
URL: https://github.com/apache/incubator-superset/issues/9045#issuecomment-636385436


   This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue `.pinned` to prevent stale bot from closing the issue.
   


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



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


[GitHub] [incubator-superset] mistercrunch edited a comment on issue #9045: Allow environment variables for sqlalchemy uri

Posted by GitBox <gi...@apache.org>.
mistercrunch edited a comment on issue #9045:
URL: https://github.com/apache/incubator-superset/issues/9045#issuecomment-636429672


   @willbarrett,  @gbrian is not referring to `SQLALCHEMY_DATABASE_URI`, but to the ones ones that we encrypt and store in the database.
   
   I'm not sure how well that is documented, but with `DB_CONNECTION_MUTATOR` (a configuration hook) you can intercept the `Database` at runtime and do whatever, meaning you can put in bogus username/password in the database, and your `DB_CONNECTION_MUTATOR` function can read an env var and replace the proper value.
   
   ```python
   # in your superset_config.py
   def DB_CONNECTION_MUTATOR(sqlalchemy_url, params, effective_username, security_manager, source):
       # Assuming that by convention your `sqlalchemy_url` references the env var you want to use
       sqlalchemy_url = os.environ.get(sqlalchemy_url)
       return sqlalchemy_url, params
   ```


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



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


[GitHub] [incubator-superset] mistercrunch commented on issue #9045: Allow environment variables for sqlalchemy uri

Posted by GitBox <gi...@apache.org>.
mistercrunch commented on issue #9045:
URL: https://github.com/apache/incubator-superset/issues/9045#issuecomment-636429672


   @willbarrett,  @gbrian is not referring to `SQLALCHEMY_DATABASE_URI`, but to the ones ones that we encrypt and store in the database.
   
   I'm not sure how well that is documented, but with `DB_CONNECTION_MUTATOR` (a configuration hook) you can intercept the `Database` at runtime and do whatever, meaning you can put in bogus username/password in the database, and your `DB_CONNECTION_MUTATOR` function can read an env var and replace the proper value.
   
   ```python
   def DB_CONNECTION_MUTATOR(sqlalchemy_url, params, effective_username, security_manager, source):
       # Assuming that by convention your `sqlalchemy_url` references the env var you want to use
       sqlalchemy_url = os.environ.get(sqlalchemy_url)
       return sqlalchemy_url, params
   ```


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



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


[GitHub] [incubator-superset] gbrian commented on issue #9045: Allow environment variables for sqlalchemy uri

Posted by GitBox <gi...@apache.org>.
gbrian commented on issue #9045:
URL: https://github.com/apache/incubator-superset/issues/9045#issuecomment-643911164


   Thanks @willbarrett , @mistercrunch.
   I implemented differently as wanted to have a flag on database connection to set if ENV replacement should apply but reconsidering in favor of:  DB_CONNECTION_MUTATOR and SQL_QUERY_MUTATOR


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



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


[GitHub] [incubator-superset] gbrian closed issue #9045: Allow environment variables for sqlalchemy uri

Posted by GitBox <gi...@apache.org>.
gbrian closed issue #9045:
URL: https://github.com/apache/incubator-superset/issues/9045


   


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



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