Skip to content

Commit 62fd30e

Browse files
Merge pull request #16 from OceanProtocolEnterprise/galex-dev
PolicyServer - accept policies as objects
2 parents cf5e7f2 + f03d238 commit 62fd30e

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/handlers/waltIdPolicyHandler.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,17 @@ export class WaltIdPolicyHandler extends PolicyHandler {
699699
const combinedCredentials = [
700700
...new Set([...credentialSubjectCredentials, ...serviceCredentials])
701701
]
702+
const normalizePolicies = (arr: any[]): string[] =>
703+
arr
704+
.map((p) =>
705+
typeof p === 'string'
706+
? p
707+
: p && typeof p === 'object' && typeof p.policy === 'string'
708+
? p.policy
709+
: null
710+
)
711+
.filter((p): p is string => !!p)
712+
702713
const vp_policies = new Set<string>()
703714
const vc_policies = new Set<string>()
704715

@@ -708,12 +719,8 @@ export class WaltIdPolicyHandler extends PolicyHandler {
708719
const envvc_policies = process.env.DEFAULT_VC_POLICIES
709720
? JSON.parse(process.env.DEFAULT_VC_POLICIES)
710721
: []
711-
712-
if (Array.isArray(envvp_policies))
713-
envvp_policies.forEach((policy: string) => vp_policies.add(policy))
714-
715-
if (Array.isArray(envvc_policies))
716-
envvc_policies.forEach((policy: string) => vc_policies.add(policy))
722+
normalizePolicies(envvp_policies).forEach((pol) => vp_policies.add(pol))
723+
normalizePolicies(envvc_policies).forEach((pol) => vc_policies.add(pol))
717724

718725
const request_credentialsMap = new Map<string, any>()
719726

0 commit comments

Comments
 (0)