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
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
!22
Feature/nat 569 add opa to gui2
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Feature/nat 569 add opa to gui2
feature/NAT-569-add-opa-to-gui2
into
develop
Overview
1
Commits
7
Pipelines
11
Changes
8
All threads resolved!
Hide all comments
Merged
Mohammad Torkashvand
requested to merge
feature/NAT-569-add-opa-to-gui2
into
develop
9 months ago
Overview
1
Commits
7
Pipelines
11
Changes
8
All threads resolved!
Hide all comments
Expand
0
0
Merge request reports
Compare
develop
version 10
55527a9e
9 months ago
version 9
ca52c977
9 months ago
version 8
9d671fe3
9 months ago
version 7
d653997d
9 months ago
version 6
97226dec
9 months ago
version 5
b722223a
9 months ago
version 4
7bc84281
9 months ago
version 3
7906b4dc
9 months ago
version 2
3610e240
9 months ago
version 1
8bca5959
9 months ago
develop (base)
and
latest version
latest version
cac94455
7 commits,
9 months ago
version 10
55527a9e
6 commits,
9 months ago
version 9
ca52c977
5 commits,
9 months ago
version 8
9d671fe3
4 commits,
9 months ago
version 7
d653997d
3 commits,
9 months ago
version 6
97226dec
3 commits,
9 months ago
version 5
b722223a
3 commits,
9 months ago
version 4
7bc84281
2 commits,
9 months ago
version 3
7906b4dc
4 commits,
9 months ago
version 2
3610e240
3 commits,
9 months ago
version 1
8bca5959
3 commits,
9 months ago
8 files
+
566
−
1101
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
8
Search (e.g. *.vue) (Ctrl+P)
components/WfoAuthWithPolicy.tsx
0 → 100644
+
114
−
0
Options
import
{
useGsoConfig
}
from
'
@/contexts/GsoConfigContext
'
;
import
{
LoadedPolicy
,
loadPolicy
}
from
'
@open-policy-agent/opa-wasm
'
;
import
{
OrchestratorConfigContext
,
WfoAuth
,
WfoLoading
,
useWfoSession
,
}
from
'
@orchestrator-ui/orchestrator-ui-components
'
;
import
{
join
}
from
'
lodash
'
;
import
React
,
{
FC
,
ReactNode
,
useContext
,
useEffect
,
useState
}
from
'
react
'
;
export
type
WfoAuthWithPolicyProps
=
{
children
:
ReactNode
;
};
export
enum
PolicyLoadingStatus
{
LOADING
=
'
loading
'
,
SUCCESS
=
'
success
'
,
FAILED
=
'
failed
'
,
NOT_LOADED
=
'
notLoaded
'
,
}
type
Policy
=
|
{
loadedPolicy
:
LoadedPolicy
;
policyLoadingStatus
:
PolicyLoadingStatus
.
SUCCESS
;
}
|
{
loadedPolicy
:
null
;
policyLoadingStatus
:
|
PolicyLoadingStatus
.
LOADING
|
PolicyLoadingStatus
.
FAILED
|
PolicyLoadingStatus
.
NOT_LOADED
;
};
export
const
WfoAuthWithPolicy
:
FC
<
WfoAuthWithPolicyProps
>
=
({
children
})
=>
{
const
{
authActive
}
=
useContext
(
OrchestratorConfigContext
);
const
{
opaPublicBundleUrl
,
oidcClientId
}
=
useGsoConfig
();
const
{
status
:
sessionStatus
,
session
}
=
useWfoSession
({
required
:
authActive
,
});
const
[
policy
,
setPolicy
]
=
useState
<
Policy
>
({
loadedPolicy
:
null
,
policyLoadingStatus
:
PolicyLoadingStatus
.
LOADING
,
});
useEffect
(()
=>
{
const
getPolicy
=
async
()
=>
{
try
{
const
policyResult
=
await
fetch
(
opaPublicBundleUrl
);
const
policyWasm
=
await
policyResult
.
arrayBuffer
();
const
loadedPolicy
=
await
loadPolicy
(
policyWasm
);
setPolicy
({
loadedPolicy
,
policyLoadingStatus
:
PolicyLoadingStatus
.
SUCCESS
,
});
}
catch
(
e
)
{
console
.
error
(
'
Failed to load policy
'
,
e
);
setPolicy
({
loadedPolicy
:
null
,
policyLoadingStatus
:
PolicyLoadingStatus
.
FAILED
,
});
}
};
// When auth is disabled, the policy should not be loaded
if
(
!
authActive
)
{
setPolicy
({
loadedPolicy
:
null
,
policyLoadingStatus
:
PolicyLoadingStatus
.
NOT_LOADED
,
});
return
;
}
getPolicy
();
},
[
authActive
,
opaPublicBundleUrl
,
oidcClientId
]);
const
isAllowedHandler
=
(
routerPath
:
string
,
resource
?:
string
)
=>
{
if
(
session
&&
policy
.
policyLoadingStatus
===
PolicyLoadingStatus
.
SUCCESS
)
{
const
{
profile
}
=
session
;
// Fix unexpected scope array
if
(
profile
&&
Array
.
isArray
(
profile
.
scope
))
{
profile
.
scope
=
join
(
profile
.
scope
,
'
'
);
}
const
policyInput
=
{
resource
:
resource
??
routerPath
,
active
:
true
,
client_id
:
oidcClientId
,
method
:
'
GET
'
,
...
profile
,
};
const
policyTestResult
=
policy
.
loadedPolicy
.
evaluate
(
policyInput
);
return
policyTestResult
[
0
].
result
===
true
;
}
return
false
;
};
if
(
policy
.
policyLoadingStatus
===
PolicyLoadingStatus
.
LOADING
||
sessionStatus
===
'
loading
'
)
{
return
<
WfoLoading
/>;
}
return
authActive
?
(
<
WfoAuth
isAllowedHandler
=
{
isAllowedHandler
}
>
{
children
}
</
WfoAuth
>
)
:
(
<
WfoAuth
>
{
children
}
</
WfoAuth
>
);
};
Loading