Skip to content

Commit

Permalink
Fix: change function name to generate rego files (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
samteb authored Feb 21, 2024
1 parent be8e8a9 commit 23c2fc0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion apps/policy-engine/src/app/core/admin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down
7 changes: 3 additions & 4 deletions apps/policy-engine/src/app/opa/opa.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@ export class OpaService implements OnApplicationBootstrap {

async onApplicationBootstrap(): Promise<void> {
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.
})
this.opaEngine = opaEngine
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
}
Expand All @@ -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)
Expand Down

0 comments on commit 23c2fc0

Please sign in to comment.