mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
* FFI bindings Generate C FFI as well as C# FFI Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com> * Regorus C binding Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com> * C# binding Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com> * Golang binding Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com> --------- Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
56 lines
1.4 KiB
C
56 lines
1.4 KiB
C
#include <stdio.h>
|
|
#include "regorus.h"
|
|
|
|
int main() {
|
|
// Create engine.
|
|
RegorusEngine* engine = regorus_engine_new();
|
|
RegorusResult r;
|
|
|
|
// Load policies.
|
|
r = regorus_engine_add_policy_from_file(engine, "../../../tests/aci/framework.rego");
|
|
if (r.status != RegorusStatusOk)
|
|
goto error;
|
|
regorus_result_drop(r);
|
|
|
|
r = regorus_engine_add_policy_from_file(engine, "../../../tests/aci/api.rego");
|
|
if (r.status != RegorusStatusOk)
|
|
goto error;
|
|
regorus_result_drop(r);
|
|
|
|
r = regorus_engine_add_policy_from_file(engine, "../../../tests/aci/policy.rego");
|
|
if (r.status != RegorusStatusOk)
|
|
goto error;
|
|
regorus_result_drop(r);
|
|
|
|
// Add data
|
|
r = regorus_engine_add_data_from_json_file(engine, "../../../tests/aci/data.json");
|
|
if (r.status != RegorusStatusOk)
|
|
goto error;
|
|
regorus_result_drop(r);
|
|
|
|
// Set input
|
|
r = regorus_engine_set_input_from_json_file(engine, "../../../tests/aci/input.json");
|
|
if (r.status != RegorusStatusOk)
|
|
goto error;
|
|
regorus_result_drop(r);
|
|
|
|
// Eval query
|
|
r = regorus_engine_eval_query(engine, "data.framework.mount_overlay=x");
|
|
if (r.status != RegorusStatusOk)
|
|
goto error;
|
|
|
|
// Print output
|
|
printf("%s", r.output);
|
|
regorus_result_drop(r);
|
|
|
|
|
|
// Free the engine.
|
|
regorus_engine_drop(engine);
|
|
|
|
return 0;
|
|
error:
|
|
printf("%s", r.error_message);
|
|
|
|
return 1;
|
|
}
|