Skip to content
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): APIs for SSH Tunnels #22199

Merged

Conversation

Antonio-RiveroMartnez
Copy link
Member

@Antonio-RiveroMartnez Antonio-RiveroMartnez commented Nov 22, 2022

SUMMARY

Add our CREATE, UPDATE and DELETE APIs for SSH Tunnels.

  • CREATE API
  • API endpoint calling the command
  • Tests
  • UPDATE API
  • API endpoint calling the command
  • Tests
  • DELETE API
  • API endpoint calling the command
  • Tests
  • API + Schemas + Tests
    • CREATE POST /api/v1/database
    • UPDATE UPDATE /api/v1/database/
    • DELETE DELETE /api/v1/database/{db_id}/ssh_tunnel

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@Antonio-RiveroMartnez Antonio-RiveroMartnez changed the title feat(ssh_tunnel): APIs for SSH Tunnels [DRAFT] feat(ssh_tunnel): APIs for SSH Tunnels Nov 22, 2022
@Antonio-RiveroMartnez Antonio-RiveroMartnez marked this pull request as draft November 22, 2022 18:59
@codecov
Copy link

codecov bot commented Nov 22, 2022

Codecov Report

Merging #22199 (0cae2a2) into create-sshtunnelconfig-tbl (7cc7bc8) will decrease coverage by 11.19%.
The diff coverage is 47.67%.

❗ Current head 0cae2a2 differs from pull request most recent head 052eee1. Consider uploading reports for the commit 052eee1 to get more accurate results

@@                       Coverage Diff                       @@
##           create-sshtunnelconfig-tbl   #22199       +/-   ##
===============================================================
- Coverage                       66.97%   55.78%   -11.20%     
===============================================================
  Files                            1858     1859        +1     
  Lines                           70928    71006       +78     
  Branches                         7764     7764               
===============================================================
- Hits                            47506    39610     -7896     
- Misses                          21400    29374     +7974     
  Partials                         2022     2022               
Flag Coverage Δ
hive 52.46% <30.23%> (-0.06%) ⬇️
mysql ?
postgres ?
presto ?
python 57.88% <47.67%> (-23.43%) ⬇️
sqlite ?
unit 51.42% <47.67%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset/constants.py 100.00% <ø> (ø)
superset/databases/commands/create.py 60.60% <18.18%> (-25.61%) ⬇️
superset/databases/commands/update.py 24.13% <20.00%> (-55.87%) ⬇️
superset/utils/ssh_tunnel.py 30.00% <30.00%> (ø)
superset/databases/api.py 53.63% <66.66%> (-39.91%) ⬇️
superset/databases/ssh_tunnel/models.py 95.65% <75.00%> (-4.35%) ⬇️
superset/databases/ssh_tunnel/commands/create.py 87.75% <85.71%> (-0.89%) ⬇️
superset/databases/schemas.py 85.38% <100.00%> (-12.96%) ⬇️
superset/utils/dashboard_import_export.py 0.00% <0.00%> (-100.00%) ⬇️
superset/tags/core.py 4.54% <0.00%> (-95.46%) ⬇️
... and 291 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Antonio-RiveroMartnez Antonio-RiveroMartnez changed the title [DRAFT] feat(ssh_tunnel): APIs for SSH Tunnels feat(ssh_tunnel): APIs for SSH Tunnels Nov 28, 2022
@Antonio-RiveroMartnez Antonio-RiveroMartnez marked this pull request as ready for review November 28, 2022 13:05
superset/databases/api.py Outdated Show resolved Hide resolved
.filter(SSHTunnel.database_id == response.get("id"))
.one_or_none()
)
assert model_ssh_tunnel is None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@hughhhh
Copy link
Member

hughhhh commented Nov 30, 2022

/testenv up

@github-actions
Copy link
Contributor

@hughhhh Ephemeral environment spinning up at http://35.90.30.149:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 1, 2022

Ephemeral environment shutdown and build artifacts deleted.

- Add not found test when deleting the tunnel
- FIx linting errors
- Fix pre-commit errors
- Remove bind properties from schema used in TestConnection
- Add test for SSH Tunnel failure and no DB creation
- Make server_address, server_port and username required fields for our SSHTunnel schema
- Update the tests so we can consider new message with required fields
- Changes from Code review feedback
- Solve conflict with base branch
- Remove safe decorator so SIP-41 errors can be returned
- Fix update tests
- Mask passwords for SSH when creating a new one
- Fix arg name in test connection
- Use SSHTunnel commands instead of DAOs
- Update tests
- Fix linting and pre-commit
- Flush only if creating a ssh tunnel
- Do not return passwords for SSH Tunnel in any API call
- Using nested transactions so we can rollback if anything fails
- Extend GET endpoint on Database APi so it includes SSH Tunnel if any
---
get:
description: >-
Get a database with its SSH Tunnel if any
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get a database

@@ -280,6 +327,12 @@ def post(self) -> FlaskResponse:
if new_model.driver:
item["driver"] = new_model.driver

# Return SSH Tunnel and hide passwords if any
if item.get("ssh_tunnel"):
item["ssh_tunnel"] = new_model.ssh_tunnel # pylint: disable=no-member
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create a util function that does the popping/deletion and returns the object without those values

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! I'll indeed use our mask as I did here: https://github.com/apache/superset/pull/22513/files#diff-f9deb9b63f5f2db38b811ff092cf90b0d4d558223f743bbbb5b203c203d2d590R336 but sure, let me add that util. Thanks!

@@ -361,6 +414,11 @@ def put(self, pk: int) -> Response:
item["sqlalchemy_uri"] = changed_model.sqlalchemy_uri
if changed_model.parameters:
item["parameters"] = changed_model.parameters
# Return SSH Tunnel and hide passwords if any
if item.get("ssh_tunnel"):
item["ssh_tunnel"] = changed_model.ssh_tunnel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the util function here as well

try:
# So database.id is not None
db.session.flush()
CreateSSHTunnelCommand(database.id, ssh_tunnel_properties).run()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to have a reference for ssh_tunnel after it's created so it can pull down all the schema

https://github.com/apache/superset/pull/22199/files#diff-c3f1c5afb1b73f705f01bfa24cb4ca2ac66b84f82875abd3ddb73cb8147ea77eR100

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, let me add it there! Thanks

- Add util method to mask password
- Adjust tests to consider password masking
- Remove the extra description on GET endpoint for databases
- Fix pre-commit error
@hughhhh hughhhh merged commit 9b09fc7 into apache:create-sshtunnelconfig-tbl Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants