vitess.io/vitess@v0.16.2/go/vt/tableacl/role.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 tableacl 18 19 import ( 20 "strings" 21 ) 22 23 // Role defines the level of access on a table 24 type Role int 25 26 const ( 27 // READER can run SELECT statements 28 READER Role = iota 29 // WRITER can run SELECT, INSERT & UPDATE statements 30 WRITER 31 // ADMIN can run any statements including DDLs 32 ADMIN 33 // NumRoles is number of Roles defined 34 NumRoles 35 ) 36 37 var roleNames = []string{ 38 "READER", 39 "WRITER", 40 "ADMIN", 41 } 42 43 // Name returns the name of a role 44 func (r Role) Name() string { 45 if r < READER || r > ADMIN { 46 return "" 47 } 48 return roleNames[r] 49 } 50 51 // RoleByName returns the Role corresponding to a name 52 func RoleByName(s string) (Role, bool) { 53 for i, v := range roleNames { 54 if v == strings.ToUpper(s) { 55 return Role(i), true 56 } 57 } 58 return NumRoles, false 59 }