forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 10
/
simpleacl.go
38 lines (32 loc) · 940 Bytes
/
simpleacl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2015, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package simpleacl
import (
querypb "github.com/youtube/vitess/go/vt/proto/query"
"github.com/youtube/vitess/go/vt/tableacl/acl"
)
// SimpleACL keeps all entries in a unique in-memory list
type SimpleACL map[string]bool
// IsMember checks the membership of a principal in this ACL
func (sacl SimpleACL) IsMember(principal *querypb.VTGateCallerID) bool {
if sacl[principal.Username] {
return true
}
for _, grp := range principal.Groups {
if sacl[grp] {
return true
}
}
return false
}
// Factory is responsible to create new ACL instance.
type Factory struct{}
// New creates a new ACL instance.
func (factory *Factory) New(entries []string) (acl.ACL, error) {
acl := SimpleACL(map[string]bool{})
for _, e := range entries {
acl[e] = true
}
return acl, nil
}