Skip to content

Commit

Permalink
feat: use firebase-json to load rules
Browse files Browse the repository at this point in the history
targaryen cli now load rules using firebase-json which support comments and multi lines string.

Fix #30
  • Loading branch information
dinoboff committed Jan 4, 2017
1 parent 97f3de0 commit c52281e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
6 changes: 2 additions & 4 deletions bin/targaryen
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

'use strict';

const fs = require('fs');
const stripJsonComments = require('strip-json-comments');
const json = require('firebase-json');

const path = require('path');
const Table = require('cli-table');
Expand All @@ -21,8 +20,7 @@ if (argv._.length < 2) {

const rulesJSONPath = path.resolve(argv._[0]);
const testJSONPath = path.resolve(argv._[1]);
const rulesJSONFile = fs.readFileSync(rulesJSONPath);
const rules = JSON.parse(stripJsonComments(rulesJSONFile.toString()));
const rules = json.loadSync(rulesJSONPath, 'utf8');
const tests = require(testJSONPath);

const jig = new TestJig(rules, tests);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"colors": "^1.0.3",
"debug": "^2.3.3",
"esprima": "^1.2.2",
"firebase-json": "^0.1.0",
"firebase-token-generator": "^2.0.0",
"lodash.set": "^4.3.2",
"minimist": "^1.1.0",
Expand Down
12 changes: 11 additions & 1 deletion test/integration/rules.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
{
"rules": {
"posts": {
/**
* Post.
*
* Read: anybody with the correct clearance level; each post has its own level requirement
* Write: by the author only.
*/
"$post": {
".read": "root.child('users').child(auth.uid).child('clearance-level').val() >= data.child('clearance-level').val()",
".write": "root.child('users').child(auth.uid).child('author').val() === true",
".validate": "newData.hasChildren() && newData.hasChild('date')",
"date": {
".validate": "data.parent().exists() === false && newData.val() <= now"
".validate": "
data.parent().exists() === false
&& newData.val() <= now
"
}
}
},
"flight-routes": {
// Flight routes are public and can be added/edited bu ticket agents
"$from": {
"$to": {
".read": "true",
Expand Down

0 comments on commit c52281e

Please sign in to comment.