diff options
| author | Adam Ierymenko <[email protected]> | 2017-03-14 21:21:12 -0700 |
|---|---|---|
| committer | Adam Ierymenko <[email protected]> | 2017-03-14 21:21:12 -0700 |
| commit | 1ef3069a7ef7692bb27d64b85dd2cfdf201e33b2 (patch) | |
| tree | 52d01244e956e5e2778f1cff9604fcaea9917d96 /rule-compiler | |
| parent | f99b62c48d6cb9d1b79a67cb3cf5ae5e352a176b (diff) | |
1.2.0 release notes and a few final tweaks and cleanup.
Diffstat (limited to 'rule-compiler')
| -rw-r--r-- | rule-compiler/README.md | 3 | ||||
| -rw-r--r-- | rule-compiler/cli.js | 35 | ||||
| -rw-r--r-- | rule-compiler/package.json | 2 |
3 files changed, 30 insertions, 10 deletions
diff --git a/rule-compiler/README.md b/rule-compiler/README.md index e3aa2615..1ceeb713 100644 --- a/rule-compiler/README.md +++ b/rule-compiler/README.md @@ -3,3 +3,6 @@ ZeroTier Rules Compiler This script converts ZeroTier rules in human-readable format into rules suitable for import into a ZeroTier network controller. It's the script that is used in the rules editor on [ZeroTier Central](https://my.zerotier.com/). +A command line interface is included that may be invoked as: `node cli.js <rules script>`. + +See the [manual](https://www.zerotier.com/manual.shtml) for information about the rules engine and rules script syntax. diff --git a/rule-compiler/cli.js b/rule-compiler/cli.js index c4a3b291..a0ff5197 100644 --- a/rule-compiler/cli.js +++ b/rule-compiler/cli.js @@ -1,7 +1,6 @@ 'use strict'; var fs = require('fs'); - var RuleCompiler = require('./rule-compiler.js'); if (process.argv.length < 3) { @@ -9,21 +8,39 @@ if (process.argv.length < 3) { process.exit(1); } -var src = fs.readFileSync(process.argv[2]).toString(); - var rules = []; var caps = {}; var tags = {}; -var err = RuleCompiler.compile(src,rules,caps,tags); +var err = RuleCompiler.compile(fs.readFileSync(process.argv[2]).toString(),rules,caps,tags); if (err) { - console.log('ERROR parsing '+process.argv[2]+' line '+err[0]+' column '+err[1]+': '+err[2]); + console.error('ERROR parsing '+process.argv[2]+' line '+err[0]+' column '+err[1]+': '+err[2]); process.exit(1); } else { + let capsArray = []; + let capabilitiesByName = {}; + for(let n in caps) { + capsArray.push(caps[n]); + capabilitiesByName[n] = caps[n].id; + } + let tagsArray = []; + for(let n in tags) { + let t = tags[n]; + tagsArray.push({ + 'id': t.id, + 'default': t['default']||null + }); + } + console.log(JSON.stringify({ - rules: rules, - caps: caps, - tags: tags - },null,2)); + config: { + rules: rules, + capabilities: capsArray, + tags: tagsArray + }, + capabilitiesByName: capabilitiesByName, + tagsByName: tags + },null,1)); + process.exit(0); } diff --git a/rule-compiler/package.json b/rule-compiler/package.json index 451295a4..e12d3759 100644 --- a/rule-compiler/package.json +++ b/rule-compiler/package.json @@ -1,6 +1,6 @@ { "name": "zerotier-rule-compiler", - "version": "1.1.17-3", + "version": "1.2.0-1", "description": "ZeroTier Rule Script Compiler", "main": "cli.js", "scripts": { |
