Class: Etcdv3
- Inherits:
-
Object
- Object
- Etcdv3
- Defined in:
- lib/etcdv3.rb,
lib/etcdv3/kv.rb,
lib/etcdv3/auth.rb,
lib/etcdv3/lease.rb,
lib/etcdv3/watch.rb,
lib/etcdv3/request.rb,
lib/etcdv3/version.rb,
lib/etcdv3/maintenance.rb
Defined Under Namespace
Classes: Auth, KV, Lease, Maintenance, Request, Watch
Constant Summary collapse
- VERSION =
'0.4.0'.freeze
Instance Attribute Summary collapse
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#add_role(name) ⇒ Object
Add role with specified name.
-
#add_user(user, password) ⇒ Object
Creates new user.
-
#alarm_list ⇒ Object
List active alarms.
-
#authenticate(user, password) ⇒ Object
Authenticate using specified user and password.
-
#change_user_password(user, new_password) ⇒ Object
Changes the specified users password.
-
#db_size ⇒ Object
Store size in bytes.
-
#deactivate_alarms ⇒ Object
Disarm alarms on a specified member.
-
#del(key, range_end: '') ⇒ Object
Deletes a specified key.
-
#delete_role(name) ⇒ Object
Delete role.
-
#delete_user(user) ⇒ Object
Delete specified user.
-
#disable_auth ⇒ Object
Disables authentication.
-
#enable_auth ⇒ Object
Enables authentication.
-
#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.
-
#get_role(name) ⇒ Object
Fetches a specified role.
-
#get_user(user) ⇒ Object
Fetch specified user.
-
#grant_lease(ttl) ⇒ Object
Grant a lease with a specified TTL.
-
#grant_permission_to_role(name, permission, key, range_end = '') ⇒ Object
Grants a new permission to an existing role.
-
#grant_role_to_user(user, role) ⇒ Object
Grants role to an existing user.
- #hostname ⇒ Object
-
#initialize(options = {}) ⇒ Etcdv3
constructor
A new instance of Etcdv3.
-
#leader_id ⇒ Object
Cluster leader id.
-
#lease_ttl(id) ⇒ Object
Returns information regarding the current state of the lease.
- #password ⇒ Object
- #port ⇒ Object
-
#put(key, value, lease_id: nil) ⇒ Object
Inserts a new key.
-
#revoke_lease(id) ⇒ Object
Revokes lease and delete all attached keys.
- #revoke_permission_from_role(name, permission, key, range_end = '') ⇒ Object
-
#revoke_role_from_user(user, role) ⇒ Object
Revokes role from a specified user.
-
#role_list ⇒ Object
List all roles.
- #scheme ⇒ Object
- #token ⇒ Object
- #uri ⇒ Object
- #user ⇒ Object
-
#user_list ⇒ Object
List all users.
-
#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.
46 47 48 49 50 51 52 |
# File 'lib/etcdv3.rb', line 46 def initialize( = {}) @options = @credentials = resolve_credentials @metadata = {} @metadata[:token] = generate_token(user, password) unless user.nil? @metacache = end |
Instance Attribute Details
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
16 17 18 |
# File 'lib/etcdv3.rb', line 16 def credentials @credentials end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
16 17 18 |
# File 'lib/etcdv3.rb', line 16 def @options end |
Instance Method Details
#add_role(name) ⇒ Object
Add role with specified name.
157 158 159 |
# File 'lib/etcdv3.rb', line 157 def add_role(name) request.handle(:auth, 'add_role', [name]) end |
#add_user(user, password) ⇒ Object
Creates new user.
127 128 129 |
# File 'lib/etcdv3.rb', line 127 def add_user(user, password) request.handle(:auth, 'add_user', [user, password]) end |
#alarm_list ⇒ Object
List active alarms
75 76 77 |
# File 'lib/etcdv3.rb', line 75 def alarm_list request.handle(:maintenance, 'alarms', [:get, leader_id]) end |
#authenticate(user, password) ⇒ Object
Authenticate using specified user and password. On successful authentication, an auth token will be assigned to the instance.
210 211 212 213 214 215 216 217 218 219 |
# File 'lib/etcdv3.rb', line 210 def authenticate(user, password) token = generate_token(user, password) return false unless token @metadata[:token] = token @options[:user] = user @options[:password] = password @metacache = true end |
#change_user_password(user, new_password) ⇒ Object
Changes the specified users password.
142 143 144 |
# File 'lib/etcdv3.rb', line 142 def change_user_password(user, new_password) request.handle(:auth, 'change_user_password', [user, new_password]) end |
#db_size ⇒ Object
Store size in bytes.
60 61 62 |
# File 'lib/etcdv3.rb', line 60 def db_size request.handle(:maintenance, 'member_status').dbSize end |
#deactivate_alarms ⇒ Object
Disarm alarms on a specified member.
80 81 82 |
# File 'lib/etcdv3.rb', line 80 def deactivate_alarms request.handle(:maintenance, 'alarms', [:deactivate, leader_id]) end |
#del(key, range_end: '') ⇒ Object
Deletes a specified key
107 108 109 |
# File 'lib/etcdv3.rb', line 107 def del(key, range_end: '') request.handle(:kv, 'del', [key, range_end]) end |
#delete_role(name) ⇒ Object
Delete role.
167 168 169 |
# File 'lib/etcdv3.rb', line 167 def delete_role(name) request.handle(:auth, 'delete_role', [name]) end |
#delete_user(user) ⇒ Object
Delete specified user.
137 138 139 |
# File 'lib/etcdv3.rb', line 137 def delete_user(user) request.handle(:auth, 'delete_user', [user]) end |
#disable_auth ⇒ Object
Disables authentication. This will clear any active auth / token data.
197 198 199 200 201 202 203 204 205 206 |
# File 'lib/etcdv3.rb', line 197 def disable_auth response = request.handle(:auth, 'disable_auth') if response @metadata.delete(:token) @options[:user] = nil @options[:password] = nil @metacache = end response end |
#enable_auth ⇒ Object
Enables authentication.
191 192 193 |
# File 'lib/etcdv3.rb', line 191 def enable_auth request.handle(:auth, 'enable_auth') 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
102 103 104 |
# File 'lib/etcdv3.rb', line 102 def get(key, opts={}) request.handle(:kv, 'get', [key, opts]) end |
#get_role(name) ⇒ Object
Fetches a specified role.
162 163 164 |
# File 'lib/etcdv3.rb', line 162 def get_role(name) request.handle(:auth, 'get_role', [name]) end |
#get_user(user) ⇒ Object
Fetch specified user
132 133 134 |
# File 'lib/etcdv3.rb', line 132 def get_user(user) request.handle(:auth, 'get_user', [user]) end |
#grant_lease(ttl) ⇒ Object
Grant a lease with a specified TTL
112 113 114 |
# File 'lib/etcdv3.rb', line 112 def grant_lease(ttl) request.handle(:lease, 'grant_lease', [ttl]) end |
#grant_permission_to_role(name, permission, key, range_end = '') ⇒ Object
Grants a new permission to an existing role.
182 183 184 |
# File 'lib/etcdv3.rb', line 182 def (name, , key, range_end='') request.handle(:auth, 'grant_permission_to_role', [name, , key, range_end]) end |
#grant_role_to_user(user, role) ⇒ Object
Grants role to an existing user.
172 173 174 |
# File 'lib/etcdv3.rb', line 172 def grant_role_to_user(user, role) request.handle(:auth, 'grant_role_to_user', [user, role]) end |
#hostname ⇒ Object
30 31 32 |
# File 'lib/etcdv3.rb', line 30 def hostname uri.hostname end |
#leader_id ⇒ Object
Cluster leader id
65 66 67 |
# File 'lib/etcdv3.rb', line 65 def leader_id request.handle(:maintenance, 'member_status').leader end |
#lease_ttl(id) ⇒ Object
Returns information regarding the current state of the lease
122 123 124 |
# File 'lib/etcdv3.rb', line 122 def lease_ttl(id) request.handle(:lease, 'lease_ttl', [id]) end |
#password ⇒ Object
42 43 44 |
# File 'lib/etcdv3.rb', line 42 def password @options[:password] end |
#port ⇒ Object
26 27 28 |
# File 'lib/etcdv3.rb', line 26 def port uri.port end |
#put(key, value, lease_id: nil) ⇒ Object
Inserts a new key.
85 86 87 |
# File 'lib/etcdv3.rb', line 85 def put(key, value, lease_id: nil) request.handle(:kv, 'put', [key, value, lease_id]) end |
#revoke_lease(id) ⇒ Object
Revokes lease and delete all attached keys
117 118 119 |
# File 'lib/etcdv3.rb', line 117 def revoke_lease(id) request.handle(:lease, 'revoke_lease', [id]) end |
#revoke_permission_from_role(name, permission, key, range_end = '') ⇒ Object
186 187 188 |
# File 'lib/etcdv3.rb', line 186 def (name, , key, range_end='') request.handle(:auth, 'revoke_permission_from_role', [name, , key, range_end]) end |
#revoke_role_from_user(user, role) ⇒ Object
Revokes role from a specified user.
177 178 179 |
# File 'lib/etcdv3.rb', line 177 def revoke_role_from_user(user, role) request.handle(:auth, 'revoke_role_from_user', [user, role]) end |
#role_list ⇒ Object
List all roles.
152 153 154 |
# File 'lib/etcdv3.rb', line 152 def role_list request.handle(:auth, 'role_list') end |
#scheme ⇒ Object
22 23 24 |
# File 'lib/etcdv3.rb', line 22 def scheme uri.scheme end |
#token ⇒ Object
34 35 36 |
# File 'lib/etcdv3.rb', line 34 def token @metadata[:token] end |
#uri ⇒ Object
18 19 20 |
# File 'lib/etcdv3.rb', line 18 def uri URI(@options[:url]) end |
#user ⇒ Object
38 39 40 |
# File 'lib/etcdv3.rb', line 38 def user @options[:user] end |
#user_list ⇒ Object
List all users.
147 148 149 |
# File 'lib/etcdv3.rb', line 147 def user_list request.handle(:auth, 'user_list') end |
#version ⇒ Object
Version of Etcd running on member
55 56 57 |
# File 'lib/etcdv3.rb', line 55 def version request.handle(:maintenance, 'member_status').version end |
#watch(key, range_end: '', &block) ⇒ Object
Watches for changes on a specified key range.
70 71 72 |
# File 'lib/etcdv3.rb', line 70 def watch(key, range_end: '', &block) request.handle(:watch, 'watch', [key, range_end, block]) end |