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: remote invoke context initial impl #5183

Merged
merged 9 commits into from
May 19, 2023

Conversation

mndeveci
Copy link
Contributor

@mndeveci mndeveci commented May 17, 2023

Adds RemoteInvokeContext class implementation with following validations;

  • If no stack_name or resource_id is provided, it fails with InvalidRemoteInvokeParameters
  • If only stack_name is provided;
    • If there is only one resource with supported type, continues execution
    • If there is more than one resource with supported type, fails with AmbiguousResourceForRemoteInvoke
    • If there is no resource definition with supported type, fails with NoResourceFoundForRemoteInvoke
  • If only resource_id is provided;
    • If resource_id is a valid ARN from supported resource, continues execution
    • If resource_id is a valid physical_resource_id in a deployed stack, continues execution
    • If resource_id is an invalid physical_resource_id (where it can't be find by CFN API call), fails with AmbiguousResourceForRemoteInvoke

Mandatory Checklist

PRs will only be reviewed after checklist is complete

  • Add input/output type hints to new functions/methods
  • Write design document if needed (Do I need to write a design document?)
  • Write/update unit tests
  • Write/update integration tests
  • Write/update functional tests if needed
  • make pr passes
  • make update-reproducible-reqs if dependencies were changed
  • Write documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@mndeveci mndeveci changed the title feat: remote invoke context impl feat: remote invoke context initial impl May 18, 2023
@mndeveci mndeveci marked this pull request as ready for review May 18, 2023 16:22
@mndeveci mndeveci requested a review from a team as a code owner May 18, 2023 16:22
samcli/commands/remote_invoke/remote_invoke_context.py Outdated Show resolved Hide resolved
f"please provide --resource-id to resolve ambiguity."
)

raise NoResourceFoundForRemoteInvoke(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: should we do a if not resource_summaries here first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we already exhausted all other options above, I was just raising the exception here. If you think that would be useful, I can add a comment on top of it to state this is the case where we don't have any resource summaries at all.

Comment on lines +30 to +34
_boto_client_provider: BotoProviderType
_boto_resource_provider: BotoProviderType
_stack_name: Optional[str]
_resource_id: Optional[str]
_resource_summary: Optional[CloudFormationResourceSummary]
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious: Why define this here? Is there some advantage this has?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes it more explicit about all the fields and their types that will/may be instantiated in this class. Mypy doesn't need to implicitly find their types from assignments. I know it is more verbose but I personally find this way more readable :)

Comment on lines +60 to +61
if not self._stack_name and not self._resource_id:
raise InvalidRemoteInvokeParameters("Either --stack-name or --resource-id parameter should be provided")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this check be in the "cli" part instead of the context? More a nit/question on where the validation of parameters happens (assuming this are parameters)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔 agreed on this one, this validation can be moved up to command.py through click. @hnnasit what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that makes sense. We will also have another validation for payload and payload-file in command.py. We can move the above validation to cli as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regarding to this one, I feel weird when removing this validation since typing system can't guarantee one or the other field should have a value. After discussing with @hnnasit we decided to keep it here as well as adding it to the command.py implementation later.

samcli/commands/remote_invoke/remote_invoke_context.py Outdated Show resolved Hide resolved
samcli/commands/remote_invoke/remote_invoke_context.py Outdated Show resolved Hide resolved
samcli/commands/remote_invoke/remote_invoke_context.py Outdated Show resolved Hide resolved
samcli/commands/remote_invoke/remote_invoke_context.py Outdated Show resolved Hide resolved
@sriram-mv sriram-mv added this pull request to the merge queue May 19, 2023
Merged via the queue into aws:develop with commit eab605a May 19, 2023
65 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants