Skip to content

Commit

Permalink
policies: update for OPA v1
Browse files Browse the repository at this point in the history
Signed-off-by: Stephan Renatus <[email protected]>
  • Loading branch information
srenatus committed Jan 8, 2025
1 parent a1bef55 commit c947c0a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion policies/aspnetcore.rego
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ main := x if {
},
},
}
}
}
90 changes: 45 additions & 45 deletions policies/spring.rego
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
package tickets.spring

default main = {"decision": false}
import rego.v1

default main := {"decision": false}

authHeader := input.action.headers.authorization

tenant := trim(split(split(authHeader, "/")[0], " ")[1], " \t")

user := trim(split(authHeader, "/")[1], " \t")

action = a {
input.action.name == "GET"
input.resource.id == "/tickets"
a := "list"
} else = a {
input.action.name == "GET"
regex.match("^/tickets/[0-9]+$", input.resource.id)
a := "get"
} else = a {
input.action.name == "POST"
input.resource.id == "/tickets"
a := "create"
} else = a {
input.action.name == "PUT"
regex.match("^/tickets/[0-9]+$", input.resource.id)
a := "overwrite"
} else = a {
input.action.name == "POST"
regex.match("^/tickets/[0-9]+/resolve$", input.resource.id)
a := "resolve"
action := a if {
input.action.name == "GET"
input.resource.id == "/tickets"
a := "list"
} else := a if {
input.action.name == "GET"
regex.match("^/tickets/[0-9]+$", input.resource.id)
a := "get"
} else := a if {
input.action.name == "POST"
input.resource.id == "/tickets"
a := "create"
} else := a if {
input.action.name == "PUT"
regex.match("^/tickets/[0-9]+$", input.resource.id)
a := "overwrite"
} else := a if {
input.action.name == "POST"
regex.match("^/tickets/[0-9]+/resolve$", input.resource.id)
a := "resolve"
}

xform := {
"user": user,
"tenant": tenant,
"action": action,
"user": user,
"tenant": tenant,
"action": action,
}

main = x {
d := data.tickets.allow with input as xform
reason_user := data.tickets.reason_user with input as xform
reason_admin := data.tickets.reason_admin with input as xform
x := {
"decision": d,
"context": {
"id": "0",
"reason_user": {
"en": reason_user
},
"reason_admin": {
"en": reason_admin
},
"data": {
"echo": input,
"tenant": tenant,
"user": user,
}
}
}
main := x if {
d := data.tickets.allow with input as xform
reason_user := data.tickets.reason_user with input as xform
reason_admin := data.tickets.reason_admin with input as xform
x := {
"decision": d,
"context": {
"id": "0",
"reason_user": {"en": reason_user},
"reason_admin": {"en": reason_admin},
"data": {
"echo": input,
"tenant": tenant,
"user": user,
},
},
}
}

0 comments on commit c947c0a

Please sign in to comment.