-
Notifications
You must be signed in to change notification settings - Fork 2
Feat: Add configurable discovery #18
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
Open
ClassicMMT
wants to merge
16
commits into
main
Choose a base branch
from
add-configurable-discovery
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
4b45721
chore: Update to datamasque-python==1.2.2
ClassicMMT 5a0d608
feat: Add support for configurable discovery
ClassicMMT eef74a5
feat: add safe data preview support
ClassicMMT 79c0e3c
style: Move error codes into an enum
ClassicMMT ecc9685
feat: Add validation status commands
ClassicMMT fdb5852
refactor: from dm-python
ClassicMMT 8de1f1b
fix: Address review
ClassicMMT 50ff5d9
feat: Add app-level error handling
ClassicMMT 4c3ca15
refactor: Route file access through abort helpers
ClassicMMT 7d052c0
refactor: Separate errors and file access from output
ClassicMMT 13b9e9d
fix: Report a rejected discovery file as bad input
ClassicMMT 2b86187
test: add new discovery rejection test
ClassicMMT cb457cf
docs: Use --type database|file consistently
ClassicMMT 327a625
test: add integration tests
ClassicMMT cffa2c1
fix: address review
ClassicMMT 58526bf
fix: Address review
ClassicMMT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,12 +2,12 @@ | |||||||||||||||
|
|
||||||||||||||||
| from __future__ import annotations | ||||||||||||||||
|
|
||||||||||||||||
| import json | ||||||||||||||||
| from enum import StrEnum | ||||||||||||||||
| from pathlib import Path | ||||||||||||||||
|
|
||||||||||||||||
| import typer | ||||||||||||||||
| from datamasque.client import DataMasqueClient | ||||||||||||||||
| from datamasque.client.exceptions import DataMasqueApiError | ||||||||||||||||
| from datamasque.client.models.connection import ( | ||||||||||||||||
| AzureConnectionConfig, | ||||||||||||||||
| ConnectionConfig, | ||||||||||||||||
|
|
@@ -22,7 +22,9 @@ | |||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| from datamasque_cli.client import get_client | ||||||||||||||||
| from datamasque_cli.output import ErrorCode, abort, print_success, redact_sensitive_fields, render_output | ||||||||||||||||
| from datamasque_cli.errors import ErrorCode, abort, abort_api_error, confirm_or_abort | ||||||||||||||||
| from datamasque_cli.fileio import read_json_object_or_abort | ||||||||||||||||
| from datamasque_cli.output import print_success, redact_sensitive_fields, render_output | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| class ConnectionType(StrEnum): | ||||||||||||||||
|
|
@@ -205,8 +207,11 @@ def create_connection( | |||||||||||||||
|
|
||||||||||||||||
| def _create_from_file(client: DataMasqueClient, file: Path) -> None: | ||||||||||||||||
| """Create a connection from a JSON file.""" | ||||||||||||||||
| data = json.loads(file.read_text()) | ||||||||||||||||
| conn_type = _parse_connection_type(data.pop("type", "database")) | ||||||||||||||||
| data = read_json_object_or_abort(file) | ||||||||||||||||
| raw_type = data.pop("type", "database") | ||||||||||||||||
| if not isinstance(raw_type, str): | ||||||||||||||||
| abort(f'{file}: "type" must be a string.', code=ErrorCode.INVALID_INPUT) | ||||||||||||||||
| conn_type = _parse_connection_type(raw_type) | ||||||||||||||||
|
|
||||||||||||||||
| # Convert db_type string to enum for database connections. | ||||||||||||||||
| if conn_type is ConnectionType.DATABASE and "database_type" in data: | ||||||||||||||||
|
|
@@ -298,7 +303,10 @@ def test_connection( | |||||||||||||||
| if match is None: | ||||||||||||||||
| abort(f"Connection '{name}' not found.", code=ErrorCode.NOT_FOUND) | ||||||||||||||||
|
|
||||||||||||||||
| response = client.make_request("POST", f"/api/connections/{match.id}/test/", data={}) | ||||||||||||||||
| try: | ||||||||||||||||
| response = client.make_request("POST", f"/api/connections/{match.id}/test/", data={}) | ||||||||||||||||
| except DataMasqueApiError as exc: | ||||||||||||||||
| abort_api_error(f"Connection '{match.name}' is not reachable", exc) | ||||||||||||||||
| body = response.json() if response.content else {} | ||||||||||||||||
| warning = body.get("message") if isinstance(body, dict) else None | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -347,7 +355,12 @@ def update_connection( | |||||||||||||||
| if not updates: | ||||||||||||||||
| abort("Pass at least one field to update (e.g. --password, --host).", code=ErrorCode.INVALID_INPUT) | ||||||||||||||||
|
|
||||||||||||||||
| client.make_request("PATCH", f"/api/connections/{match.id}/", data=updates) | ||||||||||||||||
| payload = dict(updates) | ||||||||||||||||
| # `dbpassword` is the server's field name for the database password on connection PATCH. | ||||||||||||||||
| if "password" in payload: | ||||||||||||||||
| payload["dbpassword"] = payload.pop("password") | ||||||||||||||||
|
Comment on lines
+358
to
+361
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth a line on why the outgoing field name differs from the flag.
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. |
||||||||||||||||
|
|
||||||||||||||||
| client.make_request("PATCH", f"/api/connections/{match.id}/", data=payload) | ||||||||||||||||
| print_success(f"Connection '{match.name}' updated: {', '.join(updates)}.") | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -363,7 +376,7 @@ def delete_connection( | |||||||||||||||
| abort(f"Connection '{name}' not found.", code=ErrorCode.NOT_FOUND) | ||||||||||||||||
|
|
||||||||||||||||
| if not is_confirmed: | ||||||||||||||||
| typer.confirm(f"Delete connection '{name}'?", abort=True) | ||||||||||||||||
| confirm_or_abort(f"Delete connection '{name}'?") | ||||||||||||||||
|
|
||||||||||||||||
| client.delete_connection_by_name_if_exists(name) | ||||||||||||||||
| print_success(f"Connection '{name}' deleted.") | ||||||||||||||||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.