Skip to content

Commit

Permalink
merge back
Browse files Browse the repository at this point in the history
  • Loading branch information
samteb committed Jan 23, 2024
1 parent a8ad057 commit ab4d641
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 31 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/authz_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,21 @@ jobs:
status: ${{ job.status }}
fields: message,commit,author
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}

opa-rego:
name: Open Agent Policy CI

runs-on: ubuntu-latest

steps:
- name: Check out repository code
uses: actions/checkout@v3

- name: Setup OPA
uses: open-policy-agent/setup-opa@v2
with:
version: latest

- name: Run OPA Tests
run: make authz/rego/test
25 changes: 0 additions & 25 deletions .github/workflows/authz_opa_ci.yml

This file was deleted.

14 changes: 9 additions & 5 deletions apps/authz/src/app/opa/opa.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,25 @@ export class OpaService {

constructor(private persistenceRepository: PersistenceRepository) {}

async onApplicationBootstrap() {
async onApplicationBootstrap(): Promise<void> {
this.logger.log('OPA Service boot')
this.opaEngine = await this.getOpaEngine()
}

async evaluate(input: RegoInput): Promise<OpaResult[]> {
this.opaEngine = await this.getOpaEngine()
const evalResult: { result: OpaResult }[] = await this.opaEngine.evaluate(input, 'main/evaluate')
return evalResult.map(({ result }) => result)
}

private async getOpaEngine(): Promise<OpaEngine> {
const policyWasmPath = OPA_WASM_PATH
const policyWasm = readFileSync(policyWasmPath)
const opaEngine = await loadPolicy(policyWasm, undefined, {
'time.now_ns': () => new Date().getTime() * 1000000
})
const data = await this.persistenceRepository.getEntityData()
opaEngine.setData(data)
this.opaEngine = opaEngine
if (!this.opaEngine) throw new Error('OPA Engine not initialized')
const evalResult: { result: OpaResult }[] = await this.opaEngine.evaluate(input, 'main/evaluate')
return evalResult.map(({ result }) => result)
return opaEngine
}
}

0 comments on commit ab4d641

Please sign in to comment.