diff --git a/lib/etcdv3.rb b/lib/etcdv3.rb index 742c610..81faed3 100644 --- a/lib/etcdv3.rb +++ b/lib/etcdv3.rb @@ -38,6 +38,7 @@ def initialize(**options) *sanitized_endpoints, @namespace, @options.fetch(:allow_reconnect, true), + grpc_options: @options.fetch(:grpc_options, {}), ) warn "WARNING: `url` is deprecated. Please use `endpoints` instead." if @options.key?(:url) authenticate(@options[:user], @options[:password]) if @options.key?(:user) diff --git a/lib/etcdv3/auth.rb b/lib/etcdv3/auth.rb index d8d85c7..95eee28 100644 --- a/lib/etcdv3/auth.rb +++ b/lib/etcdv3/auth.rb @@ -9,8 +9,8 @@ class Auth :readwrite => Authpb::Permission::Type::READWRITE } - def initialize(hostname, credentials, timeout, metadata = {}) - @stub = Etcdserverpb::Auth::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {}) + def initialize(hostname, credentials, timeout, metadata = {}, grpc_options = {}) + @stub = Etcdserverpb::Auth::Stub.new(hostname, credentials, **grpc_options) @timeout = timeout @metadata = metadata end diff --git a/lib/etcdv3/connection.rb b/lib/etcdv3/connection.rb index 4d4b5d0..532a8e0 100644 --- a/lib/etcdv3/connection.rb +++ b/lib/etcdv3/connection.rb @@ -18,12 +18,13 @@ class Connection attr_reader :endpoint, :hostname, :handlers, :credentials, :namespace - def initialize(url, timeout, namespace, metadata={}) + def initialize(url, timeout, namespace, metadata={}, grpc_options={}) @endpoint = URI(url) @hostname = "#{@endpoint.hostname}:#{@endpoint.port}" @namespace = namespace @credentials = resolve_credentials @timeout = timeout + @grpc_options = grpc_options @handlers = handler_map(metadata) end @@ -46,13 +47,13 @@ def refresh_metadata(metadata) def handler_map(metadata={}) handlers = Hash[ HANDLERS.map do |key, klass| - [key, klass.new(@hostname, @credentials, @timeout, metadata)] + [key, klass.new(@hostname, @credentials, @timeout, metadata, @grpc_options)] end ] # Override any handlers that are namespace compatable. if @namespace NAMESPACE_HANDLERS.each do |key, klass| - handlers[key] = klass.new(@hostname, @credentials, @timeout, @namespace, metadata) + handlers[key] = klass.new(@hostname, @credentials, @timeout, @namespace, metadata, @grpc_options) end end diff --git a/lib/etcdv3/connection_wrapper.rb b/lib/etcdv3/connection_wrapper.rb index 271b2a0..b6a2ab9 100644 --- a/lib/etcdv3/connection_wrapper.rb +++ b/lib/etcdv3/connection_wrapper.rb @@ -3,11 +3,11 @@ class ConnectionWrapper attr_accessor :connection, :endpoints, :user, :password, :token, :timeout - def initialize(timeout, *endpoints, namespace, allow_reconnect) + def initialize(timeout, *endpoints, namespace, allow_reconnect, **kwargs) @user, @password, @token = nil, nil, nil @timeout = timeout @namespace = namespace - @endpoints = endpoints.map{|endpoint| Etcdv3::Connection.new(endpoint, @timeout, @namespace) } + @endpoints = endpoints.map{|endpoint| Etcdv3::Connection.new(endpoint, @timeout, @namespace, {}, kwargs.fetch(:grpc_options, {})) } @allow_reconnect = allow_reconnect @connection = @endpoints.first end diff --git a/lib/etcdv3/kv.rb b/lib/etcdv3/kv.rb index 48f9d63..aa9c314 100644 --- a/lib/etcdv3/kv.rb +++ b/lib/etcdv3/kv.rb @@ -4,8 +4,8 @@ class KV include Etcdv3::KV::Requests include GRPC::Core::TimeConsts - def initialize(hostname, credentials, timeout, metadata={}) - @stub = Etcdserverpb::KV::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {}) + def initialize(hostname, credentials, timeout, metadata={}, grpc_options={}) + @stub = Etcdserverpb::KV::Stub.new(hostname, credentials, **grpc_options) @timeout = timeout @metadata = metadata end diff --git a/lib/etcdv3/lease.rb b/lib/etcdv3/lease.rb index 437976c..7e09d60 100644 --- a/lib/etcdv3/lease.rb +++ b/lib/etcdv3/lease.rb @@ -2,8 +2,8 @@ class Etcdv3 class Lease include GRPC::Core::TimeConsts - def initialize(hostname, credentials, timeout, metadata={}) - @stub = Etcdserverpb::Lease::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {}) + def initialize(hostname, credentials, timeout, metadata={}, grpc_options={}) + @stub = Etcdserverpb::Lease::Stub.new(hostname, credentials, **grpc_options) @timeout = timeout @metadata = metadata end diff --git a/lib/etcdv3/lock.rb b/lib/etcdv3/lock.rb index cb6ee81..280769d 100644 --- a/lib/etcdv3/lock.rb +++ b/lib/etcdv3/lock.rb @@ -2,8 +2,8 @@ class Etcdv3 class Lock include GRPC::Core::TimeConsts - def initialize(hostname, credentials, timeout, metadata = {}) - @stub = V3lockpb::Lock::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {}) + def initialize(hostname, credentials, timeout, metadata = {}, grpc_options = {}) + @stub = V3lockpb::Lock::Stub.new(hostname, credentials, **grpc_options) @timeout = timeout @metadata = metadata end diff --git a/lib/etcdv3/maintenance.rb b/lib/etcdv3/maintenance.rb index d8cd890..24e1fab 100644 --- a/lib/etcdv3/maintenance.rb +++ b/lib/etcdv3/maintenance.rb @@ -12,8 +12,8 @@ class Maintenance deactivate: 2 } - def initialize(hostname, credentials, _timeout, metadata = {}) - @stub = Etcdserverpb::Maintenance::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {}) + def initialize(hostname, credentials, _timeout, metadata = {}, grpc_options = {}) + @stub = Etcdserverpb::Maintenance::Stub.new(hostname, credentials, **grpc_options) @metadata = metadata end diff --git a/lib/etcdv3/namespace/kv.rb b/lib/etcdv3/namespace/kv.rb index f9195c2..d9dfa90 100644 --- a/lib/etcdv3/namespace/kv.rb +++ b/lib/etcdv3/namespace/kv.rb @@ -4,8 +4,8 @@ class KV include Etcdv3::Namespace::Utilities include GRPC::Core::TimeConsts - def initialize(hostname, credentials, timeout, namespace, metadata={}) - @stub = Etcdserverpb::KV::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {}) + def initialize(hostname, credentials, timeout, namespace, metadata={}, grpc_options={}) + @stub = Etcdserverpb::KV::Stub.new(hostname, credentials, **grpc_options) @timeout = timeout @namespace = namespace @metadata = metadata diff --git a/lib/etcdv3/namespace/lock.rb b/lib/etcdv3/namespace/lock.rb index 6822f1a..f929f66 100644 --- a/lib/etcdv3/namespace/lock.rb +++ b/lib/etcdv3/namespace/lock.rb @@ -3,8 +3,8 @@ class Lock include GRPC::Core::TimeConsts include Etcdv3::Namespace::Utilities - def initialize(hostname, credentials, timeout, namespace, metadata = {}) - @stub = V3lockpb::Lock::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {}) + def initialize(hostname, credentials, timeout, namespace, metadata = {}, grpc_options = {}) + @stub = V3lockpb::Lock::Stub.new(hostname, credentials, **grpc_options) @timeout = timeout @namespace = namespace @metadata = metadata diff --git a/lib/etcdv3/namespace/watch.rb b/lib/etcdv3/namespace/watch.rb index 6030d0e..3d74ec7 100644 --- a/lib/etcdv3/namespace/watch.rb +++ b/lib/etcdv3/namespace/watch.rb @@ -3,8 +3,8 @@ class Watch include GRPC::Core::TimeConsts include Etcdv3::Namespace::Utilities - def initialize(hostname, credentials, timeout, namespace, metadata = {}) - @stub = Etcdserverpb::Watch::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {}) + def initialize(hostname, credentials, timeout, namespace, metadata = {}, grpc_options = {}) + @stub = Etcdserverpb::Watch::Stub.new(hostname, credentials, **grpc_options) @timeout = timeout @namespace = namespace @metadata = metadata diff --git a/lib/etcdv3/watch.rb b/lib/etcdv3/watch.rb index 84fbfa9..b215f05 100644 --- a/lib/etcdv3/watch.rb +++ b/lib/etcdv3/watch.rb @@ -2,8 +2,8 @@ class Etcdv3 class Watch include GRPC::Core::TimeConsts - def initialize(hostname, credentials, timeout, metadata = {}) - @stub = Etcdserverpb::Watch::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {}) + def initialize(hostname, credentials, timeout, metadata = {}, grpc_options = {}) + @stub = Etcdserverpb::Watch::Stub.new(hostname, credentials, **grpc_options) @timeout = timeout @metadata = metadata end