mt-multiserver-proxy/perms.go

40 lines
690 B
Go
Raw Permalink Normal View History

2021-09-07 10:13:12 -07:00
package proxy
2021-09-10 03:47:19 -07:00
// Perms returns the permissions of the ClientConn.
2021-09-07 10:13:12 -07:00
func (cc *ClientConn) Perms() []string {
2021-09-09 11:07:36 -07:00
if cc.Name() == "" {
2021-09-07 10:13:12 -07:00
return []string{}
}
2021-09-09 11:07:36 -07:00
grp, ok := Conf().UserGroups[cc.Name()]
2021-09-07 10:17:59 -07:00
if !ok {
grp = "default"
}
2021-09-07 10:13:12 -07:00
if perms, ok := Conf().Groups[grp]; ok {
return perms
}
return []string{}
}
2021-09-09 07:19:21 -07:00
2021-09-10 03:47:19 -07:00
// HasPerms returns true if the ClientConn has all
// of the specified permissions. Otherwise it returns false.
2021-09-09 07:19:21 -07:00
func (cc *ClientConn) HasPerms(want ...string) bool {
has := map[string]struct{}{
"": struct{}{},
}
2021-09-09 07:19:21 -07:00
for _, perm := range cc.Perms() {
has[perm] = struct{}{}
}
for _, perm := range want {
if _, ok := has[perm]; !ok {
return false
}
}
return true
}