2019-06-15 23:07:46 +00:00
|
|
|
# SALTY DOG
|
|
|
|
|
2019-06-16 02:08:21 +00:00
|
|
|
YAML linter/validator.
|
|
|
|
|
|
|
|
Or, as an acronym, JSON **s**chema **a**nalysis, **l**inting, and **t**ransformation for **Y**AML, featuring
|
|
|
|
**d**efaults, **o**ptional fields, and other **g**ood stuff.
|
2019-06-15 23:07:46 +00:00
|
|
|
|
|
|
|
- [SALTY DOG](#salty-dog)
|
|
|
|
- [Build](#build)
|
|
|
|
- [Usage](#usage)
|
2019-06-16 02:08:21 +00:00
|
|
|
- [Validate](#validate)
|
|
|
|
- [Validate File](#validate-file)
|
|
|
|
- [Validate URL](#validate-url)
|
|
|
|
- [Validate Rules](#validate-rules)
|
2019-06-15 23:07:46 +00:00
|
|
|
- [Options](#options)
|
2019-06-15 23:36:44 +00:00
|
|
|
- [Count](#count)
|
2019-06-16 02:08:21 +00:00
|
|
|
- [Dest](#dest)
|
|
|
|
- [Format](#format)
|
2019-06-15 23:58:06 +00:00
|
|
|
- [Exclude](#exclude)
|
|
|
|
- [Exclude Level](#exclude-level)
|
|
|
|
- [Exclude Name](#exclude-name)
|
|
|
|
- [Exclude Tag](#exclude-tag)
|
|
|
|
- [Include](#include)
|
|
|
|
- [Include Level](#include-level)
|
|
|
|
- [Include Name](#include-name)
|
|
|
|
- [Include Tag](#include-tag)
|
2019-06-15 23:07:46 +00:00
|
|
|
- [Mode](#mode)
|
|
|
|
- [Rules](#rules)
|
|
|
|
- [Source](#source)
|
|
|
|
|
|
|
|
## Build
|
|
|
|
|
2019-06-16 02:13:15 +00:00
|
|
|
This project is written in Typescript and requires `node` and `yarn` to build.
|
2019-06-16 02:08:21 +00:00
|
|
|
|
2019-06-15 23:07:46 +00:00
|
|
|
```shell
|
2019-06-15 23:33:50 +00:00
|
|
|
> git clone git@github.com:ssube/salty-dog.git
|
2019-06-16 02:13:15 +00:00
|
|
|
> cd salty-dog
|
2019-06-15 23:33:50 +00:00
|
|
|
> make
|
2019-06-15 23:07:46 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
2019-06-16 03:04:41 +00:00
|
|
|
To run with Docker: `docker run ssube/salty-dog:master`
|
|
|
|
|
|
|
|
To run after `yarn global add` or `npm i -g`: `salty-dog`
|
|
|
|
|
|
|
|
To run after building: `node out/bundle.js`
|
|
|
|
|
2019-06-16 02:08:21 +00:00
|
|
|
### Validate
|
2019-06-16 00:57:31 +00:00
|
|
|
|
2019-06-16 02:08:21 +00:00
|
|
|
`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
|
2019-06-16 00:57:31 +00:00
|
|
|
|
|
|
|
To validate a file:
|
|
|
|
|
2019-06-15 23:07:46 +00:00
|
|
|
```shell
|
2019-06-16 02:08:21 +00:00
|
|
|
> salty-dog \
|
|
|
|
--rules rules/kubernetes.yml \
|
2019-06-16 02:21:42 +00:00
|
|
|
--source examples/kubernetes-resources-fail.yml \
|
2019-06-16 02:08:21 +00:00
|
|
|
--tag important
|
2019-06-15 23:56:42 +00:00
|
|
|
|
2019-06-16 02:08:21 +00:00
|
|
|
...
|
2019-06-15 23:56:42 +00:00
|
|
|
[2019-06-15T23:56:04.764Z] ERROR: salty-dog/22211 on cerberus: some rules failed (errors=1)
|
|
|
|
|
2019-06-16 02:21:42 +00:00
|
|
|
> cat examples/kubernetes-resources-pass.yml | salty-dog \
|
2019-06-16 02:08:21 +00:00
|
|
|
--rules rules/kubernetes.yml \
|
|
|
|
--source - \
|
|
|
|
--tag important
|
2019-06-15 23:56:42 +00:00
|
|
|
|
2019-06-16 02:08:21 +00:00
|
|
|
...
|
2019-06-15 23:56:42 +00:00
|
|
|
[2019-06-15T23:53:34.223Z] INFO: salty-dog/19839 on cerberus: all rules passed
|
2019-06-15 23:07:46 +00:00
|
|
|
```
|
|
|
|
|
2019-06-16 02:08:21 +00:00
|
|
|
#### Validate URL
|
|
|
|
|
|
|
|
To validate a URL:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
> 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:
|
|
|
|
|
|
|
|
```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}
|
|
|
|
```
|
|
|
|
|
2019-06-15 23:07:46 +00:00
|
|
|
### Options
|
|
|
|
|
2019-06-15 23:36:44 +00:00
|
|
|
#### Count
|
|
|
|
|
|
|
|
- Alias: `c`
|
|
|
|
|
|
|
|
Exit with the error count (max of 255) rather than `0` or `1`.
|
|
|
|
|
2019-06-16 02:08:21 +00:00
|
|
|
#### Dest
|
|
|
|
|
|
|
|
- Alias: `d`
|
|
|
|
- Default: `-`
|
|
|
|
|
|
|
|
Path to write output data.
|
|
|
|
|
|
|
|
Defaults to stdout (`-`).
|
|
|
|
|
|
|
|
#### Format
|
|
|
|
|
|
|
|
- Default: `yaml`
|
|
|
|
|
|
|
|
Output format.
|
|
|
|
|
|
|
|
Options:
|
|
|
|
|
|
|
|
- `yaml`
|
|
|
|
|
2019-06-15 23:58:06 +00:00
|
|
|
#### Exclude
|
|
|
|
|
|
|
|
Excludes take priority over includes: a rule matching some of both will be excluded.
|
|
|
|
|
|
|
|
##### Exclude Level
|
2019-06-15 23:07:46 +00:00
|
|
|
|
|
|
|
Exclude rules by log level.
|
|
|
|
|
2019-06-15 23:58:06 +00:00
|
|
|
##### Exclude Name
|
2019-06-15 23:07:46 +00:00
|
|
|
|
|
|
|
Exclude rules by name.
|
|
|
|
|
2019-06-15 23:58:06 +00:00
|
|
|
##### Exclude Tag
|
2019-06-15 23:07:46 +00:00
|
|
|
|
|
|
|
Exclude rules by tag.
|
|
|
|
|
2019-06-15 23:58:06 +00:00
|
|
|
#### Include
|
|
|
|
|
|
|
|
##### Include Level
|
2019-06-15 23:07:46 +00:00
|
|
|
|
|
|
|
Include rules by log level.
|
|
|
|
|
2019-06-15 23:58:06 +00:00
|
|
|
##### Include Name
|
2019-06-15 23:07:46 +00:00
|
|
|
|
|
|
|
Include rules by name.
|
|
|
|
|
2019-06-15 23:58:06 +00:00
|
|
|
##### Include Tag
|
2019-06-15 23:07:46 +00:00
|
|
|
|
|
|
|
- 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
|
|
|
|
- `clean` runs each rule and updates the source data with any defaults or other changes before running the next rule
|
|
|
|
|
|
|
|
#### Rules
|
|
|
|
|
|
|
|
The path to a file containing some `rules`.
|
|
|
|
|
|
|
|
#### Source
|
|
|
|
|
|
|
|
- Alias: `s`
|
|
|
|
- Default: `-`
|
|
|
|
|
|
|
|
The source file to validate.
|
|
|
|
|
2019-06-16 02:13:15 +00:00
|
|
|
Defaults to stdin (`-`) to work with pipes: `cat file.yml | salty-dog --source -`
|