-
Notifications
You must be signed in to change notification settings - Fork 1.2k
chore: sam sync & sam logs ux changes #3953
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c38a99e
ux: don't display managed s3 bucket location & capabilities which was…
mndeveci e3499a6
update logging messages from build definition uuid to resource name list
mndeveci ca51754
use yellow fg for experimental flag confirmation
mndeveci 419b255
fix warning message for sfn invalid logging configuration
mndeveci cb859da
fix accidental deletes from earlier commits
mndeveci ac52a09
rest of the ux improvements
mndeveci 4260843
unit tests
mndeveci 87ceaab
Merge branch 'develop' into accelerate_ux_changes
mndeveci 20f8478
update unit tests
mndeveci 752448a
Merge branch 'develop' into accelerate_ux_changes
mndeveci 693411f
fix parameter name
mndeveci bb117c3
address pr comments
mndeveci c50176d
additional tests to confirm sam logs validation
mndeveci d7f930c
add default exception handler to traces as well
mndeveci 58d5678
build tests regex changes
mndeveci 045b129
Merge branch 'develop' into accelerate_ux_changes
mndeveci 6c5e2f7
fix test cases
mndeveci 36a9db2
black formatting
mndeveci 666a927
Merge branch 'develop' into accelerate_ux_changes
mndeveci 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| """ | ||
| Contains method decorator which can be used to convert common exceptions into click exceptions | ||
| which will end exeecution gracefully | ||
| """ | ||
| from functools import wraps | ||
| from typing import Callable, Dict, Any, Optional | ||
|
|
||
| from botocore.exceptions import NoRegionError, ClientError | ||
|
|
||
| from samcli.commands._utils.options import parameterized_option | ||
| from samcli.commands.exceptions import CredentialsError, RegionError | ||
| from samcli.lib.utils.boto_utils import get_client_error_code | ||
|
|
||
|
|
||
| @parameterized_option | ||
| def command_exception_handler(f, additional_mapping: Optional[Dict[Any, Callable[[Any], None]]] = None): | ||
| """ | ||
| This function returns a wrapped function definition, which handles configured exceptions gracefully | ||
| """ | ||
|
|
||
| def decorator_command_exception_handler(func): | ||
| @wraps(func) | ||
| def wrapper_command_exception_handler(*args, **kwargs): | ||
| try: | ||
| return func(*args, **kwargs) | ||
| except Exception as ex: | ||
| exception_type = type(ex) | ||
|
|
||
| # check if there is a custom handling defined | ||
| exception_handler = (additional_mapping or {}).get(exception_type) | ||
| if exception_handler: | ||
| exception_handler(ex) | ||
|
|
||
| # if no custom handling defined search for default handlers | ||
| exception_handler = COMMON_EXCEPTION_HANDLER_MAPPING.get(exception_type) | ||
| if exception_handler: | ||
| exception_handler(ex) | ||
|
|
||
| # if no handler defined, raise the exception | ||
| raise ex | ||
|
|
||
| return wrapper_command_exception_handler | ||
|
|
||
| return decorator_command_exception_handler(f) | ||
|
|
||
|
|
||
| def _handle_no_region_error(ex: NoRegionError) -> None: | ||
| raise RegionError( | ||
| "No region information found. Please provide --region parameter or configure default region settings. " | ||
| "\nFor more information please visit https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/" | ||
| "setup-credentials.html#setup-credentials-setting-region" | ||
| ) | ||
|
|
||
|
|
||
| def _handle_client_errors(ex: ClientError) -> None: | ||
| error_code = get_client_error_code(ex) | ||
|
|
||
| if error_code in ("ExpiredToken", "ExpiredTokenException"): | ||
| raise CredentialsError( | ||
| "Your credential configuration is invalid or has expired token value. \nFor more information please " | ||
| "visit: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html" | ||
| ) | ||
|
|
||
| raise ex | ||
|
|
||
|
|
||
| COMMON_EXCEPTION_HANDLER_MAPPING: Dict[Any, Callable] = { | ||
| NoRegionError: _handle_no_region_error, | ||
| ClientError: _handle_client_errors, | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| """ | ||
| Contains helper functions for validation and exception handling of "sam logs" command | ||
| """ | ||
| from functools import wraps | ||
| from typing import Dict, Any, Callable | ||
|
|
||
| import click | ||
| from botocore.exceptions import ClientError | ||
| from click import Context, BadOptionUsage | ||
|
|
||
| from samcli.commands.exceptions import InvalidStackNameException | ||
| from samcli.lib.utils.boto_utils import get_client_error_code | ||
|
|
||
|
|
||
| def stack_name_cw_log_group_validation(func): | ||
| """ | ||
| Wrapper Validation function that will run last after the all cli parmaters have been loaded | ||
| to check for conditions surrounding `--stack-name` and `--cw-log-group`. The | ||
| reason they are done last instead of in callback functions, is because the options depend | ||
| on each other, and this breaks cyclic dependencies. | ||
|
|
||
| :param func: Click command function | ||
| :return: Click command function after validation | ||
| """ | ||
|
|
||
| @wraps(func) | ||
| def wrapped(*args, **kwargs): | ||
| ctx = click.get_current_context() | ||
| stack_name = ctx.params.get("stack_name") | ||
| cw_log_groups = ctx.params.get("cw_log_group") | ||
| names = ctx.params.get("name") | ||
|
|
||
| # if --name is provided --stack-name should be provided as well | ||
| if names and not stack_name: | ||
| raise BadOptionUsage( | ||
| option_name="--stack-name", | ||
| ctx=ctx, | ||
| message="Missing option. Please provide '--stack-name' when using '--name' option", | ||
| ) | ||
|
|
||
| # either --stack-name or --cw-log-group flags should be provided | ||
| if not stack_name and not cw_log_groups: | ||
mndeveci marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| raise BadOptionUsage( | ||
| option_name="--stack-name", | ||
| ctx=ctx, | ||
| message="Missing option. Please provide '--stack-name' or '--cw-log-group'", | ||
| ) | ||
|
|
||
| return func(*args, **kwargs) | ||
|
|
||
| return wrapped | ||
|
|
||
|
|
||
| def _handle_client_error(ex: ClientError) -> None: | ||
| """ | ||
| Handles client error which was caused by ListStackResources event | ||
| """ | ||
| operation_name = ex.operation_name | ||
| client_error_code = get_client_error_code(ex) | ||
| if client_error_code == "ValidationError" and operation_name == "ListStackResources": | ||
| click_context: Context = click.get_current_context() | ||
| stack_name_value = click_context.params.get("stack_name") | ||
| raise InvalidStackNameException( | ||
| f"Invalid --stack-name parameter. Stack with id '{stack_name_value}' does not exist" | ||
| ) | ||
|
|
||
|
|
||
| SAM_LOGS_ADDITIONAL_EXCEPTION_HANDLERS: Dict[Any, Callable] = {ClientError: _handle_client_error} | ||
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
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.