From 23c2fc0fda89b21063861b52a04b1f71d623b3c8 Mon Sep 17 00:00:00 2001 From: Samuel Date: Wed, 21 Feb 2024 16:33:59 +0100 Subject: [PATCH] Fix: change function name to generate rego files (#128) --- apps/policy-engine/src/app/core/admin.service.ts | 2 +- apps/policy-engine/src/app/opa/opa.service.ts | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/policy-engine/src/app/core/admin.service.ts b/apps/policy-engine/src/app/core/admin.service.ts index 7d637749d..99ac6858d 100644 --- a/apps/policy-engine/src/app/core/admin.service.ts +++ b/apps/policy-engine/src/app/core/admin.service.ts @@ -7,7 +7,7 @@ export class AdminService { constructor(private opaService: OpaService) {} async setPolicyRules(payload: SetPolicyRulesRequest): Promise<{ fileId: string; policies: Policy[] }> { - const { fileId, policies } = this.opaService.buildPoliciesWasm(payload.request.data) + const { fileId, policies } = this.opaService.generateRegoPolicies(payload.request.data) return { fileId, policies } } diff --git a/apps/policy-engine/src/app/opa/opa.service.ts b/apps/policy-engine/src/app/opa/opa.service.ts index 43513e917..1952409b5 100644 --- a/apps/policy-engine/src/app/opa/opa.service.ts +++ b/apps/policy-engine/src/app/opa/opa.service.ts @@ -26,9 +26,8 @@ export class OpaService implements OnApplicationBootstrap { async onApplicationBootstrap(): Promise { this.logger.log('OPA Service boot') - const policyWasmPath = OPA_WASM_PATH try { - const policyWasm = readFileSync(policyWasmPath) + const policyWasm = readFileSync(OPA_WASM_PATH) const opaEngine = await loadPolicy(policyWasm, undefined, { 'time.now_ns': () => new Date().getTime() * 1000000 // TODO: @sam this happens on app bootstrap one time; if you need a timestamp per-request then this needs to be passed in w/ Entity data not into the Policy. }) @@ -36,7 +35,7 @@ export class OpaService implements OnApplicationBootstrap { await this.reloadEntityData() } catch (err) { if (err.code === 'ENOENT') { - this.logger.error(`Policy wasm not found at ${policyWasmPath}`) + this.logger.error(`Policy wasm not found at ${OPA_WASM_PATH}`) } else { throw err } @@ -49,7 +48,7 @@ export class OpaService implements OnApplicationBootstrap { return evalResult.map(({ result }) => result) } - buildPoliciesWasm(payload: Policy[]): { fileId: string; policies: Policy[] } { + generateRegoPolicies(payload: Policy[]): { fileId: string; policies: Policy[] } { Handlebars.registerHelper('criterion', criterionToString) Handlebars.registerHelper('reason', reasonToString)