google-gax 0.8.9 → 0.8.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d01554d9585efae173a06f021c95ee26fcc6b043
4
- data.tar.gz: 8fcb4ef5ac286b1ce963ccea9d6a2ceb1b727cfa
3
+ metadata.gz: 9b97f693e0972f255cf0b0ddbbf27a63370afc04
4
+ data.tar.gz: 852fb0aeeeb4312fae5951bcf4a034466dcb38ee
5
5
  SHA512:
6
- metadata.gz: f841c39cea967f4d120e4089812bd6aa676d7f0412dc1ff865633a4c322087ec85ee0e1be3e45d621c1cb5a1bfff8bd813281795cb80242a8c73f552ef120449
7
- data.tar.gz: 3f98b5a00ca78eff391ea81de5a053e2026b1c235eb2941d2081141ed3080fa574ba29de6684ddad76d993be7d55e1eb1114a21d50575d76aed1b98a85b6c557
6
+ metadata.gz: 5552ba83b4e65d7889df1fdec4cf3f59d07b96161c5064f7c2344f0eb8299daea86cfddd55e35a1ca01b16dba846d46c34cfe933d15974a0353624862dafc9ca
7
+ data.tar.gz: 1970759850a9d2ccd7f9655a688b3bf8bbb973442e9ce542dc6b53e21f412c68b3fa0cfe6d20d85f26f06de3e1f552af4ffcd64b659e21235c7f1ca3781a7ad7
@@ -29,16 +29,21 @@
29
29
 
30
30
  require 'English'
31
31
 
32
+ require 'google/gax/grpc'
33
+
32
34
  module Google
33
35
  module Gax
34
36
  # Common base class for exceptions raised by GAX.
35
37
  class GaxError < StandardError
38
+ attr_reader :details
39
+
36
40
  # @param msg [String] describes the error that occurred.
37
41
  def initialize(msg)
38
42
  msg = "GaxError #{msg}"
39
43
  msg += ", caused by #{$ERROR_INFO}" if $ERROR_INFO
40
44
  super(msg)
41
45
  @cause = $ERROR_INFO
46
+ @details = Google::Gax::Grpc.deserialize_error_status_details(@cause)
42
47
  end
43
48
 
44
49
  # cause is a new method introduced in 2.1.0, bring this
@@ -28,8 +28,12 @@
28
28
  # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
29
 
30
30
  require 'grpc'
31
+ require 'grpc/google_rpc_status_utils'
31
32
  require 'googleauth'
32
33
  require 'google/gax/errors'
34
+ require 'google/protobuf/well_known_types'
35
+ # Required in order to deserialize common error detail proto types
36
+ require 'google/rpc/error_details_pb'
33
37
 
34
38
  module Google
35
39
  module Gax
@@ -43,6 +47,35 @@ module Google
43
47
 
44
48
  API_ERRORS = [GRPC::BadStatus, GRPC::Cancelled].freeze
45
49
 
50
+ def deserialize_error_status_details(error)
51
+ return unless error.is_a? GRPC::BadStatus
52
+ # If error status is malformed, swallow the gRPC error that gets raised.
53
+ begin
54
+ details =
55
+ GRPC::GoogleRpcStatusUtils.extract_google_rpc_status(
56
+ error.to_status
57
+ ).details
58
+ rescue
59
+ return 'Could not parse error details due to a malformed server '\
60
+ 'response trailer.'
61
+ end
62
+ return if details.nil?
63
+ details =
64
+ GRPC::GoogleRpcStatusUtils.extract_google_rpc_status(
65
+ error.to_status
66
+ ).details
67
+ details.map do |any|
68
+ # If the type of the proto wrapped by the Any instance is not
69
+ # available, do not deserialize.
70
+ candidate_class_name = class_case(any.type_name.split('.')).join('::')
71
+ begin
72
+ any.unpack(Object.const_get(candidate_class_name))
73
+ rescue NameError
74
+ any
75
+ end
76
+ end
77
+ end
78
+
46
79
  # rubocop:disable Metrics/ParameterLists
47
80
 
48
81
  # Creates a gRPC client stub.
@@ -97,7 +130,7 @@ module Google
97
130
  end
98
131
  end
99
132
 
100
- module_function :create_stub
133
+ module_function :create_stub, :deserialize_error_status_details
101
134
 
102
135
  def self.verify_params(channel, chan_creds, updater_proc)
103
136
  if (channel && chan_creds) ||
@@ -109,7 +142,15 @@ module Google
109
142
  end
110
143
  end
111
144
 
112
- private_class_method :verify_params
145
+ # Capitalize all modules except the message class, which is already
146
+ # correctly cased
147
+ def self.class_case(modules)
148
+ message = modules.pop
149
+ modules = modules.map(&:capitalize)
150
+ modules << message
151
+ end
152
+
153
+ private_class_method :verify_params, :class_case
113
154
  end
114
155
  end
115
156
  end
@@ -42,12 +42,21 @@ module Google
42
42
  # messages using hashes but does not allow for nested hashes to instantiate
43
43
  # nested submessages.
44
44
  #
