summaryrefslogtreecommitdiff
path: root/pkg/gid
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-04-02 13:32:22 -0600
committermo khan <mo@mokhan.ca>2025-04-02 13:32:22 -0600
commit894e270ab5a15de2b664cc6f4ee6fd8369985f75 (patch)
treed778e426fcd1666dd35d978215434103e78acee8 /pkg/gid
parent2a37de4a34552feac221771278236fb23f8e83c0 (diff)
refactor: combine cedar policies and add tests
Diffstat (limited to 'pkg/gid')
-rw-r--r--pkg/gid/gid.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/pkg/gid/gid.go b/pkg/gid/gid.go
new file mode 100644
index 0000000..e82b073
--- /dev/null
+++ b/pkg/gid/gid.go
@@ -0,0 +1,20 @@
+package gid
+
+import (
+ "net/url"
+ "strings"
+
+ "github.com/cedar-policy/cedar-go"
+)
+
+func NewEntityUID(globalID string) cedar.EntityUID {
+ url, err := url.Parse(globalID)
+ if err != nil {
+ return cedar.NewEntityUID("User", cedar.String(globalID))
+ }
+
+ return cedar.NewEntityUID(
+ cedar.EntityType(url.Hostname()),
+ cedar.String(strings.TrimPrefix(url.Path, "/")),
+ )
+}