aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ruby/bin/interop
diff options
context:
space:
mode:
authorGravatar Michael Lumish <mlumish@google.com>2015-02-25 08:57:01 -0800
committerGravatar Michael Lumish <mlumish@google.com>2015-02-25 08:57:01 -0800
commit886144544cf0ec1d60ef7c395d9c0ae26f53abc0 (patch)
treeaebb9dc7c0f611bcda8fba0a526ea2b7b293cf04 /src/ruby/bin/interop
parent517aa0c5358f860582e6143a29522699f61fba15 (diff)
parent635dbbe2fcb58be1bcd9086917488c5de5a90a5a (diff)
Merge pull request #783 from tbetbetbe/grpc_ruby_switch_auth_to_google_auth_library_ruby
Grpc ruby switch auth to google auth library ruby
Diffstat (limited to 'src/ruby/bin/interop')
-rwxr-xr-xsrc/ruby/bin/interop/interop_client.rb31
1 files changed, 8 insertions, 23 deletions
diff --git a/src/ruby/bin/interop/interop_client.rb b/src/ruby/bin/interop/interop_client.rb
index 380ceb11df..b0b24b949f 100755
--- a/src/ruby/bin/interop/interop_client.rb
+++ b/src/ruby/bin/interop/interop_client.rb
@@ -48,6 +48,7 @@ require 'minitest'
require 'minitest/assertions'
require 'grpc'
+require 'googleauth'
require 'google/protobuf'
require 'test/cpp/interop/test_services'
@@ -56,7 +57,7 @@ require 'test/cpp/interop/empty'
require 'signet/ssl_config'
-include GRPC::Auth
+AUTH_ENV = Google::Auth::ServiceAccountCredentials::ENV_VAR
# loads the certificates used to access the test server securely.
def load_test_certs
@@ -101,22 +102,14 @@ def create_stub(opts)
}
# Add service account creds if specified
- if %w(all service_account_creds).include?(opts.test_case)
+ wants_creds = %w(all compute_engine_creds service_account_creds)
+ if wants_creds.include?(opts.test_case)
unless opts.oauth_scope.nil?
- fd = StringIO.new(File.read(opts.oauth_key_file))
- logger.info("loading oauth certs from #{opts.oauth_key_file}")
- auth_creds = ServiceAccountCredentials.new(opts.oauth_scope, fd)
+ auth_creds = Google::Auth.get_application_default(opts.oauth_scope)
stub_opts[:update_metadata] = auth_creds.updater_proc
end
end
- # Add compute engine creds if specified
- if %w(all compute_engine_creds).include?(opts.test_case)
- unless opts.oauth_scope.nil?
- stub_opts[:update_metadata] = GCECredentials.new.update_proc
- end
- end
-
logger.info("... connecting securely to #{address}")
Grpc::Testing::TestService::Stub.new(address, **stub_opts)
else
@@ -193,11 +186,11 @@ class NamedTests
def service_account_creds
# ignore this test if the oauth options are not set
- if @args.oauth_scope.nil? || @args.oauth_key_file.nil?
+ if @args.oauth_scope.nil?
p 'NOT RUN: service_account_creds; no service_account settings'
return
end
- json_key = File.read(@args.oauth_key_file)
+ json_key = File.read(ENV[AUTH_ENV])
wanted_email = MultiJson.load(json_key)['client_email']
resp = perform_large_unary(fill_username: true,
fill_oauth_scope: true)
@@ -285,7 +278,7 @@ end
# Args is used to hold the command line info.
Args = Struct.new(:default_service_account, :host, :host_override,
- :oauth_scope, :oauth_key_file, :port, :secure, :test_case,
+ :oauth_scope, :port, :secure, :test_case,
:use_test_ca)
# validates the the command line options, returning them as a Hash.
@@ -302,10 +295,6 @@ def parse_args
'email address of the default service account') do |v|
args['default_service_account'] = v
end
- opts.on('--service_account_key_file PATH',
- 'Path to the service account json key file') do |v|
- args['oauth_key_file'] = v
- end
opts.on('--server_host_override HOST_OVERRIDE',
'override host via a HTTP header') do |v|
args['host_override'] = v
@@ -333,10 +322,6 @@ def _check_args(args)
fail(OptionParser::MissingArgument, "please specify --#{arg}")
end
end
- if args['oauth_key_file'].nil? ^ args['oauth_scope'].nil?
- fail(OptionParser::MissingArgument,
- 'please specify both of --service_account_key_file and --oauth_scope')
- end
args
end