google-gax 0.8.5 → 0.8.6
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/util.rb +17 -5
- data/lib/google/gax/version.rb +1 -1
- data/lib/google/longrunning/operations_client.rb +60 -23
- data/lib/google/longrunning/operations_client_config.json +1 -3
- data/spec/fixtures/fixture.proto +1 -0
- data/spec/fixtures/fixture_pb.rb +1 -0
- data/spec/google/gax/util_spec.rb +18 -0
- 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: f71e32189b1fb624d4eea6c700022151e4e94134
|
4
|
+
data.tar.gz: 5885fdf6ce17d16932c891b3677cf60a6b30f574
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 251e5b49190d51b23dca1350d45300687ec8b41c632df5f62198385223f25f7391f828cc5475d7ccd15847b0245128cab5b919494bb9fc6a5cbfc6671eb63a16
|
7
|
+
data.tar.gz: f8a733a59af40210710c1e1661fc5ef88692178799b37fe5d8f404e120159a461e8cf68a28fb69877dced9190a4cd8c07e965b11707083530574563bbcf0c063
|
data/lib/google/gax/util.rb
CHANGED
@@ -90,7 +90,7 @@ module Google
|
|
90
90
|
#
|
91
91
|
# @return [Object] The coerced version of the given value.
|
92
92
|
def coerce_submessage(val, field_descriptor)
|
93
|
-
if field_descriptor.label == :repeated
|
93
|
+
if (field_descriptor.label == :repeated) && !(map_field? field_descriptor)
|
94
94
|
coerce_array(val, field_descriptor)
|
95
95
|
else
|
96
96
|
coerce(val, field_descriptor)
|
@@ -108,12 +108,24 @@ module Google
|
|
108
108
|
#
|
109
109
|
# @return [Array<Object>] The coerced version of the given values.
|
110
110
|
def coerce_array(array, field_descriptor)
|
111
|
-
|
111
|
+
unless array.is_a? Array
|
112
|
+
raise ArgumentError, 'Value ' + array.to_s + ' must be an array'
|
113
|
+
end
|
112
114
|
array.map do |val|
|
113
115
|
coerce(val, field_descriptor)
|
114
116
|
end
|
115
117
|
end
|
116
118
|
|
119
|
+
# Hack to determine if field_descriptor is for a map.
|
120
|
+
#
|
121
|
+
# TODO(geigerj): Remove this once protobuf Ruby supports an official way
|
122
|
+
# to determine if a FieldDescriptor represents a map.
|
123
|
+
# See: https://github.com/google/protobuf/issues/3425
|
124
|
+
def map_field?(field_descriptor)
|
125
|
+
(field_descriptor.label == :repeated) &&
|
126
|
+
(field_descriptor.subtype.name.include? '_MapEntry_')
|
127
|
+
end
|
128
|
+
|
117
129
|
# Coerces the value of a field to be acceptable by the instantiation method
|
118
130
|
# of the wrapping message.
|
119
131
|
#
|
@@ -125,13 +137,13 @@ module Google
|
|
125
137
|
#
|
126
138
|
# @return [Object] The coerced version of the given value.
|
127
139
|
def coerce(val, field_descriptor)
|
128
|
-
return val unless val.is_a? Hash
|
140
|
+
return val unless (val.is_a? Hash) && !(map_field? field_descriptor)
|
129
141
|
to_proto(val, field_descriptor.subtype.msgclass)
|
130
142
|
end
|
131
143
|
|
132
144
|
module_function :to_proto, :coerce_submessages, :coerce_submessage,
|
133
|
-
:coerce_array, :coerce
|
145
|
+
:coerce_array, :coerce, :map_field?
|
134
146
|
private_class_method :coerce_submessages, :coerce_submessage, :coerce_array,
|
135
|
-
:coerce
|
147
|
+
:coerce, :map_field?
|
136
148
|
end
|
137
149
|
end
|
data/lib/google/gax/version.rb
CHANGED
@@ -48,7 +48,7 @@ module Google
|
|
48
48
|
# Manages long-running operations with an API service.
|
49
49
|
#
|
50
50
|
# When an API method normally takes long time to complete, it can be designed
|
51
|
-
# to return Operation to the client, and the client can use this
|
51
|
+
# to return {Google::Longrunning::Operation Operation} to the client, and the client can use this
|
52
52
|
# interface to receive the real response asynchronously by polling the
|
53
53
|
# operation resource, or pass the operation resource to another API (such as
|
54
54
|
# Google Cloud Pub/Sub API) to receive the response. Any API service that
|
@@ -86,13 +86,21 @@ module Google
|
|
86
86
|
# The domain name of the API remote host.
|
87
87
|
# @param port [Integer]
|
88
88
|
# The port on which to connect to the remote host.
|
89
|
-
# @param
|
90
|
-
#
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
#
|
95
|
-
#
|
89
|
+
# @param credentials
|
90
|
+
# [Google::Gax::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
|
91
|
+
# Provides the means for authenticating requests made by the client. This parameter can
|
92
|
+
# be many types.
|
93
|
+
# A `Google::Gax::Credentials` uses a the properties of its represented keyfile for
|
94
|
+
# authenticating requests made by this client.
|
95
|
+
# A `String` will be treated as the path to the keyfile to be used for the construction of
|
96
|
+
# credentials for this client.
|
97
|
+
# A `Hash` will be treated as the contents of a keyfile to be used for the construction of
|
98
|
+
# credentials for this client.
|
99
|
+
# A `GRPC::Core::Channel` will be used to make calls through.
|
100
|
+
# A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
|
101
|
+
# should already be composed with a `GRPC::Core::CallCredentials` object.
|
102
|
+
# A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
|
103
|
+
# metadata for requests, generally, to give OAuth credentials.
|
96
104
|
# @param scopes [Array<String>]
|
97
105
|
# The OAuth scopes for this service. This parameter is ignored if
|
98
106
|
# an updater_proc is supplied.
|
@@ -109,6 +117,7 @@ module Google
|
|
109
117
|
channel: nil,
|
110
118
|
chan_creds: nil,
|
111
119
|
updater_proc: nil,
|
120
|
+
credentials: nil,
|
112
121
|
scopes: ALL_SCOPES,
|
113
122
|
client_config: {},
|
114
123
|
timeout: DEFAULT_TIMEOUT,
|
@@ -122,11 +131,35 @@ module Google
|
|
122
131
|
require "google/gax/grpc"
|
123
132
|
require "google/longrunning/operations_services_pb"
|
124
133
|
|
125
|
-
|
134
|
+
if channel || chan_creds || updater_proc
|
135
|
+
warn "The `channel`, `chan_creds`, and `updater_proc` parameters will be removed " \
|
136
|
+
"on 2017/09/08"
|
137
|
+
credentials ||= channel
|
138
|
+
credentials ||= chan_creds
|
139
|
+
credentials ||= updater_proc
|
140
|
+
end
|
126
141
|
if app_name || app_version
|
127
142
|
warn "`app_name` and `app_version` are no longer being used in the request headers."
|
128
143
|
end
|
129
144
|
|
145
|
+
credentials ||= Google::Gax::Credentials.default
|
146
|
+
|
147
|
+
if credentials.is_a?(String) || credentials.is_a?(Hash)
|
148
|
+
updater_proc = Google::Gax::Credentials.new(credentials).updater_proc
|
149
|
+
end
|
150
|
+
if credentials.is_a?(GRPC::Core::Channel)
|
151
|
+
channel = credentials
|
152
|
+
end
|
153
|
+
if credentials.is_a?(GRPC::Core::ChannelCredentials)
|
154
|
+
chan_creds = credentials
|
155
|
+
end
|
156
|
+
if credentials.is_a?(Proc)
|
157
|
+
updater_proc = credentials
|
158
|
+
end
|
159
|
+
if credentials.is_a?(Google::Gax::Credentials)
|
160
|
+
updater_proc = credentials.updater_proc
|
161
|
+
end
|
162
|
+
|
130
163
|
google_api_client = "gl-ruby/#{RUBY_VERSION}"
|
131
164
|
google_api_client << " #{lib_name}/#{lib_version}" if lib_name
|
132
165
|
google_api_client << " gapic/0.6.8 gax/#{Google::Gax::VERSION}"
|
@@ -193,16 +226,17 @@ module Google
|
|
193
226
|
# @example
|
194
227
|
# require "google/longrunning"
|
195
228
|
#
|
196
|
-
# operations_client = Google::Longrunning
|
229
|
+
# operations_client = Google::Longrunning.new
|
197
230
|
# name = ''
|
198
231
|
# response = operations_client.get_operation(name)
|
199
232
|
|
200
233
|
def get_operation \
|
201
234
|
name,
|
202
235
|
options: nil
|
203
|
-
req =
|
236
|
+
req = {
|
204
237
|
name: name
|
205
|
-
}.delete_if { |_, v| v.nil? }
|
238
|
+
}.delete_if { |_, v| v.nil? }
|
239
|
+
req = Google::Gax::to_proto(req, Google::Longrunning::GetOperationRequest)
|
206
240
|
@get_operation.call(req, options)
|
207
241
|
end
|
208
242
|
|
@@ -234,7 +268,7 @@ module Google
|
|
234
268
|
# @example
|
235
269
|
# require "google/longrunning"
|
236
270
|
#
|
237
|
-
# operations_client = Google::Longrunning
|
271
|
+
# operations_client = Google::Longrunning.new
|
238
272
|
# name = ''
|
239
273
|
# filter = ''
|
240
274
|
#
|
@@ -256,11 +290,12 @@ module Google
|
|
256
290
|
filter,
|
257
291
|
page_size: nil,
|
258
292
|
options: nil
|
259
|
-
req =
|
293
|
+
req = {
|
260
294
|
name: name,
|
261
295
|
filter: filter,
|
262
296
|
page_size: page_size
|
263
|
-
}.delete_if { |_, v| v.nil? }
|
297
|
+
}.delete_if { |_, v| v.nil? }
|
298
|
+
req = Google::Gax::to_proto(req, Google::Longrunning::ListOperationsRequest)
|
264
299
|
@list_operations.call(req, options)
|
265
300
|
end
|
266
301
|
|
@@ -268,11 +303,11 @@ module Google
|
|
268
303
|
# makes a best effort to cancel the operation, but success is not
|
269
304
|
# guaranteed. If the server doesn't support this method, it returns
|
270
305
|
# +google.rpc.Code.UNIMPLEMENTED+. Clients can use
|
271
|
-
# Operations::GetOperation or
|
306
|
+
# {Google::Longrunning::Operations::GetOperation Operations::GetOperation} or
|
272
307
|
# other methods to check whether the cancellation succeeded or whether the
|
273
308
|
# operation completed despite cancellation. On successful cancellation,
|
274
309
|
# the operation is not deleted; instead, it becomes an operation with
|
275
|
-
# an Operation#error value with a Google::Rpc::Status#code of 1,
|
310
|
+
# an {Google::Longrunning::Operation#error Operation#error} value with a {Google::Rpc::Status#code} of 1,
|
276
311
|
# corresponding to +Code.CANCELLED+.
|
277
312
|
#
|
278
313
|
# @param name [String]
|
@@ -284,16 +319,17 @@ module Google
|
|
284
319
|
# @example
|
285
320
|
# require "google/longrunning"
|
286
321
|
#
|
287
|
-
# operations_client = Google::Longrunning
|
322
|
+
# operations_client = Google::Longrunning.new
|
288
323
|
# name = ''
|
289
324
|
# operations_client.cancel_operation(name)
|
290
325
|
|
291
326
|
def cancel_operation \
|
292
327
|
name,
|
293
328
|
options: nil
|
294
|
-
req =
|
329
|
+
req = {
|
295
330
|
name: name
|
296
|
-
}.delete_if { |_, v| v.nil? }
|
331
|
+
}.delete_if { |_, v| v.nil? }
|
332
|
+
req = Google::Gax::to_proto(req, Google::Longrunning::CancelOperationRequest)
|
297
333
|
@cancel_operation.call(req, options)
|
298
334
|
nil
|
299
335
|
end
|
@@ -312,16 +348,17 @@ module Google
|
|
312
348
|
# @example
|
313
349
|
# require "google/longrunning"
|
314
350
|
#
|
315
|
-
# operations_client = Google::Longrunning
|
351
|
+
# operations_client = Google::Longrunning.new
|
316
352
|
# name = ''
|
317
353
|
# operations_client.delete_operation(name)
|
318
354
|
|
319
355
|
def delete_operation \
|
320
356
|
name,
|
321
357
|
options: nil
|
322
|
-
req =
|
358
|
+
req = {
|
323
359
|
name: name
|
324
|
-
}.delete_if { |_, v| v.nil? }
|
360
|
+
}.delete_if { |_, v| v.nil? }
|
361
|
+
req = Google::Gax::to_proto(req, Google::Longrunning::DeleteOperationRequest)
|
325
362
|
@delete_operation.call(req, options)
|
326
363
|
nil
|
327
364
|
end
|
data/spec/fixtures/fixture.proto
CHANGED
data/spec/fixtures/fixture_pb.rb
CHANGED
@@ -12,6 +12,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
12
12
|
optional :name, :string, 1
|
13
13
|
optional :type, :enum, 2, "google.protobuf.User.UserType"
|
14
14
|
repeated :posts, :message, 3, "google.protobuf.Post"
|
15
|
+
map :map_field, :string, :string, 4
|
15
16
|
end
|
16
17
|
add_enum "google.protobuf.User.UserType" do
|
17
18
|
value :UNSPECIFIED, 0
|
@@ -36,6 +36,10 @@ describe Google::Gax do
|
|
36
36
|
USER_NAME = 'Ernest'.freeze
|
37
37
|
USER_TYPE = :ADMINISTRATOR
|
38
38
|
POST_TEXT = 'This is a test post.'.freeze
|
39
|
+
MAP = {
|
40
|
+
'key1' => 'val1',
|
41
|
+
'key2' => 'val2'
|
42
|
+
}.freeze
|
39
43
|
|
40
44
|
it 'creates a protobuf message from a simple hash' do
|
41
45
|
hash = { name: USER_NAME, type: USER_TYPE }
|
@@ -91,6 +95,20 @@ describe Google::Gax do
|
|
91
95
|
end
|
92
96
|
end
|
93
97
|
|
98
|
+
it 'handles maps' do
|
99
|
+
request_hash = {
|
100
|
+
name: USER_NAME,
|
101
|
+
map_field: MAP
|
102
|
+
}
|
103
|
+
user = Google::Gax.to_proto(request_hash, Google::Protobuf::User)
|
104
|
+
expect(user).to be_an_instance_of(Google::Protobuf::User)
|
105
|
+
expect(user.name).to eq(USER_NAME)
|
106
|
+
expect(user.map_field).to be_an_instance_of(Google::Protobuf::Map)
|
107
|
+
user.map_field.each do |k, v|
|
108
|
+
expect(MAP[k]).to eq v
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
94
112
|
it 'fails if a key does not exist in the target message type' do
|
95
113
|
user_hash = {
|
96
114
|
name: USER_NAME,
|
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.
|
4
|
+
version: 0.8.6
|
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-
|
11
|
+
date: 2017-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: googleauth
|