Class: Etcdv3

Inherits:
Object show all
Extended by:
Forwardable
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/kv.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/auth.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/lock.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/lease.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/watch.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/version.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/connection.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/maintenance.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/connection_wrapper.rb

Defined Under Namespace

Classes: Auth, Connection, ConnectionWrapper, KV, Lease, Lock, Maintenance, Namespace, Watch

Constant Summary collapse

DEFAULT_TIMEOUT =
120
VERSION =
'0.11.5'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Etcdv3

Returns a new instance of Etcdv3.



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 32

def initialize(**options)
  @options = options
  @timeout = options[:command_timeout] || DEFAULT_TIMEOUT
  @namespace = options[:namespace]
  @conn = ConnectionWrapper.new(
    @timeout,
    *sanitized_endpoints,
    @namespace,
    @options.fetch(:allow_reconnect, true),
  )
  warn "WARNING: `url` is deprecated. Please use `endpoints` instead." if @options.key?(:url)
  authenticate(@options[:user], @options[:password]) if @options.key?(:user)
end

Instance Attribute Details

#connObject (readonly)

Returns the value of attribute conn.



29
30
31
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 29

def conn
  @conn
end

#credentialsObject (readonly)

Returns the value of attribute credentials.



29
30
31
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 29

def credentials
  @credentials
end

#optionsObject (readonly)

Returns the value of attribute options.



29
30
31
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 29

def options
  @options
end

Instance Method Details

#alarm_deactivateObject

Disarm alarms on a specified member.



67
68
69
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 67

def alarm_deactivate
  @conn.handle(:maintenance, 'alarms', [:deactivate, leader_id])
end

#alarm_listObject

List active alarms



62
63
64
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 62

def alarm_list
  @conn.handle(:maintenance, 'alarms', [:get, leader_id])
end

#auth_disable(timeout: nil) ⇒ Object

Disables authentication. This will clear any active auth / token data.



79
80
81
82
83
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 79

def auth_disable(timeout: nil)
  @conn.handle(:auth, 'auth_disable', [timeout: timeout])
  @conn.clear_authentication
  true
end

#auth_enable(timeout: nil) ⇒ Object

Enables authentication.



72
73
74
75
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 72

def auth_enable(timeout: nil)
  @conn.handle(:auth, 'auth_enable', [timeout: timeout])
  true
end

#db_sizeObject

Store size in bytes.



52
53
54
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 52

def db_size
  @conn.handle(:maintenance, 'member_status').dbSize
end

#del(key, opts = {}) ⇒ Object

Deletes a specified key key - string optional :range_end - string optional :timeout - integer



147
148
149
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 147

def del(key, opts={})
  @conn.handle(:kv, 'del', [key, opts])
end

#get(key, opts = {}) ⇒ Object

key - string optional :range_end - string optional :limit - integer optional :revision - integer optional :sort_order - symbol - [:none, :ascend, :descend] optional :sort_target - symbol - [:key, :version, :create, :mode, :value] optional :serializable - boolean optional :keys_only - boolean optional :count_only - boolean optional :min_mod_revision - integer optional :max_mod_revision - integer optional :min_create_revision - integer optional :max_create_revision - integer optional :timeout - integer



99
100
101
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 99

def get(key, opts={})
  @conn.handle(:kv, 'get', [key, opts])
end

#leader_idObject

Cluster leader id



57
58
59
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 57

def leader_id
  @conn.handle(:maintenance, 'member_status').leader
end

#lease_grant(ttl, timeout: nil) ⇒ Object

Grant a lease with a specified TTL



152
153
154
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 152

def lease_grant(ttl, timeout: nil)
  @conn.handle(:lease, 'lease_grant', [ttl, timeout: timeout])
end

#lease_keep_alive_once(id, timeout: nil) ⇒ Object

Sends one lease keep-alive request



167
168
169
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 167

def lease_keep_alive_once(id, timeout: nil)
  @conn.handle(:lease, 'lease_keep_alive_once', [id, timeout: timeout])
end

#lease_revoke(id, timeout: nil) ⇒ Object

Revokes lease and delete all attached keys



157
158
159
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 157

def lease_revoke(id, timeout: nil)
  @conn.handle(:lease, 'lease_revoke', [id, timeout: timeout])
end

#lease_ttl(id, timeout: nil) ⇒ Object

Returns information regarding the current state of the lease



162
163
164
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 162

def lease_ttl(id, timeout: nil)
  @conn.handle(:lease, 'lease_ttl', [id, timeout: timeout])
end

#lock(name, lease_id, timeout: nil) ⇒ Object

Locks distributed lock with the given name. The lock will unlock automatically when lease with the given ID expires. If this is not desirable, provide a non-expiring lease ID as an argument. name - string lease_id - integer optional :timeout - integer



109
110
111
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 109

def lock(name, lease_id, timeout: nil)
  @conn.handle(:lock, 'lock', [name, lease_id, {timeout: timeout}])
end

#put(key, value, opts = {}) ⇒ Object

Inserts a new key. key - string value - string optional :lease - integer optional :timeout - integer



139
140
141
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 139

def put(key, value, opts={})
  @conn.handle(:kv, 'put', [key, value, opts])
end

#role_add(name, timeout: nil) ⇒ Object

Add role with specified name.



177
178
179
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 177

def role_add(name, timeout: nil)
  @conn.handle(:auth, 'role_add', [name, timeout: timeout])
end

#role_delete(name, timeout: nil) ⇒ Object

Delete role.



187
188
189
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 187

def role_delete(name, timeout: nil)
  @conn.handle(:auth, 'role_delete', [name, timeout: timeout])
end

#role_get(name, timeout: nil) ⇒ Object

Fetches a specified role.



182
183
184
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 182

def role_get(name, timeout: nil)
  @conn.handle(:auth, 'role_get', [name, timeout: timeout])
end

#role_grant_permission(name, permission, key, range_end: '', timeout: nil) ⇒ Object

Grants a new permission to an existing role.



192
193
194
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 192

def role_grant_permission(name, permission, key, range_end: '', timeout: nil)
  @conn.handle(:auth, 'role_grant_permission', [name, permission, key, range_end, timeout: timeout])
end

#role_list(timeout: nil) ⇒ Object

List all roles.



172
173
174
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 172

def role_list(timeout: nil)
  @conn.handle(:auth, 'role_list', [timeout: timeout])
end

#role_revoke_permission(name, permission, key, range_end: '', timeout: nil) ⇒ Object



196
197
198
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 196

def role_revoke_permission(name, permission, key, range_end: '', timeout: nil)
  @conn.handle(:auth, 'role_revoke_permission', [name, permission, key, range_end, timeout: timeout])
end

#transaction(timeout: nil, &block) ⇒ Object



240
241
242
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 240

def transaction(timeout: nil, &block)
  @conn.handle(:kv, 'transaction', [block, timeout: timeout])
end

#unlock(key, timeout: nil) ⇒ Object

Unlock distributed lock using the key previously obtained from lock. key - string optional :timeout - integer



116
117
118
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 116

def unlock(key, timeout: nil)
  @conn.handle(:lock, 'unlock', [key, {timeout: timeout}])
end

#user_add(user, password, timeout: nil) ⇒ Object

Creates new user.



206
207
208
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 206

def user_add(user, password, timeout: nil)
  @conn.handle(:auth, 'user_add', [user, password, timeout: timeout])
end

#user_change_password(user, new_password, timeout: nil) ⇒ Object

Changes the specified users password.



216
217
218
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 216

def user_change_password(user, new_password, timeout: nil)
  @conn.handle(:auth, 'user_change_password', [user, new_password, timeout: timeout])
end

#user_delete(user, timeout: nil) ⇒ Object

Delete specified user.



211
212
213
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 211

def user_delete(user, timeout: nil)
  @conn.handle(:auth, 'user_delete', [user, timeout: timeout])
end

#user_get(user, timeout: nil) ⇒ Object

Fetch specified user



201
202
203
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 201

def user_get(user, timeout: nil)
  @conn.handle(:auth, 'user_get', [user, timeout: timeout])
end

#user_grant_role(user, role, timeout: nil) ⇒ Object

Grants role to an existing user.



226
227
228
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 226

def user_grant_role(user, role, timeout: nil)
  @conn.handle(:auth, 'user_grant_role', [user, role, timeout: timeout])
end

#user_list(timeout: nil) ⇒ Object

List all users.



221
222
223
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 221

def user_list(timeout: nil)
  @conn.handle(:auth, 'user_list', [timeout: timeout])
end

#user_revoke_role(user, role, timeout: nil) ⇒ Object

Revokes role from a specified user.



231
232
233
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 231

def user_revoke_role(user, role, timeout: nil)
  @conn.handle(:auth, 'user_revoke_role', [user, role, timeout: timeout])
end

#versionObject

Version of Etcd running on member



47
48
49
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 47

def version
  @conn.handle(:maintenance, 'member_status').version
end

#watch(key, range_end: nil, start_revision: nil, timeout: nil, &block) ⇒ Object

Watches for changes on a specified key range.



236
237
238
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 236

def watch(key, range_end: nil, start_revision: nil, timeout: nil, &block)
  @conn.handle(:watch, 'watch', [key, range_end, start_revision, block, timeout: timeout])
end

#with_lock(name, lease_id, timeout: nil) ⇒ Object

Yield into the critical section while holding lock with the given name. The lock will be unlocked even if the block throws. name - string lease_id - integer optional :timeout - integer



125
126
127
128
129
130
131
132
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3.rb', line 125

def with_lock(name, lease_id, timeout: nil)
  key = lock(name, lease_id, timeout: timeout).key
  begin
    yield
  ensure
    unlock(key, timeout: timeout)
  end
end