Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
policy
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Wiki
Code
Merge requests
2
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gaia-X
Trust Services API
policy
Commits
0ce1f19f
Commit
0ce1f19f
authored
2 years ago
by
Lyuben Penkovski
Browse files
Options
Downloads
Patches
Plain Diff
Rego function to retrieve issuer DID from signer
parent
431f36a5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!29
Rego extension function to retrieve organization DID (issuer of proofs)
Pipeline
#52132
passed with stages
Stage:
Stage:
Stage:
in 1 minute and 14 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+6
-5
6 additions, 5 deletions
README.md
cmd/policy/main.go
+2
-1
2 additions, 1 deletion
cmd/policy/main.go
internal/regofunc/pubkeys.go
+36
-0
36 additions, 0 deletions
internal/regofunc/pubkeys.go
with
44 additions
and
6 deletions
README.md
+
6
−
5
View file @
0ce1f19f
...
...
@@ -30,7 +30,7 @@ flowchart LR
The policy service exposes HTTP endpoints to evaluate/execute policies.
The endpoint interface is conformant to the TSA requirements document.
To evaluate a policy a POST request is sent to the evaluation URL.
To evaluate a policy a
GET or
POST request is sent to the evaluation URL.
The example URL below is given for the local docker-compose environment.
The
`host`
and
`port`
parts will be different for the different environments.
...
...
@@ -48,10 +48,11 @@ are also important during policy development (see below) as `group`
and
`policy`
**must**
be used as package name inside the policy
source code file.
The body of the POST request
**must**
be JSON and it is passed directly
to the policy execution runtime. Inside the policy it is accessed with
the global variable name
`input`
. For example, if you pass to the evaluation
endpoint the following JSON, it will be accessible by
`input.message`
:
The body of the POST request can be empty, but if it's not empty, it
**must**
be JSON. It is passed directly to the policy execution runtime.
Inside the policy it is accessed with the global variable name
`input`
.
For example, if you pass to the evaluation endpoint the following JSON,
it will be accessible by
`input.message`
:
```
json
{
"message"
:
"hello world"
...
...
This diff is collapsed.
Click to expand it.
cmd/policy/main.go
+
2
−
1
View file @
0ce1f19f
...
...
@@ -90,7 +90,8 @@ func main() {
regofunc
.
Register
(
"taskListCreate"
,
rego
.
Function2
(
taskFuncs
.
CreateTaskListFunc
()))
regofunc
.
Register
(
"getKey"
,
rego
.
Function1
(
keysFuncs
.
GetKeyFunc
()))
regofunc
.
Register
(
"getAllKeys"
,
rego
.
FunctionDyn
(
keysFuncs
.
GetAllKeysFunc
()))
regofunc
.
Register
(
"strictBuiltinErrors"
,
rego
.
StrictBuiltinErrors
(
true
))
regofunc
.
Register
(
"getAllKeys"
,
rego
.
FunctionDyn
(
keysFuncs
.
GetAllKeysFunc
()))
regofunc
.
Register
(
"issuer"
,
rego
.
FunctionDyn
(
keysFuncs
.
IssuerDID
()))
}
// subscribe the cache for policy data changes
...
...
This diff is collapsed.
Click to expand it.
internal/regofunc/pubkeys.go
+
36
−
0
View file @
0ce1f19f
...
...
@@ -103,3 +103,39 @@ func (pf *PubkeyFuncs) GetAllKeysFunc() (*rego.Function, rego.BuiltinDyn) {
return
ast
.
NewTerm
(
v
),
nil
}
}
func
(
pf
*
PubkeyFuncs
)
IssuerDID
()
(
*
rego
.
Function
,
rego
.
BuiltinDyn
)
{
return
&
rego
.
Function
{
Name
:
"issuer"
,
Decl
:
types
.
NewFunction
(
nil
,
types
.
A
),
Memoize
:
true
,
},
func
(
bctx
rego
.
BuiltinContext
,
terms
[]
*
ast
.
Term
)
(
*
ast
.
Term
,
error
)
{
uri
,
err
:=
url
.
ParseRequestURI
(
pf
.
signerAddr
+
"/v1/issuerDID"
)
if
err
!=
nil
{
return
nil
,
err
}
req
,
err
:=
http
.
NewRequest
(
"GET"
,
uri
.
String
(),
nil
)
if
err
!=
nil
{
return
nil
,
err
}
resp
,
err
:=
pf
.
httpClient
.
Do
(
req
.
WithContext
(
bctx
.
Context
))
if
err
!=
nil
{
return
nil
,
err
}
defer
resp
.
Body
.
Close
()
// nolint:errcheck
if
resp
.
StatusCode
!=
http
.
StatusOK
{
return
nil
,
fmt
.
Errorf
(
"unexpected response from signer: %s"
,
resp
.
Status
)
}
v
,
err
:=
ast
.
ValueFromReader
(
resp
.
Body
)
if
err
!=
nil
{
return
nil
,
err
}
return
ast
.
NewTerm
(
v
),
nil
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment