-
Notifications
You must be signed in to change notification settings - Fork 26
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(dbt): Adding flag to raise an error when a model sync fails #266
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
abbb666
feat(dbt): Adding flag to raise an error when a model sync fails
Vitor-Avila 180dfc8
Addressing pre-commit issues
Vitor-Avila 1ac0628
Increasing test coverage
Vitor-Avila 167221e
Increasing test coverage
Vitor-Avila e35d4e9
Reusing some common logic
Vitor-Avila 26bab1c
Implementing PR feedback
Vitor-Avila 7fd01f6
Implementing PR feedback
Vitor-Avila 67a3f11
Merging main
Vitor-Avila 8f0ea45
Fixing tests
Vitor-Avila ce5b053
Fixing pre-commit for newer Python versions
Vitor-Avila 52908b9
Fixing typo
Vitor-Avila 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 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 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 |
---|---|---|
|
@@ -21,7 +21,8 @@ | |
from preset_cli.auth.lib import get_credentials_path, store_credentials | ||
from preset_cli.auth.preset import JWTTokenError, PresetAuth | ||
from preset_cli.cli.superset.main import superset | ||
from preset_cli.lib import setup_logging, split_comma | ||
from preset_cli.exceptions import CLIError | ||
from preset_cli.lib import raise_cli_errors, setup_logging, split_comma | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
@@ -103,6 +104,7 @@ def is_help() -> bool: | |
@click.option("--loglevel", default="INFO") | ||
@click.version_option() | ||
@click.pass_context | ||
@raise_cli_errors | ||
def preset_cli( # pylint: disable=too-many-branches, too-many-locals, too-many-arguments, too-many-statements | ||
ctx: click.core.Context, | ||
baseurl: str, | ||
|
@@ -138,14 +140,8 @@ def preset_cli( # pylint: disable=too-many-branches, too-many-locals, too-many- | |
credentials = yaml.load(input_, Loader=yaml.SafeLoader) | ||
api_token = credentials["api_token"] | ||
api_secret = credentials["api_secret"] | ||
except Exception: # pylint: disable=broad-except | ||
click.echo( | ||
click.style( | ||
"Couldn't read credentials", | ||
fg="bright_red", | ||
), | ||
) | ||
sys.exit(1) | ||
except Exception as excinfo: # pylint: disable=broad-except | ||
raise CLIError("Couldn't read credentials", 1) from excinfo | ||
else: | ||
manager_url = URL(baseurl.replace("api.", "manage.")) | ||
click.echo( | ||
|
@@ -165,15 +161,12 @@ def preset_cli( # pylint: disable=too-many-branches, too-many-locals, too-many- | |
api_secret = cast(str, api_secret) | ||
try: | ||
ctx.obj["AUTH"] = PresetAuth(manager_api_url, api_token, api_secret) | ||
except JWTTokenError: | ||
click.echo( | ||
click.style( | ||
"Failed to auth using the provided credentials." | ||
" Please run ``preset-cli auth``", | ||
fg="bright_red", | ||
), | ||
except JWTTokenError as excinfo: | ||
error_message = ( | ||
"Failed to auth using the provided credentials." | ||
" Please run ``preset-cli auth``" | ||
) | ||
sys.exit(1) | ||
raise CLIError(error_message, 1) from excinfo | ||
|
||
if not workspaces and ctx.invoked_subcommand == "superset" and not is_help(): | ||
client = PresetClient(ctx.obj["MANAGER_URL"], ctx.obj["AUTH"]) | ||
|
@@ -189,13 +182,7 @@ def preset_cli( # pylint: disable=too-many-branches, too-many-locals, too-many- | |
i += 1 | ||
|
||
if i == 0: | ||
click.echo( | ||
click.style( | ||
"No workspaces available", | ||
fg="bright_red", | ||
), | ||
) | ||
sys.exit(1) | ||
raise CLIError("No workspaces available", 1) | ||
if i == 1: | ||
workspaces = hostnames | ||
|
||
|
@@ -224,6 +211,7 @@ def preset_cli( # pylint: disable=too-many-branches, too-many-locals, too-many- | |
default=False, | ||
help="Show existing credentials", | ||
) | ||
@raise_cli_errors | ||
def auth(baseurl: str, overwrite: bool = False, show: bool = False) -> None: | ||
""" | ||
Store credentials for auth. | ||
|
@@ -232,16 +220,11 @@ def auth(baseurl: str, overwrite: bool = False, show: bool = False) -> None: | |
|
||
if show: | ||
if not credentials_path.exists(): | ||
click.echo( | ||
click.style( | ||
( | ||
f"The file {credentials_path} doesn't exist. " | ||
"Run ``preset-cli auth`` to create it." | ||
), | ||
fg="bright_red", | ||
), | ||
error_message = ( | ||
f"The file {credentials_path} doesn't exist. " | ||
"Run ``preset-cli auth`` to create it." | ||
) | ||
sys.exit(1) | ||
raise CLIError(error_message, 1) | ||
|
||
ruler = "=" * len(str(credentials_path)) | ||
with open(credentials_path, encoding="utf-8") as input_: | ||
|
@@ -251,16 +234,11 @@ def auth(baseurl: str, overwrite: bool = False, show: bool = False) -> None: | |
sys.exit(0) | ||
|
||
if credentials_path.exists() and not overwrite: | ||
click.echo( | ||
click.style( | ||
( | ||
f"The file {credentials_path} already exists. " | ||
"Pass ``--overwrite`` to replace it." | ||
), | ||
fg="bright_red", | ||
), | ||
error_message = ( | ||
f"The file {credentials_path} already exists. " | ||
"Pass ``--overwrite`` to replace it." | ||
) | ||
sys.exit(1) | ||
raise CLIError(error_message, 1) | ||
|
||
manager_url = URL(baseurl.replace("api.", "manage.")) | ||
manager_api_url = URL(baseurl) | ||
|
@@ -288,13 +266,7 @@ def get_teams(client: PresetClient) -> List[str]: | |
i += 1 | ||
|
||
if i == 0: | ||
click.echo( | ||
click.style( | ||
"No teams available", | ||
fg="bright_red", | ||
), | ||
) | ||
sys.exit(1) | ||
raise CLIError("No teams available", 1) | ||
if i == 1: | ||
return all_teams | ||
|
||
|
@@ -314,6 +286,7 @@ def get_teams(client: PresetClient) -> List[str]: | |
default="users.yaml", | ||
) | ||
@click.pass_context | ||
@raise_cli_errors | ||
def invite_users(ctx: click.core.Context, teams: List[str], path: str) -> None: | ||
""" | ||
Invite users to join Preset teams. | ||
|
@@ -336,6 +309,7 @@ def invite_users(ctx: click.core.Context, teams: List[str], path: str) -> None: | |
help="Save results to a YAML or CSV file instead of priting on the terminal", | ||
) | ||
@click.pass_context | ||
@raise_cli_errors | ||
def list_group_membership( | ||
ctx: click.core.Context, | ||
teams: List[str], | ||
|
@@ -351,13 +325,10 @@ def list_group_membership( | |
|
||
# in case --save-report was used, confirm if a valid option was used before sending requests | ||
if save_report and save_report.casefold() not in {"yaml", "csv"}: | ||
click.echo( | ||
click.style( | ||
"Invalid option. Please use ``--save-report=csv`` or ``--save-report=yaml``", | ||
fg="bright_red", | ||
), | ||
raise CLIError( | ||
"Invalid option. Please use ``--save-report=csv`` or ``--save-report=yaml``", | ||
1, | ||
) | ||
sys.exit(1) | ||
|
||
for team in teams: | ||
# print the team name in case multiple teams were provided and it's not an export | ||
|
@@ -464,6 +435,7 @@ def export_group_membership_csv(groups: Dict[str, Any], team: str) -> None: | |
default="users.yaml", | ||
) | ||
@click.pass_context | ||
@raise_cli_errors | ||
def import_users(ctx: click.core.Context, teams: List[str], path: str) -> None: | ||
""" | ||
Import users by adding them via SCIM. | ||
|
@@ -629,9 +601,9 @@ def sync_user_role_to_workspace( | |
) | ||
|
||
|
||
preset_cli.add_command(auth) | ||
preset_cli.add_command(invite_users) | ||
preset_cli.add_command(import_users) | ||
preset_cli.add_command(auth, name="auth") | ||
preset_cli.add_command(invite_users, name="invite-users") | ||
preset_cli.add_command(import_users, name="import-users") | ||
Comment on lines
+604
to
+606
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. For some reason, for the commands that involved the |
||
preset_cli.add_command(sync_roles) | ||
preset_cli.add_command(superset) | ||
preset_cli.add_command(list_group_membership) | ||
preset_cli.add_command(list_group_membership, name="list-group-membership") |
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.
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.
Had to bump it to fix
pre-commit
for newer Python versions. python/mypy#13627