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

schnauzer: Add any_enabled template helper #2541

Merged

Conversation

stmcginnis
Copy link
Contributor

Issue number:

Related #1702

Description of changes:

This adds a new template helper called any_enabled that can be used in our templates to check if anything in a collection contains something with the property of enabled set to true.

The helper looks for an array, then checks that the objects within the array has an "enabled" property. If they do and if any of them are set to "true" the condition evaluates to be "truey" for conditional blocks within the template.

If the passed in value is not an array, does not have an "enabled" property, or has no elements with that property set to true it will evaluate to falsey.

Testing done:

See #2377 for complete testing details.

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

@stmcginnis stmcginnis force-pushed the cred-prov-any_enabled branch from db6030c to c63df8a Compare November 1, 2022 17:42
sources/api/schnauzer/src/helpers.rs Show resolved Hide resolved
@etungsten
Copy link
Contributor

I think depending on the resolution of #2377 (comment), we might need to change this from interpreting a list to a map.

@stmcginnis
Copy link
Contributor Author

I think depending on the resolution of #2377 (comment), we might need to change this from interpreting a list to a map.

Hmm, this may be an issue. Not sure how that would be handled using handlebar syntax. Maybe another helper that would convert the items in the hashmap into a list that would then be passed in to this helper?

This adds a new template helper called `any_enabled` that can be used in
our templates to check if anything in a collection contains something
with the property of `enabled` set to true.

The helper looks for an array, then checks that the objects within the
array has an "enabled" property. If they do and if any of them are set
to "true" the condition evaluates to be "truey" for conditional blocks
within the template.

If the passed in value is not an array, does not have an "enabled"
property, or has no elements with that property set to true it will
evaluate to falsey.

Signed-off-by: Sean McGinnis <stmcg@amazon.com>
@stmcginnis stmcginnis force-pushed the cred-prov-any_enabled branch from c63df8a to dd29094 Compare November 2, 2022 14:59
@stmcginnis
Copy link
Contributor Author

we might need to change this from interpreting a list to a map.

Added ability to also use a map as input with unit test coverage for various input.

@stmcginnis stmcginnis mentioned this pull request Nov 2, 2022
14 tasks
Copy link
Contributor

@etungsten etungsten left a comment

Choose a reason for hiding this comment

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

🍨

@stmcginnis stmcginnis merged commit 5e5470a into bottlerocket-os:develop Nov 2, 2022
@stmcginnis stmcginnis deleted the cred-prov-any_enabled branch November 2, 2022 15:59
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.

3 participants