etcdv3 0.11.4 → 0.11.6

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
  SHA256:
3
- metadata.gz: 18d76403d57c3e56b75e603931345900a4583b2e94d773b33ca04aa1547e304d
4
- data.tar.gz: f1d1f9336f62f18b32fb9d3f055e0043bddb6076022b922b097c0104a7467c8b
3
+ metadata.gz: f63c528f864012711cf608ca262674d7efd89caa6ac67674bb23e007df2920ab
4
+ data.tar.gz: 7a6c37da695eb6759a206ca5bfbd953ac647b17c7c19918596e7a6db86d065bf
5
5
  SHA512:
6
- metadata.gz: 9633a47e982b7777ccda7e5472a663a661e4cf6368689cfbbd8d06a6ca862be47e7c3a75d075919b645611879513d4c88c7f59686b2a0eac15cc160e3ea7520f
7
- data.tar.gz: 5a330de810e02ebdec73c279e33b7c2ece0c2aa7c4c877da89a2b285976ce68578ca20b3c51206d9a14c9fccbf18ef6310254010053eaefa59b06b898e1c195a
6
+ metadata.gz: 9b6b51ca358da66d57cd16358146f54f9c220a925f43fea326aa764887c647de76c40b860a05005d48f7bd9528fe239e985be39ceb0c886052147459bdc6e98f
7
+ data.tar.gz: fcf41864b7e54c74d8788a2d94688255880f193a6ad3527262f3a0b0512301693fb5cb90b72db9a52f0abcb9fad1541427dfda1970a9348225ec9579d651345d
data/lib/etcdv3/auth.rb CHANGED
@@ -10,7 +10,7 @@ class Etcdv3
10
10
  }
11
11
 
12
12
  def initialize(hostname, credentials, timeout, metadata = {})
13
- @stub = Etcdserverpb::Auth::Stub.new(hostname, credentials)
13
+ @stub = Etcdserverpb::Auth::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {})
14
14
  @timeout = timeout
15
15
  @metadata = metadata
16
16
  end
data/lib/etcdv3/kv.rb CHANGED
@@ -5,7 +5,7 @@ class Etcdv3
5
5
  include GRPC::Core::TimeConsts
6
6
 
7
7
  def initialize(hostname, credentials, timeout, metadata={})
8
- @stub = Etcdserverpb::KV::Stub.new(hostname, credentials)
8
+ @stub = Etcdserverpb::KV::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {})
9
9
  @timeout = timeout
10
10
  @metadata = metadata
11
11
  end
data/lib/etcdv3/lease.rb CHANGED
@@ -3,7 +3,7 @@ class Etcdv3
3
3
  include GRPC::Core::TimeConsts
4
4
 
5
5
  def initialize(hostname, credentials, timeout, metadata={})
6
- @stub = Etcdserverpb::Lease::Stub.new(hostname, credentials)
6
+ @stub = Etcdserverpb::Lease::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {})
7
7
  @timeout = timeout
8
8
  @metadata = metadata
9
9
  end
data/lib/etcdv3/lock.rb CHANGED
@@ -3,19 +3,19 @@ class Etcdv3
3
3
  include GRPC::Core::TimeConsts
4
4
 
5
5
  def initialize(hostname, credentials, timeout, metadata = {})
6
- @stub = V3lockpb::Lock::Stub.new(hostname, credentials)
6
+ @stub = V3lockpb::Lock::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {})
7
7
  @timeout = timeout
8
8
  @metadata = metadata
9
9
  end
10
10
 
11
11
  def lock(name, lease_id, timeout: nil)
12
12
  request = V3lockpb::LockRequest.new(name: name, lease: lease_id)
13
- @stub.lock(request, deadline: deadline(timeout))
13
+ @stub.lock(request, metadata: @metadata, deadline: deadline(timeout))
14
14
  end
15
15
 
16
16
  def unlock(key, timeout: nil)
17
17
  request = V3lockpb::UnlockRequest.new(key: key)
18
- @stub.unlock(request, deadline: deadline(timeout))
18
+ @stub.unlock(request, metadata: @metadata, deadline: deadline(timeout))
19
19
  end
20
20
 
21
21
  private
@@ -13,7 +13,7 @@ class Etcdv3
13
13
  }
14
14
 
15
15
  def initialize(hostname, credentials, _timeout, metadata = {})
