From 5e05c72b7e7afa0ad05375baf884f8a4267badef Mon Sep 17 00:00:00 2001 From: ssube Date: Sat, 15 Jun 2019 18:07:46 -0500 Subject: [PATCH] feat: add modes, basic readme --- LICENSE.md | 21 ++++++++++++ README.md | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/index.ts | 19 +++++++---- src/rule.ts | 5 +-- 4 files changed, 125 insertions(+), 10 deletions(-) create mode 100644 LICENSE.md create mode 100644 README.md diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..3ead5f0 --- /dev/null +++ b/LICENSE.md @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..7bef7c4 --- /dev/null +++ b/README.md @@ -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 -` diff --git a/src/index.ts b/src/index.ts index 7f06c10..2ac86b0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -70,13 +70,20 @@ export async function main(argv: Array): Promise { // 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; diff --git a/src/rule.ts b/src/rule.ts index 6a6f873..fe55282 100644 --- a/src/rule.ts +++ b/src/rule.ts @@ -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)); } \ No newline at end of file