Skip to content
Snippets Groups Projects
Commit f10a5b5d authored by Mohammad Torkashvand's avatar Mohammad Torkashvand
Browse files

integrate GUI with our custom OPA server

parent beb2692d
Branches
Tags
2 merge requests!16Develop,!7NAT-402/integrate GUI with our custom OPA server
Pipeline #85235 passed
......@@ -15,6 +15,7 @@ REACT_APP_OAUTH2_ENABLED=False
REACT_APP_OAUTH2_CLIENT_ID=
REACT_APP_OAUTH2_OPENID_CONNECT_URL=
REACT_APP_OAUTH2_SCOPE=
REACT_APP_OPA_BUNDLE_URL="http://localhost:8080/opa/bundles/policy.wasm"
# Needed because some libs misbehave
GENERATE_SOURCEMAP=false
......
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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment