Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GÉANT Service Orchestrator GUI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GÉANT Orchestration and Automation Team
GAP
GÉANT Service Orchestrator GUI
Merge requests
!7
NAT-402/integrate GUI with our custom OPA server
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
NAT-402/integrate GUI with our custom OPA server
feature/NAT-402-integrate-with-custom-opa
into
develop
Overview
0
Commits
1
Pipelines
0
Changes
2
Merged
Mohammad Torkashvand
requested to merge
feature/NAT-402-integrate-with-custom-opa
into
develop
1 year ago
Overview
0
Commits
1
Pipelines
0
Changes
2
Expand
0
0
Merge request reports
Viewing commit
f10a5b5d
Show latest version
2 files
+
29
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
f10a5b5d
integrate GUI with our custom OPA server
· f10a5b5d
Mohammad Torkashvand
authored
1 year ago
src/utils/policy.ts
+
28
−
1
Options
import
{
loadPolicy
}
from
"
@open-policy-agent/opa-wasm
"
;
export
async
function
createPolicyCheck
(
user
?:
Partial
<
Oidc
.
Profile
>
)
{
if
(
!
user
)
{
return
()
=>
true
;
}
const
opaBundletUrl
=
process
.
env
.
REACT_APP_OPA_BUNDLE_URL
;
if
(
typeof
opaBundletUrl
===
'
undefined
'
)
{
throw
new
Error
(
'
REACT_APP_OPA_BUNDLE_URL is not defined
'
);
}
const
policyResult
=
await
fetch
(
opaBundletUrl
);
const
policyWasm
=
await
policyResult
.
arrayBuffer
();
try
{
const
policy
=
await
loadPolicy
(
policyWasm
);
function
allowed
(
resource
:
string
):
boolean
{
return
true
;
const
input
:
any
=
{
resource
:
resource
,
method
:
"
GET
"
,
...
user
,
};
const
resultSet
=
policy
.
evaluate
(
input
);
if
(
resultSet
==
null
||
resultSet
.
length
===
0
)
{
console
.
error
(
"
evaluation error
"
,
resultSet
);
return
false
;
}
return
resultSet
[
0
].
result
;
}
return
allowed
;
}
catch
{
Loading