Class: Etcdv3
- Inherits:
-
Object
- Object
- Etcdv3
- Extended by:
- Forwardable
- Defined in:
- lib/etcdv3.rb,
lib/etcdv3/kv.rb,
lib/etcdv3/auth.rb,
lib/etcdv3/lease.rb,
lib/etcdv3/watch.rb,
lib/etcdv3/version.rb,
lib/etcdv3/connection.rb,
lib/etcdv3/maintenance.rb,
lib/etcdv3/connection_wrapper.rb
Defined Under Namespace
Classes: Auth, Connection, ConnectionWrapper, KV, Lease, Maintenance, Watch
Constant Summary collapse
- DEFAULT_TIMEOUT =
120- VERSION =
'0.8.1'.freeze
Instance Attribute Summary collapse
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#alarm_deactivate ⇒ Object
Disarm alarms on a specified member.
-
#alarm_list ⇒ Object
List active alarms.
-
#auth_disable(timeout: nil) ⇒ Object
Disables authentication.
-
#auth_enable(timeout: nil) ⇒ Object
Enables authentication.
-
#db_size ⇒ Object
Store size in bytes.
-
#del(key, opts = {}) ⇒ Object
Deletes a specified key key - string optional :range_end - string optional :timeout - integer.
-
#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.
-
#initialize(options = {}) ⇒ Etcdv3
constructor
A new instance of Etcdv3.
-
#leader_id ⇒ Object
Cluster leader id.
-
#lease_grant(ttl, timeout: nil) ⇒ Object
Grant a lease with a specified TTL.
-
#lease_revoke(id, timeout: nil) ⇒ Object
Revokes lease and delete all attached keys.
-
#lease_ttl(id, timeout: nil) ⇒ Object
Returns information regarding the current state of the lease.
-
#put(key, value, opts = {}) ⇒ Object
Inserts a new key.
-
#role_add(name, timeout: nil) ⇒ Object
Add role with specified name.
-
#role_delete(name, timeout: nil) ⇒ Object
Delete role.
-
#role_get(name, timeout: nil) ⇒ Object
Fetches a specified role.
-
#role_grant_permission(name, permission, key, range_end: '', timeout: nil) ⇒ Object
Grants a new permission to an existing role.
-
#role_list(timeout: nil) ⇒ Object
List all roles.
- #role_revoke_permission(name, permission, key, range_end: '', timeout: nil) ⇒ Object
- #transaction(timeout: nil, &block) ⇒ Object
-
#user_add(user, password, timeout: nil) ⇒ Object
Creates new user.
-
#user_change_password(user, new_password, timeout: nil) ⇒ Object
Changes the specified users password.
-
#user_delete(user, timeout: nil) ⇒ Object
Delete specified user.
-
#user_get(user, timeout: nil) ⇒ Object
Fetch specified user.
-
#user_grant_role(user, role, timeout: nil) ⇒ Object
Grants role to an existing user.
-
#user_list(timeout: nil) ⇒ Object
List all users.
-
#user_revoke_role(user, role, timeout: nil) ⇒ Object
Revokes role from a specified user.
-
#version ⇒ Object
Version of Etcd running on member.
-
#watch(key, range_end: '', &block) ⇒ Object
Watches for changes on a specified key range.
Constructor Details
#initialize(options = {}) ⇒ Etcdv3
Returns a new instance of Etcdv3.
22 23 24 25 26 27 28 |
# File 'lib/etcdv3.rb', line 22 def initialize( = {}) = @timeout = [:command_timeout] || DEFAULT_TIMEOUT @conn = ConnectionWrapper.new(@timeout, *sanitized_endpoints) warn "WARNING: `url` is deprecated. Please use `endpoints` instead." if .key?(:url) authenticate([:user], [:password]) if .key?(:user) end |
Instance Attribute Details
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
19 20 21 |
# File 'lib/etcdv3.rb', line 19 def conn @conn end |
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
19 20 21 |
# File 'lib/etcdv3.rb', line 19 def credentials @credentials end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
19 20 21 |
# File 'lib/etcdv3.rb', line 19 def end |
Instance Method Details
#alarm_deactivate ⇒ Object
Disarm alarms on a specified member.
51 52 53 |
# File 'lib/etcdv3.rb', line 51 def alarm_deactivate @conn.handle(:maintenance, 'alarms', [:deactivate, leader_id]) end |
#alarm_list ⇒ Object
List active alarms
46 47 48 |
# File 'lib/etcdv3.rb', line 46 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.
63 64 65 66 67 |
# File 'lib/etcdv3.rb', line 63 def auth_disable(timeout: nil) @conn.handle(:auth, 'auth_disable', [timeout: timeout]) @conn.clear_authentication true end |
#auth_enable(timeout: nil) ⇒ Object
Enables authentication.
56 57 58 59 |
# File 'lib/etcdv3.rb', line 56 def auth_enable(timeout: nil) @conn.handle(:auth, 'auth_enable', [timeout: timeout]) true end |
#db_size ⇒ Object
Store size in bytes.
36 37 38 |
# File 'lib/etcdv3.rb', line 36 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
100 101 102 |
# File 'lib/etcdv3.rb', line 100 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
83 84 85 |
# File 'lib/etcdv3.rb', line 83 def get(key, opts={}) @conn.handle(:kv, 'get', [key, opts]) end |
#leader_id ⇒ Object
Cluster leader id
41 42 43 |
# File 'lib/etcdv3.rb', line 41 def leader_id @conn.handle(:maintenance, 'member_status').leader end |
#lease_grant(ttl, timeout: nil) ⇒ Object
Grant a lease with a specified TTL
105 106 107 |
# File 'lib/etcdv3.rb', line 105 def lease_grant(ttl, timeout: nil) @conn.handle(:lease, 'lease_grant', [ttl, timeout: timeout]) end |
#lease_revoke(id, timeout: nil) ⇒ Object
Revokes lease and delete all attached keys
110 111 112 |
# File 'lib/etcdv3.rb', line 110 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
115 116 117 |
# File 'lib/etcdv3.rb', line 115 def lease_ttl(id, timeout: nil) @conn.handle(:lease, 'lease_ttl', [id, timeout: timeout]) end |
#put(key, value, opts = {}) ⇒ Object
Inserts a new key. key - string value - string optional :lease - integer optional :timeout - integer
92 93 94 |
# File 'lib/etcdv3.rb', line 92 def put(key, value, opts={}) @conn.handle(:kv, 'put', [key, value, opts]) end |
#role_add(name, timeout: nil) ⇒ Object
Add role with specified name.
125 126 127 |
# File 'lib/etcdv3.rb', line 125 def role_add(name, timeout: nil) @conn.handle(:auth, 'role_add', [name, timeout: timeout]) end |
#role_delete(name, timeout: nil) ⇒ Object
Delete role.
135 136 137 |
# File 'lib/etcdv3.rb', line 135 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.
130 131 132 |
# File 'lib/etcdv3.rb', line 130 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.
140 141 142 |
# File 'lib/etcdv3.rb', line 140 def (name, , key, range_end: '', timeout: nil) @conn.handle(:auth, 'role_grant_permission', [name, , key, range_end, timeout: timeout]) end |
#role_list(timeout: nil) ⇒ Object
List all roles.
120 121 122 |
# File 'lib/etcdv3.rb', line 120 def role_list(timeout: nil) @conn.handle(:auth, 'role_list', [timeout: timeout]) end |
#role_revoke_permission(name, permission, key, range_end: '', timeout: nil) ⇒ Object
144 145 146 |
# File 'lib/etcdv3.rb', line 144 def (name, , key, range_end: '', timeout: nil) @conn.handle(:auth, 'role_revoke_permission', [name, , key, range_end, timeout: timeout]) end |
#transaction(timeout: nil, &block) ⇒ Object
188 189 190 |
# File 'lib/etcdv3.rb', line 188 def transaction(timeout: nil, &block) @conn.handle(:kv, 'transaction', [block, timeout: timeout]) end |
#user_add(user, password, timeout: nil) ⇒ Object
Creates new user.
154 155 156 |
# File 'lib/etcdv3.rb', line 154 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.
164 165 166 |
# File 'lib/etcdv3.rb', line 164 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.
159 160 161 |
# File 'lib/etcdv3.rb', line 159 def user_delete(user, timeout: nil) @conn.handle(:auth, 'user_delete', [user, timeout: timeout]) end |
#user_get(user, timeout: nil) ⇒ Object
Fetch specified user
149 150 151 |
# File 'lib/etcdv3.rb', line 149 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.
174 175 176 |
# File 'lib/etcdv3.rb', line 174 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.
169 170 171 |
# File 'lib/etcdv3.rb', line 169 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.
179 180 181 |
# File 'lib/etcdv3.rb', line 179 def user_revoke_role(user, role, timeout: nil) @conn.handle(:auth, 'user_revoke_role', [user, role, timeout: timeout]) end |
#version ⇒ Object
Version of Etcd running on member
31 32 33 |
# File 'lib/etcdv3.rb', line 31 def version @conn.handle(:maintenance, 'member_status').version end |
#watch(key, range_end: '', &block) ⇒ Object
Watches for changes on a specified key range.
184 185 186 |
# File 'lib/etcdv3.rb', line 184 def watch(key, range_end: '', &block) @conn.handle(:watch, 'watch', [key, range_end, block]) end |