Skip to content

Commit 5b12d27

Browse files
committed
ability to set grpc_options on all levels
1 parent 939dec1 commit 5b12d27

12 files changed

Lines changed: 25 additions & 23 deletions

File tree

lib/etcdv3.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def initialize(**options)
3838
*sanitized_endpoints,
3939
@namespace,
4040
@options.fetch(:allow_reconnect, true),
41+
grpc_options: @options.fetch(:grpc_options, {}),
4142
)
4243
warn "WARNING: `url` is deprecated. Please use `endpoints` instead." if @options.key?(:url)
4344
authenticate(@options[:user], @options[:password]) if @options.key?(:user)

lib/etcdv3/auth.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class Auth
99
:readwrite => Authpb::Permission::Type::READWRITE
1010
}
1111

12-
def initialize(hostname, credentials, timeout, metadata = {})
13-
@stub = Etcdserverpb::Auth::Stub.new(hostname, credentials)
12+
def initialize(hostname, credentials, timeout, metadata = {}, grpc_options = {})
13+
@stub = Etcdserverpb::Auth::Stub.new(hostname, credentials, **grpc_options)
1414
@timeout = timeout
1515
@metadata = metadata
1616
end

lib/etcdv3/connection.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ class Connection
1818

1919
attr_reader :endpoint, :hostname, :handlers, :credentials, :namespace
2020

21-
def initialize(url, timeout, namespace, metadata={})
21+
def initialize(url, timeout, namespace, metadata={}, grpc_options={})
2222
@endpoint = URI(url)
2323
@hostname = "#{@endpoint.hostname}:#{@endpoint.port}"
2424
@namespace = namespace
2525
@credentials = resolve_credentials
2626
@timeout = timeout
27+
@grpc_options = grpc_options
2728
@handlers = handler_map(metadata)
2829
end
2930

@@ -46,13 +47,13 @@ def refresh_metadata(metadata)
4647
def handler_map(metadata={})
4748
handlers = Hash[
4849
HANDLERS.map do |key, klass|
49-
[key, klass.new(@hostname, @credentials, @timeout, metadata)]
50+
[key, klass.new(@hostname, @credentials, @timeout, metadata, @grpc_options)]
5051
end
5152
]
5253
# Override any handlers that are namespace compatable.
5354
if @namespace
5455
NAMESPACE_HANDLERS.each do |key, klass|
55-
handlers[key] = klass.new(@hostname, @credentials, @timeout, @namespace, metadata)
56+
handlers[key] = klass.new(@hostname, @credentials, @timeout, @namespace, metadata, @grpc_options)
5657
end
5758
end
5859

lib/etcdv3/connection_wrapper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ class ConnectionWrapper
33

44
attr_accessor :connection, :endpoints, :user, :password, :token, :timeout
55

6-
def initialize(timeout, *endpoints, namespace, allow_reconnect)
6+
def initialize(timeout, *endpoints, namespace, allow_reconnect, **kwargs)
77
@user, @password, @token = nil, nil, nil
88
@timeout = timeout
99
@namespace = namespace
10-
@endpoints = endpoints.map{|endpoint| Etcdv3::Connection.new(endpoint, @timeout, @namespace) }
10+
@endpoints = endpoints.map{|endpoint| Etcdv3::Connection.new(endpoint, @timeout, @namespace, {}, kwargs.fetch(:grpc_options, {})) }
1111
@allow_reconnect = allow_reconnect
1212
@connection = @endpoints.first
1313
end

lib/etcdv3/kv.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ class KV
44
include Etcdv3::KV::Requests
55
include GRPC::Core::TimeConsts
66

7-
def initialize(hostname, credentials, timeout, metadata={})
8-
@stub = Etcdserverpb::KV::Stub.new(hostname, credentials)
7+
def initialize(hostname, credentials, timeout, metadata={}, grpc_options={})
8+
@stub = Etcdserverpb::KV::Stub.new(hostname, credentials, **grpc_options)
99
@timeout = timeout
1010
@metadata = metadata
1111
end

lib/etcdv3/lease.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ class Etcdv3
22
class Lease
33
include GRPC::Core::TimeConsts
44

5-
def initialize(hostname, credentials, timeout, metadata={})
6-
@stub = Etcdserverpb::Lease::Stub.new(hostname, credentials)
5+
def initialize(hostname, credentials, timeout, metadata={}, grpc_options={})
6+
@stub = Etcdserverpb::Lease::Stub.new(hostname, credentials, **grpc_options)
77
@timeout = timeout
88
@metadata = metadata
99
end

lib/etcdv3/lock.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ class Etcdv3
22
class Lock
33
include GRPC::Core::TimeConsts
44

5-
def initialize(hostname, credentials, timeout, metadata = {})
6-
@stub = V3lockpb::Lock::Stub.new(hostname, credentials)
5+
def initialize(hostname, credentials, timeout, metadata = {}, grpc_options = {})
6+
@stub = V3lockpb::Lock::Stub.new(hostname, credentials, **grpc_options)
77
@timeout = timeout
88
@metadata = metadata
99
end

lib/etcdv3/maintenance.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class Maintenance
1212
deactivate: 2
1313
}
1414

15-
def initialize(hostname, credentials, _timeout, metadata = {})
16-
@stub = Etcdserverpb::Maintenance::Stub.new(hostname, credentials)
15+
def initialize(hostname, credentials, _timeout, metadata = {}, grpc_options = {})
16+
@stub = Etcdserverpb::Maintenance::Stub.new(hostname, credentials, **grpc_options)
1717
@metadata = metadata
1818
end
1919

lib/etcdv3/namespace/kv.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ class KV
44
include Etcdv3::Namespace::Utilities
55
include GRPC::Core::TimeConsts
66

7-
def initialize(hostname, credentials, timeout, namespace, metadata={})
8-
@stub = Etcdserverpb::KV::Stub.new(hostname, credentials)
7+
def initialize(hostname, credentials, timeout, namespace, metadata={}, grpc_options={})
8+
@stub = Etcdserverpb::KV::Stub.new(hostname, credentials, **grpc_options)
99
@timeout = timeout
1010
@namespace = namespace
1111
@metadata = metadata

lib/etcdv3/namespace/lock.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ class Lock
33
include GRPC::Core::TimeConsts
44
include Etcdv3::Namespace::Utilities
55

6-
def initialize(hostname, credentials, timeout, namespace, metadata = {})
7-
@stub = V3lockpb::Lock::Stub.new(hostname, credentials)
6+
def initialize(hostname, credentials, timeout, namespace, metadata = {}, grpc_options = {})
7+
@stub = V3lockpb::Lock::Stub.new(hostname, credentials, **grpc_options)
88
@timeout = timeout
99
@namespace = namespace
1010
@metadata = metadata

0 commit comments

Comments
 (0)