-
Notifications
You must be signed in to change notification settings - Fork 200
ENT-8193: Added validfiledata policy function #6267
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| body common control | ||
| { | ||
| inputs => { "../../default.sub.cf" }; | ||
| bundlesequence => { init, test, check }; | ||
| version => "1.0"; | ||
| } | ||
|
|
||
| bundle agent generate_files(template, data) | ||
| { | ||
| vars: | ||
| "content" string => string_mustache("$(template[mustache])", @(data)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems a bit overly complicated to use mustache templates here. Is it not easier to just write the content directly? It may be a little bit more code, but easier to read / understand when debugging this in the future. Also I'd prefer using the test directory variables from
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It just seemed easier to maintain to me: instead of maintaining a hard coded string for each filetype, we have one general data container and one mustache for each filetype. Also, it doesn't pollute the folder with a lot of redundant files:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I meant is that you write these files to the |
||
|
|
||
| files: | ||
| "/tmp/config.$(template[format])" | ||
| create => "true", | ||
| content => "$(content)"; | ||
|
|
||
| "/tmp/config.x.$(template[format])" | ||
| create => "true", | ||
| content => "-$(content)", # Add some text that makes the json and yaml invalid | ||
| if => strcmp("$(template[create_invalid])", "yes"); # csv and env are invalid ONLY when the file doesn't exist | ||
| } | ||
|
|
||
| bundle agent init | ||
| { | ||
| vars: | ||
| "config_data" | ||
| data => parsejson( | ||
| '{"hello" : "world", "bye" : "everyone", "pizza" : "hamburger"}' | ||
| ); | ||
| @if feature(yaml) | ||
| "templates" | ||
| data => parsejson( | ||
| '[ | ||
| {"format": "json", "mustache": "{{%-top-}}", "create_invalid" : "yes"}, | ||
| {"format": "yaml", "mustache": "---\\n{{#-top-}}\\n{{@}}: \\\"{{.}}\\\"\\n{{/-top-}}", "create_invalid" : "yes"}, | ||
| {"format": "csv", "mustache": "Key,Value\\r\\n{{#-top-}}\\r\\n{{@}},\\\"{{.}}\\\"\\r\\n{{/-top-}}", "create_invalid" : "no"}, | ||
| {"format": "env", "mustache": "{{#-top-}}\\n{{{@}}}={{{.}}}\\n{{/-top-}}", "create_invalid" : "no"} | ||
| ]' | ||
| ); | ||
| @else | ||
| "templates" | ||
| data => parsejson( | ||
| '[ | ||
| {"format": "json", "mustache": "{{%-top-}}", "create_invalid" : "yes"}, | ||
| {"format": "csv", "mustache": "Key,Value\\r\\n{{#-top-}}\\r\\n{{@}},\\\"{{.}}\\\"\\r\\n{{/-top-}}", "create_invalid" : "no"}, | ||
| {"format": "env", "mustache": "{{#-top-}}\\n{{{@}}}={{{.}}}\\n{{/-top-}}", "create_invalid" : "no"} | ||
| ]' | ||
| ); | ||
| @endif | ||
| "template_idx" slist => getindices(templates); | ||
|
|
||
| methods: | ||
| "generate" | ||
| usebundle => generate_files( | ||
| "@(templates[$(template_idx)])", @(config_data) | ||
| ); | ||
| } | ||
|
|
||
| bundle agent test | ||
| { | ||
| vars: | ||
| "formats" | ||
| slist => maparray("$(init.templates[$(this.k)][format])", init.templates); | ||
|
|
||
| "valid_classes" slist => maplist("valid_$(this)", formats); | ||
| "invalid_classes" slist => maplist("invalid_$(this)", formats); | ||
|
|
||
| classes: | ||
| "valid_$(formats)" | ||
| expression => validfiledata("/tmp/config.$(formats)", "auto"), | ||
| scope => "namespace"; | ||
|
|
||
| "invalid_$(formats)" | ||
| expression => validfiledata("/tmp/config.x.$(formats)", "auto"), | ||
| scope => "namespace"; | ||
| } | ||
|
|
||
| bundle agent check | ||
| { | ||
| classes: | ||
| "valid" and => { @(test.valid_classes) }; | ||
| "invalid" or => { @(test.invalid_classes) }; | ||
|
|
||
| files: | ||
| "/tmp/config.x.$(test.formats)" delete => tidy; | ||
|
|
||
| reports: | ||
| valid.!invalid:: | ||
| "$(this.promise_filename) Pass"; | ||
|
|
||
| !valid|invalid:: | ||
| "$(this.promise_filename) FAIL"; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.