45
- # @param hash [Hash] The hash to be converted into a proto message.
45
+ # @param hash [Hash || Class] The hash to be converted into a proto message.
46
+ # If an instance of the proto message class is given, it is returned
47
+ # unchanged.
46
48
  # @param message_class [Class] The corresponding protobuf message class of
47
49
  # the given hash.
48
50
  #
49
51
  # @return [Object] An instance of the given message class.
50
52
  def to_proto(hash, message_class)
53
+ return hash if hash.is_a? message_class
54
+
55
+ # Sanity check: input must be a Hash
56
+ unless hash.is_a? Hash
57
+ raise ArgumentError,
58
+ "Value #{hash} must be a Hash or a #{message_class.name}"
59
+ end
51
60
  hash = coerce_submessages(hash, message_class)
52
61
  message_class.new(hash)
53
62
  end
@@ -29,6 +29,6 @@
29
29
 
30
30
  module Google
31
31
  module Gax
32
- VERSION = '0.8.9'.freeze
32
+ VERSION = '0.8.12'.freeze
33
33
  end
34
34
  end
@@ -0,0 +1,34 @@
1
+ # Copyright 2016, Google Inc.
2
+ # All rights reserved.
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are
6
+ # met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright
9
+ # notice, this list of conditions and the following disclaimer.
10
+ # * Redistributions in binary form must reproduce the above
11
+ # copyright notice, this list of conditions and the following disclaimer
12
+ # in the documentation and/or other materials provided with the
13
+ # distribution.
14
+ # * Neither the name of Google Inc. nor the names of its
15
+ # contributors may be used to endorse or promote products derived from
16
+ # this software without specific prior written permission.
17
+ #
18
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
+ # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
+ # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
+ # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
+ # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+ # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
+ # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+
30
+ module Google
31
+ module Gax
32
+ VERSION = '0.8.7'.freeze
33
+ end
34
+ end
@@ -114,4 +114,37 @@ describe Google::Gax::Grpc do
114
114
  end.to raise_error(ArgumentError)
115
115
  end
116
116
  end
117
+ describe '#deserialize_error_status_details' do
118
+ it 'deserializes a known error type' do
119
+ expected_error = Google::Rpc::DebugInfo.new(detail: 'shoes are untied')
120
+
121
+ any = Google::Protobuf::Any.new
122
+ any.pack(expected_error)
123
+ status = Google::Rpc::Status.new(details: [any])
124
+ encoded = Google::Rpc::Status.encode(status)
125
+ metadata = {
126
+ 'grpc-status-details-bin' => encoded
127
+ }
128
+ error = GRPC::BadStatus.new(1, '', metadata)
129
+
130
+ expect(Google::Gax::Grpc.deserialize_error_status_details(error))
131
+ .to eq [expected_error]
132
+ end
133
+ it 'does not deserialize an unknown error type' do
134
+ expected_error = Random.new.bytes(8)
135
+
136
+ any = Google::Protobuf::Any.new(
137
+ type_url: 'unknown-type', value: expected_error
138
+ )
139
+ status = Google::Rpc::Status.new(details: [any])
140
+ encoded = Google::Rpc::Status.encode(status)
141
+ metadata = {
142
+ 'grpc-status-details-bin' => encoded
143
+ }
144
+ error = GRPC::BadStatus.new(1, '', metadata)
145
+
146
+ expect(Google::Gax::Grpc.deserialize_error_status_details(error))
147
+ .to eq [any]
148
+ end
149
+ end
117
150
  end
@@ -28,6 +28,7 @@
28
28
  # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
29
 
30
30
  require 'google/gax'
31
+ require 'google/protobuf/any_pb'
31
32
  require 'spec/fixtures/fixture_pb'
32
33
 
33
34
  describe Google::Gax do
@@ -118,5 +119,20 @@ describe Google::Gax do
118
119
  Google::Gax.to_proto(user_hash, Google::Protobuf::User)
119
120
  end.to raise_error(ArgumentError)
120
121
  end
122
+
123
+ it 'handles proto messages' do
124
+ user_message = Google::Protobuf::User.new(
125
+ name: USER_NAME, type: USER_TYPE
126
+ )
127
+ user = Google::Gax.to_proto(user_message, Google::Protobuf::User)
128
+ expect(user).to eq user_message
129
+ end
130
+
131
+ it 'fails if proto message has unexpected type' do
132
+ user_message = Google::Protobuf::Any
133
+ expect do
134
+ Google::Gax.to_proto(user_message, Google::Protobuf::User)
135
+ end.to raise_error(ArgumentError)
136
+ end
121
137
  end
122
138
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-gax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.9
4
+ version: 0.8.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Google API Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-26 00:00:00.000000000 Z
11
+ date: 2017-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: googleauth
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.0'
33
+ version: 1.6.6
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.0'
40
+ version: 1.6.6
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: googleapis-common-protos
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -170,6 +170,7 @@ files:
170
170
  - lib/google/gax/settings.rb
171
171
  - lib/google/gax/util.rb
172
172
  - lib/google/gax/version.rb
173
+ - lib/google/gax/version.rb~
173
174
  - lib/google/longrunning/operations_client.rb
174
175
  - lib/google/longrunning/operations_client_config.json
175
176
  - spec/fixtures/fixture.proto