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

841 Validate properties are defined on cfn validate #892

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mgentry612
Copy link

Issue #, if available:
841

Description of changes:
This PR is not ready for production - it makes several of the current test cases fail. I wanted to start a conversation about whether all of this validation is needed before I considered modifying current test cases. The main reason I made this PR was to introduce myself to the codebase. I realize this PR may or may not be helpful to your team. If you find that this PR is heading in the right direction, please provide feedback. If you're not interested in adding this functionality, no problem, it was fun diving in.

This PR implements validation for the top level of properties in the resource schema. For the following resource schema keys, a validation function ensures that properties at the top level of the "property" object are defined.
"readOnlyProperties", "createOnlyProperties", "primaryIdentifier", "required", "additionalIdentifiers", "deprecatedProperties", "writeOnlyProperties",

The following assumptions are made in these changes, please confirm:

  • Properties are case sensitive
  • additionalIdentifiers, when defined, are always two dimensional arrays.

These changes handle examples like this:
"createOnlyProperties": [ "/properties/Name" ]

but not nested properties like this, see below section about traversing the json structure:
"createOnlyProperties": [ "/properties/obj1/obj2/str1" ]

As mentioned above, this PR omits nested properties. I started diving into nested properties but I decided I would need discuss the requirements before doing any more work. There were several complexities which I had questions about including the array data type and circular references. If you think it would be helpful to show you what I have so far for this on another branch, let me know and I'll share.

I've included several new test cases which run successfully only in isolation at this time.
pytest --cov="rpdk.core" --doctest-modules --random-order-bucket="parent" "tests/test_data_loaders.py" -k test_load_resource_spec_property_not_defined --pyargs "rpdk.core" --verbose

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

@mgentry612 mgentry612 marked this pull request as ready for review July 9, 2022 20:51
@mgentry612 mgentry612 marked this pull request as draft July 9, 2022 20:52
def verify_listed_properties_are_defined(resource_spec):
LOG.debug("verify_listed_properties_are_defined")

schema_keys = [
Copy link
Contributor

Choose a reason for hiding this comment

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

Some newer JSON pointer property types

Suggested change
schema_keys = [
schema_keys = [
"nonPublicProperties",
"conditionalCreateOnlyProperties",

https://github.com/aws-cloudformation/cloudformation-resource-schema/blob/master/src/main/resources/schema/provider.definition.schema.v1.json

@mircealam
Copy link
Member

To get all the validations included and keep them up to date over time is not a trivial task. May I suggest you give https://github.com/aws-cloudformation/resource-schema-guard-rail a try and see if it helps solve your problems?
In the medium to long term I believe integrating guard rail into the cli is the way to go to keep the validations consistent.

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.

5 participants