Skip to content
Snippets Groups Projects

NAT-402/integrate GUI with our custom OPA server

Merged Mohammad Torkashvand requested to merge feature/NAT-402-integrate-with-custom-opa into develop
2 files
+ 29
1
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 28
1
import { loadPolicy } from "@open-policy-agent/opa-wasm";
export async function createPolicyCheck(user?: Partial<Oidc.Profile>) {
if (!user) {
return () => true;
}
const opaBundletUrl = process.env.REACT_APP_OPA_BUNDLE_URL;
if (typeof opaBundletUrl === 'undefined') {
throw new Error('REACT_APP_OPA_BUNDLE_URL is not defined');
}
const policyResult = await fetch(opaBundletUrl);
const policyWasm = await policyResult.arrayBuffer();
try {
const policy = await loadPolicy(policyWasm);
function allowed(resource: string): boolean {
return true;
const input: any = {
resource: resource,
method: "GET",
...user,
};
const resultSet = policy.evaluate(input);
if (resultSet == null || resultSet.length === 0) {
console.error("evaluation error", resultSet);
return false;
}
return resultSet[0].result;
}
return allowed;
} catch {
Loading