16
- @stub = Etcdserverpb::Maintenance::Stub.new(hostname, credentials)
16
+ @stub = Etcdserverpb::Maintenance::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {})
17
17
  @metadata = metadata
18
18
  end
19
19
 
@@ -5,7 +5,7 @@ class Etcdv3::Namespace
5
5
  include GRPC::Core::TimeConsts
6
6
 
7
7
  def initialize(hostname, credentials, timeout, namespace, metadata={})
8
- @stub = Etcdserverpb::KV::Stub.new(hostname, credentials)
8
+ @stub = Etcdserverpb::KV::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {})
9
9
  @timeout = timeout
10
10
  @namespace = namespace
11
11
  @metadata = metadata
@@ -4,7 +4,7 @@ class Etcdv3::Namespace
4
4
  include Etcdv3::Namespace::Utilities
5
5
 
6
6
  def initialize(hostname, credentials, timeout, namespace, metadata = {})
7
- @stub = V3lockpb::Lock::Stub.new(hostname, credentials)
7
+ @stub = V3lockpb::Lock::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {})
8
8
  @timeout = timeout
9
9
  @namespace = namespace
10
10
  @metadata = metadata
@@ -13,14 +13,14 @@ class Etcdv3::Namespace
13
13
  def lock(name, lease_id, timeout: nil)
14
14
  name = prepend_prefix(@namespace, name)
15
15
  request = V3lockpb::LockRequest.new(name: name, lease: lease_id)
16
- resp = @stub.lock(request, deadline: deadline(timeout))
16
+ resp = @stub.lock(request, metadata: @metadata, deadline: deadline(timeout))
17
17
  strip_prefix_from_lock(@namespace, resp)
18
18
  end
19
19
 
20
20
  def unlock(key, timeout: nil)
21
21
  key = prepend_prefix(@namespace, key)
22
22
  request = V3lockpb::UnlockRequest.new(key: key)
23
- @stub.unlock(request, deadline: deadline(timeout))
23
+ @stub.unlock(request, metadata: @metadata, deadline: deadline(timeout))
24
24
  end
25
25
 
26
26
  private
@@ -4,7 +4,7 @@ class Etcdv3::Namespace
4
4
  include Etcdv3::Namespace::Utilities
5
5
 
6
6
  def initialize(hostname, credentials, timeout, namespace, metadata = {})
7
- @stub = Etcdserverpb::Watch::Stub.new(hostname, credentials)
7
+ @stub = Etcdserverpb::Watch::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {})
8
8
  @timeout = timeout
9
9
  @namespace = namespace
10
10
  @metadata = metadata
@@ -1,3 +1,3 @@
1
1
  class Etcdv3
2
- VERSION = '0.11.4'.freeze
2
+ VERSION = '0.11.6'.freeze
3
3
  end
data/lib/etcdv3/watch.rb CHANGED
@@ -3,7 +3,7 @@ class Etcdv3
3
3
  include GRPC::Core::TimeConsts
4
4
 
5
5
  def initialize(hostname, credentials, timeout, metadata = {})
6
- @stub = Etcdserverpb::Watch::Stub.new(hostname, credentials)
6
+ @stub = Etcdserverpb::Watch::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {})
7
7
  @timeout = timeout
8
8
  @metadata = metadata
9
9
  end
@@ -10,14 +10,28 @@ unless $instance.version < Gem::Version.new("3.2.0")
10
10
  #it_should_behave_like "a method with a GRPC timeout", described_class, :lock, :lock, 'foo'
11
11
 
12
12
  describe '#lock' do
13
- let(:lease_id) { lease_stub.lease_grant(10)['ID'] }
14
- subject { stub.lock('foo', lease_id) }
15
- it { is_expected.to be_an_instance_of(V3lockpb::LockResponse) }
13
+ it 'returns a response' do
14
+ lease_id = lease_stub.lease_grant(10)['ID']
15
+
16
+ expect(stub.lock('example1', lease_id)).to be_an_instance_of(V3lockpb::LockResponse)
17
+ end
18
+
19
+ it 'passes metadata correctly' do
20
+ lease_id = lease_stub.lease_grant(10)['ID']
21
+ stub = expect_metadata_passthrough(described_class, :lock, :lock)
22
+ stub.lock('example2', lease_id)
23
+ end
16
24
  end
17
25
 
18
26
  describe '#unlock' do
19
- subject { stub.unlock('foo') }
20
- it { is_expected.to be_an_instance_of(V3lockpb::UnlockResponse) }
27
+ it 'returns a response' do
28
+ expect(stub.unlock('example3')).to be_an_instance_of(V3lockpb::UnlockResponse)
29
+ end
30
+
31
+ it 'passes metadata correctly' do
32
+ stub = expect_metadata_passthrough(described_class, :unlock, :unlock)
33
+ stub.unlock('example4')
34
+ end
21
35
  end
22
36
  end
23
37
  end
@@ -2,22 +2,41 @@ require 'spec_helper'
2
2
 
3
3
  # Locking is not implemented in etcd v3.1.X
4
4
  unless $instance.version < Gem::Version.new("3.2.0")
5
- describe Etcdv3::Lock do
5
+ describe Etcdv3::Namespace::Lock do
6
6
  let(:stub) { local_namespace_stub(Etcdv3::Namespace::Lock, 1, '/namespace/') }
7
7
  let(:lease_stub) { local_stub(Etcdv3::Lease, 1) }
8
8
 
9
- it_should_behave_like "a method with a GRPC timeout", described_class, :unlock, :unlock, 'foo'
9
+ # NOTE: this was running duplicate tests against Etcdv3::Lock before, but it
10
+ # doesn't work with Etcdv3::Namespace::Lock
11
+ #
12
+ # it_should_behave_like "a method with a GRPC timeout", described_class, :unlock, :unlock, 'foo'
13
+
10
14
  # it_should_behave_like "a method with a GRPC timeout", described_class, :lock, :lock, 'foo'
11
15
 
12
16
  describe '#lock' do
13
- let(:lease_id) { lease_stub.lease_grant(10)['ID'] }
14
- subject { stub.lock('foo', lease_id) }
15
- it { is_expected.to be_an_instance_of(V3lockpb::LockResponse) }
17
+ it 'returns a response' do
18
+ lease_id = lease_stub.lease_grant(10)['ID']
19
+ expect(stub.lock('example1', lease_id)).to(
20
+ be_an_instance_of(V3lockpb::LockResponse)
21
+ )
22
+ end
23
+
24
+ it 'passes metadata correctly' do
25
+ lease_id = lease_stub.lease_grant(10)['ID']
26
+ stub = expect_metadata_passthrough_namespace(described_class, :lock, :lock, '/namespace/')
27
+ stub.lock('example2', lease_id)
28
+ end
16
29
  end
17
30
 
18
31
  describe '#unlock' do
19
- subject { stub.unlock('foo') }
20
- it { is_expected.to be_an_instance_of(V3lockpb::UnlockResponse) }
32
+ it 'returns a response' do
33
+ expect(stub.unlock('example3')).to be_an_instance_of(V3lockpb::UnlockResponse)
34
+ end
35
+
36
+ it 'passes metadata correctly' do
37
+ stub = expect_metadata_passthrough_namespace(described_class, :unlock, :unlock, '/namespace/')
38
+ stub.unlock('example4')
39
+ end
21
40
  end
22
41
  end
23
42
  end
@@ -21,10 +21,18 @@ module Helpers
21
21
  interface.new(local_url, :this_channel_is_insecure, timeout, {})
22
22
  end
23
23
 
24
+ def local_stub_with_metadata(interface, timeout: nil, metadata: {})
25
+ interface.new(local_url, :this_channel_is_insecure, timeout, metadata)
26
+ end
27
+
24
28
  def local_namespace_stub(interface, timeout=nil, namespace)
25
29
  interface.new(local_url, :this_channel_is_insecure, timeout, namespace, {})
26
30
  end
27
31
 
32
+ def local_namespace_stub_with_metadata(interface, timeout: nil, namespace:, metadata: {})
33
+ interface.new(local_url, :this_channel_is_insecure, timeout, namespace, metadata)
34
+ end
35
+
28
36
  def local_url
29
37
  "127.0.0.1:#{port}"
30
38
  end
