etcdv3 0.1.5 → 0.2.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: 3e2fce5dfb236ef001c050f60f6fec8162914121
4
- data.tar.gz: 0ae18b137efb5cbd7c328a6690615f2f6c68c65b
3
+ metadata.gz: 6054abb122d9d779e4fc044e0e18cb6f06b03e26
4
+ data.tar.gz: 93fb0231d2ebb440f38e2e23fbd8e5c78ab45b6b
5
5
  SHA512:
6
- metadata.gz: b06266232676bd25db0521874cd846069b473091f34cf1dc7d0a5dc2b06575d141323aa917411854ba186d8134d5f1ef09c22e5ff919167c6ecae164a65dce4b
7
- data.tar.gz: 305a579ce7e7c0c202c8643ba1ea3cbb265abf3dded50a748b6ad839ef78acb22f1ce72e3d62ad0edefa6ef288f65b52e0828482d7658f3fbb5192b4a1017ec0
6
+ metadata.gz: eca14e0abaad2095e87ad37a6236f304e53319a58f93adfaee300f6d068b5be039f161a066259e1941a45288ea1e41137d0746ec71d36a4c0f884bec91421512
7
+ data.tar.gz: 3a636b3b397101ed7dd479e0ecbe16ae30ffad4d3c23fa804dab9bb196d41ce0d94ee0a09bf562d36bb5e94ef55c6ead6594822af84365a72f2a6c37e9141dab
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem "grpc"
4
- gem 'rspec'
5
4
  gem 'faraday', '0.11.0'
6
5
 
7
-
6
+ gem 'rspec', :group => :test
7
+ gem 'codecov', :require => false, :group => :test
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- # etcdv3-ruby [![Gem Version](https://badge.fury.io/rb/etcdv3.svg)](https://badge.fury.io/rb/etcdv3) [![Build Status](https://travis-ci.org/davissp14/etcdv3-ruby.svg?branch=master)](https://travis-ci.org/davissp14/etcdv3-ruby)
1
+ # etcdv3-ruby [![Gem Version](https://badge.fury.io/rb/etcdv3.svg)](https://badge.fury.io/rb/etcdv3) [![Build Status](https://travis-ci.org/davissp14/etcdv3-ruby.svg?branch=master)](https://travis-ci.org/davissp14/etcdv3-ruby) [![codecov](https://codecov.io/gh/davissp14/etcdv3-ruby/branch/master/graph/badge.svg)](https://codecov.io/gh/davissp14/etcdv3-ruby)
2
+
2
3
 
3
4
  Ruby client for Etcd V3
4
5
 
@@ -40,7 +41,7 @@ conn = Etcd.new(url: 'https://hostname:port', user: "gary", password: "secret")
40
41
  conn.get("my")
41
42
 
42
43
  # Get Key Range
43
- conn.get('my', 'myyyy')
44
+ conn.get('my', range_end: 'myyyy')
44
45
 
45
46
  # Delete Key
46
47
  conn.del('my')
data/lib/etcdv3/kv.rb CHANGED
@@ -1,6 +1,21 @@
1
1
 
2
2
  class Etcd
3
3
  class KV
4
+
5
+ SORT_TARGET = {
6
+ key: 0,
7
+ version: 1,
8
+ create: 2,
9
+ mod: 3,
10
+ value: 4
11
+ }
12
+
13
+ SORT_ORDER = {
14
+ none: 0,
15
+ ascend: 1,
16
+ descend: 2
17
+ }
18
+
4
19
  def initialize(hostname, credentials, metadata={})
5
20
  @stub = Etcdserverpb::KV::Stub.new(hostname, credentials)
6
21
  @metadata = metadata
@@ -12,8 +27,13 @@ class Etcd
12
27
  @stub.put(kv, metadata: @metadata)
13
28
  end
14
29
 
15
- def get(key, range_end="")
16
- kv = Etcdserverpb::RangeRequest.new(key: key, range_end: range_end)
30
+ def get(key, opts={})
31
+ opts[:sort_order] = SORT_ORDER[opts[:sort_order]] \
32
+ if opts[:sort_order]
33
+ opts[:sort_target] = SORT_TARGET[opts[:sort_target]] \
34
+ if opts[:sort_target]
35
+ opts[:key] = key
36
+ kv = Etcdserverpb::RangeRequest.new(opts)
17
37
  @stub.range(kv, metadata: @metadata)
18
38
  end
19
39
 
@@ -1,3 +1,3 @@
1
1
  class Etcd
2
- VERSION = '0.1.5'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/lib/etcdv3.rb CHANGED
@@ -80,9 +80,21 @@ class Etcd
80
80
  request.handle(:kv, 'put', [key, value, lease_id])
81
81
  end
82
82
 
83
- # Fetches key(s).
84
- def get(key, range_end='')
85
- request.handle(:kv, 'get', [key, range_end])
83
+ # key - string
84
+ # optional :range_end - string
85
+ # optional :limit - integer
86
+ # optional :revision - integer
87
+ # optional :sort_order - symbol - [:none, :ascend, :descend]
88
+ # optional :sort_target - symbol - [:key, :version, :create, :mode, :value]
89
+ # optional :serializable - boolean
90
+ # optional :keys_only - boolean
91
+ # optional :count_only - boolean
92
+ # optional :min_mod_revision - integer
93
+ # optional :max_mod_revision - integer
94
+ # optional :min_create_revision - integer
95
+ # optional :max_create_revision - integer
96
+ def get(key, opts={})
97
+ request.handle(:kv, 'get', [key, opts])
86
98
  end
87
99
 
88
100
  # Grant a lease with a speified TTL
data/spec/etcdv3_spec.rb CHANGED
@@ -41,8 +41,35 @@ describe Etcd do
41
41
  end
