Module: Google::Gax::Grpc
- Defined in:
- lib/google/gax/grpc.rb
Overview
Grpc adapts the gRPC surface
Constant Summary collapse
- STATUS_CODE_NAMES =
Hash[ GRPC::Core::StatusCodes.constants.map do |sym| [sym.to_s, GRPC::Core::StatusCodes.const_get(sym)] end ].freeze
- API_ERRORS =
[GRPC::BadStatus, GRPC::Cancelled].freeze
Class Method Summary collapse
-
.create_stub(service_path, port, channel: nil, chan_creds: nil, updater_proc: nil, scopes: nil) {|address, creds| ... } ⇒ Object
Creates a gRPC client stub.
- .deserialize_error_status_details(error) ⇒ Object
Class Method Details
.create_stub(service_path, port, channel: nil, chan_creds: nil, updater_proc: nil, scopes: nil) {|address, creds| ... } ⇒ Object
Creates a gRPC client stub.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/google/gax/grpc.rb', line 110 def create_stub(service_path, port, channel: nil, chan_creds: nil, updater_proc: nil, scopes: nil) verify_params(channel, chan_creds, updater_proc) address = "#{service_path}:#{port}" if channel yield(address, nil, channel_override: channel) elsif chan_creds yield(address, chan_creds) else if updater_proc.nil? auth_creds = Google::Auth.get_application_default(scopes) updater_proc = auth_creds.updater_proc end call_creds = GRPC::Core::CallCredentials.new(updater_proc) chan_creds = GRPC::Core::ChannelCredentials.new.compose(call_creds) yield(address, chan_creds) end end |
.deserialize_error_status_details(error) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/google/gax/grpc.rb', line 50 def deserialize_error_status_details(error) return unless error.is_a? GRPC::BadStatus # If error status is malformed, swallow the gRPC error that gets raised. begin details = GRPC::GoogleRpcStatusUtils.extract_google_rpc_status( error.to_status ).details rescue return 'Could not parse error details due to a malformed server '\ 'response trailer.' end return if details.nil? details = GRPC::GoogleRpcStatusUtils.extract_google_rpc_status( error.to_status ).details details.map do |any| # If the type of the proto wrapped by the Any instance is not # available, do not deserialize. candidate_class_name = class_case(any.type_name.split('.')).join('::') begin any.unpack(Object.const_get(candidate_class_name)) rescue NameError any end end end |