etcdv3 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +30 -8
- data/lib/etcdv3/auth.rb +24 -15
- data/lib/etcdv3/kv.rb +11 -2
- data/lib/etcdv3/lease.rb +25 -0
- data/lib/etcdv3/version.rb +1 -1
- data/lib/etcdv3.rb +22 -2
- data/spec/etcd_spec.rb +67 -0
- data/spec/etcdv3/auth_spec.rb +39 -94
- data/spec/etcdv3/kv_spec.rb +29 -10
- data/spec/etcdv3/lease_spec.rb +29 -0
- data/spec/etcdv3/maintenance_spec.rb +11 -28
- metadata +6 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: afad56a64c9b93a3438296356e13a9980625d193
|
|
4
|
+
data.tar.gz: 6190434f69a1645f25f5336f3bebaf1efc8f3775
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 95d1672d8f0e0cd1843bf76d2998977c347711887ebacbae463d2d4aa86586b9c4ce663b9dd28e220c8a7cd87d55c94c7cb3381af98988c4ad232d2a733e9913
|
|
7
|
+
data.tar.gz: 520c207ec53edc8a5ea840f138780c4b7a3e0f2a21180f135045dbb170e3bdaed9a2ebc2fb72b192e7de8295d67f83be9a5572cc9677196a4607b917c3a5f5e7
|
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Ruby client for Etcd V3
|
|
4
4
|
|
|
5
|
-
**
|
|
5
|
+
**Warning: This is under active development and should be considered unstable**
|
|
6
6
|
|
|
7
7
|
## Getting Started
|
|
8
8
|
|
|
@@ -31,16 +31,23 @@ conn = Etcd.new(url: 'https://hostname:port', user: "gary", password: "secret")
|
|
|
31
31
|
# Coming soon...
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
**Adding and
|
|
34
|
+
**Adding, Fetching and Deleting Keys**
|
|
35
|
+
```
|
|
36
|
+
# Put
|
|
37
|
+
conn.put("my", "value")
|
|
38
|
+
|
|
39
|
+
# Get
|
|
40
|
+
conn.get("my")
|
|
35
41
|
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
# Get Key Range
|
|
43
|
+
conn.get('my', 'myyyy')
|
|
38
44
|
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
# Delete Key
|
|
46
|
+
conn.del('my')
|
|
41
47
|
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
# Delete Key Range
|
|
49
|
+
conn.del('my', 'myyy')
|
|
50
|
+
```
|
|
44
51
|
|
|
45
52
|
**User Management**
|
|
46
53
|
```
|
|
@@ -90,6 +97,21 @@ Disabling auth will clear the auth token and all previously attached user inform
|
|
|
90
97
|
conn.disable_auth
|
|
91
98
|
```
|
|
92
99
|
|
|
100
|
+
**Leases**
|
|
101
|
+
```
|
|
102
|
+
# Grant a lease with a 100 second TTL
|
|
103
|
+
conn.grant_lease(100)
|
|
104
|
+
|
|
105
|
+
# Attach key to lease
|
|
106
|
+
conn.put("testkey", "testvalue", lease: 1234566789)
|
|
107
|
+
|
|
108
|
+
# Get information about lease and its attached keys
|
|
109
|
+
conn.lease_ttl(1234566789)
|
|
110
|
+
|
|
111
|
+
# Revoke lease and delete all keys attached
|
|
112
|
+
conn.revoke_lease(1234566789)
|
|
113
|
+
```
|
|
114
|
+
|
|
93
115
|
**Alarms**
|
|
94
116
|
```
|
|
95
117
|
# List all active Alarms
|
data/lib/etcdv3/auth.rb
CHANGED
|
@@ -14,30 +14,34 @@ class Etcd
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def generate_token(user, password)
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
request = Etcdserverpb::AuthenticateRequest.new(
|
|
18
|
+
name: user,
|
|
19
|
+
password: password
|
|
19
20
|
)
|
|
20
|
-
|
|
21
|
-
rescue GRPC::FailedPrecondition, GRPC::InvalidArgument => exception
|
|
22
|
-
false
|
|
21
|
+
@stub.authenticate(request).token
|
|
23
22
|
end
|
|
24
23
|
|
|
25
24
|
def user_list
|
|
26
|
-
|
|
25
|
+
request = Etcdserverpb::AuthUserListRequest.new
|
|
26
|
+
@stub.user_list(request, metadata: @metadata)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def add_user(user, password)
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
request = Etcdserverpb::AuthUserAddRequest.new(
|
|
31
|
+
name: user,
|
|
32
|
+
password: password
|
|
32
33
|
)
|
|
34
|
+
@stub.user_add(request, metadata: @metadata)
|
|
33
35
|
end
|
|
34
36
|
|
|
35
37
|
def delete_user(user)
|
|
36
|
-
|
|
38
|
+
request = Etcdserverpb::AuthUserDeleteRequest.new(name: user)
|
|
39
|
+
@stub.user_delete(request)
|
|
37
40
|
end
|
|
38
41
|
|
|
39
42
|
def get_user(user)
|
|
40
|
-
|
|
43
|
+
request = Etcdserverpb::AuthUserGetRequest.new(name: user)
|
|
44
|
+
@stub.user_get(request)
|
|
41
45
|
end
|
|
42
46
|
|
|
43
47
|
def change_user_password(user, new_password)
|
|
@@ -49,7 +53,8 @@ class Etcd
|
|
|
49
53
|
end
|
|
50
54
|
|
|
51
55
|
def add_role(name)
|
|
52
|
-
|
|
56
|
+
request = Etcdserverpb::AuthRoleAddRequest.new(name: name)
|
|
57
|
+
@stub.role_add(request, metadata: @metadata)
|
|
53
58
|
end
|
|
54
59
|
|
|
55
60
|
def get_role(name)
|
|
@@ -58,7 +63,8 @@ class Etcd
|
|
|
58
63
|
end
|
|
59
64
|
|
|
60
65
|
def delete_role(name)
|
|
61
|
-
|
|
66
|
+
request = Etcdserverpb::AuthRoleDeleteRequest.new(role: name)
|
|
67
|
+
@stub.role_delete(request, metadata: @metadata)
|
|
62
68
|
end
|
|
63
69
|
|
|
64
70
|
def grant_role_to_user(user, role)
|
|
@@ -96,15 +102,18 @@ class Etcd
|
|
|
96
102
|
end
|
|
97
103
|
|
|
98
104
|
def role_list
|
|
99
|
-
|
|
105
|
+
request = Etcdserverpb::AuthRoleListRequest.new
|
|
106
|
+
@stub.role_list(request, metadata: @metadata)
|
|
100
107
|
end
|
|
101
108
|
|
|
102
109
|
def enable_auth
|
|
103
|
-
|
|
110
|
+
request = Etcdserverpb::AuthEnableRequest.new
|
|
111
|
+
@stub.auth_enable(request)
|
|
104
112
|
end
|
|
105
113
|
|
|
106
114
|
def disable_auth
|
|
107
|
-
|
|
115
|
+
request = Etcdserverpb::AuthDisableRequest.new
|
|
116
|
+
@stub.auth_disable(request, metadata: @metadata)
|
|
108
117
|
end
|
|
109
118
|
|
|
110
119
|
end
|
data/lib/etcdv3/kv.rb
CHANGED
|
@@ -6,14 +6,23 @@ class Etcd
|
|
|
6
6
|
@metadata = metadata
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
def put(key, value)
|
|
9
|
+
def put(key, value, lease=nil)
|
|
10
10
|
kv = Etcdserverpb::PutRequest.new(key: key, value: value)
|
|
11
|
+
kv.lease = lease if lease
|
|
11
12
|
@stub.put(kv, metadata: @metadata)
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
def get(key, range_end="")
|
|
15
16
|
kv = Etcdserverpb::RangeRequest.new(key: key, range_end: range_end)
|
|
16
|
-
@stub.range(kv, metadata: @metadata)
|
|
17
|
+
@stub.range(kv, metadata: @metadata)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def del(key, range_end="")
|
|
21
|
+
request = Etcdserverpb::DeleteRangeRequest.new(
|
|
22
|
+
key: key,
|
|
23
|
+
range_end: range_end
|
|
24
|
+
)
|
|
25
|
+
@stub.delete_range(request, metadata: @metadata)
|
|
17
26
|
end
|
|
18
27
|
end
|
|
19
28
|
end
|
data/lib/etcdv3/lease.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
class Etcd
|
|
3
|
+
class Lease
|
|
4
|
+
def initialize(hostname, port, credentials, metadata={})
|
|
5
|
+
@stub = Etcdserverpb::Lease::Stub.new("#{hostname}:#{port}", credentials)
|
|
6
|
+
@metadata = metadata
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def grant_lease(ttl)
|
|
10
|
+
request = Etcdserverpb::LeaseGrantRequest.new(TTL: ttl)
|
|
11
|
+
@stub.lease_grant(request, metadata: @metadata)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def revoke_lease(id)
|
|
15
|
+
request = Etcdserverpb::LeaseRevokeRequest.new(ID: id)
|
|
16
|
+
@stub.lease_revoke(request, metadata: @metadata)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def lease_ttl(id)
|
|
20
|
+
request = Etcdserverpb::LeaseTimeToLiveRequest.new(ID: id, keys: true)
|
|
21
|
+
@stub.lease_time_to_live(request, metadata: @metadata)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
end
|
data/lib/etcdv3/version.rb
CHANGED
data/lib/etcdv3.rb
CHANGED
|
@@ -6,6 +6,7 @@ require 'etcdv3/etcdrpc/rpc_services_pb'
|
|
|
6
6
|
require 'etcdv3/auth'
|
|
7
7
|
require 'etcdv3/kv'
|
|
8
8
|
require 'etcdv3/maintenance'
|
|
9
|
+
require 'etcdv3/lease'
|
|
9
10
|
|
|
10
11
|
class Etcd
|
|
11
12
|
|
|
@@ -62,8 +63,8 @@ class Etcd
|
|
|
62
63
|
end
|
|
63
64
|
|
|
64
65
|
# Inserts a new key.
|
|
65
|
-
def put(key, value)
|
|
66
|
-
kv.put(key, value)
|
|
66
|
+
def put(key, value, lease_id: nil)
|
|
67
|
+
kv.put(key, value, lease_id)
|
|
67
68
|
end
|
|
68
69
|
|
|
69
70
|
# Fetches key(s).
|
|
@@ -71,6 +72,21 @@ class Etcd
|
|
|
71
72
|
kv.get(key, range_end)
|
|
72
73
|
end
|
|
73
74
|
|
|
75
|
+
# Grant a lease with a speified TTL
|
|
76
|
+
def grant_lease(ttl)
|
|
77
|
+
lease.grant_lease(ttl)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Revokes lease and delete all attached keys
|
|
81
|
+
def revoke_lease(id)
|
|
82
|
+
lease.revoke_lease(id)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Returns information regarding the current state of the lease
|
|
86
|
+
def lease_ttl(id)
|
|
87
|
+
lease.lease_ttl(id)
|
|
88
|
+
end
|
|
89
|
+
|
|
74
90
|
# Creates new user.
|
|
75
91
|
def add_user(user, password)
|
|
76
92
|
auth.add_user(user, password)
|
|
@@ -188,6 +204,10 @@ class Etcd
|
|
|
188
204
|
Etcd::Maintenance.new(hostname, port, @credentials, @metadata)
|
|
189
205
|
end
|
|
190
206
|
|
|
207
|
+
def lease
|
|
208
|
+
Etcd::Lease.new(hostname, port, @credentials, @metadata)
|
|
209
|
+
end
|
|
210
|
+
|
|
191
211
|
def resolve_credentials
|
|
192
212
|
case scheme
|
|
193
213
|
when 'http'
|
data/spec/etcd_spec.rb
CHANGED
|
@@ -15,5 +15,72 @@ describe Etcd do
|
|
|
15
15
|
it { is_expected.to have_attributes(user: nil) }
|
|
16
16
|
it { is_expected.to have_attributes(password: nil) }
|
|
17
17
|
end
|
|
18
|
+
|
|
19
|
+
describe '#version' do
|
|
20
|
+
subject { conn.version }
|
|
21
|
+
it { is_expected.to be_an_instance_of(String) }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe '#db_size' do
|
|
25
|
+
subject { conn.db_size }
|
|
26
|
+
it { is_expected.to_not be_nil }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe '#leader_id' do
|
|
30
|
+
subject { conn.leader_id.class }
|
|
31
|
+
it { is_expected.to_not be_nil }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe '#disable_auth' do
|
|
35
|
+
before do
|
|
36
|
+
conn.add_user('root', 'test')
|
|
37
|
+
conn.grant_role_to_user('root', 'root')
|
|
38
|
+
conn.enable_auth
|
|
39
|
+
conn.authenticate('root', 'test')
|
|
40
|
+
end
|
|
41
|
+
after { conn.delete_user('root') }
|
|
42
|
+
subject { conn.disable_auth }
|
|
43
|
+
it { is_expected.to be_an_instance_of(Etcdserverpb::AuthDisableResponse) }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe '#enable_auth' do
|
|
47
|
+
before do
|
|
48
|
+
conn.add_user('root', 'test')
|
|
49
|
+
conn.grant_role_to_user('root', 'root')
|
|
50
|
+
end
|
|
51
|
+
after do
|
|
52
|
+
conn.authenticate('root', 'test')
|
|
53
|
+
conn.disable_auth
|
|
54
|
+
conn.delete_user('root')
|
|
55
|
+
end
|
|
56
|
+
subject { conn.enable_auth }
|
|
57
|
+
it { is_expected.to be_an_instance_of(Etcdserverpb::AuthEnableResponse) }
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
describe "#authenticate" do
|
|
61
|
+
context "auth enabled" do
|
|
62
|
+
before do
|
|
63
|
+
conn.add_user('root', 'test')
|
|
64
|
+
conn.grant_role_to_user('root', 'root')
|
|
65
|
+
conn.enable_auth
|
|
66
|
+
conn.authenticate('root', 'test')
|
|
67
|
+
end
|
|
68
|
+
after do
|
|
69
|
+
conn.disable_auth
|
|
70
|
+
conn.delete_user('root')
|
|
71
|
+
end
|
|
72
|
+
it 'properly reconfigures auth and token' do
|
|
73
|
+
expect(conn.token).to_not be_nil
|
|
74
|
+
expect(conn.user).to eq('root')
|
|
75
|
+
expect(conn.password).to eq('test')
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
context 'auth disabled' do
|
|
80
|
+
it 'raises error' do
|
|
81
|
+
expect { conn.authenticate('root', 'root') }.to raise_error(GRPC::InvalidArgument)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
18
85
|
end
|
|
19
86
|
end
|
data/spec/etcdv3/auth_spec.rb
CHANGED
|
@@ -2,90 +2,85 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe Etcd::Auth do
|
|
4
4
|
|
|
5
|
-
let(:
|
|
6
|
-
Etcd.new(
|
|
5
|
+
let(:stub) do
|
|
6
|
+
Etcd::Auth.new("127.0.0.1", 2379, :this_channel_is_insecure, {})
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
describe '#add_user' do
|
|
10
|
-
after {
|
|
11
|
-
subject {
|
|
10
|
+
after { stub.delete_user('boom') }
|
|
11
|
+
subject { stub.add_user('boom', 'test') }
|
|
12
12
|
it { is_expected.to be_an_instance_of(Etcdserverpb::AuthUserAddResponse) }
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
describe '#get_user' do
|
|
16
|
-
before {
|
|
17
|
-
after {
|
|
18
|
-
subject {
|
|
16
|
+
before { stub.add_user('get_user', 'password') }
|
|
17
|
+
after { stub.delete_user('get_user') }
|
|
18
|
+
subject { stub.get_user('get_user') }
|
|
19
19
|
it { is_expected.to be_an_instance_of(Etcdserverpb::AuthUserGetResponse) }
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
describe '#user_list' do
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
subject { conn.user_list }
|
|
26
|
-
it 'returns correcty user information' do
|
|
27
|
-
expect(subject).to be_an_instance_of(Google::Protobuf::RepeatedField)
|
|
28
|
-
expect(subject).to include('list')
|
|
29
|
-
end
|
|
23
|
+
subject { stub.user_list }
|
|
24
|
+
it { is_expected.to be_an_instance_of(Etcdserverpb::AuthUserListResponse) }
|
|
30
25
|
end
|
|
31
26
|
|
|
32
27
|
describe '#delete_user' do
|
|
33
|
-
before {
|
|
34
|
-
subject {
|
|
28
|
+
before { stub.add_user('delete_user', 'test') }
|
|
29
|
+
subject { stub.delete_user('delete_user') }
|
|
35
30
|
it { is_expected.to be_an_instance_of(Etcdserverpb::AuthUserDeleteResponse) }
|
|
36
31
|
end
|
|
37
32
|
|
|
38
33
|
describe '#grant_role_to_user' do
|
|
39
|
-
before {
|
|
40
|
-
after {
|
|
41
|
-
subject {
|
|
34
|
+
before { stub.add_user('grant_user', 'test') }
|
|
35
|
+
after { stub.delete_user('grant_user') }
|
|
36
|
+
subject { stub.grant_role_to_user('grant_user', 'root') }
|
|
42
37
|
it { is_expected.to be_an_instance_of(Etcdserverpb::AuthUserGrantRoleResponse) }
|
|
43
38
|
end
|
|
44
39
|
|
|
45
40
|
describe '#revoke_role_from_user' do
|
|
46
41
|
before do
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
stub.add_user('revoke_user', 'password')
|
|
43
|
+
stub.grant_role_to_user('revoke_user', 'root')
|
|
49
44
|
end
|
|
50
|
-
after {
|
|
51
|
-
subject {
|
|
45
|
+
after { stub.delete_user('revoke_user') }
|
|
46
|
+
subject { stub.revoke_role_from_user('revoke_user', 'root') }
|
|
52
47
|
it { is_expected.to be_an_instance_of(Etcdserverpb::AuthUserRevokeRoleResponse) }
|
|
53
48
|
end
|
|
54
49
|
|
|
55
50
|
describe '#add_role' do
|
|
56
|
-
after {
|
|
57
|
-
subject {
|
|
51
|
+
after { stub.delete_role('add_role') }
|
|
52
|
+
subject { stub.add_role('add_role') }
|
|
58
53
|
it 'adds a role' do
|
|
59
54
|
expect(subject).to be_an_instance_of(Etcdserverpb::AuthRoleAddResponse)
|
|
60
|
-
expect(
|
|
55
|
+
expect(stub.role_list.roles).to include('add_role')
|
|
61
56
|
end
|
|
62
57
|
end
|
|
63
58
|
|
|
64
59
|
describe '#get_role' do
|
|
65
|
-
before {
|
|
66
|
-
after {
|
|
67
|
-
subject {
|
|
60
|
+
before { stub.add_role('get_role') }
|
|
61
|
+
after { stub.delete_role('get_role') }
|
|
62
|
+
subject { stub.get_role('get_role') }
|
|
68
63
|
it { is_expected.to be_an_instance_of(Etcdserverpb::AuthRoleGetResponse) }
|
|
69
64
|
end
|
|
70
65
|
|
|
71
66
|
describe '#delete_role' do
|
|
72
|
-
before {
|
|
73
|
-
subject {
|
|
67
|
+
before { stub.add_role('delete_role') }
|
|
68
|
+
subject { stub.delete_role('delete_role') }
|
|
74
69
|
it 'deletes role' do
|
|
75
70
|
expect(subject).to be_an_instance_of(Etcdserverpb::AuthRoleDeleteResponse)
|
|
76
|
-
expect(
|
|
71
|
+
expect(stub.role_list.roles).to_not include('delete_role')
|
|
77
72
|
end
|
|
78
73
|
end
|
|
79
74
|
|
|
80
75
|
describe '#role_list' do
|
|
81
|
-
subject {
|
|
76
|
+
subject { stub.role_list }
|
|
82
77
|
it { is_expected.to be_an_instance_of(Etcdserverpb::AuthRoleListResponse) }
|
|
83
78
|
end
|
|
84
79
|
|
|
85
80
|
describe '#grant_permission_to_role' do
|
|
86
|
-
before {
|
|
87
|
-
after {
|
|
88
|
-
subject {
|
|
81
|
+
before { stub.add_role('grant_perm') }
|
|
82
|
+
after { stub.delete_role('grant_perm') }
|
|
83
|
+
subject { stub.grant_permission_to_role('grant_perm', 'write', 'c', 'cc') }
|
|
89
84
|
it 'sets permission' do
|
|
90
85
|
expect(subject).to be_an_instance_of(Etcdserverpb::AuthRoleGrantPermissionResponse)
|
|
91
86
|
end
|
|
@@ -93,72 +88,22 @@ describe Etcd::Auth do
|
|
|
93
88
|
|
|
94
89
|
describe '#revoke_permission_from_role' do
|
|
95
90
|
before do
|
|
96
|
-
|
|
97
|
-
|
|
91
|
+
stub.add_role('myrole')
|
|
92
|
+
stub.grant_permission_to_role('myrole', 'write', 'c', 'cc')
|
|
98
93
|
end
|
|
99
|
-
after {
|
|
100
|
-
subject {
|
|
94
|
+
after { stub.delete_role('myrole') }
|
|
95
|
+
subject { stub.revoke_permission_from_role('myrole', 'write', 'c', 'cc') }
|
|
101
96
|
it 'revokes permission' do
|
|
102
97
|
expect(subject).to be_an_instance_of(Etcdserverpb::AuthRoleRevokePermissionResponse)
|
|
103
|
-
expect(
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
describe '#disable_auth' do
|
|
108
|
-
before do
|
|
109
|
-
conn.add_user('root', 'test')
|
|
110
|
-
conn.grant_role_to_user('root', 'root')
|
|
111
|
-
conn.enable_auth
|
|
112
|
-
conn.authenticate('root', 'test')
|
|
113
|
-
end
|
|
114
|
-
after { conn.delete_user('root') }
|
|
115
|
-
subject { conn.disable_auth }
|
|
116
|
-
it { is_expected.to be_an_instance_of(Etcdserverpb::AuthDisableResponse) }
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
describe '#enable_auth' do
|
|
120
|
-
before do
|
|
121
|
-
conn.add_user('root', 'test')
|
|
122
|
-
conn.grant_role_to_user('root', 'root')
|
|
98
|
+
expect(stub.get_role('myrole').perm.size).to eq(0)
|
|
123
99
|
end
|
|
124
|
-
after do
|
|
125
|
-
conn.authenticate('root', 'test')
|
|
126
|
-
conn.disable_auth
|
|
127
|
-
conn.delete_user('root')
|
|
128
|
-
end
|
|
129
|
-
subject { conn.enable_auth }
|
|
130
|
-
it { is_expected.to be_an_instance_of(Etcdserverpb::AuthEnableResponse) }
|
|
131
100
|
end
|
|
132
101
|
|
|
133
102
|
describe '#change_user_password' do
|
|
134
|
-
before {
|
|
135
|
-
after {
|
|
136
|
-
subject {
|
|
103
|
+
before { stub.add_user('myuser', 'test') }
|
|
104
|
+
after { stub.delete_user('myuser') }
|
|
105
|
+
subject { stub.change_user_password('myuser', 'boom') }
|
|
137
106
|
it { is_expected.to be_an_instance_of(Etcdserverpb::AuthUserChangePasswordResponse) }
|
|
138
107
|
end
|
|
139
108
|
|
|
140
|
-
describe "#authenticate" do
|
|
141
|
-
context "auth enabled" do
|
|
142
|
-
before do
|
|
143
|
-
conn.add_user('root', 'test')
|
|
144
|
-
conn.grant_role_to_user('root', 'root')
|
|
145
|
-
conn.enable_auth
|
|
146
|
-
conn.authenticate('root', 'test')
|
|
147
|
-
end
|
|
148
|
-
after do
|
|
149
|
-
conn.disable_auth
|
|
150
|
-
conn.delete_user('root')
|
|
151
|
-
end
|
|
152
|
-
it 'properly reconfigures auth and token' do
|
|
153
|
-
expect(conn.token).to_not be_nil
|
|
154
|
-
expect(conn.user).to eq('root')
|
|
155
|
-
expect(conn.password).to eq('test')
|
|
156
|
-
end
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
context 'auth disabled' do
|
|
160
|
-
subject { conn.authenticate('root', 'root') }
|
|
161
|
-
it { is_expected.to eq(false) }
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
109
|
end
|
data/spec/etcdv3/kv_spec.rb
CHANGED
|
@@ -2,22 +2,41 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe Etcd::KV do
|
|
4
4
|
|
|
5
|
-
let(:
|
|
6
|
-
Etcd.new(
|
|
5
|
+
let(:stub) do
|
|
6
|
+
Etcd::KV.new("127.0.0.1", 2379, :this_channel_is_insecure, {})
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
let(:lease_stub) do
|
|
10
|
+
Etcd::Lease.new("127.0.0.1", 2379, :this_channel_is_insecure, {})
|
|
7
11
|
end
|
|
8
12
|
|
|
9
13
|
describe '#put' do
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
context 'without lease' do
|
|
15
|
+
subject { stub.put('test', 'test') }
|
|
16
|
+
it { is_expected.to be_an_instance_of(Etcdserverpb::PutResponse) }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
context 'with lease' do
|
|
20
|
+
let(:lease_id) { lease_stub.grant_lease(1)['ID'] }
|
|
21
|
+
subject { stub.put('lease', 'test', lease_id) }
|
|
22
|
+
it { is_expected.to be_an_instance_of(Etcdserverpb::PutResponse) }
|
|
23
|
+
end
|
|
12
24
|
end
|
|
13
25
|
|
|
14
26
|
describe '#get' do
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
27
|
+
subject { stub.get('test') }
|
|
28
|
+
it { is_expected.to be_an_instance_of(Etcdserverpb::RangeResponse) }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe '#del' do
|
|
32
|
+
context 'del without range' do
|
|
33
|
+
subject { stub.del('test') }
|
|
34
|
+
it { is_expected.to be_an_instance_of(Etcdserverpb::DeleteRangeResponse) }
|
|
35
|
+
end
|
|
36
|
+
context 'del with range' do
|
|
37
|
+
subject { stub.del('test', 'testtt') }
|
|
38
|
+
it { is_expected.to be_an_instance_of(Etcdserverpb::DeleteRangeResponse) }
|
|
21
39
|
end
|
|
22
40
|
end
|
|
41
|
+
|
|
23
42
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Etcd::Lease do
|
|
4
|
+
|
|
5
|
+
let(:stub) do
|
|
6
|
+
Etcd::Lease.new("127.0.0.1", 2379, :this_channel_is_insecure, {})
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe '#grant_lease' do
|
|
10
|
+
subject { stub.grant_lease(10) }
|
|
11
|
+
it 'grants lease' do
|
|
12
|
+
expect(subject).to be_an_instance_of(Etcdserverpb::LeaseGrantResponse)
|
|
13
|
+
expect(subject['ID']).to_not be_nil
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe '#revoke_lease' do
|
|
18
|
+
let(:id) { stub.grant_lease(60)['ID'] }
|
|
19
|
+
subject { stub.revoke_lease(id) }
|
|
20
|
+
it { is_expected.to be_an_instance_of(Etcdserverpb::LeaseRevokeResponse) }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe '#lease_ttl' do
|
|
24
|
+
let(:id) { stub.grant_lease(10)['ID'] }
|
|
25
|
+
subject { stub.lease_ttl(id) }
|
|
26
|
+
it { is_expected.to be_an_instance_of(Etcdserverpb::LeaseTimeToLiveResponse) }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
@@ -2,42 +2,25 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe Etcd::Maintenance do
|
|
4
4
|
|
|
5
|
-
let(:
|
|
6
|
-
Etcd.new(
|
|
5
|
+
let(:stub) do
|
|
6
|
+
Etcd::Maintenance.new("127.0.0.1", 2379, :this_channel_is_insecure, {})
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
describe
|
|
10
|
-
subject {
|
|
11
|
-
it { is_expected.
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
describe '#leader_id' do
|
|
15
|
-
subject { conn.leader_id }
|
|
16
|
-
it { is_expected.to_not be_nil }
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
describe '#db_size' do
|
|
20
|
-
subject { conn.db_size }
|
|
21
|
-
it { is_expected.to_not be_nil }
|
|
9
|
+
describe "#member_status" do
|
|
10
|
+
subject { stub.member_status }
|
|
11
|
+
it { is_expected.to be_an_instance_of(Etcdserverpb::StatusResponse)}
|
|
22
12
|
end
|
|
23
13
|
|
|
24
14
|
describe '#alarm_list' do
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
it 'returns an alarm' do
|
|
29
|
-
expect(subject).to be_an_instance_of(Etcdserverpb::AlarmResponse)
|
|
30
|
-
expect(subject.alarms.size).to eq(1)
|
|
31
|
-
end
|
|
15
|
+
let(:leader_id) { stub.member_status.leader }
|
|
16
|
+
subject { stub.alarms(:get, leader_id)}
|
|
17
|
+
it { is_expected.to be_an_instance_of(Etcdserverpb::AlarmResponse) }
|
|
32
18
|
end
|
|
33
19
|
|
|
34
20
|
describe '#deactivate_alarms' do
|
|
35
|
-
|
|
36
|
-
subject {
|
|
37
|
-
it
|
|
38
|
-
expect(subject).to be_an_instance_of(Etcdserverpb::AlarmResponse)
|
|
39
|
-
expect(conn.alarm_list.alarms.size).to eq(0)
|
|
40
|
-
end
|
|
21
|
+
let(:leader_id) { stub.member_status.leader }
|
|
22
|
+
subject { stub.alarms(:deactivate, leader_id, :NOSPACE) }
|
|
23
|
+
it { is_expected.to be_an_instance_of(Etcdserverpb::AlarmResponse) }
|
|
41
24
|
end
|
|
42
25
|
|
|
43
26
|
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.3
|
|
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-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: grpc
|
|
@@ -57,6 +57,7 @@ files:
|
|
|
57
57
|
- lib/etcdv3/etcdrpc/rpc_pb.rb
|
|
58
58
|
- lib/etcdv3/etcdrpc/rpc_services_pb.rb
|
|
59
59
|
- lib/etcdv3/kv.rb
|
|
60
|
+
- lib/etcdv3/lease.rb
|
|
60
61
|
- lib/etcdv3/maintenance.rb
|
|
61
62
|
- lib/etcdv3/protos/annotations.proto
|
|
62
63
|
- lib/etcdv3/protos/auth.proto
|
|
@@ -69,6 +70,7 @@ files:
|
|
|
69
70
|
- spec/etcd_spec.rb
|
|
70
71
|
- spec/etcdv3/auth_spec.rb
|
|
71
72
|
- spec/etcdv3/kv_spec.rb
|
|
73
|
+
- spec/etcdv3/lease_spec.rb
|
|
72
74
|
- spec/etcdv3/maintenance_spec.rb
|
|
73
75
|
- spec/helpers/test_instance.rb
|
|
74
76
|
- spec/spec_helper.rb
|
|
@@ -92,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
92
94
|
version: '0'
|
|
93
95
|
requirements: []
|
|
94
96
|
rubyforge_project:
|
|
95
|
-
rubygems_version: 2.
|
|
97
|
+
rubygems_version: 2.4.5.1
|
|
96
98
|
signing_key:
|
|
97
99
|
specification_version: 4
|
|
98
100
|
summary: A Etcd client library for Version 3
|
|
@@ -100,6 +102,7 @@ test_files:
|
|
|
100
102
|
- spec/etcd_spec.rb
|
|
101
103
|
- spec/etcdv3/auth_spec.rb
|
|
102
104
|
- spec/etcdv3/kv_spec.rb
|
|
105
|
+
- spec/etcdv3/lease_spec.rb
|
|
103
106
|
- spec/etcdv3/maintenance_spec.rb
|
|
104
107
|
- spec/helpers/test_instance.rb
|
|
105
108
|
- spec/spec_helper.rb
|