Method: #create_stub
- Defined in:
-
src/ruby/pb/test/client.rb,
src/ruby/pb/test/xds_client.rb more...
creates a test stub
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'src/ruby/pb/test/client.rb', line 97 def create_stub(opts) address = "#{opts.server_host}:#{opts.server_port}" # Provide channel args that request compression by default # for compression interop tests if ['client_compressed_unary', 'client_compressed_streaming'].include?(opts.test_case) = GRPC::Core::CompressionOptions.new(default_algorithm: :gzip) compression_channel_args = .to_channel_arg_hash else compression_channel_args = {} end if opts.secure creds = ssl_creds(opts.use_test_ca) stub_opts = { channel_args: {} } unless opts.server_host_override.empty? stub_opts[:channel_args].merge!({ GRPC::Core::Channel::SSL_TARGET => opts.server_host_override }) end # Add service account creds if specified 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({}) # gives as an auth token # use a metadata update proc that just adds the auth token. call_creds = GRPC::Core::CallCredentials.new(proc { |md| md.merge(kw) }) creds = creds.compose call_creds end if opts.test_case == 'jwt_token_creds' # don't use a scope 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) if opts.test_case == "unimplemented_service" Grpc::Testing::UnimplementedService::Stub.new(address, creds, **stub_opts) else Grpc::Testing::TestService::Stub.new(address, creds, **stub_opts) end else GRPC.logger.info("... connecting insecurely to #{address}") if opts.test_case == "unimplemented_service" Grpc::Testing::UnimplementedService::Stub.new( address, :this_channel_is_insecure, channel_args: compression_channel_args ) else Grpc::Testing::TestService::Stub.new( address, :this_channel_is_insecure, channel_args: compression_channel_args ) end end end |