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(clover): add Joi validations #5469

Merged
merged 2 commits into from
Feb 13, 2025
Merged

feat(clover): add Joi validations #5469

merged 2 commits into from
Feb 13, 2025

Conversation

jkeiser
Copy link
Contributor

@jkeiser jkeiser commented Feb 13, 2025

This PR adds Joi validations for scalars:

  • number: minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf
  • string: minLength, maxLength, pattern, format: date-time/timestamp/uri

It does this by:

  1. prop.joiValidationGenerating the Joi validation expression (Joi.string().max(255).pattern(new RegExp("^arn:"))) based on the type and validation criteria on the property. If there are no modifiers besides the type (like string / number / boolean), validation is not generated. This is stuffed in prop.joiValidation, which will be used by the asset function generator later.
  2. prop.data.validationFormat: We then eval() the joiValidation Calling it in the generator with eval(), calling describe() on the resulting Joi object and encoding that to JSON before putting it into package spec format.
  3. Asset function: when generating the asset function for a prop with joiValidation, we add a setValidationFormat(<prop.joiValidation>) builder call to the PropBuilder, and prop.joiValidation is deleted to make sure we don't dump it unnecessarily into the PkgSpec we upload.

Testing

  • Uploaded AWS::ECR::Repository locally and set RepositoryName to a single character. Watched validation go red.
  • Did Regenerate Asset and updated said component. Validation still red!

@jkeiser jkeiser requested a review from vbustamante February 13, 2025 02:42
Copy link

github-actions bot commented Feb 13, 2025

Dependency Review

✅ No vulnerabilities or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Files

Base automatically changed from jkeiser/space-socket-fix to main February 13, 2025 10:21
bin/clover/src/cfDb.ts Show resolved Hide resolved
bin/clover/src/spec/props.ts Show resolved Hide resolved
}
}

// Some patterns in cloudformation are broken and need to be ignored
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks Amazon! (great job mapping this out 😄)

@jkeiser jkeiser added this pull request to the merge queue Feb 13, 2025
Merged via the queue into main with commit da8808e Feb 13, 2025
8 checks passed
@jkeiser jkeiser deleted the clover/validation branch February 13, 2025 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants