-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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
feat(ssh-tunnel): ssh manager config + feature flag #22201
Conversation
Codecov Report
@@ Coverage Diff @@
## create-sshtunnelconfig-tbl #22201 +/- ##
===============================================================
- Coverage 66.95% 55.79% -11.17%
===============================================================
Files 1852 1852
Lines 70504 70511 +7
Branches 7689 7689
===============================================================
- Hits 47206 39341 -7865
- Misses 21304 29176 +7872
Partials 1994 1994
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
32e0564
to
d720e75
Compare
superset/config.py
Outdated
# # `server` return value | ||
# return "127.0.0.1" | ||
|
||
SSH_TUNNEL_MANAGER = None |
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.
Should we provide a default impl here?
@@ -20,16 +20,24 @@ | |||
from flask_appbuilder.models.sqla import Model | |||
from marshmallow import ValidationError | |||
|
|||
|
|||
from superset import app, is_feature_enabled |
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.
Don't directly import app here. Instead, use flask.current_app
from superset.commands.base import BaseCommand | ||
from superset.dao.exceptions import DAOCreateFailedError | ||
from superset.databases.dao import DatabaseDAO | ||
from superset.databases.ssh_tunnel.commands.exceptions import SSHTunnelCreateFailedError | ||
from superset.databases.ssh_tunnel.dao import SSHTunnelDAO | ||
|
||
config = app.config | ||
ssh_tunnel_manager = config["SSH_TUNNEL_MANAGER"] |
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.
Put this inside the command's init()
and leverage current_app.config
superset/config.py
Outdated
# FIREWALL (only port 22 is open) | ||
|
||
# ---------------------------------------------------------------------- | ||
# class SSHManager: |
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.
The default manager should leverage the app_init
pattern. So, inside the AppInitializer
, the actual manager would be instantiated and then would have init_app(app: Flask)
invoked on it
@@ -33,6 +34,9 @@ | |||
|
|||
logger = logging.getLogger(__name__) | |||
|
|||
config = app.config | |||
ssh_tunnel_manager = config["SSH_TUNNEL_MANAGER"] |
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.
Same comment as before. We should be getting the SSHManager
from the current_app
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.
Let's use the app factory pattern for the SSHManager: https://flask.palletsprojects.com/en/2.2.x/extensiondev/#the-extension-class-and-initialization
225ea11
to
466703a
Compare
superset/config.py
Outdated
|
||
# def mutator(self, ssh_tunnel_params: Dict[str, Any]) -> Dict[str, Any]: | ||
# # override any ssh tunnel configuration object | ||
# raise NotImplemented() |
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.
do we need to make these two methods required? They seems more like nice to haves.
logger = logging.getLogger(__name__) | ||
|
||
|
||
class CreateSSHTunnelCommand(BaseCommand): | ||
def __str__(self) -> str: | ||
return super().__str__() |
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.
isn't this redundant?
# using the config.SSH_TUNNEL_MANAGER | ||
return | ||
if is_feature_enabled("SSH_TUNNELING") and ssh_tunnel_manager: | ||
ssh_tunnel_manager.validate(self._properties) |
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.
is this the only validation that we want to do here?
superset/models/core.py
Outdated
else: | ||
# do look up in table for using database_id | ||
try: | ||
with sshtunnel.open_tunnel(**ssh_params) as server: |
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.
are there any known errors from the library that we need to catch here?
1a1141a
to
b25ff51
Compare
2ba07f5
to
1f57d4a
Compare
dde7f64
to
19f9368
Compare
19f9368
to
71ff153
Compare
6b3c0c4
to
146c476
Compare
SUMMARY
Created a config object class to manage how ssh tunnels can be configured. The main use case for this is to allow mutation and validation on ssh tunnels being created for a given superset instance. For the SSHManager the
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION