Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
samteb committed Feb 29, 2024
1 parent c6ab57a commit b2b729d
Show file tree
Hide file tree
Showing 8 changed files with 644 additions and 801 deletions.

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion apps/policy-engine/src/opa/script/data/users.json

This file was deleted.

1 change: 0 additions & 1 deletion apps/policy-engine/src/opa/script/data/wallets.json

This file was deleted.

27 changes: 10 additions & 17 deletions apps/policy-engine/src/opa/script/evaluate-legacy-policy.script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ import { loadPolicy } from '@open-policy-agent/opa-wasm'
import { readFileSync } from 'fs'
import path from 'path'
import { OpaResult, RegoInput } from '../../shared/types/domain.type'
import users from './data/users.json'
import wallets from './data/wallets.json'
import legacyRequests from './requests/legacy-requests.json'

export const run = async () => {
export const evaluate = async (users: any[], wallets: any[], legacyActivityRequests: any[]) => {
const entities: { [key: string]: any } = { users: {}, wallets: {} }

for (const user of users as any[]) {
for (const user of users) {
let role = user.guildUserRole

if (['SCHOLAR'].includes(role)) {
role = UserRole.MEMBER
} else if (['ADMIN', 'API'].includes(role)) {
role = UserRole.ADMIN
}

entities.users[user.id] = { uid: user.id, role }
}

for (const wallet of wallets as any[]) {
for (const wallet of wallets) {
const uid = `eip155:${wallet.accountType}:${wallet.address}`

entities.wallets[uid] = {
uid,
address: wallet.address,
Expand All @@ -32,7 +32,7 @@ export const run = async () => {
}
}

const requests = legacyRequests.filter(
const requests = legacyActivityRequests.filter(
({ initiator_user_id }) => undefined !== entities.users[initiator_user_id]
) as {
status: string
Expand Down Expand Up @@ -139,19 +139,12 @@ export const run = async () => {
const evalResult: { result: OpaResult }[] = await opaEngine.evaluate(input, 'main/evaluate')
const results = evalResult.map(({ result }) => result)

// if (status == 'denied' && results[0].permit) {
// // console.log({ id: results[0].reasons.map((reason) => reason.policyName), status, result: results[0].permit })
// if ((input.intent as any).type.includes('transfer')) {
// console.log({ intent: input.intent, initiator_user_id, status, result: results[0].permit })
// }
// }

if (status == 'completed' && !results[0].permit) {
console.log({ id: results[0].reasons.map((reason) => reason.policyName), status, result: results[0].permit })
}
}
}

run()
.then(() => console.log('done'))
.catch((error) => console.log('error', error))
// evaluate(users, wallets, requests)
// .then(() => console.log('done'))
// .catch((error) => console.log('error', error))

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit b2b729d

Please sign in to comment.