vitess.io/vitess@v0.16.2/go/vt/tableacl/simpleacl/simpleacl.go (about)

     1  /*
     2  Copyright 2019 The Vitess Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package simpleacl
    18  
    19  import (
    20  	querypb "vitess.io/vitess/go/vt/proto/query"
    21  	"vitess.io/vitess/go/vt/tableacl/acl"
    22  )
    23  
    24  // SimpleACL keeps all entries in a unique in-memory list
    25  type SimpleACL map[string]bool
    26  
    27  // IsMember checks the membership of a principal in this ACL
    28  func (sacl SimpleACL) IsMember(principal *querypb.VTGateCallerID) bool {
    29  	if sacl[principal.Username] {
    30  		return true
    31  	}
    32  	for _, grp := range principal.Groups {
    33  		if sacl[grp] {
    34  			return true
    35  		}
    36  	}
    37  	return false
    38  }
    39  
    40  // Factory is responsible to create new ACL instance.
    41  type Factory struct{}
    42  
    43  // New creates a new ACL instance.
    44  func (factory *Factory) New(entries []string) (acl.ACL, error) {
    45  	acl := SimpleACL(map[string]bool{})
    46  	for _, e := range entries {
    47  		acl[e] = true
    48  	}
    49  	return acl, nil
    50  }