Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Commit

Permalink
Allow Signet::OAuth2::Client as credential arg (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
blowmage committed May 28, 2019
1 parent feb51ed commit e0b6499
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Metrics/MethodLength:
Metrics/PerceivedComplexity:
Exclude:
- "lib/google/gax/config.rb"
- "lib/google/gax/grpc/stub.rb"

Style/Documentation:
Exclude:
Expand Down
18 changes: 7 additions & 11 deletions lib/google/gax/grpc/stub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ module Stub
# @param stub_class [Class] gRPC stub class to create a new instance of.
# @param host [String] The domain name of the API remote host.
# @param port [Fixnum] The port on which to connect to the remote host.
# @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel,
# GRPC::Core::ChannelCredentials, Proc] Provides the means for authenticating requests made by the client.
# This parameter can be many types:
# @param credentials [Google::Auth::Credentials, Signet::OAuth2::Client, String, Hash, Proc,
# GRPC::Core::Channel, GRPC::Core::ChannelCredentials] Provides the means for authenticating requests made by
# the client. This parameter can be many types:
#
# * A `Google::Auth::Credentials` uses a the properties of its represented keyfile for authenticating requests
# made by this client.
# * A `Signet::OAuth2::Client` object used to apply the OAuth credentials.
# * A `GRPC::Core::Channel` will be used to make calls through.
# * A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials should
# already be composed with a `GRPC::Core::CallCredentials` object.
Expand Down Expand Up @@ -77,14 +78,9 @@ def self.new stub_class, host:, port:, credentials:, channel_args: nil, intercep
return stub_class.new address, credentials, channel_args: channel_args, interceptors: interceptors
end

updater_proc = case credentials
when Google::Auth::Credentials
credentials.updater_proc
when Proc
credentials
else
raise ArgumentError, "invalid credentials (#{credentials.class})"
end
updater_proc = credentials.updater_proc if credentials.respond_to? :updater_proc
updater_proc ||= credentials if credentials.is_a? Proc
raise ArgumentError, "invalid credentials (#{credentials.class})" if updater_proc.nil?

call_creds = GRPC::Core::CallCredentials.new updater_proc
chan_creds = GRPC::Core::ChannelCredentials.new.compose call_creds
Expand Down

0 comments on commit e0b6499

Please sign in to comment.