mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
* Instructions for WASM/JS binding Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com> * Document Python, WASM/JS bindings Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com> --------- Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
48 lines
778 B
JavaScript
48 lines
778 B
JavaScript
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT License.
|
|
|
|
var regorus = require('./pkg/regorusjs')
|
|
|
|
// Create an engine.
|
|
var engine = new regorus.Engine();
|
|
|
|
// Add Rego policy.
|
|
engine.add_policy(
|
|
// Associate this file name with policy
|
|
'hello.rego',
|
|
|
|
// Rego policy
|
|
`
|
|
package test
|
|
|
|
# Join messages
|
|
message = concat(", ", [input.message, data.message])
|
|
`)
|
|
|
|
// Set policy data
|
|
engine.add_data_json(`
|
|
{
|
|
"message" : "World!"
|
|
}
|
|
`)
|
|
|
|
// Set policy input
|
|
engine.set_input_json(`
|
|
{
|
|
"message" : "Hello"
|
|
}
|
|
`)
|
|
|
|
// Eval query
|
|
results = engine.eval_query('data.test.message')
|
|
|
|
// Display
|
|
console.log(results)
|
|
|
|
// Convert results to object
|
|
results = JSON.parse(results)
|
|
|
|
// Process result
|
|
console.log(results.result[0].expressions[0].value)
|
|
|