google-gax 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/google/gax/bundling.rb +0 -2
- data/lib/google/gax/grpc.rb +6 -5
- data/lib/google/gax/operation.rb +20 -3
- data/lib/google/gax/version.rb +1 -1
- data/lib/google/longrunning/operations_client.rb +2 -2
- data/spec/google/gax/grpc_spec.rb +2 -0
- data/spec/google/gax/operation_spec.rb +54 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f85f3914efd1320cd9f01cfe77ec1e7fff36e092
|
4
|
+
data.tar.gz: 7326644db9b2b1157eeab214f9f327b14961c6c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b48de10a41fbe57711a32e0018a2004134871b115469eafed271dc6a301ff5a732b6866c55dba6b580b2e24d424cb329bce815b2f8ec64d522e2ea30cf950a5d
|
7
|
+
data.tar.gz: 127ad3139e211fd901e3a5943937d0da7f12ea7150a8385365f212a77a12c8a1fdd1e84592ea677190667cfaa8b2c260468eb4389ca5f2ffb5c486360d4023ce
|
data/lib/google/gax/bundling.rb
CHANGED
data/lib/google/gax/grpc.rb
CHANGED
@@ -65,12 +65,13 @@ module Google
|
|
65
65
|
error.to_status
|
66
66
|
).details
|
67
67
|
details.map do |any|
|
68
|
-
#
|
69
|
-
# available, do not deserialize.
|
70
|
-
candidate_class_name = class_case(any.type_name.split('.')).join('::')
|
68
|
+
# deserialize the proto wrapped by the Any in the error details
|
71
69
|
begin
|
72
|
-
|
73
|
-
|
70
|
+
type = Google::Protobuf::DescriptorPool.generated_pool.lookup(
|
71
|
+
any.type_name
|
72
|
+
)
|
73
|
+
any.unpack(type.msgclass)
|
74
|
+
rescue
|
74
75
|
any
|
75
76
|
end
|
76
77
|
end
|
data/lib/google/gax/operation.rb
CHANGED
@@ -155,8 +155,16 @@ module Google
|
|
155
155
|
# @return [Object, nil]
|
156
156
|
# The metadata of the operation. Can be nil.
|
157
157
|
def metadata
|
158
|
-
return
|
159
|
-
|
158
|
+
return if @grpc_op.metadata.nil?
|
159
|
+
|
160
|
+
return @grpc_op.metadata.unpack(@metadata_type) if @metadata_type
|
161
|
+
|
162
|
+
descriptor = Google::Protobuf::DescriptorPool.generated_pool.lookup(
|
163
|
+
@grpc_op.metadata.type_name
|
164
|
+
)
|
165
|
+
return @grpc_op.metadata.unpack(descriptor.msgclass) if descriptor
|
166
|
+
|
167
|
+
@grpc_op.metadata
|
160
168
|
end
|
161
169
|
|
162
170
|
# Checks if the operation is done. This does not send a new api call,
|
@@ -180,7 +188,16 @@ module Google
|
|
180
188
|
# @return [Object, nil]
|
181
189
|
# The response of the operation.
|
182
190
|
def response
|
183
|
-
|
191
|
+
return unless response?
|
192
|
+
|
193
|
+
return @grpc_op.response.unpack(@result_type) if @result_type
|
194
|
+
|
195
|
+
descriptor = Google::Protobuf::DescriptorPool.generated_pool.lookup(
|
196
|
+
@grpc_op.response.type_name
|
197
|
+
)
|
198
|
+
return @grpc_op.response.unpack(descriptor.msgclass) if descriptor
|
199
|
+
|
200
|
+
@grpc_op.response
|
184
201
|
end
|
185
202
|
|
186
203
|
# Checks if the operation is done and the result is an error.
|
data/lib/google/gax/version.rb
CHANGED
@@ -121,10 +121,10 @@ module Google
|
|
121
121
|
require "google/gax/grpc"
|
122
122
|
require "google/longrunning/operations_services_pb"
|
123
123
|
|
124
|
-
credentials ||= Google::Auth::Credentials.default(
|
124
|
+
credentials ||= Google::Auth::Credentials.default(scope: scopes)
|
125
125
|
|
126
126
|
if credentials.is_a?(String) || credentials.is_a?(Hash)
|
127
|
-
updater_proc = Google::Auth::Credentials.new(credentials).updater_proc
|
127
|
+
updater_proc = Google::Auth::Credentials.new(credentials, scope: scopes).updater_proc
|
128
128
|
end
|
129
129
|
if credentials.is_a?(GRPC::Core::Channel)
|
130
130
|
channel = credentials
|
@@ -161,6 +161,7 @@ describe Google::Gax::Grpc do
|
|
161
161
|
end.to raise_error(ArgumentError)
|
162
162
|
end
|
163
163
|
end
|
164
|
+
|
164
165
|
describe '#deserialize_error_status_details' do
|
165
166
|
it 'deserializes a known error type' do
|
166
167
|
expected_error = Google::Rpc::DebugInfo.new(detail: 'shoes are untied')
|
@@ -177,6 +178,7 @@ describe Google::Gax::Grpc do
|
|
177
178
|
expect(Google::Gax::Grpc.deserialize_error_status_details(error))
|
178
179
|
.to eq [expected_error]
|
179
180
|
end
|
181
|
+
|
180
182
|
it 'does not deserialize an unknown error type' do
|
181
183
|
expected_error = Random.new.bytes(8)
|
182
184
|
|
@@ -70,17 +70,30 @@ METADATA_ANY = Google::Protobuf::Any.new
|
|
70
70
|
METADATA = Google::Rpc::Status.new(code: 2, message: 'Metadata')
|
71
71
|
METADATA_ANY.pack(METADATA)
|
72
72
|
|
73
|
+
TIMESTAMP_ANY = Google::Protobuf::Any.new
|
74
|
+
TIMESTAMP = Google::Protobuf::Timestamp.new(
|
75
|
+
seconds: 123_456_789,
|
76
|
+
nanos: 987_654_321
|
77
|
+
)
|
78
|
+
TIMESTAMP_ANY.pack(TIMESTAMP)
|
79
|
+
|
80
|
+
UNKNOWN_ANY = Google::Protobuf::Any.new(
|
81
|
+
type_url: 'type.unknown.tld/this.does.not.Exist',
|
82
|
+
value: ''
|
83
|
+
)
|
84
|
+
|
73
85
|
DONE_GET_METHOD = proc do
|
74
86
|
GrpcOp.new(done: true, response: RESULT_ANY, metadata: METADATA_ANY)
|
75
87
|
end
|
76
88
|
DONE_ON_GET_CLIENT = MockLroClient.new(get_method: DONE_GET_METHOD)
|
77
89
|
|
78
|
-
def create_op(operation, client: nil,
|
90
|
+
def create_op(operation, client: nil, result_type: Google::Rpc::Status,
|
91
|
+
metadata_type: Google::Rpc::Status, call_options: nil)
|
79
92
|
GaxOp.new(
|
80
93
|
operation,
|
81
94
|
client || DONE_ON_GET_CLIENT,
|
82
|
-
|
83
|
-
|
95
|
+
result_type,
|
96
|
+
metadata_type,
|
84
97
|
call_options: call_options
|
85
98
|
)
|
86
99
|
end
|
@@ -116,6 +129,25 @@ describe Google::Gax::Operation do
|
|
116
129
|
op = create_op(GrpcOp.new(done: true, metadata: METADATA_ANY))
|
117
130
|
expect(op.metadata).to eq(METADATA)
|
118
131
|
end
|
132
|
+
|
133
|
+
it 'should unpack the metadata when metadata_type is set to type class.' do
|
134
|
+
op = create_op(GrpcOp.new(done: true, metadata: TIMESTAMP_ANY),
|
135
|
+
metadata_type: Google::Protobuf::Timestamp)
|
136
|
+
expect(op.metadata).to eq(TIMESTAMP)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'should unpack the metadata when metadata_type is looked up.' do
|
140
|
+
op = create_op(GrpcOp.new(done: true, metadata: TIMESTAMP_ANY),
|
141
|
+
metadata_type: nil)
|
142
|
+
expect(op.metadata).to eq(TIMESTAMP)
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'should return original metadata when metadata_type is not found when ' \
|
146
|
+
'looked up.' do
|
147
|
+
op = create_op(GrpcOp.new(done: true, metadata: UNKNOWN_ANY),
|
148
|
+
metadata_type: nil)
|
149
|
+
expect(op.metadata).to eq(UNKNOWN_ANY)
|
150
|
+
end
|
119
151
|
end
|
120
152
|
|
121
153
|
context 'method `done?`' do
|
@@ -193,6 +225,25 @@ describe Google::Gax::Operation do
|
|
193
225
|
op = create_op(GrpcOp.new(done: true, response: RESULT_ANY))
|
194
226
|
expect(op.response).to eq(RESULT)
|
195
227
|
end
|
228
|
+
|
229
|
+
it 'should unpack the result when result_type is set to type class.' do
|
230
|
+
op = create_op(GrpcOp.new(done: true, response: TIMESTAMP_ANY),
|
231
|
+
result_type: Google::Protobuf::Timestamp)
|
232
|
+
expect(op.response).to eq(TIMESTAMP)
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'should unpack the result when result_type is looked up.' do
|
236
|
+
op = create_op(GrpcOp.new(done: true, response: TIMESTAMP_ANY),
|
237
|
+
result_type: nil)
|
238
|
+
expect(op.response).to eq(TIMESTAMP)
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'should return original response when result_type is not found when ' \
|
242
|
+
'looked up.' do
|
243
|
+
op = create_op(GrpcOp.new(done: true, response: UNKNOWN_ANY),
|
244
|
+
result_type: nil)
|
245
|
+
expect(op.response).to eq(UNKNOWN_ANY)
|
246
|
+
end
|
196
247
|
end
|
197
248
|
|
198
249
|
context 'method `cancel`' do
|
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: 1.
|
4
|
+
version: 1.4.0
|
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: 2018-
|
11
|
+
date: 2018-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: googleauth
|