npm

Need private packages and team management tools?Check out npm Orgs. »

opa-compile-response-parser

1.0.4 • Public • Published

opa-compile-response-parser

GitHub stars npm version unpkg npm bundle size (minified + gzip) Build Status

An Open Policy Agent Compile Response Parser

Open Policy Agent provides a compile API that allows you partially evaluate your policy.

This library can parse the compile JSON response and allow you to access the Rego AST (Abstract Syntax Tree) in the response body by Rego language structure.

Moreover, it further processes the AST to:

  • eliminate tautological rules
    • e.g. r { x; false }
  • replace rule reference with inline value
    • e.g. r1 { r2 } r2 { true } => r1 { true }

API document

https://t83714.github.io/opa-compile-response-parser/

Examples

import OpaCompileResponseParser from "opa-compile-response-parser";
 
const parser = new OpaCompileResponseParser();
parser.parse(jsonResponse);
 
const result = parser.evaluate();
/**
 returned evaluate result:
    interface CompleteRuleResult {
        fullName: string;
        name: string;
        value: RegoValue;
        isCompleteEvaluated: boolean;
        residualRules?: RegoRule[];
    }
*/
 
// --- Print residual rules as human readable string
console.log(parser.evaluateAsHumanReadableString());

More Examples

Todo

  • replace rule reference with inline rules

Compatibility

Work with Open Policy Agent version 0.11.0 or higher.

install

npm i opa-compile-response-parser

Downloadsweekly downloads

15

version

1.0.4

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability