diff --git a/Makefile b/Makefile index 9dcc321..55a4a1d 100755 --- a/Makefile +++ b/Makefile @@ -112,3 +112,11 @@ upload-climate: upload-codecov: codecov --disable=gcov --file=$(TARGET_PATH)/coverage/lcov.info --token=$(shell echo "${CODECOV_SECRET}" | base64 -d) + +# run targets +run-rules: ## validate the rules directory + find $(ROOT_PATH)/rules -maxdepth 1 -name '*.yml' | while read file; \ + do \ + echo "Validating $${file}..."; \ + node out/bundle.js --rules $(ROOT_PATH)/rules/salty-dog.yml --source $${file} --tag important; \ + done \ No newline at end of file diff --git a/README.md b/README.md index 9cc20c0..d880d41 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,16 @@ fields, and other **g**ood stuff. ## Usage +To validate the rules in the `rules/` directory: + +```shell +> make run-rules +... +{"name":"salty-dog","hostname":"cerberus","pid":29403,"level":30,"msg":"all rules passed","time":"2019-06-16T00:56:55.132Z","v":0} +``` + +To validate a file: + ```shell > cat rules/examples/kubernetes-require-resources-fail.yml |\ salty-dog \ diff --git a/docs/outline.md b/docs/outline.md new file mode 100644 index 0000000..8837cc2 --- /dev/null +++ b/docs/outline.md @@ -0,0 +1,70 @@ +# Outline + +Original rough outline document. + +- Json path & schema based +- Select nodes using path +- Validate each using schema (fragment) + +## Feedback & Output + +- message if schema mutates fragment +- message if fragment fails schema + +## Rules + +### Metadata + +- level (debug, info, warn, error) +- tags + +### Body + +- check (schema) +- filter (jsonpath) +- select (jsonpath) + +## Arguments + +- config file +- dest (file, stdout) +- exclude-level +- exclude-rule +- exclude-tag +- include-level +- include-rule +- include-tag +- mode (check, fix) +- rule paths +- source (file, stdin) + +## Config + +- should have schema and be validated +- support all arguments (except config file) +- TODO: parent config + +## Run + +1. Load source and copy to state +2. Load all fragments in rule paths +3. Build list of applicable rules by level, name, tag +4. For each rule: +5. Select potential nodes +6. Filter applicable nodes +7. Copy fragment +8. Apply schema +9. If schema passes and output matches, log success +10. If schema passes and output differs, log difference +11. If schema fails, log errors and mark error +12. If running in fix mode and schema passed, update state +13. After all rules: +14. If running in fix mode and all rules passed: +15. Log differences between source and state +16. Write state to dest + +## Dependencies + +- ajv +- jsonpath-plus +- js-yaml diff --git a/docs/salty.yml b/docs/salty.yml deleted file mode 100644 index 16b64d3..0000000 --- a/docs/salty.yml +++ /dev/null @@ -1,3 +0,0 @@ -data: - logger: - name: salty