@@ -0,0 +1,21 @@
1
+ module Helpers
2
+ module MetadataPassthrough
3
+ include Connections
4
+
5
+ def expect_metadata_passthrough(stub_class, method_name, expectation_target)
6
+ metadata = { user: "foo", password: "bar" }
7
+ handler = local_stub_with_metadata(stub_class, metadata: metadata, timeout: 1)
8
+ inner_stub = handler.instance_variable_get("@stub")
9
+ expect(inner_stub).to receive(expectation_target).with(anything, hash_including(metadata: metadata)).and_call_original
10
+ return handler
11
+ end
12
+
13
+ def expect_metadata_passthrough_namespace(stub_class, method_name, expectation_target, namespace)
14
+ metadata = { user: "foo", password: "bar" }
15
+ handler = local_namespace_stub_with_metadata(stub_class, metadata: metadata, timeout: 1, namespace: namespace)
16
+ inner_stub = handler.instance_variable_get("@stub")
17
+ expect(inner_stub).to receive(expectation_target).with(anything, hash_including(metadata: metadata)).and_call_original
18
+ return handler
19
+ end
20
+ end
21
+ end
@@ -3,10 +3,12 @@ require 'tmpdir'
3
3
  require 'socket'
4
4
  require 'timeout'
5
5
  require 'helpers/connections'
6
+ require 'helpers/metadata_passthrough'
6
7
 
7
8
  module Helpers
8
9
  class TestInstance
9
10
  include Helpers::Connections
11
+ include Helpers::MetadataPassthrough
10
12
 
11
13
  class InvalidVersionException < StandardError; end
12
14
  class PortInUseException < StandardError; end
data/spec/spec_helper.rb CHANGED
@@ -3,20 +3,22 @@ $LOAD_PATH.unshift File.expand_path('./helpers', __FILE__)
3
3
  $LOAD_PATH.unshift File.expand_path('./namespace', __FILE__)
4
4
 
5
5
 
6
- # require 'simplecov'
7
- # require 'codecov'
8
- # SimpleCov.start
9
- # SimpleCov.formatter = SimpleCov::Formatter::Codecov
6
+ require 'simplecov'
7
+ require 'codecov'
8
+ SimpleCov.start
9
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
10
10
 
11
11
  require 'etcdv3'
12
12
  require 'helpers/test_instance'
13
13
  require 'helpers/connections'
14
+ require 'helpers/metadata_passthrough'
14
15
  require 'helpers/shared_examples_for_timeout'
15
16
 
16
17
  $instance = Helpers::TestInstance.new
17
18
 
18
19
  RSpec.configure do |config|
19
20
  config.include(Helpers::Connections)
21
+ config.include(Helpers::MetadataPassthrough)
20
22
 
21
23
  config.expect_with :rspec do |expectations|
22
24
  expectations.include_chain_clauses_in_custom_matcher_descriptions = true
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.11.4
4
+ version: 0.11.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaun Davis
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-23 00:00:00.000000000 Z
11
+ date: 2023-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grpc
@@ -126,6 +126,7 @@ files:
126
126
  - spec/etcdv3/watch_spec.rb
127
127
  - spec/etcdv3_spec.rb
128
128
  - spec/helpers/connections.rb
129
+ - spec/helpers/metadata_passthrough.rb
129
130
  - spec/helpers/shared_examples_for_timeout.rb
130
131
  - spec/helpers/test_instance.rb
131
132
  - spec/spec_helper.rb
@@ -133,7 +134,7 @@ homepage: https://github.com/davissp14/etcdv3-ruby
133
134
  licenses:
134
135
  - MIT
135
136
  metadata: {}
136
- post_install_message:
137
+ post_install_message:
137
138
  rdoc_options: []
138
139
  require_paths:
139
140
  - lib
@@ -148,8 +149,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
149
  - !ruby/object:Gem::Version
149
150
  version: '0'
150
151
  requirements: []
151
- rubygems_version: 3.2.20
152
- signing_key:
152
+ rubygems_version: 3.3.7
153
+ signing_key:
153
154
  specification_version: 4
154
155
  summary: A Etcd client library for Version 3
155
156
  test_files:
@@ -166,6 +167,7 @@ test_files:
166
167
  - spec/etcdv3/watch_spec.rb
167
168
  - spec/etcdv3_spec.rb
168
169
  - spec/helpers/connections.rb
170
+ - spec/helpers/metadata_passthrough.rb
169
171
  - spec/helpers/shared_examples_for_timeout.rb
170
172
  - spec/helpers/test_instance.rb
171
173
  - spec/spec_helper.rb