etcdv3 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f86e90b466cc1cf9999d8f9cbf08f5df1e2ac86
4
- data.tar.gz: f8f237e1253a7218dfba6eae660e1553f54b07f6
3
+ metadata.gz: c30c373c3727bf2bf9fb11361e12c868f23b0c63
4
+ data.tar.gz: bf013c81510a227345e7cb8924a80ceb5549cf3e
5
5
  SHA512:
6
- metadata.gz: 57d227117a3f8f82ae8d2a6691ed3468d7c8faf0a071d12182b2980c7784c456277315fb9945931ffa9c81882da7c748c188635d6dddf172ddbd9cc1aaf380e3
7
- data.tar.gz: f53b3f71bb23e3961eaef3858f7cf22b69182835072fc1936146cd88b9d499cd6ed118538945a274e694e392f28ca57ae5bc1e29c73111a350a30afeaba9e59a
6
+ metadata.gz: 1f58b5adcdb86fafa2cbc5e924e1406d71d4e26988a5000211870e54b48dfa9a8f72cd663dcfc09dcfe9507b60cf8d6d337fe284e41bc85361486787407748ad
7
+ data.tar.gz: b6c432b3e2963cc7cb20b2c1151d27c55da1022094fb3047ff685b9de129ce8ffd16f8ee0dc35eec7942fdeaca454ddef986fe551e6f44bd57428ac1a75e927d
data/README.md CHANGED
@@ -7,7 +7,7 @@ Ruby client for Etcd V3
7
7
 
8
8
  ## Getting Started
9
9
 
