1
0
Fork 0
Schema analysis, linting, and transformation for YAML
Go to file
ssube 9eb41fc38e feat: load definitions from rules (fixes #2)
BREAKING CHANGE: adds a required `name` property (string) at the
top level of each `--rules` file, used as the schema name
2019-06-22 12:26:11 -05:00
config feat: display diff when rule modifies data (fixes #3) 2019-06-22 11:48:41 -05:00
docs feat: add rules to image, doc 2019-06-17 09:11:26 -05:00
examples feat: display diff when rule modifies data (fixes #3) 2019-06-22 11:48:41 -05:00
rules feat: load definitions from rules (fixes #2) 2019-06-22 12:26:11 -05:00
scripts fix(build): add github status script, remove coverage jobs 2019-06-15 23:10:24 -05:00
src feat: load definitions from rules (fixes #2) 2019-06-22 12:26:11 -05:00
vendor/jsonpath-plus feat: make node selectors work 2019-06-15 17:53:07 -05:00
.gitignore docs: include some examples, explicitly state success 2019-06-15 18:56:42 -05:00
.gitlab-ci.yml fix(build): fix artifacts 2019-06-16 00:25:11 -05:00
.npmignore build: omit cache from npm bundle 2019-06-16 16:48:58 -05:00
CHANGELOG.md docs: fix changelog 2019-06-16 16:44:29 -05:00
Dockerfile feat: add rules to image, doc 2019-06-17 09:11:26 -05:00
LICENSE.md docs: add repo url, fix example command 2019-06-15 18:33:50 -05:00
Makefile feat: load definitions from rules (fixes #2) 2019-06-22 12:26:11 -05:00
README.md feat: add rules to image, doc 2019-06-17 09:11:26 -05:00
package.json feat: display diff when rule modifies data (fixes #3) 2019-06-22 11:48:41 -05:00
tsconfig.json feat: project, build, and bundle 2019-06-15 15:20:04 -05:00
yarn.lock feat: display diff when rule modifies data (fixes #3) 2019-06-22 11:48:41 -05:00

README.md

SALTY DOG

YAML linter/validator.

Or, as an acronym, JSON schema analysis, linting, and transformation for YAML, featuring defaults, optional fields, and other good stuff.

Build

This project is written in Typescript and requires node and yarn to build.

> git clone git@github.com:ssube/salty-dog.git
> cd salty-dog
> make

Usage

To run with Docker (recommended): docker run -v ${HOME}:/root:ro --rm -i ssube/salty-dog:master

To run after yarn global add or npm i -g: salty-dog

To run after building: node out/bundle.js

To run with make, apply with kubectl, and format logs with bunyan:

> curl https://raw.githubusercontent.com/ssube/k8s-shards/master/roles/apps/gitlab/server/templates/ingress.yml | make run-stream 2> >(./node_modules/.bin/bunyan) > >(kubectl apply --dry-run -f -)

...
[2019-06-16T03:23:56.645Z]  INFO: salty-dog/8015 on cerberus: all rules passed
ingress.extensions/gitlab created (dry run)

Docker

The Docker container is published for each branch and tag, using the slug (. replaced with -, mostly). The latest semi-stable image is ssube/salty-dog:master.

Rules are located in /rules within the image. To add your own rules, mount them with -v ${HOME}/your-rules:/user-rules:ro and include with --rules /user-rules/rules.yml.

Validate

salty-dog can validate JSON and YAML from files and streams, and emit it to a file or stream (with logs going elsewhere).

Validate File

To validate a file:

> salty-dog \
    --rules rules/kubernetes.yml \
    --source examples/kubernetes-resources-fail.yml \
    --tag important

...
[2019-06-15T23:56:04.764Z] ERROR: salty-dog/22211 on cerberus: some rules failed (errors=1)

> cat examples/kubernetes-resources-pass.yml | salty-dog \
    --rules rules/kubernetes.yml \
    --source - \
    --tag important

...
[2019-06-15T23:53:34.223Z]  INFO: salty-dog/19839 on cerberus: all rules passed

Validate URL

To validate a URL:

> curl https://raw.githubusercontent.com/ssube/k8s-shards/master/roles/apps/gitlab/server/templates/ingress.yml | salty-dog \
    --rules rules/kubernetes.yml \
    --source - \
    --tag important | kubectl apply --dry-run -f -

...
{"name":"salty-dog","hostname":"cerberus","pid":7860,"level":30,"msg":"all rules passed","time":"2019-06-16T02:04:37.797Z","v":0}
ingress.extensions/gitlab created (dry run)
...

Validate Rules

To validate the rules in the rules/ directory using the meta-rules:

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

Options

Count

  • Alias: c

Exit with the error count (max of 255) rather than 0 or 1.

Dest

  • Alias: d
  • Default: -

Path to write output data.

Defaults to stdout (-).

Format

  • Default: yaml

Output format.

Options:

  • yaml

Exclude

Excludes take priority over includes: a rule matching some of both will be excluded.

Exclude Level

Exclude rules by log level.

Exclude Name

Exclude rules by name.

Exclude Tag

Exclude rules by tag.

Include

Include Level

Include rules by log level.

Include Name

Include rules by name.

Include Tag
  • Alias: t, tag

Include rules by tag.

Mode

  • Alias: m
  • Default: check

The application mode.

Options:

  • check runs each rule and exits with an indicative status
  • fix runs each rule and updates the source data with any defaults before running the next rule

Rules

The path to a file containing some rules.

Source

  • Alias: s
  • Default: -

The source file to validate.

Defaults to stdin (-) to work with pipes: cat file.yml | salty-dog --source -