1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-30 09:45:15 +01:00
Files
dozzle/internal/auth/roles.go
2025-09-21 14:57:06 -07:00

43 lines
610 B
Go

package auth
import (
"strings"
)
type Role int
const (
None Role = 0
Shell Role = 1 << iota
Actions
Download
)
const All = Shell | Actions | Download
func ParseRole(commaValues string) Role {
if commaValues == "" {
return All
}
var roles Role
for r := range strings.SplitSeq(commaValues, ",") {
role := strings.TrimSpace(strings.ToLower(r))
switch role {
case "shell":
roles |= Shell
case "actions":
roles |= Actions
case "download":
roles |= Download
case "none":
return None
}
}
return roles
}
func (roles Role) Has(role Role) bool {
return roles&role != 0
}