1
0
Fork 0

build: add and document target to validate rules

This commit is contained in:
ssube 2019-06-15 19:57:31 -05:00
parent 9de751b62b
commit 1b42c26d85
4 changed files with 88 additions and 3 deletions

View File

@ -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

View File

@ -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 \

70
docs/outline.md Normal file
View File

@ -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

View File

@ -1,3 +0,0 @@
data:
logger:
name: salty