summaryrefslogtreecommitdiff
path: root/app/middleware/permission.go
blob: 03e7cf941d094bd1dc834ca7e70a9baf69b7e3e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package middleware

import (
	"gitlab.com/gitlab-org/software-supply-chain-security/authorization/authzd.git/pkg/rpc"
	"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain"
)

type Permission string

func (p Permission) ToGID() string {
	return "gid://sparkle/Permission/" + p.String()
}

func (p Permission) RequestFor(user domain.Identifiable, resource domain.Identifiable) *rpc.AllowRequest {
	return &rpc.AllowRequest{
		Subject:    user.ToGID(),
		Permission: p.ToGID(),
		Resource:   resource.ToGID(),
	}
}

func (p Permission) String() string {
	return string(p)
}