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

added some pre-actionable checks for update and read handler to align with handler contract #294

Merged
merged 2 commits into from
Aug 4, 2020

Conversation

ammokhov
Copy link
Contributor

@ammokhov ammokhov commented Aug 1, 2020

Codegen enhancements to provide to a developer additional tools for contract test passing:

  • An update handler MUST return FAILED with a NotFound error code if the resource did not exist prior to the update request.

  • When the delete handler returns SUCCESS, the ProgressEvent object MUST NOT contain a model.

  • A read handler MUST return FAILED with a NotFound error code if the resource does not exist.

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

@ammokhov ammokhov self-assigned this Aug 1, 2020
@ammokhov ammokhov added code quality codegen It's like magic! enhancement New feature or request labels Aug 1, 2020
@@ -52,6 +52,7 @@ static ResourceModel translateFromReadResponse(final AwsResponse awsResponse) {
// e.g. https://github.com/aws-cloudformation/aws-cloudformation-resource-providers-logs/blob/2077c92299aeb9a68ae8f4418b5e932b12a8b186/aws-logs-loggroup/src/main/java/com/aws/logs/loggroup/Translator.java#L58-L73
return ResourceModel.builder()
//.someProperty(response.property())
// IMPORTANT: exclude writeOnlyProperties
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't this done by lambda wrapper?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes it should be. At least in this language plugin.

Copy link
Contributor

Choose a reason for hiding this comment

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

could you just remove this line about write only properties. This might cause some confusion.

Comment on lines +32 to +35

// STEP 1 [check if resource already exists]
// for more information -> https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html
// if target API does not support 'ResourceNotFoundException' then following check is required
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems we are checking for not found at multiple places. May be consolidate this to be in on place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we might be having same callGraph value cached in case you cross handler interaction. also I think it's already quite wordy if we refer in multiple places it will be confusing

@ammokhov ammokhov merged commit 682214d into aws-cloudformation:master Aug 4, 2020
@ammokhov ammokhov deleted the codegen-enhancement branch August 4, 2020 21:01
@PatMyron PatMyron changed the title added some pre-actionable checks for update and read handler to align… added some pre-actionable checks for update and read handler to align with handler contract Aug 26, 2020
.then(progress ->
// STEP 1.0 [initialize a proxy context]
// If your service API does not return ResourceNotFoundException on update requests against some identifier (e.g; resource Name)
// and instead returns a 200 even though a resource does not exist, you must first check if the resource exists here
// NOTE: If your service API throws 'ResourceNotFoundException' for update requests this method is not necessary
Copy link
Contributor

Choose a reason for hiding this comment

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

Even if the service API throws ResourceNotFoundException, the contract tests as currently implemented expect ResourceNotFoundException to be thrown even when calling the handlers with obviously invalid inputs which likely will hit model validation before checking if the resource exists or not, even for services that do throw ResourceNotFoundException

also discussed in aws-cloudformation/cloudformation-cli#527

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality codegen It's like magic! enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants