Class: Aerospike::Privilege

Inherits:
Object
  • Object
show all
Defined in:
lib/aerospike/privilege.rb

Overview

Determines user access granularity.

Constant Summary collapse

USER_ADMIN =

Manage users and their roles.

'user-admin'
SYS_ADMIN =

Manage indicies, user-defined functions and server configuration.

'sys-admin'
DATA_ADMIN =

Manage indicies and user defined functions.

'data-admin'
UDF_ADMIN =

Manage user defined functions.

'udf-admin'
SINDEX_ADMIN =

Manage indicies.

'sindex-admin'
READ_WRITE_UDF =

Allow read, write and UDF transactions with the database.

"read-write-udf"
READ_WRITE =

Allow read and write transactions with the database.

'read-write'
READ =

Allow read transactions with the database.

'read'
WRITE =

Write allows write transactions with the database.

'write'
TRUNCATE =

Truncate allow issuing truncate commands.

'truncate'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opt = {}) ⇒ Privilege

Returns a new instance of Privilege.



63
64
65
66
67
# File 'lib/aerospike/privilege.rb', line 63

def initialize(opt={})
  @code = opt[:code]
  @namespace = opt[:namespace]
  @set_name = opt[:set_name]
end

Instance Attribute Details

#codeObject

Role



23
24
25
# File 'lib/aerospike/privilege.rb', line 23

def code
  @code
end

#namespaceObject

Namespace determines namespace scope. Apply permission to this namespace only. If namespace is zero value, the privilege applies to all namespaces.



27
28
29
# File 'lib/aerospike/privilege.rb', line 27

def namespace
  @namespace
end

#set_nameObject

Set name scope. Apply permission to this set within namespace only. If set is zero value, the privilege applies to all sets within namespace.



31
32
33
# File 'lib/aerospike/privilege.rb', line 31

def set_name
  @set_name
end

Class Method Details

.from(code) ⇒ Object

def



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/aerospike/privilege.rb', line 100

def self.from(code)
	case code
	when 0
		USER_ADMIN
	when 1
		SYS_ADMIN
	when 2
		DATA_ADMIN
	when 3
		UDF_ADMIN
	when 4
		SINDEX_ADMIN
	when 10
		READ
	when 11
		READ_WRITE
	when 12
		READ_WRITE_UDF
	when 13
		WRITE
	when 14
		TRUNCATE
	else
		raise Exceptions::Aerospike.new(Aerospike::ResultCode::INVALID_PRIVILEGE, "Invalid code #{code}")
	end # case
end

Instance Method Details

#can_scope?Boolean

def

Returns:

  • (Boolean)


127
128
129
# File 'lib/aerospike/privilege.rb', line 127

def can_scope?
	to_code >= 10
end

#to_codeObject



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
# File 'lib/aerospike/privilege.rb', line 73

def to_code
	case @code
	when USER_ADMIN
		0
	when SYS_ADMIN
		1
	when DATA_ADMIN
		2
	when UDF_ADMIN
		3
	when SINDEX_ADMIN
		4
	when READ
		10
	when READ_WRITE
		11
	when READ_WRITE_UDF
		12
	when WRITE
		13
	when TRUNCATE
		14
	else
		raise Exceptions::Aerospike.new(Aerospike::ResultCode::INVALID_PRIVILEGE, "Invalid role #{@code}")
	end # case
end

#to_sObject



69
70
71
# File 'lib/aerospike/privilege.rb', line 69

def to_s
	"code: #{@code}, namespace: #{@namespace}, set_name: #{@set_name}"
end