diff options
author | Craig Tiller <ctiller@google.com> | 2015-03-06 13:47:58 -0800 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2015-03-06 13:47:58 -0800 |
commit | c20324e8aa3d98237100a4edf2fe19c212f9b8fc (patch) | |
tree | 69ac9ffef7a66faf5c599301440c2290231a5e81 /src/ruby | |
parent | bea386b1c6e8f93cb8e6deb64f132dd1c99b09de (diff) | |
parent | 3e0f48b2ec8d8d64728f3662d9e2180bdbd9c803 (diff) |
Merge github.com:grpc/grpc into credit
Diffstat (limited to 'src/ruby')
-rwxr-xr-x | src/ruby/grpc.gemspec | 4 | ||||
-rw-r--r-- | src/ruby/lib/grpc/generic/client_stub.rb | 61 |
2 files changed, 26 insertions, 39 deletions
diff --git a/src/ruby/grpc.gemspec b/src/ruby/grpc.gemspec index ed26fef4a9..45cbacfeb0 100755 --- a/src/ruby/grpc.gemspec +++ b/src/ruby/grpc.gemspec @@ -21,14 +21,10 @@ Gem::Specification.new do |s| s.require_paths = ['lib'] s.platform = Gem::Platform::RUBY - s.add_dependency 'faraday', '~> 0.9' s.add_dependency 'google-protobuf', '~> 3.0.0alpha.1.1' s.add_dependency 'googleauth', '~> 0.1' s.add_dependency 'logging', '~> 1.8' - s.add_dependency 'jwt', '~> 1.2.1' s.add_dependency 'minitest', '~> 5.4' # reqd for interop tests - s.add_dependency 'multi_json', '1.10.1' - s.add_dependency 'signet', '~> 0.6.0' s.add_dependency 'xray', '~> 1.1' s.add_development_dependency 'bundler', '~> 1.7' diff --git a/src/ruby/lib/grpc/generic/client_stub.rb b/src/ruby/lib/grpc/generic/client_stub.rb index f234984eec..01328d4a5b 100644 --- a/src/ruby/lib/grpc/generic/client_stub.rb +++ b/src/ruby/lib/grpc/generic/client_stub.rb @@ -39,6 +39,25 @@ module GRPC # Default deadline is 5 seconds. DEFAULT_DEADLINE = 5 + # setup_channel is used by #initialize to constuct a channel from its + # arguments. + def self.setup_channel(alt_chan, host, creds, **kw) + unless alt_chan.nil? + fail(TypeError, '!Channel') unless alt_chan.is_a?(Core::Channel) + return alt_chan + end + return Core::Channel.new(host, kw) if creds.nil? + fail(TypeError, '!Credentials') unless creds.is_a?(Core::Credentials) + Core::Channel.new(host, kw, creds) + end + + # check_update_metadata is used by #initialize verify that it's a Proc. + def self.check_update_metadata(update_metadata) + return update_metadata if update_metadata.nil? + fail(TypeError, '!is_a?Proc') unless update_metadata.is_a?(Proc) + update_metadata + end + # Creates a new ClientStub. # # Minimally, a stub is created with the just the host of the gRPC service @@ -73,40 +92,17 @@ module GRPC # @param update_metadata a func that updates metadata as described above # @param kw [KeywordArgs]the channel arguments def initialize(host, q, - channel_override:nil, + channel_override: nil, deadline: DEFAULT_DEADLINE, creds: nil, update_metadata: nil, **kw) - unless q.is_a? Core::CompletionQueue - fail(ArgumentError, 'not a CompletionQueue') - end + fail(TypeError, '!CompletionQueue') unless q.is_a?(Core::CompletionQueue) @queue = q - - # set the channel instance - if !channel_override.nil? - ch = channel_override - fail(ArgumentError, 'not a Channel') unless ch.is_a? Core::Channel - else - if creds.nil? - ch = Core::Channel.new(host, kw) - elsif !creds.is_a?(Core::Credentials) - fail(ArgumentError, 'not a Credentials') - else - ch = Core::Channel.new(host, kw, creds) - end - end - @ch = ch - - @update_metadata = nil - unless update_metadata.nil? - unless update_metadata.is_a? Proc - fail(ArgumentError, 'update_metadata is not a Proc') - end - @update_metadata = update_metadata - end - - @host = host + @ch = ClientStub.setup_channel(channel_override, host, creds, **kw) + @update_metadata = ClientStub.check_update_metadata(update_metadata) + alt_host = kw[Core::Channel::SSL_TARGET] + @host = alt_host.nil? ? host : alt_host @deadline = deadline end @@ -400,12 +396,7 @@ module GRPC # @param deadline [TimeConst] def new_active_call(ch, marshal, unmarshal, deadline = nil) absolute_deadline = Core::TimeConsts.from_relative_time(deadline) - # It should be OK to to pass the hostname:port to create_call, but at - # the moment this fails a security check. This will be corrected. - # - # TODO: # remove this after create_call is updated - host = @host.split(':')[0] - call = @ch.create_call(ch, host, absolute_deadline) + call = @ch.create_call(ch, @host, absolute_deadline) ActiveCall.new(call, @queue, marshal, unmarshal, absolute_deadline, started: false) end |