diff options
| author | mo khan <mo@mokhan.ca> | 2025-07-23 11:50:42 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-07-23 11:50:42 -0600 |
| commit | 944ef4ca499fe27a57d4cd3c21bccb99508526ca (patch) | |
| tree | 3c929141ee07fc2a4f2c2b825630cb2ad3121b44 /app/domain | |
| parent | 8a1b03afb949a5a3be6a78e9b2c88d2e48643f46 (diff) | |
refactor: Update RequirePermission middleware to connect to spicedb CheckPermission API
Diffstat (limited to 'app/domain')
| -rw-r--r-- | app/domain/identifiable.go | 6 | ||||
| -rw-r--r-- | app/domain/sparkle.go | 8 | ||||
| -rw-r--r-- | app/domain/user.go | 13 |
3 files changed, 25 insertions, 2 deletions
diff --git a/app/domain/identifiable.go b/app/domain/identifiable.go index 06bec07..190f20c 100644 --- a/app/domain/identifiable.go +++ b/app/domain/identifiable.go @@ -1,11 +1,15 @@ package domain -import "github.com/xlgmokha/x/pkg/x" +import ( + v1 "github.com/authzed/authzed-go/proto/authzed/api/v1" + "github.com/xlgmokha/x/pkg/x" +) type Identifiable interface { GetID() ID SetID(id ID) error ToGID() string + ToObjectReference() *v1.ObjectReference } func WithID[T Identifiable](id ID) x.Configure[T] { diff --git a/app/domain/sparkle.go b/app/domain/sparkle.go index d4f70b2..2ea5a53 100644 --- a/app/domain/sparkle.go +++ b/app/domain/sparkle.go @@ -4,6 +4,7 @@ import ( "errors" "regexp" + v1 "github.com/authzed/authzed-go/proto/authzed/api/v1" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/pls" ) @@ -53,6 +54,13 @@ func (s *Sparkle) ToGID() string { return "gid://sparkle/Sparkle/" + s.ID.String() } +func (self *Sparkle) ToObjectReference() *v1.ObjectReference { + return &v1.ObjectReference{ + ObjectType: "sparkle", + ObjectId: self.ID.String(), + } +} + func (s *Sparkle) Validate() error { if s.Sparklee == "" { return SparkleeIsRequired diff --git a/app/domain/user.go b/app/domain/user.go index 52cd780..88930c5 100644 --- a/app/domain/user.go +++ b/app/domain/user.go @@ -1,6 +1,9 @@ package domain -import "github.com/xlgmokha/x/pkg/x" +import ( + v1 "github.com/authzed/authzed-go/proto/authzed/api/v1" + "github.com/xlgmokha/x/pkg/x" +) type User struct { ID ID `json:"id" jsonapi:"primary,users"` @@ -37,3 +40,11 @@ func (self *User) Sparkle(sparklee string, reason string) *Sparkle { func (self *User) ToGID() string { return "gid://sparkle/User/" + self.ID.String() } + +func (self *User) ToObjectReference() *v1.ObjectReference { + // TODO:: Username is easy for demos but will need to change to ID + return &v1.ObjectReference{ + ObjectType: "user", + ObjectId: self.Username, + } +} |
