feat: add modes, basic readme
This commit is contained in:
parent
282e93d8c6
commit
5e05c72b7e
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018 Sean Sube
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -0,0 +1,90 @@
|
|||
# SALTY DOG
|
||||
|
||||
**S**chema **a**nalysis, **l**inting, and **t**ransformation for **Y**AML with **d**efaults, **o**ptional fields, and
|
||||
other **g**ood stuff.
|
||||
|
||||
- [SALTY DOG](#salty-dog)
|
||||
- [Build](#build)
|
||||
- [Usage](#usage)
|
||||
- [Options](#options)
|
||||
- [Exclude Level](#exclude-level)
|
||||
- [Exclude Name](#exclude-name)
|
||||
- [Exclude Tag](#exclude-tag)
|
||||
- [Include Level](#include-level)
|
||||
- [Include Name](#include-name)
|
||||
- [Include Tag](#include-tag)
|
||||
- [Mode](#mode)
|
||||
- [Rules](#rules)
|
||||
- [Source](#source)
|
||||
|
||||
## Build
|
||||
|
||||
```shell
|
||||
> git clone
|
||||
> make bundle
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```shell
|
||||
> cat rules/examples/kubernetes-require-resources-pass.yml |\
|
||||
node out/bundle.js \
|
||||
--rules rules/kubernetes.yml \
|
||||
--source - \
|
||||
--tag important
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
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 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
|
||||
- `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.
|
||||
|
||||
Defaults to stdin (`-`) to work with pipes: `cat file.yml | salty --source -`
|
19
src/index.ts
19
src/index.ts
|
@ -70,13 +70,20 @@ export async function main(argv: Array<string>): Promise<number> {
|
|||
|
||||
// run rules
|
||||
let status = STATUS_SUCCESS;
|
||||
for (const rule of activeRules) {
|
||||
if (checkRule(rule, data)) {
|
||||
logger.info({ rule }, 'passed rule');
|
||||
} else {
|
||||
logger.warn({ rule }, 'failed rule');
|
||||
switch (args.argv.mode) {
|
||||
case 'check':
|
||||
for (const rule of activeRules) {
|
||||
if (checkRule(rule, data)) {
|
||||
logger.info({ rule }, 'passed rule');
|
||||
} else {
|
||||
logger.warn({ rule }, 'failed rule');
|
||||
status = STATUS_ERROR;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
logger.error({ mode: args.argv.mode }, 'unsupported mode');
|
||||
status = STATUS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
|
|
|
@ -88,8 +88,5 @@ export function checkRule(rule: Rule, data: any): boolean {
|
|||
json: data,
|
||||
path: rule.nodes.select,
|
||||
});
|
||||
const valid = scopes.every((s: any) => schema(s));
|
||||
console.log(rule.nodes.select, scopes, valid, data, rule.schema);
|
||||
console.log(schema.errors);
|
||||
return !!valid;
|
||||
return scopes.every((s: any) => schema(s));
|
||||
}
|
Loading…
Reference in New Issue