etcdv3 0.0.4 → 0.0.5
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/.codeclimate.yml +27 -0
- data/.gitignore +6 -0
- data/.travis.yml +14 -0
- data/README.md +39 -14
- data/lib/etcdv3.rb +33 -18
- data/lib/etcdv3/auth.rb +61 -6
- data/lib/etcdv3/kv.rb +2 -4
- data/lib/etcdv3/version.rb +1 -1
- data/spec/etcd_spec.rb +3 -25
- data/spec/etcdv3/auth_spec.rb +103 -38
- data/spec/etcdv3/kv_spec.rb +31 -0
- data/spec/helpers/test_instance.rb +59 -0
- data/spec/spec_helper.rb +11 -3
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e8425d9e034d0a1bab9cc37a5250694854807e8
|
4
|
+
data.tar.gz: b49869fe7b0fa100faccc29dd9d06806753c6a5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '073189ecdbaa0c0719731731a4d2d05a0db0271855e7777f1c35d775d1196ea57554aa2cd8eaca7951e1a329dcf476d80f2024ee1aabe0ae540afe5ef024f5f7'
|
7
|
+
data.tar.gz: 0bdc23ddadaebb5827e3a241e5f7d7ec4a536d32196f1c1e64bbc3991433cd81fdbd05f664ea5cd1e776bede027b65da78754f1f1e8604a40295e63cdc83b920
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
engines:
|
2
|
+
duplication:
|
3
|
+
enabled: true
|
4
|
+
config:
|
5
|
+
languages:
|
6
|
+
- ruby
|
7
|
+
fixme:
|
8
|
+
enabled: true
|
9
|
+
rubocop:
|
10
|
+
enabled: true
|
11
|
+
ratings:
|
12
|
+
paths:
|
13
|
+
- "**.rb"
|
14
|
+
exclude_paths:
|
15
|
+
- spec/
|
16
|
+
engines:
|
17
|
+
rubocop:
|
18
|
+
enabled: true
|
19
|
+
duplication:
|
20
|
+
enabled: true
|
21
|
+
ratings:
|
22
|
+
paths:
|
23
|
+
- lib/**
|
24
|
+
- "**.rb"
|
25
|
+
exclude_paths:
|
26
|
+
- "lib/etcdv3/protos/*"
|
27
|
+
- "lib/etcdv3/etcdrpc/*"
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
language: ruby
|
2
|
+
python: 2.4
|
3
|
+
|
4
|
+
env:
|
5
|
+
global:
|
6
|
+
- ETCD_VERSION=v3.1.4
|
7
|
+
|
8
|
+
install:
|
9
|
+
- bundle install
|
10
|
+
- wget https://github.com/coreos/etcd/releases/download/$ETCD_VERSION/etcd-$ETCD_VERSION-linux-amd64.tar.gz -O etcd.tar.gz --no-check-certificate
|
11
|
+
- tar zxvf etcd.tar.gz
|
12
|
+
- export PATH=$PATH:etcd-$ETCD_VERSION-linux-amd64
|
13
|
+
|
14
|
+
script: bundle exec rspec
|
data/README.md
CHANGED
@@ -1,36 +1,61 @@
|
|
1
|
-
# etcdv3-ruby
|
1
|
+
# etcdv3-ruby [](https://travis-ci.org/davissp14/etcdv3-ruby)
|
2
2
|
|
3
3
|
Ruby client for Etcd V3
|
4
4
|
|
5
5
|
**WARNING: This is very much a work in progress and should be considered unstable.**
|
6
6
|
|
7
|
-
##
|
7
|
+
## Getting Started
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
To install etcdv3, run the following command:
|
10
|
+
```
|
11
|
+
gem install etcdv3
|
12
|
+
```
|
11
13
|
|
12
|
-
|
13
|
-
conn = Etcd.new(url: 'https://hostname:port')
|
14
|
+
You can connect to Etcd by instantiating the Etcd class:
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
```
|
17
|
+
require 'etcdv3'
|
18
|
+
|
19
|
+
# Insecure connection
|
20
|
+
conn = Etcd.new(url: 'http://127.0.0.1:2379')
|
21
|
+
|
22
|
+
# Secure connection using default certificates
|
23
|
+
conn = Etcd.new(url: 'https://hostname:port')
|
24
|
+
|
25
|
+
# Secure connection with Auth
|
26
|
+
conn = Etcd.new(url: 'https://hostname:port', user: "gary", password: "secret")
|
27
|
+
|
28
|
+
# Secure connection specifying own certificates
|
29
|
+
# Coming soon...
|
30
|
+
```
|
17
31
|
|
18
32
|
**Adding and Fetching Keys**
|
19
|
-
|
33
|
+
|
20
34
|
# Put
|
21
35
|
conn.put("my", "value")
|
22
36
|
|
23
37
|
# Range
|
24
38
|
conn.range("my")
|
25
|
-
|
39
|
+
|
26
40
|
**User Managment**
|
27
|
-
|
41
|
+
|
28
42
|
# Add User
|
29
43
|
conn.add_user('admin', 'secret')
|
30
|
-
|
44
|
+
|
31
45
|
# Delete User
|
32
46
|
conn.delete_user('admin')
|
33
|
-
|
47
|
+
|
34
48
|
# List users
|
35
49
|
conn.user_list
|
36
|
-
|
50
|
+
|
51
|
+
# Add Role
|
52
|
+
conn.add_role('rolename', 'readwrite', 'a', 'Z')
|
53
|
+
|
54
|
+
# Enable Authentication
|
55
|
+
conn.add_user('root', "secret")
|
56
|
+
conn.grant_role_to_user('root', 'root')
|
57
|
+
conn.enable_auth
|
58
|
+
|
59
|
+
# Disable Authentication
|
60
|
+
conn = Etcd.new(url: 'http://127.0.0.1:2379', user: 'root', password: 'secret')
|
61
|
+
conn.disable_auth
|
data/lib/etcdv3.rb
CHANGED
@@ -8,9 +8,7 @@ require 'etcdv3/kv'
|
|
8
8
|
|
9
9
|
class Etcd
|
10
10
|
|
11
|
-
|
12
|
-
Marshal.load(Martial.dump(@options))
|
13
|
-
end
|
11
|
+
attr_reader :credentials, :options
|
14
12
|
|
15
13
|
def uri
|
16
14
|
URI(@options[:url])
|
@@ -28,6 +26,10 @@ class Etcd
|
|
28
26
|
uri.hostname
|
29
27
|
end
|
30
28
|
|
29
|
+
def token
|
30
|
+
@metadata[:token]
|
31
|
+
end
|
32
|
+
|
31
33
|
def user
|
32
34
|
@options[:user]
|
33
35
|
end
|
@@ -36,21 +38,11 @@ class Etcd
|
|
36
38
|
@options[:password]
|
37
39
|
end
|
38
40
|
|
39
|
-
def
|
40
|
-
@metadata[:token]
|
41
|
-
end
|
42
|
-
|
43
|
-
def credentials
|
44
|
-
@credentials
|
45
|
-
end
|
46
|
-
|
47
|
-
def initialize(options={})
|
41
|
+
def initialize(options = {})
|
48
42
|
@options = options
|
49
43
|
@credentials = resolve_credentials
|
50
44
|
@metadata = {}
|
51
|
-
unless user.nil?
|
52
|
-
@metadata[:token] = auth.generate_token(user, password)
|
53
|
-
end
|
45
|
+
@metadata[:token] = auth.generate_token(user, password) unless user.nil?
|
54
46
|
end
|
55
47
|
|
56
48
|
def put(key, value)
|
@@ -61,7 +53,6 @@ class Etcd
|
|
61
53
|
kv.range(key, range_end, @metadata)
|
62
54
|
end
|
63
55
|
|
64
|
-
|
65
56
|
def add_user(user, password)
|
66
57
|
auth.add_user(user, password, @metadata)
|
67
58
|
end
|
@@ -74,6 +65,30 @@ class Etcd
|
|
74
65
|
auth.user_list(@metadata)
|
75
66
|
end
|
76
67
|
|
68
|
+
def role_list
|
69
|
+
auth.role_list(@metadata)
|
70
|
+
end
|
71
|
+
|
72
|
+
def add_role(name, permission, key, range_end='')
|
73
|
+
auth.add_role(name, permission, key, range_end, @metadata)
|
74
|
+
end
|
75
|
+
|
76
|
+
def delete_role(name)
|
77
|
+
auth.delete_role(name, @metadata)
|
78
|
+
end
|
79
|
+
|
80
|
+
def grant_role_to_user(user, role)
|
81
|
+
auth.grant_role_to_user(user, role, @metadata)
|
82
|
+
end
|
83
|
+
|
84
|
+
def enable_auth
|
85
|
+
auth.enable_auth
|
86
|
+
end
|
87
|
+
|
88
|
+
def disable_auth
|
89
|
+
auth.disable_auth(@metadata)
|
90
|
+
end
|
91
|
+
|
77
92
|
private
|
78
93
|
|
79
94
|
def auth
|
@@ -86,9 +101,9 @@ class Etcd
|
|
86
101
|
|
87
102
|
def resolve_credentials
|
88
103
|
case scheme
|
89
|
-
when
|
104
|
+
when 'http'
|
90
105
|
:this_channel_is_insecure
|
91
|
-
when
|
106
|
+
when 'https'
|
92
107
|
# Use default certs for now.
|
93
108
|
GRPC::Core::ChannelCredentials.new
|
94
109
|
else
|
data/lib/etcdv3/auth.rb
CHANGED
@@ -2,29 +2,84 @@
|
|
2
2
|
class Etcd
|
3
3
|
class Auth
|
4
4
|
|
5
|
+
PERMISSIONS = {
|
6
|
+
'read' => Authpb::Permission::Type::READ,
|
7
|
+
'write' => Authpb::Permission::Type::WRITE,
|
8
|
+
'readwrite' => Authpb::Permission::Type::READWRITE
|
9
|
+
}
|
10
|
+
|
5
11
|
def initialize(hostname, port, credentials)
|
6
12
|
@stub = Etcdserverpb::Auth::Stub.new("#{hostname}:#{port}", credentials)
|
7
13
|
end
|
8
14
|
|
9
15
|
def generate_token(user, password)
|
10
|
-
response = @stub.authenticate(
|
16
|
+
response = @stub.authenticate(
|
17
|
+
Authpb::User.new(name: user, password: password)
|
18
|
+
)
|
11
19
|
response.token
|
20
|
+
rescue GRPC::FailedPrecondition => exception
|
21
|
+
puts exception.message
|
12
22
|
end
|
13
23
|
|
14
|
-
def user_list(metadata={})
|
24
|
+
def user_list(metadata = {})
|
15
25
|
@stub.user_list(Authpb::User.new, metadata: metadata).users
|
26
|
+
rescue GRPC::FailedPrecondition => exception
|
27
|
+
puts exception.message
|
16
28
|
end
|
17
29
|
|
18
|
-
def add_user(user, password, metadata={})
|
19
|
-
@stub.user_add(
|
20
|
-
|
30
|
+
def add_user(user, password, metadata = {})
|
31
|
+
@stub.user_add(
|
32
|
+
Authpb::User.new(name: user, password: password), metadata: metadata
|
33
|
+
)
|
21
34
|
rescue GRPC::FailedPrecondition => exception
|
22
35
|
puts exception.message
|
23
36
|
end
|
24
37
|
|
25
|
-
def delete_user(user, metadata={})
|
38
|
+
def delete_user(user, metadata = {})
|
26
39
|
@stub.user_delete(Authpb::User.new(name: user), metadata: metadata)
|
40
|
+
rescue GRPC::FailedPrecondition => exception
|
41
|
+
puts exception.message
|
42
|
+
end
|
43
|
+
|
44
|
+
def add_role(name, permission, key, range_end, metadata = {})
|
45
|
+
permission = Authpb::Permission.new(
|
46
|
+
permType: Etcd::Auth::PERMISSIONS[permission], key: key, range_end: range_end
|
47
|
+
)
|
48
|
+
@stub.role_add(
|
49
|
+
Authpb::Role.new(name: name, keyPermission: [permission]),
|
50
|
+
metadata: metadata
|
51
|
+
)
|
52
|
+
rescue GRPC::FailedPrecondition => exception
|
53
|
+
puts exception.message
|
54
|
+
end
|
55
|
+
|
56
|
+
def delete_role(name, metadata = {})
|
57
|
+
@stub.role_delete(Authpb::Role.new(name: name), metadata: metadata)
|
58
|
+
rescue GRPC::FailedPrecondition => exception
|
59
|
+
puts exception.message
|
60
|
+
end
|
61
|
+
|
62
|
+
def grant_role_to_user(user, role, metadata = {})
|
63
|
+
request = Etcdserverpb::AuthUserGrantRoleRequest.new(user: user, role: role)
|
64
|
+
@stub.user_grant_role(request)
|
65
|
+
rescue GRPC::FailedPrecondition => exception
|
66
|
+
puts exception.message
|
67
|
+
end
|
68
|
+
|
69
|
+
def role_list(metadata = {})
|
70
|
+
@stub.role_list(Authpb::Role.new, metadata: metadata)
|
71
|
+
rescue GRPC::FailedPrecondition => exception
|
72
|
+
puts exception.message
|
73
|
+
end
|
74
|
+
|
75
|
+
def enable_auth
|
76
|
+
@stub.auth_enable(Authpb::User.new)
|
77
|
+
rescue GRPC::FailedPrecondition => exception
|
78
|
+
puts exception.message
|
79
|
+
end
|
27
80
|
|
81
|
+
def disable_auth(metadata = {})
|
82
|
+
@stub.auth_disable(Authpb::User.new, metadata: metadata)
|
28
83
|
rescue GRPC::FailedPrecondition => exception
|
29
84
|
puts exception.message
|
30
85
|
end
|
data/lib/etcdv3/kv.rb
CHANGED
@@ -1,21 +1,19 @@
|
|
1
1
|
|
2
2
|
class Etcd
|
3
3
|
class KV
|
4
|
-
|
5
4
|
def initialize(hostname, port, credentials)
|
6
5
|
@stub = Etcdserverpb::KV::Stub.new("#{hostname}:#{port}", credentials)
|
7
6
|
end
|
8
7
|
|
9
|
-
def put(key, value, metadata)
|
8
|
+
def put(key, value, metadata = {})
|
10
9
|
kv = Etcdserverpb::PutRequest.new(key: key, value: value)
|
11
10
|
@stub.put(kv, metadata: metadata)
|
12
11
|
end
|
13
12
|
|
14
|
-
def range(key, range_end, metadata)
|
13
|
+
def range(key, range_end, metadata = {})
|
15
14
|
kv = Etcdserverpb::RangeRequest.new(key: key, range_end: range_end)
|
16
15
|
result = @stub.range(kv, metadata: metadata)
|
17
16
|
result.kvs
|
18
17
|
end
|
19
|
-
|
20
18
|
end
|
21
19
|
end
|
data/lib/etcdv3/version.rb
CHANGED
data/spec/etcd_spec.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Etcd do
|
4
|
-
|
5
4
|
context 'Insecure connection without Auth' do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
)}
|
10
|
-
|
5
|
+
let(:conn) do
|
6
|
+
Etcd.new(url: 'http://127.0.0.1:2379')
|
7
|
+
end
|
11
8
|
describe '#initialize' do
|
12
|
-
|
13
9
|
it 'assigns scheme' do
|
14
10
|
expect(conn.scheme).to eq('http')
|
15
11
|
end
|
@@ -30,23 +26,5 @@ describe Etcd do
|
|
30
26
|
expect(conn.credentials).to eq(:this_channel_is_insecure)
|
31
27
|
end
|
32
28
|
end
|
33
|
-
|
34
|
-
describe "#put" do
|
35
|
-
it 'issues put request' do
|
36
|
-
expect(conn.put('test', 'test')).to be_an_instance_of(Etcdserverpb::PutResponse)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "#range" do
|
41
|
-
it 'returns protobuf' do
|
42
|
-
expect(conn.range('test', '')).to be_an_instance_of(Google::Protobuf::RepeatedField)
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'returns correct result' do
|
46
|
-
expect(conn.range('test', '').first.key).to eq('test')
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
29
|
end
|
51
|
-
|
52
30
|
end
|
data/spec/etcdv3/auth_spec.rb
CHANGED
@@ -1,38 +1,103 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
#
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
#
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Etcd::Auth do
|
4
|
+
|
5
|
+
let(:stub) do
|
6
|
+
Etcd::Auth.new('127.0.0.1', 2379, :this_channel_is_insecure)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#add_user' do
|
10
|
+
it 'returns AuthUserAddResponse' do
|
11
|
+
expect(stub.add_user("boom", 'test')).to \
|
12
|
+
be_an_instance_of(Etcdserverpb::AuthUserAddResponse)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#user_list' do
|
17
|
+
|
18
|
+
it 'returns Protobuf' do
|
19
|
+
expect(stub.user_list).to \
|
20
|
+
be_an_instance_of(Google::Protobuf::RepeatedField)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'returns listme user' do
|
24
|
+
stub.add_user('listme', 'test')
|
25
|
+
expect(stub.user_list).to include('listme')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#delete_user' do
|
30
|
+
before do
|
31
|
+
stub.add_user('testuser', 'test')
|
32
|
+
end
|
33
|
+
it 'returns AuthUserDeleteResponse' do
|
34
|
+
expect(stub.delete_user('testuser')).to \
|
35
|
+
be_an_instance_of(Etcdserverpb::AuthUserDeleteResponse)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#grant_role_to_user' do
|
40
|
+
before do
|
41
|
+
stub.add_user('root', 'password')
|
42
|
+
end
|
43
|
+
after do
|
44
|
+
stub.delete_user('root')
|
45
|
+
end
|
46
|
+
it 'returns AuthUserGrantRoleResponse' do
|
47
|
+
expect(stub.grant_role_to_user("root", 'root')).to \
|
48
|
+
be_an_instance_of(Etcdserverpb::AuthUserGrantRoleResponse)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#add_role' do
|
53
|
+
it 'returns AuthRoleAddResponse' do
|
54
|
+
expect(stub.add_role('testRole', 'readwrite', 'a', 'Z')).to \
|
55
|
+
be_an_instance_of(Etcdserverpb::AuthRoleAddResponse)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#add_delete' do
|
60
|
+
it 'returns AuthRoleAddResponse' do
|
61
|
+
expect(stub.delete_role('testRole')).to \
|
62
|
+
be_an_instance_of(Etcdserverpb::AuthRoleDeleteResponse)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#role_list' do
|
67
|
+
it 'returns AuthRoleListResponse' do
|
68
|
+
expect(stub.role_list).to \
|
69
|
+
be_an_instance_of(Etcdserverpb::AuthRoleListResponse)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#disable_auth' do
|
74
|
+
before do
|
75
|
+
stub.add_user('root', 'test')
|
76
|
+
stub.grant_role_to_user('root', 'root')
|
77
|
+
stub.enable_auth
|
78
|
+
end
|
79
|
+
after do
|
80
|
+
stub.delete_user('root')
|
81
|
+
end
|
82
|
+
it 'returns AuthDisableResponse' do
|
83
|
+
token = stub.generate_token('root', 'test')
|
84
|
+
expect(stub.disable_auth(token: token)).to \
|
85
|
+
be_an_instance_of(Etcdserverpb::AuthDisableResponse)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '#enable_auth' do
|
90
|
+
before do
|
91
|
+
stub.add_user('root', 'test')
|
92
|
+
stub.grant_role_to_user('root', 'root')
|
93
|
+
end
|
94
|
+
after do
|
95
|
+
token = stub.generate_token('root', 'test')
|
96
|
+
stub.disable_auth(token: token)
|
97
|
+
stub.delete_user('root')
|
98
|
+
end
|
99
|
+
it 'returns AuthEnableResponse' do
|
100
|
+
expect(stub.enable_auth).to be_an_instance_of(Etcdserverpb::AuthEnableResponse)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Etcd::KV do
|
4
|
+
|
5
|
+
let(:stub) do
|
6
|
+
Etcd::KV.new('127.0.0.1', 2379, :this_channel_is_insecure)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#put' do
|
10
|
+
it 'returns PutResponse' do
|
11
|
+
expect(stub.put('test', 'test')).to \
|
12
|
+
be_an_instance_of(Etcdserverpb::PutResponse)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#range' do
|
17
|
+
before do
|
18
|
+
stub.put('test', "zoom")
|
19
|
+
end
|
20
|
+
it 'returns protobuf' do
|
21
|
+
expect(stub.range('test', '')).to \
|
22
|
+
be_an_instance_of(Google::Protobuf::RepeatedField)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'returns correct result' do
|
26
|
+
expect(stub.range('test', '').first.key).to eq('test')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'tmpdir'
|
3
|
+
|
4
|
+
module Helpers
|
5
|
+
class TestInstance
|
6
|
+
MINIMUM_VERSION = Gem::Version.new('3.0.0')
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@pids = []
|
10
|
+
@tmpdir = Dir.mktmpdir
|
11
|
+
@bin = discover_binary_path
|
12
|
+
@version = discover_binary_version
|
13
|
+
|
14
|
+
raise "Invalid Etcd Version: #{@version}. Must be running 3.0+" \
|
15
|
+
if @version < MINIMUM_VERSION
|
16
|
+
end
|
17
|
+
|
18
|
+
def start
|
19
|
+
raise "Already running etcd servers(#{@pids.inspect})" unless @pids.empty?
|
20
|
+
puts 'Starting up testing environment...'
|
21
|
+
@pids << spawn_etcd_instance
|
22
|
+
sleep(5)
|
23
|
+
end
|
24
|
+
|
25
|
+
def spawn_etcd_instance
|
26
|
+
peer_url = 'http://127.0.0.1:2380'
|
27
|
+
client_url = 'http://127.0.0.1:2379'
|
28
|
+
cluster_url = 'node=http://127.0.0.1:2380'
|
29
|
+
flags = ' --name=node'
|
30
|
+
flags << " --initial-advertise-peer-urls=#{peer_url}"
|
31
|
+
flags << " --listen-peer-urls=#{peer_url}"
|
32
|
+
flags << " --listen-client-urls=#{client_url}"
|
33
|
+
flags << " --advertise-client-urls=#{client_url}"
|
34
|
+
flags << " --initial-cluster=#{cluster_url}"
|
35
|
+
flags << " --data-dir=#{@tmpdir} "
|
36
|
+
|
37
|
+
# Assumes etcd is in PATH
|
38
|
+
command = "ETCDCTL_API=3 #{@bin} " + flags
|
39
|
+
pid = spawn(command, out: '/dev/null', err: '/dev/null')
|
40
|
+
Process.detach(pid)
|
41
|
+
pid
|
42
|
+
end
|
43
|
+
|
44
|
+
def stop
|
45
|
+
@pids.each { |pid| Process.kill('TERM', pid) }
|
46
|
+
FileUtils.remove_entry_secure(@tmpdir, true)
|
47
|
+
@pids.clear
|
48
|
+
end
|
49
|
+
|
50
|
+
def discover_binary_path
|
51
|
+
'etcd'
|
52
|
+
end
|
53
|
+
|
54
|
+
def discover_binary_version
|
55
|
+
result = `#{@bin} --version | grep "etcd Version"`
|
56
|
+
Gem::Version.new(result.split(':').last.strip)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,14 +1,22 @@
|
|
1
|
-
|
2
|
-
$LOAD_PATH.unshift
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift File.expand_path('./helpers', __FILE__)
|
3
3
|
|
4
4
|
require 'etcdv3'
|
5
|
+
require 'helpers/test_instance'
|
6
|
+
|
5
7
|
RSpec.configure do |config|
|
6
8
|
config.expect_with :rspec do |expectations|
|
7
9
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
8
10
|
end
|
9
|
-
|
10
11
|
config.mock_with :rspec do |mocks|
|
11
12
|
mocks.verify_partial_doubles = true
|
12
13
|
end
|
13
14
|
config.shared_context_metadata_behavior = :apply_to_host_groups
|
15
|
+
instance = Helpers::TestInstance.new
|
16
|
+
config.before(:suite) do
|
17
|
+
instance.start
|
18
|
+
end
|
19
|
+
config.after(:suite) do
|
20
|
+
instance.stop
|
21
|
+
end
|
14
22
|
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.0.
|
4
|
+
version: 0.0.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-03-
|
11
|
+
date: 2017-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grpc
|
@@ -44,9 +44,11 @@ executables: []
|
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files: []
|
46
46
|
files:
|
47
|
+
- ".codeclimate.yml"
|
47
48
|
- ".gitignore"
|
48
49
|
- ".rspec"
|
49
50
|
- ".ruby-version"
|
51
|
+
- ".travis.yml"
|
50
52
|
- Gemfile
|
51
53
|
- README.md
|
52
54
|
- etcdv3.gemspec
|
@@ -67,6 +69,8 @@ files:
|
|
67
69
|
- lib/etcdv3/version.rb
|
68
70
|
- spec/etcd_spec.rb
|
69
71
|
- spec/etcdv3/auth_spec.rb
|
72
|
+
- spec/etcdv3/kv_spec.rb
|
73
|
+
- spec/helpers/test_instance.rb
|
70
74
|
- spec/spec_helper.rb
|
71
75
|
homepage: https://github.com/davissp14/etcdv3-ruby
|
72
76
|
licenses:
|
@@ -95,4 +99,6 @@ summary: A Etcd client library for Version 3
|
|
95
99
|
test_files:
|
96
100
|
- spec/etcd_spec.rb
|
97
101
|
- spec/etcdv3/auth_spec.rb
|
102
|
+
- spec/etcdv3/kv_spec.rb
|
103
|
+
- spec/helpers/test_instance.rb
|
98
104
|
- spec/spec_helper.rb
|