42
42
 
43
43
  describe '#get' do
44
- subject { conn.get('test') }
45
- it { is_expected.to_not be_nil }
44
+ before do
45
+ conn.put('apple', 'test')
46
+ conn.put('applee', 'test')
47
+ conn.put('appleee', 'test')
48
+ end
49
+ context 'no filters' do
50
+ subject { conn.get('apple') }
51
+ it { is_expected.to_not be_nil }
52
+ end
53
+ context 'sorts desc' do
54
+ subject do
55
+ conn.get('apple', range_end: 'appleeee', sort_order: :descend) \
56
+ .kvs.first.key
57
+ end
58
+ it { is_expected.to eq('appleee') }
59
+ end
60
+ context 'sorts asc' do
61
+ subject do
62
+ conn.get('apple', range_end: 'appleeee', sort_order: :ascend) \
63
+ .kvs.first.key
64
+ end
65
+ it { is_expected.to eq('apple') }
66
+ end
67
+ context 'count only' do
68
+ subject do
69
+ conn.get('apple', range_end: 'appleeee', count_only: true).kvs
70
+ end
71
+ it { is_expected.to be_empty }
72
+ end
46
73
  end
47
74
 
48
75
  describe '#put' do
data/spec/spec_helper.rb CHANGED
@@ -2,12 +2,17 @@ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
2
  $LOAD_PATH.unshift File.expand_path('./helpers', __FILE__)
3
3
 
4
4
  require 'etcdv3'
5
+ require 'simplecov'
6
+ require 'codecov'
5
7
  require 'helpers/test_instance'
6
8
  require 'helpers/connections'
7
9
 
10
+ SimpleCov.start
11
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
12
+
8
13
  RSpec.configure do |config|
9
14
  config.include(Helpers::Connections)
10
-
15
+
11
16
  config.expect_with :rspec do |expectations|
12
17
  expectations.include_chain_clauses_in_custom_matcher_descriptions = true
13
18
  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.5
4
+ version: 0.2.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-09 00:00:00.000000000 Z
11
+ date: 2017-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grpc
@@ -68,7 +68,6 @@ files:
68
68
  - lib/etcdv3/protos/rpc.proto
69
69
  - lib/etcdv3/request.rb
70
70
  - lib/etcdv3/version.rb
71
- - spec/etcd_spec.rb
72
71
  - spec/etcdv3/auth_spec.rb
73
72
  - spec/etcdv3/kv_spec.rb
74
73
  - spec/etcdv3/lease_spec.rb
@@ -102,7 +101,6 @@ signing_key:
102
101
  specification_version: 4
103
102
  summary: A Etcd client library for Version 3
104
103
  test_files:
105
- - spec/etcd_spec.rb
106
104
  - spec/etcdv3/auth_spec.rb
107
105
  - spec/etcdv3/kv_spec.rb
108
106
  - spec/etcdv3/lease_spec.rb
data/spec/etcd_spec.rb DELETED
@@ -1,112 +0,0 @@
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.class }
30
- it { is_expected.to_not be_nil }
31
- end
32
-
33
- describe '#disable_auth' do
34
- before do
35
- conn.add_user('root', 'test')
36
- conn.grant_role_to_user('root', 'root')
37
- conn.enable_auth
38
- conn.authenticate('root', 'test')
39
- end
40
- after { conn.delete_user('root') }
41
- subject { conn.disable_auth }
42
- it { is_expected.to be_an_instance_of(Etcdserverpb::AuthDisableResponse) }
43
- end
44
-
45
- describe '#enable_auth' do
46
- before do
47
- conn.add_user('root', 'test')
48
- conn.grant_role_to_user('root', 'root')
49
- end
50
- after do
51
- conn.authenticate('root', 'test')
52
- conn.disable_auth
53
- conn.delete_user('root')
54
- end
55
- subject { conn.enable_auth }
56
- it { is_expected.to be_an_instance_of(Etcdserverpb::AuthEnableResponse) }
57
- end
58
-
59
- describe "#authenticate" do
60
- context "auth enabled" do
61
- before do
62
- conn.add_user('root', 'test')
63
- conn.grant_role_to_user('root', 'root')
64
- conn.enable_auth
65
- conn.authenticate('root', 'test')
66
- end
67
- after do
68
- conn.disable_auth
69
- conn.delete_user('root')
70
- end
71
- it 'properly reconfigures auth and token' do
72
- expect(conn.token).to_not be_nil
73
- expect(conn.user).to eq('root')
74
- expect(conn.password).to eq('test')
75
- end
76
- end
77
-
78
- context 'auth disabled' do
79
- it 'raises error' do
80
- expect { conn.authenticate('root', 'root') }.to raise_error(GRPC::InvalidArgument)
81
- end
82
- end
83
- end
84
-
85
- describe '#metacache' do
86
- context 'uses cached request object' do
87
- let!(:object_id) { conn.send(:request).object_id }
88
- before { conn.add_user('root', 'test') }
89
- after { conn.delete_user('root') }
90
- subject { conn.send(:request).object_id }
91
- it { is_expected.to eq(object_id) }
92
- end
93
- context 'resets cache on auth' do
94
- let!(:object_id) { conn.send(:request).object_id }
95
- before do
96
- conn.add_user('root', 'test')
97
- conn.grant_role_to_user('root', 'root')
98
- conn.enable_auth
99
- conn.authenticate('root', 'test')
100
- conn.add_user('boom', 'password')
101
- end
102
- after do
103
- conn.disable_auth
104
- conn.delete_user('root')
105
- conn.delete_user('boom')
106
- end
107
- subject { conn.send(:request).object_id }
108
- it { is_expected.to_not eq(object_id) }
109
- end
110
- end
111
- end
112
- end