Skip to content

Commit

Permalink
ability to set grpc_options on all levels
Browse files Browse the repository at this point in the history
  • Loading branch information
t0ch1k committed Nov 19, 2023
1 parent 939dec1 commit 5b12d27
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 23 deletions.
1 change: 1 addition & 0 deletions lib/etcdv3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/etcdv3/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class Auth
:readwrite => Authpb::Permission::Type::READWRITE
}

def initialize(hostname, credentials, timeout, metadata = {})
@stub = Etcdserverpb::Auth::Stub.new(hostname, credentials)
def initialize(hostname, credentials, timeout, metadata = {}, grpc_options = {})
@stub = Etcdserverpb::Auth::Stub.new(hostname, credentials, **grpc_options)
@timeout = timeout
@metadata = metadata
end
Expand Down
7 changes: 4 additions & 3 deletions lib/etcdv3/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/etcdv3/connection_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/etcdv3/kv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
def initialize(hostname, credentials, timeout, metadata={}, grpc_options={})
@stub = Etcdserverpb::KV::Stub.new(hostname, credentials, **grpc_options)
@timeout = timeout
@metadata = metadata
end
Expand Down
4 changes: 2 additions & 2 deletions lib/etcdv3/lease.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
def initialize(hostname, credentials, timeout, metadata={}, grpc_options={})
@stub = Etcdserverpb::Lease::Stub.new(hostname, credentials, **grpc_options)
@timeout = timeout
@metadata = metadata
end
Expand Down
4 changes: 2 additions & 2 deletions lib/etcdv3/lock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
def initialize(hostname, credentials, timeout, metadata = {}, grpc_options = {})
@stub = V3lockpb::Lock::Stub.new(hostname, credentials, **grpc_options)
@timeout = timeout
@metadata = metadata
end
Expand Down
4 changes: 2 additions & 2 deletions lib/etcdv3/maintenance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class Maintenance
deactivate: 2
}

def initialize(hostname, credentials, _timeout, metadata = {})
@stub = Etcdserverpb::Maintenance::Stub.new(hostname, credentials)
def initialize(hostname, credentials, _timeout, metadata = {}, grpc_options = {})
@stub = Etcdserverpb::Maintenance::Stub.new(hostname, credentials, **grpc_options)
@metadata = metadata
end

Expand Down
4 changes: 2 additions & 2 deletions lib/etcdv3/namespace/kv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
def initialize(hostname, credentials, timeout, namespace, metadata={}, grpc_options={})
@stub = Etcdserverpb::KV::Stub.new(hostname, credentials, **grpc_options)
@timeout = timeout
@namespace = namespace
@metadata = metadata
Expand Down
4 changes: 2 additions & 2 deletions lib/etcdv3/namespace/lock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
def initialize(hostname, credentials, timeout, namespace, metadata = {}, grpc_options = {})
@stub = V3lockpb::Lock::Stub.new(hostname, credentials, **grpc_options)
@timeout = timeout
@namespace = namespace
@metadata = metadata
Expand Down
4 changes: 2 additions & 2 deletions lib/etcdv3/namespace/watch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
def initialize(hostname, credentials, timeout, namespace, metadata = {}, grpc_options = {})
@stub = Etcdserverpb::Watch::Stub.new(hostname, credentials, **grpc_options)
@timeout = timeout
@namespace = namespace
@metadata = metadata
Expand Down
4 changes: 2 additions & 2 deletions lib/etcdv3/watch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
def initialize(hostname, credentials, timeout, metadata = {}, grpc_options = {})
@stub = Etcdserverpb::Watch::Stub.new(hostname, credentials, **grpc_options)
@timeout = timeout
@metadata = metadata
end
Expand Down

0 comments on commit 5b12d27

Please sign in to comment.