src/ruby/pb/test/client.rb
# creates a test stub that accesses host:port securely.
creates a test stub that accesses host:port securely.
creates a test stub that accesses host : port securely .
def create_stub(opts)
  address = "#{opts.host}:#{opts.port}"
  if ['client_compressed_unary',
      'client_compressed_streaming'].include?(opts.test_case)
    compression_options =
      GRPC::Core::CompressionOptions.new(default_algorithm: :gzip)
    compression_channel_args = compression_options.to_channel_arg_hash
  else
    compression_channel_args = {}
  end
  if opts.secure
    creds = ssl_creds(opts.use_test_ca)
    stub_opts = {
      channel_args: {
        GRPC::Core::Channel::SSL_TARGET => opts.host_override
      }
    }
    wants_creds = %w(all compute_engine_creds service_account_creds)
    if wants_creds.include?(opts.test_case)
      unless opts.oauth_scope.nil?
        auth_creds = Google::Auth.get_application_default(opts.oauth_scope)
        call_creds = GRPC::Core::CallCredentials.new(auth_creds.updater_proc)
        creds = creds.compose call_creds
      end
    end
    if opts.test_case == 'oauth2_auth_token'
      auth_creds = Google::Auth.get_application_default(opts.oauth_scope)
      kw = auth_creds.updater_proc.call({})  
      call_creds = GRPC::Core::CallCredentials.new(proc { |md| md.merge(kw) })
      creds = creds.compose call_creds
    end
    if opts.test_case == 'jwt_token_creds'  
      auth_creds = Google::Auth.get_application_default
      call_creds = GRPC::Core::CallCredentials.new(auth_creds.updater_proc)
      creds = creds.compose call_creds
    end
    GRPC.logger.info("... connecting securely to #{address}")
    stub_opts[:channel_args].merge!(compression_channel_args)
    Grpc::Testing::TestService::Stub.new(address, creds, **stub_opts)
  else
    GRPC.logger.info("... connecting insecurely to #{address}")
    Grpc::Testing::TestService::Stub.new(
      address,
      :this_channel_is_insecure,
      channel_args: compression_channel_args
    )
  end
end
def create_stub ( opts ) address = "#{opts.host}:#{opts.port}" if [ 'client_compressed_unary' , 'client_compressed_streaming' ] . include? ( opts . test_case ) compression_options = GRPC :: Core :: CompressionOptions . new ( default_algorithm : :gzip ) compression_channel_args = compression_options . to_channel_arg_hash else compression_channel_args = { } end if opts . secure creds = ssl_creds ( opts . use_test_ca ) stub_opts = { channel_args : { GRPC :: Core :: Channel :: SSL_TARGET => opts . host_override } } wants_creds = %w( all compute_engine_creds service_account_creds ) if wants_creds . include? ( opts . test_case ) unless opts . oauth_scope . nil? auth_creds = Google :: Auth . get_application_default ( opts . oauth_scope ) call_creds = GRPC :: Core :: CallCredentials . new ( auth_creds . updater_proc ) creds = creds . compose call_creds end end if opts . test_case == 'oauth2_auth_token' auth_creds = Google :: Auth . get_application_default ( opts . oauth_scope ) kw = auth_creds . updater_proc . call ( { } ) call_creds = GRPC :: Core :: CallCredentials . new ( proc { | md | md . merge ( kw ) } ) creds = creds . compose call_creds end if opts . test_case == 'jwt_token_creds' auth_creds = Google :: Auth . get_application_default call_creds = GRPC :: Core :: CallCredentials . new ( auth_creds . updater_proc ) creds = creds . compose call_creds end GRPC . logger . info ( "... connecting securely to #{address}" ) stub_opts [ :channel_args ] . merge! ( compression_channel_args ) Grpc :: Testing :: TestService :: Stub . new ( address , creds , ** stub_opts ) else GRPC . logger . info ( "... connecting insecurely to #{address}" ) Grpc :: Testing :: TestService :: Stub . new ( address , :this_channel_is_insecure , channel_args : compression_channel_args ) end end
creates a test stub that accesses host:port securely.
creates a test stub that accesses host : port securely .
# Provide channel args that request compression by default # for compression interop tests # Add service account creds if specified # gives as an auth token # use a metadata update proc that just adds the auth token. # don't use a scope
opts
<not_specific>