Skip to content

Commit

Permalink
Set data in the Open Policy Agent instance
Browse files Browse the repository at this point in the history
  • Loading branch information
wcalderipe committed Mar 18, 2024
1 parent 5e0bbe8 commit 75a9be5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ import { loadPolicy } from '@open-policy-agent/opa-wasm'
import { resolve } from 'path'
import { v4 } from 'uuid'
import { OpenPolicyAgentException } from './exception/open-policy-agent.exception'
import { OpenPolicyAgentPolicy } from './type/open-policy-agent.type'

Check failure on line 7 in apps/policy-engine/src/open-policy-agent/core/open-policy-agent.engine.ts

View workflow job for this annotation

GitHub Actions / Build and test

Module '"./type/open-policy-agent.type"' has no exported member 'OpenPolicyAgentPolicy'.
import { toData } from './util/evaluation.util'
import { build } from './util/wasm-build.util'

type PromiseType<T extends Promise<unknown>> = T extends Promise<infer U> ? U : never

type OpaEngine = PromiseType<ReturnType<typeof loadPolicy>>

export class OpenPolicyAgentEngine implements Engine<OpenPolicyAgentEngine> {
private policies: Policy[]

private entities: Entities

private opa?: OpaEngine
private opa?: OpenPolicyAgentPolicy

constructor(policies?: Policy[], entities?: Entities) {
this.entities = entities || {
Expand Down Expand Up @@ -44,7 +42,7 @@ export class OpenPolicyAgentEngine implements Engine<OpenPolicyAgentEngine> {
return this.policies
}

getOpenPolicyAgentInstance(): OpaEngine | undefined {
getOpenPolicyAgentPolicy(): OpenPolicyAgentPolicy | undefined {
return this.opa
}

Expand All @@ -70,6 +68,8 @@ export class OpenPolicyAgentEngine implements Engine<OpenPolicyAgentEngine> {
'time.now_ns': () => new Date().getTime() * 1000000
})

this.opa.setData(toData(this.getEntities()))

return this
} catch (error) {
throw new OpenPolicyAgentException({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import {
UserRole
} from '@narval/policy-engine-shared'
import { Intent } from '@narval/transaction-request-intent'
import { loadPolicy } from '@open-policy-agent/opa-wasm'

type PromiseType<T extends Promise<unknown>> = T extends Promise<infer U> ? U : never

export type OpenPolicyAgentInstance = PromiseType<ReturnType<typeof loadPolicy>>

export type Input = {
action: Action
Expand Down

0 comments on commit 75a9be5

Please sign in to comment.