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): Create command & exceptions #22148

Merged
merged 21 commits into from
Nov 22, 2022

Conversation

hughhhh
Copy link
Member

@hughhhh hughhhh commented Nov 17, 2022

SUMMARY

Create a command to allow users to generate a SSHTunnel object to be saved once a Database is being commited to the metastore.

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

@hughhhh hughhhh changed the title feat: add create command for ssh tunnels feat(ssh_tunnel): Create command & exceptions Nov 17, 2022
@hughhhh hughhhh changed the base branch from master to create-sshtunnelconfig-tbl November 17, 2022 19:06
@@ -71,6 +71,10 @@ def run(self) -> Model:
database = DatabaseDAO.create(self._properties, commit=False)
database.set_sqlalchemy_uri(database.sqlalchemy_uri)

# create ssh tunnel

Choose a reason for hiding this comment

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

Should we remove this comment block?

@@ -176,3 +176,8 @@ class DatabaseOfflineError(SupersetErrorException):

class InvalidParametersError(SupersetErrorsException):
status = 422


class SSHTunnelCreateFailedError(CommandException):

Choose a reason for hiding this comment

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

This class should be in databases/ssh_tunnel/commands/exceptions.py like the others.

class CreateSSHTunnelCommand(BaseCommand):
def __init__(self, database_id: int, data: Dict[str, Any]):
self._properties = data.copy()
self._properties["database_id"] = database_id

Choose a reason for hiding this comment

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

Why not pulling it from the data dict instead of having database_id as a separated arg? I mean, even in the create_test.py (dao and command) you have the database_id as part of the properties of the tunnel.

Copy link
Member Author

Choose a reason for hiding this comment

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

i removed it, i think the pattern is better since the database_id is the first class citizen

@@ -50,7 +53,7 @@ def session_with_data(session: Session) -> Iterator[Session]:
session.rollback()


def test_database_get_shh_tunnel(session_with_data: Session) -> None:
def test_database_get_ssh_tunnel(session_with_data: Session) -> None:

Choose a reason for hiding this comment

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

Wondering what "changed" here because I see no difference 🤔 👀

Copy link
Member Author

@hughhhh hughhhh Nov 17, 2022

Choose a reason for hiding this comment

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

test_database_get_shh_tunnel to test_database_get_ssh_tunnel

we misspelt ssh lol

Choose a reason for hiding this comment

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

oh boy! yeah! hahaha trust me I had to read this like 10+ times to realize the mistake. kk thanks!

@hughhhh hughhhh marked this pull request as ready for review November 18, 2022 19:46
"password": "bar",
}

result = SSHTunnelDAO.create(properties, commit=True)

Choose a reason for hiding this comment

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

where is it getting the database_id from?

@codecov
Copy link

codecov bot commented Nov 18, 2022

Codecov Report

Merging #22148 (ab8cf7b) into create-sshtunnelconfig-tbl (92e41f1) will decrease coverage by 0.71%.
The diff coverage is 92.00%.

@@                      Coverage Diff                       @@
##           create-sshtunnelconfig-tbl   #22148      +/-   ##
==============================================================
- Coverage                       66.97%   66.25%   -0.72%     
==============================================================
  Files                            1840     1839       -1     
  Lines                           70062    70049      -13     
  Branches                         7590     7571      -19     
==============================================================
- Hits                            46922    46413     -509     
- Misses                          21174    21677     +503     
+ Partials                         1966     1959       -7     
Flag Coverage Δ
hive 52.59% <ø> (ø)
postgres ?
presto 52.48% <ø> (ø)
python 79.79% <92.00%> (-1.51%) ⬇️
sqlite 76.57% <ø> (ø)
unit 51.05% <92.00%> (+0.03%) ⬆️

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

Impacted Files Coverage Δ
superset/databases/ssh_tunnel/commands/create.py 91.30% <91.30%> (ø)
...perset/databases/ssh_tunnel/commands/exceptions.py 100.00% <100.00%> (ø)
superset/datasets/commands/create.py 30.61% <0.00%> (-69.39%) ⬇️
superset/datasets/commands/update.py 25.00% <0.00%> (-69.05%) ⬇️
superset/datasets/commands/bulk_delete.py 33.33% <0.00%> (-53.34%) ⬇️
superset/datasets/columns/commands/delete.py 44.11% <0.00%> (-52.95%) ⬇️
superset/datasets/metrics/commands/delete.py 44.11% <0.00%> (-52.95%) ⬇️
superset/datasets/dao.py 44.21% <0.00%> (-50.35%) ⬇️
superset/sql_validators/postgres.py 50.00% <0.00%> (-50.00%) ⬇️
superset/datasets/commands/delete.py 48.57% <0.00%> (-48.58%) ⬇️
... and 42 more

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

return tunnel

def validate(self) -> None:
# check to make sure the server port is not localhost
Copy link
Member

Choose a reason for hiding this comment

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

can we fill in the validation for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

@eschutho going to implement an SSH_MANAGER class to handle this, was talking to @craig-rueda yesterday about the approach and we basically allow users define how the want manage this one their end.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, do we need this validation method then or can we remove it?

@hughhhh hughhhh force-pushed the ssh-create-command branch 2 times, most recently from 486ac2d to e5de217 Compare November 22, 2022 02:27
Copy link
Member

@Antonio-RiveroMartnez Antonio-RiveroMartnez left a comment

Choose a reason for hiding this comment

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

LGTM!

@hughhhh
Copy link
Member Author

hughhhh commented Nov 22, 2022

merging to unblock following PRs

@eschutho let me know if there are any concerns with this approach

@hughhhh hughhhh merged commit 6c59663 into create-sshtunnelconfig-tbl Nov 22, 2022
@mistercrunch mistercrunch deleted the ssh-create-command branch March 26, 2024 16:20
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