etcdv3 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/etcdv3/version.rb +1 -1
- data/lib/etcdv3.rb +11 -11
- data/spec/etcdv3_spec.rb +211 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e2fce5dfb236ef001c050f60f6fec8162914121
|
4
|
+
data.tar.gz: 0ae18b137efb5cbd7c328a6690615f2f6c68c65b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b06266232676bd25db0521874cd846069b473091f34cf1dc7d0a5dc2b06575d141323aa917411854ba186d8134d5f1ef09c22e5ff919167c6ecae164a65dce4b
|
7
|
+
data.tar.gz: 305a579ce7e7c0c202c8643ba1ea3cbb265abf3dded50a748b6ad839ef78acb22f1ce72e3d62ad0edefa6ef288f65b52e0828482d7658f3fbb5192b4a1017ec0
|
data/lib/etcdv3/version.rb
CHANGED
data/lib/etcdv3.rb
CHANGED
@@ -65,6 +65,16 @@ class Etcd
|
|
65
65
|
request.handle(:maintenance, 'member_status').leader
|
66
66
|
end
|
67
67
|
|
68
|
+
# List active alarms
|
69
|
+
def alarm_list
|
70
|
+
request.handle(:maintenance, 'alarms', [:get, leader_id])
|
71
|
+
end
|
72
|
+
|
73
|
+
# Disarm alarms on a specified member.
|
74
|
+
def deactivate_alarms
|
75
|
+
request.handle(:maintenance, 'alarms', [:deactivate, leader_id])
|
76
|
+
end
|
77
|
+
|
68
78
|
# Inserts a new key.
|
69
79
|
def put(key, value, lease_id: nil)
|
70
80
|
request.handle(:kv, 'put', [key, value, lease_id])
|
@@ -72,7 +82,7 @@ class Etcd
|
|
72
82
|
|
73
83
|
# Fetches key(s).
|
74
84
|
def get(key, range_end='')
|
75
|
-
request.handle(:
|
85
|
+
request.handle(:kv, 'get', [key, range_end])
|
76
86
|
end
|
77
87
|
|
78
88
|
# Grant a lease with a speified TTL
|
@@ -154,16 +164,6 @@ class Etcd
|
|
154
164
|
request.handle(:auth, 'revoke_permission_from_role', [name, permission, key, range_end])
|
155
165
|
end
|
156
166
|
|
157
|
-
# List active alarms
|
158
|
-
def alarm_list
|
159
|
-
request.handle(:maintenance, 'alarms', [:get, leader_id])
|
160
|
-
end
|
161
|
-
|
162
|
-
# Disarm alarms on a specified member.
|
163
|
-
def deactivate_alarms
|
164
|
-
request.handle(:maintenance, 'alarms', [leader_id])
|
165
|
-
end
|
166
|
-
|
167
167
|
# Enables authentication.
|
168
168
|
def enable_auth
|
169
169
|
request.handle(:auth, 'enable_auth')
|
data/spec/etcdv3_spec.rb
ADDED
@@ -0,0 +1,211 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Etcd do
|
4
|
+
context 'Insecure connection without Auth' do
|
5
|
+
|
6
|
+
let(:conn) { local_connection }
|
7
|
+
|
8
|
+
describe '#initialize' do
|
9
|
+
subject { conn }
|
10
|
+
it { is_expected.to have_attributes(scheme: 'http') }
|
11
|
+
it { is_expected.to have_attributes(hostname: '127.0.0.1') }
|
12
|
+
it { is_expected.to have_attributes(credentials: :this_channel_is_insecure) }
|
13
|
+
it { is_expected.to have_attributes(token: nil) }
|
14
|
+
it { is_expected.to have_attributes(user: nil) }
|
15
|
+
it { is_expected.to have_attributes(password: nil) }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#version' do
|
19
|
+
subject { conn.version }
|
20
|
+
it { is_expected.to be_an_instance_of(String) }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#db_size' do
|
24
|
+
subject { conn.db_size }
|
25
|
+
it { is_expected.to_not be_nil }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#leader_id' do
|
29
|
+
subject { conn.leader_id }
|
30
|
+
it { is_expected.to_not be_nil }
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#alarm_list' do
|
34
|
+
subject { conn.alarm_list }
|
35
|
+
it { is_expected.to_not be_nil }
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#deactivate_alarms' do
|
39
|
+
subject { conn.deactivate_alarms }
|
40
|
+
it { is_expected.to_not be_nil }
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#get' do
|
44
|
+
subject { conn.get('test') }
|
45
|
+
it { is_expected.to_not be_nil }
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#put' do
|
49
|
+
subject { conn.put('test', 'value') }
|
50
|
+
it { is_expected.to_not be_nil }
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#grant_lease' do
|
54
|
+
subject { conn.grant_lease(2) }
|
55
|
+
it { is_expected.to_not be_nil }
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#revoke_lease' do
|
59
|
+
let!(:lease_id) { conn.grant_lease(2)['ID'] }
|
60
|
+
subject { conn.revoke_lease(lease_id) }
|
61
|
+
it { is_expected.to_not be_nil }
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#lease_ttl' do
|
65
|
+
let!(:lease_id) { conn.grant_lease(2)['ID'] }
|
66
|
+
subject { conn.lease_ttl(lease_id) }
|
67
|
+
it { is_expected.to_not be_nil }
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#add_user' do
|
71
|
+
after { conn.delete_user('test') }
|
72
|
+
subject { conn.add_user('test', 'user') }
|
73
|
+
it { is_expected.to_not be_nil }
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#delete_user' do
|
77
|
+
before { conn.add_user('test', 'user') }
|
78
|
+
subject { conn.delete_user('test') }
|
79
|
+
it { is_expected.to_not be_nil }
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '#change_user_password' do
|
83
|
+
before { conn.add_user('change_user', 'pass') }
|
84
|
+
after { conn.delete_user('change_user') }
|
85
|
+
subject { conn.change_user_password('change_user', 'new_pass') }
|
86
|
+
it { is_expected.to_not be_nil }
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '#user_list' do
|
90
|
+
subject { conn.user_list }
|
91
|
+
it { is_expected.to_not be_nil }
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '#role_list' do
|
95
|
+
subject { conn.role_list }
|
96
|
+
it { is_expected.to_not be_nil }
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#add_role' do
|
100
|
+
subject { conn.add_role('add_role') }
|
101
|
+
it { is_expected.to_not be_nil }
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '#delete_role' do
|
105
|
+
before { conn.add_role('delete_role') }
|
106
|
+
subject { conn.delete_role('delete_role') }
|
107
|
+
it { is_expected.to_not be_nil }
|
108
|
+
end
|
109
|
+
|
110
|
+
describe '#grant_role_to_user' do
|
111
|
+
before { conn.add_user('grant_me', 'pass') }
|
112
|
+
subject { conn.grant_role_to_user('grant_me', 'root') }
|
113
|
+
it { is_expected.to_not be_nil }
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '#revoke_role_from_user' do
|
117
|
+
subject { conn.revoke_role_from_user('grant_me', 'root') }
|
118
|
+
it { is_expected.to_not be_nil }
|
119
|
+
end
|
120
|
+
|
121
|
+
describe '#grant_permission_to_role' do
|
122
|
+
before { conn.add_role('grant') }
|
123
|
+
subject { conn.grant_permission_to_role('grant', 'readwrite', 'a', 'Z') }
|
124
|
+
it { is_expected.to_not be_nil }
|
125
|
+
end
|
126
|
+
|
127
|
+
describe '#revoke_permission_to_role' do
|
128
|
+
subject { conn.revoke_permission_from_role('grant', 'readwrite', 'a', 'Z') }
|
129
|
+
it { is_expected.to_not be_nil }
|
130
|
+
end
|
131
|
+
|
132
|
+
describe '#disable_auth' do
|
133
|
+
before do
|
134
|
+
conn.add_user('root', 'test')
|
135
|
+
conn.grant_role_to_user('root', 'root')
|
136
|
+
conn.enable_auth
|
137
|
+
conn.authenticate('root', 'test')
|
138
|
+
end
|
139
|
+
after { conn.delete_user('root') }
|
140
|
+
subject { conn.disable_auth }
|
141
|
+
it { is_expected.to be_an_instance_of(Etcdserverpb::AuthDisableResponse) }
|
142
|
+
end
|
143
|
+
|
144
|
+
describe '#enable_auth' do
|
145
|
+
before do
|
146
|
+
conn.add_user('root', 'test')
|
147
|
+
conn.grant_role_to_user('root', 'root')
|
148
|
+
end
|
149
|
+
after do
|
150
|
+
conn.authenticate('root', 'test')
|
151
|
+
conn.disable_auth
|
152
|
+
conn.delete_user('root')
|
153
|
+
end
|
154
|
+
subject { conn.enable_auth }
|
155
|
+
it { is_expected.to be_an_instance_of(Etcdserverpb::AuthEnableResponse) }
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "#authenticate" do
|
159
|
+
context "auth enabled" do
|
160
|
+
before do
|
161
|
+
conn.add_user('root', 'test')
|
162
|
+
conn.grant_role_to_user('root', 'root')
|
163
|
+
conn.enable_auth
|
164
|
+
conn.authenticate('root', 'test')
|
165
|
+
end
|
166
|
+
after do
|
167
|
+
conn.disable_auth
|
168
|
+
conn.delete_user('root')
|
169
|
+
end
|
170
|
+
it 'properly reconfigures auth and token' do
|
171
|
+
expect(conn.token).to_not be_nil
|
172
|
+
expect(conn.user).to eq('root')
|
173
|
+
expect(conn.password).to eq('test')
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context 'auth disabled' do
|
178
|
+
it 'raises error' do
|
179
|
+
expect { conn.authenticate('root', 'root') }.to raise_error(GRPC::InvalidArgument)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
describe '#metacache' do
|
185
|
+
context 'uses cached request object' do
|
186
|
+
let!(:object_id) { conn.send(:request).object_id }
|
187
|
+
before { conn.add_user('root', 'test') }
|
188
|
+
after { conn.delete_user('root') }
|
189
|
+
subject { conn.send(:request).object_id }
|
190
|
+
it { is_expected.to eq(object_id) }
|
191
|
+
end
|
192
|
+
context 'resets cache on auth' do
|
193
|
+
let!(:object_id) { conn.send(:request).object_id }
|
194
|
+
before do
|
195
|
+
conn.add_user('root', 'test')
|
196
|
+
conn.grant_role_to_user('root', 'root')
|
197
|
+
conn.enable_auth
|
198
|
+
conn.authenticate('root', 'test')
|
199
|
+
conn.add_user('boom', 'password')
|
200
|
+
end
|
201
|
+
after do
|
202
|
+
conn.disable_auth
|
203
|
+
conn.delete_user('root')
|
204
|
+
conn.delete_user('boom')
|
205
|
+
end
|
206
|
+
subject { conn.send(:request).object_id }
|
207
|
+
it { is_expected.to_not eq(object_id) }
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
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.1.
|
4
|
+
version: 0.1.5
|
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-
|
11
|
+
date: 2017-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grpc
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- spec/etcdv3/kv_spec.rb
|
74
74
|
- spec/etcdv3/lease_spec.rb
|
75
75
|
- spec/etcdv3/maintenance_spec.rb
|
76
|
+
- spec/etcdv3_spec.rb
|
76
77
|
- spec/helpers/connections.rb
|
77
78
|
- spec/helpers/test_instance.rb
|
78
79
|
- spec/spec_helper.rb
|
@@ -106,6 +107,7 @@ test_files:
|
|
106
107
|
- spec/etcdv3/kv_spec.rb
|
107
108
|
- spec/etcdv3/lease_spec.rb
|
108
109
|
- spec/etcdv3/maintenance_spec.rb
|
110
|
+
- spec/etcdv3_spec.rb
|
109
111
|
- spec/helpers/connections.rb
|
110
112
|
- spec/helpers/test_instance.rb
|
111
113
|
- spec/spec_helper.rb
|