10
- [RubyDocs](http://www.rubydoc.info/gems/etcdv3/0.1.1/Etcd)
10
+ [RubyDocs](http://www.rubydoc.info/gems/etcdv3)
11
11
 
12
12
  To install etcdv3, run the following command:
13
13
  ```ruby
@@ -53,10 +53,10 @@ conn = Etcdv3.new(url: 'https://hostname:port', user: "gary", password: "secret"
53
53
  ## User Management
54
54
  ```ruby
55
55
  # Add User
56
- conn.add_user('admin', 'secret')
56
+ conn.user_add('admin', 'secret')
57
57
 
58
58
  # Delete User
59
- conn.delete_user('admin')
59
+ conn.user_delete('admin')
60
60
 
61
61
  # List users
62
62
  conn.user_list
@@ -65,13 +65,13 @@ conn.user_list
65
65
  ## Role Management
66
66
  ```ruby
67
67
  # Add Role
68
- conn.add_role('rolename')
68
+ conn.role_add('rolename')
69
69
 
70
70
  # Grant Permission to Role
71
- conn.grant_permission_to_role('rolename', 'readwrite', 'a', 'z')
71
+ conn.role_grant_permission('rolename', :readwrite, 'a', 'z')
72
72
 
73
73
  # Delete Role
74
- conn.delete_role('rolename')
74
+ conn.role_delete('rolename')
75
75
 
76
76
  # List Roles
77
77
  conn.role_list
@@ -80,13 +80,13 @@ conn.role_list
80
80
  ## Authentication Management
81
81
  ```ruby
82
82
  # Configure a root user
83
- conn.add_user('root', 'mysecretpassword')
83
+ conn.user_add('root', 'mysecretpassword')
84
84
 
85
85
  # Grant root user the root role
86
- conn.grant_role_to_user('root', 'root')
86
+ conn.user_grant_role('root', 'root')
87
87
 
88
88
  # Enable Authentication
89
- conn.enable_auth
89
+ conn.auth_enable
90
90
  ```
91
91
  After you enable authentication, you must authenticate.
92
92
  ```ruby
@@ -95,13 +95,13 @@ conn.authenticate('root', 'mysecretpassword')
95
95
  ```
96
96
  Disabling auth will clear the auth token and all previously attached user information
97
97
  ```
98
- conn.disable_auth
98
+ conn.auth_disable
99
99
  ```
100
100
 
101
101
  ## Leases
102
102
  ```ruby
103
103
  # Grant a lease with a 100 second TTL
104
- conn.grant_lease(100)
104
+ conn.lease_grant(100)
105
105
 
106
106
  # Attach key to lease
107
107
  conn.put("testkey", "testvalue", lease_id: 1234566789)
@@ -110,7 +110,7 @@ conn.put("testkey", "testvalue", lease_id: 1234566789)
110
110
  conn.lease_ttl(1234566789)
111
111
 
112
112
  # Revoke lease and delete all keys attached
113
- conn.revoke_lease(1234566789)
113
+ conn.lease_revoke(1234566789)
114
114
  ```
115
115
 
116
116
  ## Watch
@@ -136,5 +136,5 @@ end
136
136
  conn.alarm_list
137
137
 
138
138
  # Deactivate ALL active Alarms
139
- conn.deactivate_alarms
139
+ conn.alarm_deactivate
140
140
  ```
data/lib/etcdv3.rb CHANGED
@@ -66,24 +66,44 @@ class Etcdv3
66
66
  request.handle(:maintenance, 'member_status').leader
67
67
  end
68
68
 
69
- # Watches for changes on a specified key range.
70
- def watch(key, range_end: '', &block)
71
- request.handle(:watch, 'watch', [key, range_end, block])
72
- end
73
-
74
69
  # List active alarms
75
70
  def alarm_list
76
71
  request.handle(:maintenance, 'alarms', [:get, leader_id])
77
72
  end
78
73
 
79
74
  # Disarm alarms on a specified member.
80
- def deactivate_alarms
75
+ def alarm_deactivate
81
76
  request.handle(:maintenance, 'alarms', [:deactivate, leader_id])
82
77
  end
83
78
 
84
- # Inserts a new key.
85
- def put(key, value, lease_id: nil)
86
- request.handle(:kv, 'put', [key, value, lease_id])
79
+ # Authenticate using specified user and password.
80
+ # On successful authentication, an auth token will be assigned to the instance.
81
+ def authenticate(user, password)
82
+ token = generate_token(user, password)
83
+ return false unless token
84
+ @metadata[:token] = token
85
+ @options[:user] = user
86
+ @options[:password] = password
87
+ @metacache = set_metacache
88
+ true
89
+ end
90
+
91
+ # Enables authentication.
92
+ def auth_enable
93
+ request.handle(:auth, 'auth_enable')
94
+ end
95
+
96
+ # Disables authentication.
97
+ # This will clear any active auth / token data.
98
+ def auth_disable
99
+ response = request.handle(:auth, 'auth_disable')
100
+ if response
101
+ @metadata.delete(:token)
102
+ @options[:user] = nil
103
+ @options[:password] = nil
104
+ @metacache = set_metacache
105
+ end
106
+ response
87
107
  end
88
108
 
89
109
  # key - string
@@ -103,19 +123,24 @@ class Etcdv3
103
123
  request.handle(:kv, 'get', [key, opts])
104
124
  end
105
125
 
126
+ # Inserts a new key.
127
+ def put(key, value, lease_id: nil)
128
+ request.handle(:kv, 'put', [key, value, lease_id])
129
+ end
130
+
106
131
  # Deletes a specified key
107
132
  def del(key, range_end: '')
108
133
  request.handle(:kv, 'del', [key, range_end])
109
134
  end
110
135
 
111
136
  # Grant a lease with a specified TTL
112
- def grant_lease(ttl)
113
- request.handle(:lease, 'grant_lease', [ttl])
137
+ def lease_grant(ttl)
138
+ request.handle(:lease, 'lease_grant', [ttl])
114
139
  end
115
140
 
116
141
  # Revokes lease and delete all attached keys
117
- def revoke_lease(id)
118
- request.handle(:lease, 'revoke_lease', [id])
142
+ def lease_revoke(id)
143
+ request.handle(:lease, 'lease_revoke', [id])
119
144
  end
120
145
 
121
146
  # Returns information regarding the current state of the lease
@@ -123,99 +148,73 @@ class Etcdv3
123
148
  request.handle(:lease, 'lease_ttl', [id])
124
149
  end
125
150
 
126
- # Creates new user.
127
- def add_user(user, password)
128
- request.handle(:auth, 'add_user', [user, password])
129
- end
130
-
131
- # Fetch specified user
132
- def get_user(user)
133
- request.handle(:auth, 'get_user', [user])
134
- end
135
-
136
- # Delete specified user.
137
- def delete_user(user)
138
- request.handle(:auth, 'delete_user', [user])
139
- end
140
-
141
- # Changes the specified users password.
142
- def change_user_password(user, new_password)
143
- request.handle(:auth, 'change_user_password', [user, new_password])
144
- end
145
-
146
- # List all users.
147
- def user_list
148
- request.handle(:auth, 'user_list')
149
- end
150
-
151
151
  # List all roles.
152
152
  def role_list
153
153
  request.handle(:auth, 'role_list')
154
154
  end
155
155
 
156
156
  # Add role with specified name.
157
- def add_role(name)
158
- request.handle(:auth, 'add_role', [name])
157
+ def role_add(name)
158
+ request.handle(:auth, 'role_add', [name])
159
159
  end
160
160
 
161
161
  # Fetches a specified role.
162
- def get_role(name)
163
- request.handle(:auth, 'get_role', [name])
162
+ def role_get(name)
163
+ request.handle(:auth, 'role_get', [name])
164
164
  end
165
165
 
166
166
  # Delete role.
167
- def delete_role(name)
168
- request.handle(:auth, 'delete_role', [name])
167
+ def role_delete(name)
168
+ request.handle(:auth, 'role_delete', [name])
169
169
  end
170
170
 
171
- # Grants role to an existing user.
172
- def grant_role_to_user(user, role)
173
- request.handle(:auth, 'grant_role_to_user', [user, role])
171
+ # Grants a new permission to an existing role.
172
+ def role_grant_permission(name, permission, key, range_end='')
173
+ request.handle(:auth, 'role_grant_permission', [name, permission, key, range_end])
174
174
  end
175
175
 
176
- # Revokes role from a specified user.
177
- def revoke_role_from_user(user, role)
178
- request.handle(:auth, 'revoke_role_from_user', [user, role])
176
+ def role_revoke_permission(name, permission, key, range_end='')
177
+ request.handle(:auth, 'role_revoke_permission', [name, permission, key, range_end])
179
178
  end
180
179
 
181
- # Grants a new permission to an existing role.
182
- def grant_permission_to_role(name, permission, key, range_end='')
183
- request.handle(:auth, 'grant_permission_to_role', [name, permission, key, range_end])
180
+ # Fetch specified user
181
+ def user_get(user)
182
+ request.handle(:auth, 'user_get', [user])
184
183
  end
185
184
 
186
- def revoke_permission_from_role(name, permission, key, range_end='')
187
- request.handle(:auth, 'revoke_permission_from_role', [name, permission, key, range_end])
185
+ # Creates new user.
186
+ def user_add(user, password)
187
+ request.handle(:auth, 'user_add', [user, password])
188
188
  end
189
189
 
190
- # Enables authentication.
191
- def enable_auth
192
- request.handle(:auth, 'enable_auth')
190
+ # Delete specified user.
191
+ def user_delete(user)
192
+ request.handle(:auth, 'user_delete', [user])
193
193
  end
194
194
 
195
- # Disables authentication.
196
- # This will clear any active auth / token data.
197
- def disable_auth
198
- response = request.handle(:auth, 'disable_auth')
199
- if response
200
- @metadata.delete(:token)
201
- @options[:user] = nil
202
- @options[:password] = nil
203
- @metacache = set_metacache
204
- end
205
- response
195
+ # Changes the specified users password.
196
+ def user_change_password(user, new_password)
197
+ request.handle(:auth, 'user_change_password', [user, new_password])
206
198
  end
207
199
 
208
- # Authenticate using specified user and password.
209
- # On successful authentication, an auth token will be assigned to the instance.
210
- def authenticate(user, password)
211
- token = generate_token(user, password)
212
- return false unless token
213
- @metadata[:token] = token
214
- @options[:user] = user
215
- @options[:password] = password
216
- @metacache = set_metacache
200
+ # List all users.
201
+ def user_list
202
+ request.handle(:auth, 'user_list')
203
+ end
217
204
 
218
- true
205
+ # Grants role to an existing user.
206
+ def user_grant_role(user, role)
207
+ request.handle(:auth, 'user_grant_role', [user, role])
208
+ end
209
+
210
+ # Revokes role from a specified user.
211
+ def user_revoke_role(user, role)
212
+ request.handle(:auth, 'user_revoke_role', [user, role])
213
+ end
214
+
215
+ # Watches for changes on a specified key range.
216
+ def watch(key, range_end: '', &block)
217
+ request.handle(:watch, 'watch', [key, range_end, block])
219
218
  end
220
219
 
221
220
  private
data/lib/etcdv3/auth.rb CHANGED
@@ -3,9 +3,9 @@ class Etcdv3
3
3
  class Auth
4
4
 
5
5
  PERMISSIONS = {
6
- 'read' => Authpb::Permission::Type::READ,
7
- 'write' => Authpb::Permission::Type::WRITE,
8
- 'readwrite' => Authpb::Permission::Type::READWRITE
6
+ :read => Authpb::Permission::Type::READ,
7
+ :write => Authpb::Permission::Type::WRITE,
8
+ :readwrite => Authpb::Permission::Type::READWRITE
9
9
  }
10
10
 
11
11
  def initialize(hostname, credentials, metadata = {})
@@ -13,71 +13,32 @@ class Etcdv3
13
13
  @metadata = metadata
14
14
  end
15
15
 
16
- def generate_token(user, password)
17
- request = Etcdserverpb::AuthenticateRequest.new(
18
- name: user,
19
- password: password
20
- )
21
- @stub.authenticate(request).token
22
- end
23
-
24
- def user_list
25
- request = Etcdserverpb::AuthUserListRequest.new
26
- @stub.user_list(request, metadata: @metadata)
27
- end
28
-
29
- def add_user(user, password)
30
- request = Etcdserverpb::AuthUserAddRequest.new(
31
- name: user,
32
- password: password
33
- )
34
- @stub.user_add(request, metadata: @metadata)
35
- end
36
-
37
- def delete_user(user)
38
- request = Etcdserverpb::AuthUserDeleteRequest.new(name: user)
39
- @stub.user_delete(request)
40
- end
41
-
42
- def get_user(user)
43
- request = Etcdserverpb::AuthUserGetRequest.new(name: user)
44
- @stub.user_get(request)
16
+ def auth_enable
17
+ request = Etcdserverpb::AuthEnableRequest.new
18
+ @stub.auth_enable(request)
45
19
  end
46
20
 
47
- def change_user_password(user, new_password)
48
- request = Etcdserverpb::AuthUserChangePasswordRequest.new(
49
- name: user,
50
- password: new_password
51
- )
52
- @stub.user_change_password(request, metadata: @metadata)
21
+ def auth_disable
22
+ request = Etcdserverpb::AuthDisableRequest.new
23
+ @stub.auth_disable(request, metadata: @metadata)
53
24
  end
54
25
 
55
- def add_role(name)
26
+ def role_add(name)
56
27
  request = Etcdserverpb::AuthRoleAddRequest.new(name: name)
57
28
  @stub.role_add(request, metadata: @metadata)
58
29
  end
59
30
 
60
- def get_role(name)
31
+ def role_get(name)
61
32
  request = Etcdserverpb::AuthRoleGetRequest.new(role: name)
62
33
  @stub.role_get(request, metadata: @metadata)
63
34
  end
64
35
 
65
- def delete_role(name)
36
+ def role_delete(name)
66
37
  request = Etcdserverpb::AuthRoleDeleteRequest.new(role: name)
67
38
  @stub.role_delete(request, metadata: @metadata)
68
39
  end
69
40
 
70
- def grant_role_to_user(user, role)
71
- request = Etcdserverpb::AuthUserGrantRoleRequest.new(user: user, role: role)
72
- @stub.user_grant_role(request, metadata: @metadata)
73
- end
74
-
75
- def revoke_role_from_user(user, role)
76
- request = Etcdserverpb::AuthUserRevokeRoleRequest.new(name: user, role: role)
77
- @stub.user_revoke_role(request, metadata: @metadata)
78
- end
79
-
80
- def grant_permission_to_role(name, permission, key, range_end)
41
+ def role_grant_permission(name, permission, key, range_end)
81
42
  permission = Authpb::Permission.new(
82
43
  permType: Etcdv3::Auth::PERMISSIONS[permission], key: key, range_end: range_end
83
44
  )
@@ -90,7 +51,7 @@ class Etcdv3
90
51
  )
91
52
  end
92
53
 
93
- def revoke_permission_from_role(name, permission, key, range_end)
54
+ def role_revoke_permission(name, permission, key, range_end)
94
55
  @stub.role_revoke_permission(
95
56
  Etcdserverpb::AuthRoleRevokePermissionRequest.new(
96
57
  role: name,
@@ -106,14 +67,53 @@ class Etcdv3
106
67
  @stub.role_list(request, metadata: @metadata)
107
68
  end
108
69
 
109
- def enable_auth
110
- request = Etcdserverpb::AuthEnableRequest.new
111
- @stub.auth_enable(request)
70
+ def user_list
71
+ request = Etcdserverpb::AuthUserListRequest.new
72
+ @stub.user_list(request, metadata: @metadata)
112
73
  end
113
74
 
114
- def disable_auth
115
- request = Etcdserverpb::AuthDisableRequest.new
116
- @stub.auth_disable(request, metadata: @metadata)
75
+ def user_add(user, password)
76
+ request = Etcdserverpb::AuthUserAddRequest.new(
77
+ name: user,
78
+ password: password
79
+ )
80
+ @stub.user_add(request, metadata: @metadata)
81
+ end
82
+
83
+ def user_delete(user)
84
+ request = Etcdserverpb::AuthUserDeleteRequest.new(name: user)
85
+ @stub.user_delete(request)
86
+ end
87
+
88
+ def user_get(user)
89
+ request = Etcdserverpb::AuthUserGetRequest.new(name: user)
90
+ @stub.user_get(request)
91
+ end
92
+
93
+ def user_change_password(user, new_password)
94
+ request = Etcdserverpb::AuthUserChangePasswordRequest.new(
95
+ name: user,
96
+ password: new_password
97
+ )
98
+ @stub.user_change_password(request, metadata: @metadata)
99
+ end
100
+
101
+ def user_grant_role(user, role)
102
+ request = Etcdserverpb::AuthUserGrantRoleRequest.new(user: user, role: role)
103
+ @stub.user_grant_role(request, metadata: @metadata)
104
+ end
105
+
106
+ def user_revoke_role(user, role)
107
+ request = Etcdserverpb::AuthUserRevokeRoleRequest.new(name: user, role: role)
108
+ @stub.user_revoke_role(request, metadata: @metadata)
109
+ end
110
+
111
+ def generate_token(user, password)
112
+ request = Etcdserverpb::AuthenticateRequest.new(
113
+ name: user,
114
+ password: password
115
+ )
116
+ @stub.authenticate(request).token
117
117
  end
118
118
 
119
119
  end
data/lib/etcdv3/kv.rb CHANGED
@@ -21,12 +21,6 @@ class Etcdv3
21
21
  @metadata = metadata
22
22
  end
23
23
 
24
- def put(key, value, lease=nil)
25
- kv = Etcdserverpb::PutRequest.new(key: key, value: value)
26
- kv.lease = lease if lease
27
- @stub.put(kv, metadata: @metadata)
28
- end
29
-
30
24
  def get(key, opts={})
31
25
  opts[:sort_order] = SORT_ORDER[opts[:sort_order]] \
32
26
  if opts[:sort_order]
@@ -44,5 +38,11 @@ class Etcdv3
44
38
  )
45
39
  @stub.delete_range(request, metadata: @metadata)
46
40
  end
41
+
42
+ def put(key, value, lease=nil)
43
+ kv = Etcdserverpb::PutRequest.new(key: key, value: value)
44
+ kv.lease = lease if lease
45
+ @stub.put(kv, metadata: @metadata)
46
+ end
47
47
  end
48
48
  end
data/lib/etcdv3/lease.rb CHANGED
@@ -6,12 +6,12 @@ class Etcdv3
6
6
  @metadata = metadata
7
7
  end
8
8
 
9
- def grant_lease(ttl)
9
+ def lease_grant(ttl)
10
10
  request = Etcdserverpb::LeaseGrantRequest.new(TTL: ttl)
11
11
  @stub.lease_grant(request, metadata: @metadata)
12
12
  end
13
13
 
14
- def revoke_lease(id)
14
+ def lease_revoke(id)
15
15
  request = Etcdserverpb::LeaseRevokeRequest.new(ID: id)
16
16
  @stub.lease_revoke(request, metadata: @metadata)
17
17
  end
@@ -21,5 +21,7 @@ class Etcdv3
21
21
  @stub.lease_time_to_live(request, metadata: @metadata)
22
22
  end
23
23
 
24
+
25
+
24
26
  end
25
27
  end
@@ -17,10 +17,6 @@ class Etcdv3
17
17
  @metadata = metadata
18
18
  end
19
19
 
20
- def member_status
21
- @stub.status(Etcdserverpb::StatusRequest.new, metadata: @metadata)
22
- end
23
-
24
20
  def alarms(action, member_id, alarm=:NONE)
25
21
  alarm = ALARM_TYPES[alarm]
26
22
  request = Etcdserverpb::AlarmRequest.new(
@@ -30,5 +26,10 @@ class Etcdv3
30
26
  )
31
27
  @stub.alarm(request)
32
28
  end
29
+
30
+ def member_status
31
+ @stub.status(Etcdserverpb::StatusRequest.new, metadata: @metadata)
32
+ end
33
+
33
34
  end
34
35
  end
@@ -3,43 +3,33 @@ class Etcdv3
3
3
 
4
4
  attr_reader :metacache
5
5
 
6
- def initialize(hostname, credentials, metadata, metacache)
7
- @hostname = hostname
8
- @credentials = credentials
9
- @metadata = metadata
6
+ def initialize(hostname, credentials, metadata, metacache='')
7
+ @handlers ||= handler_map(hostname, credentials, metadata)
10
8
  @metacache = metacache
11
9
  end
12
10
 
13
- def handle(interface, method, method_args=[])
14
- interface = resolve_interface(interface)
15
- interface.send(method, *method_args)
11
+ def handle(stub, method, method_args=[])
12
+ @handlers.fetch(stub).send(method, *method_args)
16
13
  end
17
14
 
18
15
  private
19
16
 
20
- def resolve_interface(interface)
21
- self.send(interface)
17
+ def handler_map(hostname, credentials, metadata)
18
+ Hash[
19
+ handler_constants.map do |key, klass|
20
+ [key, klass.new(hostname, credentials, metadata)]
21
+ end
22
+ ]
22
23
  end
23
24
 
24
- def auth
25
- @auth ||= Etcdv3::Auth.new(@hostname, @credentials, @metadata)
25
+ def handler_constants
26
+ {
27
+ auth: Etcdv3::Auth,
28
+ kv: Etcdv3::KV,
29
+ maintenance: Etcdv3::Maintenance,
30
+ lease: Etcdv3::Lease,
31
+ watch: Etcdv3::Watch
32
+ }
26
33
  end
27
-
28
- def kv
29
- @kv ||= Etcdv3::KV.new(@hostname, @credentials, @metadata)
30
- end
31
-
32
- def maintenance
33
- @maintenance ||= Etcdv3::Maintenance.new(@hostname, @credentials, @metadata)
34
- end
35
-
36
- def lease
37
- @lease ||= Etcdv3::Lease.new(@hostname, @credentials, @metadata)
38
- end
39
-
40
- def watch
41
- @watch ||= Etcdv3::Watch.new(@hostname, @credentials, @metadata)
42
- end
43
-
44
34
  end
45
35
  end
@@ -1,3 +1,3 @@
1
1
  class Etcdv3
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  end
data/lib/etcdv3/watch.rb CHANGED
@@ -10,7 +10,7 @@ class Etcdv3
10
10
  create_req = Etcdserverpb::WatchCreateRequest.new(key: key, range_end: range_end)
11
11
  watch_req = Etcdserverpb::WatchRequest.new(create_request: create_req)
12
12
  events = nil
13
- @stub.watch([watch_req]).each do |resp|
13
+ @stub.watch([watch_req], metadata: @metadata).each do |resp|
14
14
  next if resp.events.empty?
15
15
  if block
16
16
  block.call(resp.events)
@@ -21,6 +21,5 @@ class Etcdv3
21
21
  end
22
22
  events
23
23
  end
24
-
25
24
  end
26
25
  end
@@ -4,16 +4,16 @@ describe Etcdv3::Auth do
4
4
 
5
5
  let(:stub) { local_stub(Etcdv3::Auth) }
6
6
 
7
- describe '#add_user' do
8
- after { stub.delete_user('boom') }
9
- subject { stub.add_user('boom', 'test') }
7
+ describe '#user_add' do
8
+ after { stub.user_delete('boom') }
9
+ subject { stub.user_add('boom', 'test') }
10
10
  it { is_expected.to be_an_instance_of(Etcdserverpb::AuthUserAddResponse) }
11
11
  end
12
12
 
13
- describe '#get_user' do
14
- before { stub.add_user('get_user', 'password') }
15
- after { stub.delete_user('get_user') }
16
- subject { stub.get_user('get_user') }
13
+ describe '#user_get' do
14
+ before { stub.user_add('user_get', 'password') }
15
+ after { stub.user_delete('user_get') }
16
+ subject { stub.user_get('user_get') }
17
17
  it { is_expected.to be_an_instance_of(Etcdserverpb::AuthUserGetResponse) }
18
18
  end
19
19
 
@@ -22,51 +22,51 @@ describe Etcdv3::Auth do
22
22
  it { is_expected.to be_an_instance_of(Etcdserverpb::AuthUserListResponse) }
23
23
  end
24
24
 
25
- describe '#delete_user' do
26
- before { stub.add_user('delete_user', 'test') }
27
- subject { stub.delete_user('delete_user') }
25
+ describe '#user_delete' do
26
+ before { stub.user_add('user_delete', 'test') }
27
+ subject { stub.user_delete('user_delete') }
28
28
  it { is_expected.to be_an_instance_of(Etcdserverpb::AuthUserDeleteResponse) }
29
29
  end
30
30
 
31
- describe '#grant_role_to_user' do
32
- before { stub.add_user('grant_user', 'test') }
33
- after { stub.delete_user('grant_user') }
34
- subject { stub.grant_role_to_user('grant_user', 'root') }
31
+ describe '#user_grant_role' do
32
+ before { stub.user_add('grant_user', 'test') }
33
+ after { stub.user_delete('grant_user') }
34
+ subject { stub.user_grant_role('grant_user', 'root') }
35
35
  it { is_expected.to be_an_instance_of(Etcdserverpb::AuthUserGrantRoleResponse) }
36
36
  end
37
37
 
38
- describe '#revoke_role_from_user' do
38
+ describe '#user_revoke_role' do
39
39
  before do
40
- stub.add_user('revoke_user', 'password')
41
- stub.grant_role_to_user('revoke_user', 'root')
40
+ stub.user_add('revoke_user', 'password')
41
+ stub.user_grant_role('revoke_user', 'root')
42
42
  end
43
- after { stub.delete_user('revoke_user') }
44
- subject { stub.revoke_role_from_user('revoke_user', 'root') }
43
+ after { stub.user_delete('revoke_user') }
44
+ subject { stub.user_revoke_role('revoke_user', 'root') }
45
45
  it { is_expected.to be_an_instance_of(Etcdserverpb::AuthUserRevokeRoleResponse) }
46
46
  end
47
47
 
48
- describe '#add_role' do
49
- after { stub.delete_role('add_role') }
50
- subject { stub.add_role('add_role') }
48
+ describe '#role_add' do
49
+ after { stub.role_delete('role_add') }
50
+ subject { stub.role_add('role_add') }
51
51
  it 'adds a role' do
52
52
  expect(subject).to be_an_instance_of(Etcdserverpb::AuthRoleAddResponse)
53
- expect(stub.role_list.roles).to include('add_role')
53
+ expect(stub.role_list.roles).to include('role_add')
54
54
  end
55
55
  end
56
56
 
57
- describe '#get_role' do
58
- before { stub.add_role('get_role') }
59
- after { stub.delete_role('get_role') }
60
- subject { stub.get_role('get_role') }
57
+ describe '#role_get' do
58
+ before { stub.role_add('role_get') }
59
+ after { stub.role_delete('role_get') }
60
+ subject { stub.role_get('role_get') }
61
61
  it { is_expected.to be_an_instance_of(Etcdserverpb::AuthRoleGetResponse) }
62
62
  end
63
63
 
64
- describe '#delete_role' do
65
- before { stub.add_role('delete_role') }
66
- subject { stub.delete_role('delete_role') }
64
+ describe '#role_delete' do
65
+ before { stub.role_add('role_delete') }
66
+ subject { stub.role_delete('role_delete') }
67
67
  it 'deletes role' do
68
68
  expect(subject).to be_an_instance_of(Etcdserverpb::AuthRoleDeleteResponse)
69
- expect(stub.role_list.roles).to_not include('delete_role')
69
+ expect(stub.role_list.roles).to_not include('role_delete')
70
70
  end
71
71
  end
72
72
 
@@ -75,10 +75,10 @@ describe Etcdv3::Auth do
75
75
  it { is_expected.to be_an_instance_of(Etcdserverpb::AuthRoleListResponse) }
76
76
  end
77
77
 
78
- describe '#grant_permission_to_role' do
79
- before { stub.add_role('grant_perm') }
80
- after { stub.delete_role('grant_perm') }
81
- subject { stub.grant_permission_to_role('grant_perm', 'write', 'c', 'cc') }
78
+ describe '#role_grant_permission' do
79
+ before { stub.role_add('grant_perm') }
80
+ after { stub.role_delete('grant_perm') }
81
+ subject { stub.role_grant_permission('grant_perm', :write, 'c', 'cc') }
82
82
  it 'sets permission' do
83
83
  expect(subject).to be_an_instance_of(Etcdserverpb::AuthRoleGrantPermissionResponse)
84
84
  end
@@ -86,21 +86,21 @@ describe Etcdv3::Auth do
86
86
 
87
87
  describe '#revoke_permission_from_role' do
88
88
  before do
89
- stub.add_role('myrole')
90
- stub.grant_permission_to_role('myrole', 'write', 'c', 'cc')
89
+ stub.role_add('myrole')
90
+ stub.role_grant_permission('myrole', :write, 'c', 'cc')
91
91
  end
92
- after { stub.delete_role('myrole') }
93
- subject { stub.revoke_permission_from_role('myrole', 'write', 'c', 'cc') }
92
+ after { stub.role_delete('myrole') }
93
+ subject { stub.role_revoke_permission('myrole', :write, 'c', 'cc') }
94
94
  it 'revokes permission' do
95
95
  expect(subject).to be_an_instance_of(Etcdserverpb::AuthRoleRevokePermissionResponse)
96
- expect(stub.get_role('myrole').perm.size).to eq(0)
96
+ expect(stub.role_get('myrole').perm.size).to eq(0)
97
97
  end
98
98
  end
99
99
 
100
- describe '#change_user_password' do
101
- before { stub.add_user('myuser', 'test') }
102
- after { stub.delete_user('myuser') }
103
- subject { stub.change_user_password('myuser', 'boom') }
100
+ describe '#user_change_password' do
101
+ before { stub.user_add('myuser', 'test') }
102
+ after { stub.user_delete('myuser') }
103
+ subject { stub.user_change_password('myuser', 'boom') }
104
104
  it { is_expected.to be_an_instance_of(Etcdserverpb::AuthUserChangePasswordResponse) }
105
105
  end
106
106
 
@@ -11,7 +11,7 @@ describe Etcdv3::KV do
11
11
  end
12
12
 
13
13
  context 'with lease' do
14
- let(:lease_id) { lease_stub.grant_lease(1)['ID'] }
14
+ let(:lease_id) { lease_stub.lease_grant(1)['ID'] }
15
15
  subject { stub.put('lease', 'test', lease_id) }
16
16
  it { is_expected.to be_an_instance_of(Etcdserverpb::PutResponse) }
17
17
  end
@@ -4,22 +4,22 @@ describe Etcdv3::Lease do
4
4
 
5
5
  let(:stub) { local_stub(Etcdv3::Lease) }
6
6
 
7
- describe '#grant_lease' do
8
- subject { stub.grant_lease(10) }
7
+ describe '#lease_grant' do
8
+ subject { stub.lease_grant(10) }
9
9
  it 'grants lease' do
10
10
  expect(subject).to be_an_instance_of(Etcdserverpb::LeaseGrantResponse)
11
11
  expect(subject['ID']).to_not be_nil
12
12
  end
13
13
  end
14
14
 
15
- describe '#revoke_lease' do
16
- let(:id) { stub.grant_lease(60)['ID'] }
17
- subject { stub.revoke_lease(id) }
15
+ describe '#lease_revoke' do
16
+ let(:id) { stub.lease_grant(60)['ID'] }
17
+ subject { stub.lease_revoke(id) }
18
18
  it { is_expected.to be_an_instance_of(Etcdserverpb::LeaseRevokeResponse) }
19
19
  end
20
20
 
21
21
  describe '#lease_ttl' do
22
- let(:id) { stub.grant_lease(10)['ID'] }
22
+ let(:id) { stub.lease_grant(10)['ID'] }
23
23
  subject { stub.lease_ttl(id) }
24
24
  it { is_expected.to be_an_instance_of(Etcdserverpb::LeaseTimeToLiveResponse) }
25
25
  end
@@ -15,7 +15,7 @@ describe Etcdv3::Maintenance do
15
15
  it { is_expected.to be_an_instance_of(Etcdserverpb::AlarmResponse) }
16
16
  end
17
17
 
18
- describe '#deactivate_alarms' do
18
+ describe '#alarm_deactivate' do
19
19
  let(:leader_id) { stub.member_status.leader }
20
20
  subject { stub.alarms(:deactivate, leader_id, :NOSPACE) }
21
21
  it { is_expected.to be_an_instance_of(Etcdserverpb::AlarmResponse) }
data/spec/etcdv3_spec.rb CHANGED
@@ -18,16 +18,16 @@ describe Etcdv3 do
18
18
  context 'with auth' do
19
19
  let(:auth_conn) { local_connection_with_auth('test', 'pass') }
20
20
  before do
21
- conn.add_user('root', 'pass')
22
- conn.grant_role_to_user('root', 'root')
23
- conn.add_user('test', 'pass')
24
- conn.enable_auth
21
+ conn.user_add('root', 'pass')
22
+ conn.user_grant_role('root', 'root')
23
+ conn.user_add('test', 'pass')
24
+ conn.auth_enable
25
25
  end
26
26
  after do
27
27
  conn.authenticate('root', 'pass')
28
- conn.disable_auth
29
- conn.delete_user('root')
30
- conn.delete_user('test')
28
+ conn.auth_disable
29
+ conn.user_delete('root')
30
+ conn.user_delete('test')
31
31
  end
32
32
  it 'doesnt raise error' do
33
33
  expect{ auth_conn }.to_not raise_error
@@ -55,8 +55,8 @@ describe Etcdv3 do
55
55
  it { is_expected.to_not be_nil }
56
56
  end
57
57
 
58
- describe '#deactivate_alarms' do
59
- subject { conn.deactivate_alarms }
58
+ describe '#alarm_deactivate' do
59
+ subject { conn.alarm_deactivate }
60
60
  it { is_expected.to_not be_nil }
61
61
  end
62
62
 
@@ -113,39 +113,39 @@ describe Etcdv3 do
113
113
  end
114
114
  end
115
115
 
116
- describe '#grant_lease' do
117
- subject { conn.grant_lease(2) }
116
+ describe '#lease_grant' do
117
+ subject { conn.lease_grant(2) }
118
118
  it { is_expected.to_not be_nil }
119
119
  end
120
120
 
121
- describe '#revoke_lease' do
122
- let!(:lease_id) { conn.grant_lease(2)['ID'] }
123
- subject { conn.revoke_lease(lease_id) }
121
+ describe '#lease_revoke' do
122
+ let!(:lease_id) { conn.lease_grant(2)['ID'] }
123
+ subject { conn.lease_revoke(lease_id) }
124
124
  it { is_expected.to_not be_nil }
125
125
  end
126
126
 
127
127
  describe '#lease_ttl' do
128
- let!(:lease_id) { conn.grant_lease(2)['ID'] }
128
+ let!(:lease_id) { conn.lease_grant(2)['ID'] }
129
129
  subject { conn.lease_ttl(lease_id) }
130
130
  it { is_expected.to_not be_nil }
131
131
  end
132
132
 
133
- describe '#add_user' do
134
- after { conn.delete_user('test') }
135
- subject { conn.add_user('test', 'user') }
133
+ describe '#user_add' do
134
+ after { conn.user_delete('test') }
135
+ subject { conn.user_add('test', 'user') }
136
136
  it { is_expected.to_not be_nil }
137
137
  end
138
138
 
139
- describe '#delete_user' do
140
- before { conn.add_user('test', 'user') }
141
- subject { conn.delete_user('test') }
139
+ describe '#user_delete' do
140
+ before { conn.user_add('test', 'user') }
141
+ subject { conn.user_delete('test') }
142
142
  it { is_expected.to_not be_nil }
143
143
  end
144
144
 
145
- describe '#change_user_password' do
146
- before { conn.add_user('change_user', 'pass') }
147
- after { conn.delete_user('change_user') }
148
- subject { conn.change_user_password('change_user', 'new_pass') }
145
+ describe '#user_change_password' do
146
+ before { conn.user_add('change_user', 'pass') }
147
+ after { conn.user_delete('change_user') }
148
+ subject { conn.user_change_password('change_user', 'new_pass') }
149
149
  it { is_expected.to_not be_nil }
150
150
  end
151
151
 
@@ -159,76 +159,76 @@ describe Etcdv3 do
159
159
  it { is_expected.to_not be_nil }
160
160
  end
161
161
 
162
- describe '#add_role' do
163
- subject { conn.add_role('add_role') }
162
+ describe '#role_add' do
163
+ subject { conn.role_add('role_add') }
164
164
  it { is_expected.to_not be_nil }
165
165
  end
166
166
 
167
- describe '#delete_role' do
168
- before { conn.add_role('delete_role') }
169
- subject { conn.delete_role('delete_role') }
167
+ describe '#role_delete' do
168
+ before { conn.role_add('role_delete') }
169
+ subject { conn.role_delete('role_delete') }
170
170
  it { is_expected.to_not be_nil }
171
171
  end
172
172
 
173
- describe '#grant_role_to_user' do
174
- before { conn.add_user('grant_me', 'pass') }
175
- subject { conn.grant_role_to_user('grant_me', 'root') }
173
+ describe '#user_grant_role' do
174
+ before { conn.user_add('grant_me', 'pass') }
175
+ subject { conn.user_grant_role('grant_me', 'root') }
176
176
  it { is_expected.to_not be_nil }
177
177
  end
178
178
 
179
- describe '#revoke_role_from_user' do
180
- subject { conn.revoke_role_from_user('grant_me', 'root') }
179
+ describe '#user_revoke_role' do
180
+ subject { conn.user_revoke_role('grant_me', 'root') }
181
181
  it { is_expected.to_not be_nil }
182
182
  end
183
183
 
184
- describe '#grant_permission_to_role' do
185
- before { conn.add_role('grant') }
186
- subject { conn.grant_permission_to_role('grant', 'readwrite', 'a', 'Z') }
184
+ describe '#role_grant_permission' do
185
+ before { conn.role_add('grant') }
186
+ subject { conn.role_grant_permission('grant', :readwrite, 'a', 'Z') }
187
187
  it { is_expected.to_not be_nil }
188
188
  end
189
189
 
190
190
  describe '#revoke_permission_to_role' do
191
- subject { conn.revoke_permission_from_role('grant', 'readwrite', 'a', 'Z') }
191
+ subject { conn.role_revoke_permission('grant', :readwrite, 'a', 'Z') }
192
192
  it { is_expected.to_not be_nil }
193
193
  end
194
194
 
195
- describe '#disable_auth' do
195
+ describe '#auth_disable' do
196
196
  before do
197
- conn.add_user('root', 'test')
198
- conn.grant_role_to_user('root', 'root')
199
- conn.enable_auth
197
+ conn.user_add('root', 'test')
198
+ conn.user_grant_role('root', 'root')
199
+ conn.auth_enable
200
200
  conn.authenticate('root', 'test')
201
201
  end
202
- after { conn.delete_user('root') }
203
- subject { conn.disable_auth }
202
+ after { conn.user_delete('root') }
203
+ subject { conn.auth_disable }
204
204
  it { is_expected.to be_an_instance_of(Etcdserverpb::AuthDisableResponse) }
205
205
  end
206
206
 
207
- describe '#enable_auth' do
207
+ describe '#auth_enable' do
208
208
  before do
209
- conn.add_user('root', 'test')
210
- conn.grant_role_to_user('root', 'root')
209
+ conn.user_add('root', 'test')
210
+ conn.user_grant_role('root', 'root')
211
211
  end
212
212
  after do
213
213
  conn.authenticate('root', 'test')
214
- conn.disable_auth
215
- conn.delete_user('root')
214
+ conn.auth_disable
215
+ conn.user_delete('root')
216
216
  end
217
- subject { conn.enable_auth }
217
+ subject { conn.auth_enable }
218
218
  it { is_expected.to be_an_instance_of(Etcdserverpb::AuthEnableResponse) }
219
219
  end
220
220
 
221
221
  describe "#authenticate" do
222
222
  context "auth enabled" do
223
223
  before do
224
- conn.add_user('root', 'test')
225
- conn.grant_role_to_user('root', 'root')
226
- conn.enable_auth
224
+ conn.user_add('root', 'test')
225
+ conn.user_grant_role('root', 'root')
226
+ conn.auth_enable
227
227
  conn.authenticate('root', 'test')
228
228
  end
229
229
  after do
230
- conn.disable_auth
231
- conn.delete_user('root')
230
+ conn.auth_disable
231
+ conn.user_delete('root')
232
232
  end
233
233
  it 'properly reconfigures auth and token' do
234
234
  expect(conn.token).to_not be_nil
@@ -247,24 +247,24 @@ describe Etcdv3 do
247
247
  describe '#metacache' do
248
248
  context 'uses cached request object' do
249
249
  let!(:object_id) { conn.send(:request).object_id }
250
- before { conn.add_user('root', 'test') }
251
- after { conn.delete_user('root') }
250
+ before { conn.user_add('root', 'test') }
251
+ after { conn.user_delete('root') }
252
252
  subject { conn.send(:request).object_id }
253
253
  it { is_expected.to eq(object_id) }
254
254
  end
255
255
  context 'resets cache on auth' do
256
256
  let!(:object_id) { conn.send(:request).object_id }
257
257
  before do
258
- conn.add_user('root', 'test')
259
- conn.grant_role_to_user('root', 'root')
260
- conn.enable_auth
258
+ conn.user_add('root', 'test')
259
+ conn.user_grant_role('root', 'root')
260
+ conn.auth_enable
261
261
  conn.authenticate('root', 'test')
262
- conn.add_user('boom', 'password')
262
+ conn.user_add('boom', 'password')
263
263
  end
264
264
  after do
265
- conn.disable_auth
266
- conn.delete_user('root')
267
- conn.delete_user('boom')
265
+ conn.auth_disable
266
+ conn.user_delete('root')
267
+ conn.user_delete('boom')
268
268
  end
269
269
  subject { conn.send(:request).object_id }
270
270
  it { is_expected.to_not eq(object_id) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etcdv3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaun Davis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-14 00:00:00.000000000 Z
11
+ date: 2017-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grpc