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 primary id validation #482

Merged

Conversation

ammokhov
Copy link
Contributor

@ammokhov ammokhov commented Jul 8, 2020

Issue #, if available: #361

Description of changes:

we do not allow mutable updates on primary identifier, instead it could be updated immutably, which causes the replacement.
However, primary identifier could be specified in two ways:

  • readOnly - auto generated by handler or api
  • createOnly - specified by the user and cant be further mutably updated

Since, we would want to enforce the schema modeling it makes sense to add this to schema validation to provide definition correctness.

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 Jul 8, 2020
@ammokhov ammokhov added code quality enhancement New feature or request schema Related to the provider meta schema schema processing labels Jul 8, 2020
@ammokhov ammokhov linked an issue Jul 8, 2020 that may be closed by this pull request
@rjlohan
Copy link
Contributor

rjlohan commented Jul 8, 2020

Should this validation be added to https://github.com/aws-cloudformation/aws-cloudformation-resource-schema/tree/master/src as well/instead?

@johnttompkins
Copy link
Contributor

Should this validation be added to https://github.com/aws-cloudformation/aws-cloudformation-resource-schema/tree/master/src as well/instead?

Agree with this we should just schematize this

@anshikg anshikg self-requested a review July 8, 2020 18:11
in_createonly = _is_in(resource_spec, "createOnlyProperties")

primary_id = resource_spec["primaryIdentifier"]
if not in_readonly(primary_id) and not in_createonly(primary_id):
Copy link
Contributor

Choose a reason for hiding this comment

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

can simplify a bit to make condition primaryIdentifier - (createOnlyProperties | readOnlyProperties) where they are all sets

Copy link
Contributor Author

Choose a reason for hiding this comment

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

used closure to reuse the subset operation but we might use a disjoint of createOnly | readOnly

Copy link
Contributor

Choose a reason for hiding this comment

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

@ammokhov
Copy link
Contributor Author

ammokhov commented Jul 8, 2020

Should this validation be added to https://github.com/aws-cloudformation/aws-cloudformation-resource-schema/tree/master/src as well/instead?

Agree with this we should just schematize this

as discussed offline, we cant really schematize the condition, so this change should go in both repos.
However, if we start raising this exception it might break the registration, so alternatively we can log a warning to highlight the issue

@ammokhov ammokhov force-pushed the primary-identifier-validation branch from b12e00b to cf31c37 Compare July 21, 2020 05:14
@ammokhov
Copy link
Contributor Author

why do we want to change this to warning?

we want to inform a customer that id should be either createonly or readonly but if we start throwing an exception it will block existing resources from registration. warning still informs but make it backward compatible

@ammokhov ammokhov merged commit e4e8199 into aws-cloudformation:master Aug 12, 2020
@ammokhov ammokhov deleted the primary-identifier-validation branch August 12, 2020 18:15
@@ -0,0 +1,13 @@
{
"typeName": "AWS::Valid::TypeName",
Copy link
Contributor

@PatMyron PatMyron Jan 14, 2021

Choose a reason for hiding this comment

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

Was this schema meant to test aws-cloudformation/cloudformation-resource-schema#98 as well?
typeName should be renamed and wondering if the directory name is confusing as well. Having trouble putting LOG.warning violating schemas in invalid/ in #663 as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality enhancement New feature or request schema processing schema Related to the provider meta schema
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Contract tests: catch primary identifier change during update
5 participants