This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
forked from aerospike/aerospike-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
privilege.go
109 lines (88 loc) · 2.9 KB
/
privilege.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2013-2017 Aerospike, Inc.
//
// Portions may be licensed to Aerospike, Inc. under one or more contributor
// license agreements.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
package aerospike
import "fmt"
type privilegeCode string
// Privilege determines user access granularity.
type Privilege struct {
// Role
Code privilegeCode
// Namespace determines namespace scope. Apply permission to this namespace only.
// If namespace is zero value, the privilege applies to all namespaces.
Namespace string
// Set name scope. Apply permission to this set within namespace only.
// If set is zero value, the privilege applies to all sets within namespace.
SetName string
}
func (p *Privilege) code() int {
switch p.Code {
// User can edit/remove other users. Global scope only.
case UserAdmin:
return 0
// User can perform systems administration functions on a database that do not involve user
// administration. Examples include server configuration.
// Global scope only.
case SysAdmin:
return 1
// User can perform data administration functions on a database that do not involve user
// administration. Examples include index and user defined function management.
// Global scope only.
case DataAdmin:
return 2
// User can read data only.
case Read:
return 10
// User can read and write data.
case ReadWrite:
return 11
// User can read and write data through user defined functions.
case ReadWriteUDF:
return 12
}
panic("invalid role: " + p.Code)
}
func privilegeFrom(code uint8) privilegeCode {
switch code {
// User can edit/remove other users. Global scope only.
case 0:
return UserAdmin
// User can perform systems administration functions on a database that do not involve user
// administration. Examples include server configuration.
// Global scope only.
case 1:
return SysAdmin
// User can perform data administration functions on a database that do not involve user
// administration. Examples include index and user defined function management.
// Global scope only.
case 2:
return DataAdmin
// User can read data only.
case 10:
return Read
// User can read and write data.
case 11:
return ReadWrite
// User can read and write data through user defined functions.
case 12:
return ReadWriteUDF
}
panic(fmt.Sprintf("invalid privilege code: %v", code))
}
func (p *Privilege) canScope() bool {
if p.code() >= 10 {
return true
}
return false
}