gcloud 0.11.0 → 0.12.0
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 +8 -8
- data/AUTHENTICATION.md +3 -3
- data/CHANGELOG.md +92 -0
- data/OVERVIEW.md +3 -3
- data/lib/gcloud.rb +75 -25
- data/lib/gcloud/backoff.rb +5 -1
- data/lib/gcloud/bigquery.rb +25 -43
- data/lib/gcloud/bigquery/copy_job.rb +13 -13
- data/lib/gcloud/bigquery/data.rb +20 -16
- data/lib/gcloud/bigquery/dataset.rb +202 -177
- data/lib/gcloud/bigquery/dataset/access.rb +118 -104
- data/lib/gcloud/bigquery/dataset/list.rb +14 -18
- data/lib/gcloud/bigquery/extract_job.rb +12 -12
- data/lib/gcloud/bigquery/insert_response.rb +12 -14
- data/lib/gcloud/bigquery/job.rb +45 -57
- data/lib/gcloud/bigquery/job/list.rb +18 -24
- data/lib/gcloud/bigquery/load_job.rb +35 -27
- data/lib/gcloud/bigquery/project.rb +53 -73
- data/lib/gcloud/bigquery/query_data.rb +28 -35
- data/lib/gcloud/bigquery/query_job.rb +18 -18
- data/lib/gcloud/bigquery/schema.rb +359 -0
- data/lib/gcloud/bigquery/service.rb +506 -0
- data/lib/gcloud/bigquery/table.rb +185 -266
- data/lib/gcloud/bigquery/table/list.rb +15 -19
- data/lib/gcloud/bigquery/view.rb +126 -81
- data/lib/gcloud/datastore.rb +39 -27
- data/lib/gcloud/datastore/commit.rb +2 -2
- data/lib/gcloud/datastore/dataset.rb +8 -19
- data/lib/gcloud/datastore/dataset/lookup_results.rb +2 -4
- data/lib/gcloud/datastore/dataset/query_results.rb +0 -2
- data/lib/gcloud/datastore/entity.rb +7 -1
- data/lib/gcloud/datastore/errors.rb +5 -27
- data/lib/gcloud/datastore/grpc_utils.rb +4 -3
- data/lib/gcloud/datastore/key.rb +6 -0
- data/lib/gcloud/datastore/service.rb +18 -12
- data/lib/gcloud/datastore/transaction.rb +0 -10
- data/lib/gcloud/dns.rb +29 -19
- data/lib/gcloud/dns/change.rb +10 -15
- data/lib/gcloud/dns/change/list.rb +4 -4
- data/lib/gcloud/dns/importer.rb +1 -1
- data/lib/gcloud/dns/project.rb +32 -49
- data/lib/gcloud/dns/record.rb +8 -2
- data/lib/gcloud/dns/record/list.rb +4 -4
- data/lib/gcloud/dns/service.rb +167 -0
- data/lib/gcloud/dns/zone.rb +33 -52
- data/lib/gcloud/dns/zone/list.rb +12 -16
- data/lib/gcloud/errors.rb +31 -19
- data/lib/gcloud/logging.rb +50 -39
- data/lib/gcloud/logging/entry.rb +197 -24
- data/lib/gcloud/logging/entry/list.rb +0 -2
- data/lib/gcloud/logging/logger.rb +1 -1
- data/lib/gcloud/logging/metric.rb +3 -9
- data/lib/gcloud/logging/metric/list.rb +0 -2
- data/lib/gcloud/logging/project.rb +58 -54
- data/lib/gcloud/logging/resource_descriptor.rb +2 -2
- data/lib/gcloud/logging/resource_descriptor/list.rb +0 -2
- data/lib/gcloud/logging/service.rb +32 -23
- data/lib/gcloud/logging/sink.rb +8 -14
- data/lib/gcloud/logging/sink/list.rb +0 -2
- data/lib/gcloud/pubsub.rb +21 -16
- data/lib/gcloud/pubsub/policy.rb +204 -0
- data/lib/gcloud/pubsub/project.rb +26 -38
- data/lib/gcloud/pubsub/service.rb +39 -31
- data/lib/gcloud/pubsub/subscription.rb +56 -59
- data/lib/gcloud/pubsub/subscription/list.rb +4 -4
- data/lib/gcloud/pubsub/topic.rb +69 -66
- data/lib/gcloud/pubsub/topic/list.rb +0 -2
- data/lib/gcloud/pubsub/topic/{batch.rb → publisher.rb} +15 -2
- data/lib/gcloud/resource_manager.rb +27 -26
- data/lib/gcloud/resource_manager/manager.rb +19 -39
- data/lib/gcloud/resource_manager/policy.rb +211 -0
- data/lib/gcloud/resource_manager/project.rb +97 -121
- data/lib/gcloud/resource_manager/project/list.rb +7 -7
- data/lib/gcloud/resource_manager/project/updater.rb +4 -9
- data/lib/gcloud/resource_manager/service.rb +127 -0
- data/lib/gcloud/storage.rb +24 -42
- data/lib/gcloud/storage/bucket.rb +104 -192
- data/lib/gcloud/storage/bucket/acl.rb +47 -143
- data/lib/gcloud/storage/bucket/cors.rb +55 -11
- data/lib/gcloud/storage/bucket/list.rb +14 -14
- data/lib/gcloud/storage/errors.rb +3 -43
- data/lib/gcloud/storage/file.rb +114 -111
- data/lib/gcloud/storage/file/acl.rb +27 -113
- data/lib/gcloud/storage/file/list.rb +21 -21
- data/lib/gcloud/storage/project.rb +49 -59
- data/lib/gcloud/storage/service.rb +347 -0
- data/lib/gcloud/translate.rb +24 -14
- data/lib/gcloud/translate/api.rb +12 -21
- data/lib/gcloud/translate/detection.rb +5 -5
- data/lib/gcloud/translate/language.rb +1 -1
- data/lib/gcloud/translate/service.rb +80 -0
- data/lib/gcloud/translate/translation.rb +6 -6
- data/lib/gcloud/version.rb +1 -1
- data/lib/gcloud/vision.rb +24 -15
- data/lib/gcloud/vision/annotate.rb +24 -21
- data/lib/gcloud/vision/annotation.rb +9 -9
- data/lib/gcloud/vision/annotation/entity.rb +11 -11
- data/lib/gcloud/vision/annotation/face.rb +25 -25
- data/lib/gcloud/vision/annotation/properties.rb +8 -8
- data/lib/gcloud/vision/annotation/safe_search.rb +4 -4
- data/lib/gcloud/vision/annotation/text.rb +7 -7
- data/lib/gcloud/vision/annotation/vertex.rb +1 -1
- data/lib/gcloud/vision/image.rb +11 -11
- data/lib/gcloud/vision/location.rb +5 -2
- data/lib/gcloud/vision/project.rb +14 -16
- data/lib/gcloud/vision/service.rb +66 -0
- data/lib/google/api_client.rb +0 -0
- metadata +27 -24
- data/lib/gcloud/bigquery/connection.rb +0 -624
- data/lib/gcloud/bigquery/errors.rb +0 -68
- data/lib/gcloud/bigquery/table/schema.rb +0 -234
- data/lib/gcloud/dns/connection.rb +0 -173
- data/lib/gcloud/dns/errors.rb +0 -68
- data/lib/gcloud/resource_manager/connection.rb +0 -134
- data/lib/gcloud/resource_manager/errors.rb +0 -68
- data/lib/gcloud/storage/connection.rb +0 -444
- data/lib/gcloud/translate/connection.rb +0 -85
- data/lib/gcloud/translate/errors.rb +0 -68
- data/lib/gcloud/upload.rb +0 -95
- data/lib/gcloud/vision/connection.rb +0 -63
- data/lib/gcloud/vision/errors.rb +0 -69
|
@@ -30,6 +30,10 @@ module Gcloud
|
|
|
30
30
|
##
|
|
31
31
|
# @private Create a new Subscription::List with an array of values.
|
|
32
32
|
def initialize arr = []
|
|
33
|
+
@topic = nil
|
|
34
|
+
@prefix = nil
|
|
35
|
+
@token = nil
|
|
36
|
+
@max = nil
|
|
33
37
|
super arr
|
|
34
38
|
end
|
|
35
39
|
|
|
@@ -191,16 +195,12 @@ module Gcloud
|
|
|
191
195
|
options = { prefix: @prefix, token: @token, max: @max }
|
|
192
196
|
grpc = @service.list_subscriptions options
|
|
193
197
|
self.class.from_grpc grpc, @service, @max
|
|
194
|
-
rescue GRPC::BadStatus => e
|
|
195
|
-
raise Error.from_error(e)
|
|
196
198
|
end
|
|
197
199
|
|
|
198
200
|
def next_topic_subscriptions
|
|
199
201
|
options = { token: @token, max: @max }
|
|
200
202
|
grpc = @service.list_topics_subscriptions @topic, options
|
|
201
203
|
self.class.from_topic_grpc grpc, @service, @topic, @max
|
|
202
|
-
rescue GRPC::BadStatus => e
|
|
203
|
-
raise Error.from_error(e)
|
|
204
204
|
end
|
|
205
205
|
end
|
|
206
206
|
end
|
data/lib/gcloud/pubsub/topic.rb
CHANGED
|
@@ -14,9 +14,10 @@
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
require "gcloud/errors"
|
|
17
|
-
require "gcloud/pubsub/topic/
|
|
17
|
+
require "gcloud/pubsub/topic/publisher"
|
|
18
18
|
require "gcloud/pubsub/topic/list"
|
|
19
19
|
require "gcloud/pubsub/subscription"
|
|
20
|
+
require "gcloud/pubsub/policy"
|
|
20
21
|
|
|
21
22
|
module Gcloud
|
|
22
23
|
module Pubsub
|
|
@@ -86,9 +87,7 @@ module Gcloud
|
|
|
86
87
|
def delete
|
|
87
88
|
ensure_service!
|
|
88
89
|
service.delete_topic name
|
|
89
|
-
|
|
90
|
-
rescue GRPC::BadStatus => e
|
|
91
|
-
raise Error.from_error(e)
|
|
90
|
+
true
|
|
92
91
|
end
|
|
93
92
|
|
|
94
93
|
##
|
|
@@ -143,8 +142,6 @@ module Gcloud
|
|
|
143
142
|
options = { deadline: deadline, endpoint: endpoint }
|
|
144
143
|
grpc = service.create_subscription name, subscription_name, options
|
|
145
144
|
Subscription.from_grpc grpc, service
|
|
146
|
-
rescue GRPC::BadStatus => e
|
|
147
|
-
raise Error.from_error(e)
|
|
148
145
|
end
|
|
149
146
|
alias_method :create_subscription, :subscribe
|
|
150
147
|
alias_method :new_subscription, :subscribe
|
|
@@ -186,9 +183,8 @@ module Gcloud
|
|
|
186
183
|
return Subscription.new_lazy subscription_name, service if skip_lookup
|
|
187
184
|
grpc = service.get_subscription subscription_name
|
|
188
185
|
Subscription.from_grpc grpc, service
|
|
189
|
-
rescue
|
|
190
|
-
|
|
191
|
-
raise Error.from_error(e)
|
|
186
|
+
rescue Gcloud::NotFoundError
|
|
187
|
+
nil
|
|
192
188
|
end
|
|
193
189
|
alias_method :get_subscription, :subscription
|
|
194
190
|
alias_method :find_subscription, :subscription
|
|
@@ -232,8 +228,6 @@ module Gcloud
|
|
|
232
228
|
options = { token: token, max: max }
|
|
233
229
|
grpc = service.list_topics_subscriptions name, options
|
|
234
230
|
Subscription::List.from_topic_grpc grpc, service, name, max
|
|
235
|
-
rescue GRPC::BadStatus => e
|
|
236
|
-
raise Error.from_error(e)
|
|
237
231
|
end
|
|
238
232
|
alias_method :find_subscriptions, :subscriptions
|
|
239
233
|
alias_method :list_subscriptions, :subscriptions
|
|
@@ -243,8 +237,9 @@ module Gcloud
|
|
|
243
237
|
#
|
|
244
238
|
# @param [String, File] data The message data.
|
|
245
239
|
# @param [Hash] attributes Optional attributes for the message.
|
|
246
|
-
# @yield [
|
|
247
|
-
#
|
|
240
|
+
# @yield [publisher] a block for publishing multiple messages in one
|
|
241
|
+
# request
|
|
242
|
+
# @yieldparam [Topic::Publisher] publisher the topic publisher object
|
|
248
243
|
#
|
|
249
244
|
# @return [Message, Array<Message>] Returns the published message when
|
|
250
245
|
# called without a block, or an array of messages when called with a
|
|
@@ -286,102 +281,115 @@ module Gcloud
|
|
|
286
281
|
# pubsub = gcloud.pubsub
|
|
287
282
|
#
|
|
288
283
|
# topic = pubsub.topic "my-topic"
|
|
289
|
-
# msgs = topic.publish do |
|
|
290
|
-
#
|
|
291
|
-
#
|
|
292
|
-
#
|
|
284
|
+
# msgs = topic.publish do |t|
|
|
285
|
+
# t.publish "new-message-1", foo: :bar
|
|
286
|
+
# t.publish "new-message-2", foo: :baz
|
|
287
|
+
# t.publish "new-message-3", foo: :bif
|
|
293
288
|
# end
|
|
294
289
|
#
|
|
295
290
|
def publish data = nil, attributes = {}
|
|
296
291
|
ensure_service!
|
|
297
|
-
|
|
298
|
-
yield
|
|
299
|
-
return nil if
|
|
300
|
-
publish_batch_messages
|
|
292
|
+
publisher = Publisher.new data, attributes
|
|
293
|
+
yield publisher if block_given?
|
|
294
|
+
return nil if publisher.messages.count.zero?
|
|
295
|
+
publish_batch_messages publisher
|
|
301
296
|
end
|
|
302
297
|
|
|
303
298
|
##
|
|
304
|
-
# Gets the access control
|
|
299
|
+
# Gets the [Cloud IAM](https://cloud.google.com/iam/) access control
|
|
300
|
+
# policy for this topic.
|
|
301
|
+
#
|
|
302
|
+
# @see https://cloud.google.com/pubsub/reference/rpc/google.iam.v1#iampolicy
|
|
303
|
+
# google.iam.v1.IAMPolicy
|
|
305
304
|
#
|
|
306
305
|
# @param [Boolean] force Force the latest policy to be retrieved from the
|
|
307
306
|
# Pub/Sub service when `true`. Otherwise the policy will be memoized to
|
|
308
307
|
# reduce the number of API calls made to the Pub/Sub service. The
|
|
309
308
|
# default is `false`.
|
|
310
309
|
#
|
|
311
|
-
# @
|
|
310
|
+
# @yield [policy] A block for updating the policy. The latest policy will
|
|
311
|
+
# be read from the Pub/Sub service and passed to the block. After the
|
|
312
|
+
# block completes, the modified policy will be written to the service.
|
|
313
|
+
# @yieldparam [Policy] policy the current Cloud IAM Policy for this topic
|
|
312
314
|
#
|
|
313
|
-
#
|
|
314
|
-
# "etag"=>"CAE=",
|
|
315
|
-
# "bindings" => [{
|
|
316
|
-
# "role" => "roles/viewer",
|
|
317
|
-
# "members" => ["serviceAccount:your-service-account"]
|
|
318
|
-
# }]
|
|
319
|
-
# }
|
|
315
|
+
# @return [Policy] the current Cloud IAM Policy for this topic
|
|
320
316
|
#
|
|
321
317
|
# @example Policy values are memoized to reduce the number of API calls:
|
|
322
318
|
# require "gcloud"
|
|
323
319
|
#
|
|
324
320
|
# gcloud = Gcloud.new
|
|
325
321
|
# pubsub = gcloud.pubsub
|
|
326
|
-
#
|
|
327
322
|
# topic = pubsub.topic "my-topic"
|
|
328
|
-
#
|
|
329
|
-
#
|
|
323
|
+
#
|
|
324
|
+
# policy = topic.policy # API call
|
|
325
|
+
# policy_2 = topic.policy # No API call
|
|
330
326
|
#
|
|
331
327
|
# @example Use `force` to retrieve the latest policy from the service:
|
|
332
328
|
# require "gcloud"
|
|
333
329
|
#
|
|
334
330
|
# gcloud = Gcloud.new
|
|
335
331
|
# pubsub = gcloud.pubsub
|
|
332
|
+
# topic = pubsub.topic "my-topic"
|
|
336
333
|
#
|
|
334
|
+
# policy = topic.policy force: true # API call
|
|
335
|
+
# policy_2 = topic.policy force: true # API call
|
|
336
|
+
#
|
|
337
|
+
# @example Update the policy by passing a block:
|
|
338
|
+
# require "gcloud"
|
|
339
|
+
#
|
|
340
|
+
# gcloud = Gcloud.new
|
|
341
|
+
# pubsub = gcloud.pubsub
|
|
337
342
|
# topic = pubsub.topic "my-topic"
|
|
338
|
-
#
|
|
343
|
+
#
|
|
344
|
+
# policy = topic.policy do |p|
|
|
345
|
+
# p.add "roles/owner", "user:owner@example.com"
|
|
346
|
+
# end # 2 API calls
|
|
339
347
|
#
|
|
340
348
|
def policy force: nil
|
|
341
|
-
@policy = nil if force
|
|
349
|
+
@policy = nil if force || block_given?
|
|
342
350
|
@policy ||= begin
|
|
343
351
|
ensure_service!
|
|
344
352
|
grpc = service.get_topic_policy name
|
|
345
|
-
|
|
346
|
-
rescue GRPC::BadStatus => e
|
|
347
|
-
raise Error.from_error(e)
|
|
353
|
+
Policy.from_grpc grpc
|
|
348
354
|
end
|
|
355
|
+
return @policy unless block_given?
|
|
356
|
+
p = @policy.deep_dup
|
|
357
|
+
yield p
|
|
358
|
+
self.policy = p
|
|
349
359
|
end
|
|
350
360
|
|
|
351
361
|
##
|
|
352
|
-
#
|
|
362
|
+
# Updates the [Cloud IAM](https://cloud.google.com/iam/) access control
|
|
363
|
+
# policy for this topic. The policy should be read from {#policy}. See
|
|
364
|
+
# {Gcloud::Pubsub::Policy} for an explanation of the policy `etag`
|
|
365
|
+
# property and how to modify policies.
|
|
353
366
|
#
|
|
354
|
-
#
|
|
355
|
-
#
|
|
367
|
+
# You can also update the policy by passing a block to {#policy}, which
|
|
368
|
+
# will call this method internally after the block completes.
|
|
356
369
|
#
|
|
357
|
-
#
|
|
358
|
-
#
|
|
359
|
-
#
|
|
360
|
-
#
|
|
361
|
-
#
|
|
362
|
-
# }
|
|
370
|
+
# @see https://cloud.google.com/pubsub/reference/rpc/google.iam.v1#iampolicy
|
|
371
|
+
# google.iam.v1.IAMPolicy
|
|
372
|
+
#
|
|
373
|
+
# @param [Policy] new_policy a new or modified Cloud IAM Policy for this
|
|
374
|
+
# topic
|
|
363
375
|
#
|
|
364
376
|
# @example
|
|
365
377
|
# require "gcloud"
|
|
366
378
|
#
|
|
367
379
|
# gcloud = Gcloud.new
|
|
368
380
|
# pubsub = gcloud.pubsub
|
|
369
|
-
#
|
|
370
|
-
# viewer_policy = {
|
|
371
|
-
# "bindings" => [{
|
|
372
|
-
# "role" => "roles/viewer",
|
|
373
|
-
# "members" => ["serviceAccount:your-service-account"]
|
|
374
|
-
# }]
|
|
375
|
-
# }
|
|
376
381
|
# topic = pubsub.topic "my-topic"
|
|
377
|
-
#
|
|
382
|
+
#
|
|
383
|
+
# policy = topic.policy # API call
|
|
384
|
+
#
|
|
385
|
+
# policy.add "roles/owner", "user:owner@example.com"
|
|
386
|
+
#
|
|
387
|
+
# topic.policy = policy # API call
|
|
378
388
|
#
|
|
379
389
|
def policy= new_policy
|
|
380
390
|
ensure_service!
|
|
381
|
-
grpc = service.set_topic_policy name, new_policy
|
|
382
|
-
@policy =
|
|
383
|
-
rescue GRPC::BadStatus => e
|
|
384
|
-
raise Error.from_error(e)
|
|
391
|
+
grpc = service.set_topic_policy name, new_policy.to_grpc
|
|
392
|
+
@policy = Policy.from_grpc grpc
|
|
385
393
|
end
|
|
386
394
|
|
|
387
395
|
##
|
|
@@ -424,8 +432,6 @@ module Gcloud
|
|
|
424
432
|
ensure_service!
|
|
425
433
|
grpc = service.test_topic_permissions name, permissions
|
|
426
434
|
grpc.permissions
|
|
427
|
-
rescue GRPC::BadStatus => e
|
|
428
|
-
raise Error.from_error(e)
|
|
429
435
|
end
|
|
430
436
|
|
|
431
437
|
##
|
|
@@ -490,9 +496,8 @@ module Gcloud
|
|
|
490
496
|
ensure_service!
|
|
491
497
|
return @grpc if @grpc
|
|
492
498
|
@grpc = service.get_topic @name
|
|
493
|
-
rescue
|
|
494
|
-
|
|
495
|
-
raise Error.from_error(e)
|
|
499
|
+
rescue Gcloud::NotFoundError
|
|
500
|
+
nil
|
|
496
501
|
end
|
|
497
502
|
|
|
498
503
|
##
|
|
@@ -500,8 +505,6 @@ module Gcloud
|
|
|
500
505
|
def publish_batch_messages batch
|
|
501
506
|
grpc = service.publish name, batch.messages
|
|
502
507
|
batch.to_gcloud_messages Array(grpc.message_ids)
|
|
503
|
-
rescue GRPC::BadStatus => e
|
|
504
|
-
raise Error.from_error(e)
|
|
505
508
|
end
|
|
506
509
|
end
|
|
507
510
|
end
|
|
@@ -17,8 +17,21 @@ module Gcloud
|
|
|
17
17
|
module Pubsub
|
|
18
18
|
class Topic
|
|
19
19
|
##
|
|
20
|
-
#
|
|
21
|
-
|
|
20
|
+
# Topic Publisher object used to publish multiple messages at once.
|
|
21
|
+
#
|
|
22
|
+
# @example
|
|
23
|
+
# require "gcloud"
|
|
24
|
+
#
|
|
25
|
+
# gcloud = Gcloud.new
|
|
26
|
+
# pubsub = gcloud.pubsub
|
|
27
|
+
#
|
|
28
|
+
# topic = pubsub.topic "my-topic"
|
|
29
|
+
# msgs = topic.publish do |t|
|
|
30
|
+
# t.publish "new-message-1", foo: :bar
|
|
31
|
+
# t.publish "new-message-2", foo: :baz
|
|
32
|
+
# t.publish "new-message-3", foo: :bif
|
|
33
|
+
# end
|
|
34
|
+
class Publisher
|
|
22
35
|
##
|
|
23
36
|
# @private The messages to publish
|
|
24
37
|
attr_reader :messages
|
|
@@ -34,6 +34,9 @@ module Gcloud
|
|
|
34
34
|
# The default scope is:
|
|
35
35
|
#
|
|
36
36
|
# * `https://www.googleapis.com/auth/cloud-platform`
|
|
37
|
+
# @param [Integer] retries Number of times to retry requests on server error.
|
|
38
|
+
# The default value is `3`. Optional.
|
|
39
|
+
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
|
37
40
|
#
|
|
38
41
|
# @return [Gcloud::ResourceManager::Manager]
|
|
39
42
|
#
|
|
@@ -45,14 +48,17 @@ module Gcloud
|
|
|
45
48
|
# puts projects.project_id
|
|
46
49
|
# end
|
|
47
50
|
#
|
|
48
|
-
def self.resource_manager keyfile = nil, scope: nil
|
|
51
|
+
def self.resource_manager keyfile = nil, scope: nil, retries: nil,
|
|
52
|
+
timeout: nil
|
|
49
53
|
if keyfile.nil?
|
|
50
54
|
credentials = Gcloud::ResourceManager::Credentials.default scope: scope
|
|
51
55
|
else
|
|
52
56
|
credentials = Gcloud::ResourceManager::Credentials.new keyfile,
|
|
53
57
|
scope: scope
|
|
54
58
|
end
|
|
55
|
-
Gcloud::ResourceManager::Manager.new
|
|
59
|
+
Gcloud::ResourceManager::Manager.new(
|
|
60
|
+
Gcloud::ResourceManager::Service.new(
|
|
61
|
+
credentials, retries: retries, timeout: timeout))
|
|
56
62
|
end
|
|
57
63
|
|
|
58
64
|
##
|
|
@@ -97,8 +103,8 @@ module Gcloud
|
|
|
97
103
|
# ```
|
|
98
104
|
#
|
|
99
105
|
# Also make sure all `GCLOUD` environment variables are cleared of any service
|
|
100
|
-
# accounts. Then gcloud will be able to detect the user authentication
|
|
101
|
-
# connect with those credentials.
|
|
106
|
+
# accounts. Then gcloud-ruby will be able to detect the user authentication
|
|
107
|
+
# and connect with those credentials.
|
|
102
108
|
#
|
|
103
109
|
# ```ruby
|
|
104
110
|
# require "gcloud"
|
|
@@ -201,24 +207,23 @@ module Gcloud
|
|
|
201
207
|
# resource_manager.undelete "tokyo-rain-123"
|
|
202
208
|
# ```
|
|
203
209
|
#
|
|
204
|
-
# ## Configuring
|
|
210
|
+
# ## Configuring retries and timeout
|
|
205
211
|
#
|
|
206
|
-
#
|
|
207
|
-
#
|
|
208
|
-
#
|
|
209
|
-
# `
|
|
212
|
+
# You can configure how many times API requests may be automatically retried.
|
|
213
|
+
# When an API request fails, the response will be inspected to see if the
|
|
214
|
+
# request meets criteria indicating that it may succeed on retry, such as
|
|
215
|
+
# `500` and `503` status codes or a specific internal error code such as
|
|
216
|
+
# `rateLimitExceeded`. If it meets the criteria, the request will be retried
|
|
217
|
+
# after a delay. If another error occurs, the delay will be increased before a
|
|
218
|
+
# subsequent attempt, until the `retries` limit is reached.
|
|
210
219
|
#
|
|
211
|
-
#
|
|
212
|
-
# should be retried. If the response matches the criteria, then the request
|
|
213
|
-
# will be retried after a delay. If another error occurs, the delay will be
|
|
214
|
-
# increased incrementally before a subsequent attempt. The first retry will be
|
|
215
|
-
# delayed one second, the second retry two seconds, and so on.
|
|
220
|
+
# You can also set the request `timeout` value in seconds.
|
|
216
221
|
#
|
|
217
222
|
# ```ruby
|
|
218
223
|
# require "gcloud"
|
|
219
|
-
# require "gcloud/backoff"
|
|
220
224
|
#
|
|
221
|
-
#
|
|
225
|
+
# gcloud = Gcloud.new
|
|
226
|
+
# resource_manager = gcloud.resource_manager retries: 10, timeout: 120
|
|
222
227
|
# ```
|
|
223
228
|
#
|
|
224
229
|
# See the [Resource Manager error
|
|
@@ -234,7 +239,8 @@ module Gcloud
|
|
|
234
239
|
# Overview](https://cloud.google.com/iam/docs/overview) for more information.
|
|
235
240
|
#
|
|
236
241
|
# A project's access control policy can be retrieved. (See
|
|
237
|
-
# {Gcloud::ResourceManager::Project#policy}
|
|
242
|
+
# {Gcloud::ResourceManager::Project#policy} and
|
|
243
|
+
# {Gcloud::ResourceManager::Policy}.)
|
|
238
244
|
#
|
|
239
245
|
# ```ruby
|
|
240
246
|
# require "gcloud"
|
|
@@ -245,8 +251,7 @@ module Gcloud
|
|
|
245
251
|
# policy = project.policy
|
|
246
252
|
# ```
|
|
247
253
|
#
|
|
248
|
-
# A project's access control policy can also be
|
|
249
|
-
# {Gcloud::ResourceManager::Project#policy=})
|
|
254
|
+
# A project's access control policy can also be updated:
|
|
250
255
|
#
|
|
251
256
|
# ```ruby
|
|
252
257
|
# require "gcloud"
|
|
@@ -255,13 +260,9 @@ module Gcloud
|
|
|
255
260
|
# resource_manager = gcloud.resource_manager
|
|
256
261
|
# project = resource_manager.project "tokyo-rain-123"
|
|
257
262
|
#
|
|
258
|
-
#
|
|
259
|
-
# "
|
|
260
|
-
#
|
|
261
|
-
# "members" => ["serviceAccount:your-service-account"]
|
|
262
|
-
# }]
|
|
263
|
-
# }
|
|
264
|
-
# project.policy = viewer_policy
|
|
263
|
+
# policy = project.policy do |p|
|
|
264
|
+
# p.add "roles/viewer", "serviceAccount:your-service-account"
|
|
265
|
+
# end
|
|
265
266
|
# ```
|
|
266
267
|
#
|
|
267
268
|
# And permissions can be tested on a project. (See
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
15
|
|
|
16
|
+
require "gcloud/errors"
|
|
16
17
|
require "gcloud/resource_manager/credentials"
|
|
17
|
-
require "gcloud/resource_manager/
|
|
18
|
-
require "gcloud/resource_manager/errors"
|
|
18
|
+
require "gcloud/resource_manager/service"
|
|
19
19
|
require "gcloud/resource_manager/project"
|
|
20
20
|
|
|
21
21
|
module Gcloud
|
|
@@ -37,15 +37,15 @@ module Gcloud
|
|
|
37
37
|
# See {Gcloud#resource_manager}
|
|
38
38
|
class Manager
|
|
39
39
|
##
|
|
40
|
-
# @private The
|
|
41
|
-
attr_accessor :
|
|
40
|
+
# @private The Service object.
|
|
41
|
+
attr_accessor :service
|
|
42
42
|
|
|
43
43
|
##
|
|
44
|
-
# @private Creates a new
|
|
44
|
+
# @private Creates a new Service instance.
|
|
45
45
|
#
|
|
46
46
|
# See {Gcloud.resource_manager}
|
|
47
|
-
def initialize
|
|
48
|
-
@
|
|
47
|
+
def initialize service
|
|
48
|
+
@service = service
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
##
|
|
@@ -113,12 +113,8 @@ module Gcloud
|
|
|
113
113
|
# end
|
|
114
114
|
#
|
|
115
115
|
def projects filter: nil, token: nil, max: nil
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
Project::List.from_response resp, self, filter, max
|
|
119
|
-
else
|
|
120
|
-
fail ApiError.from_response(resp)
|
|
121
|
-
end
|
|
116
|
+
gapi = service.list_project filter: filter, token: token, max: max
|
|
117
|
+
Project::List.from_gapi gapi, self, filter, max
|
|
122
118
|
end
|
|
123
119
|
|
|
124
120
|
##
|
|
@@ -138,12 +134,10 @@ module Gcloud
|
|
|
138
134
|
# project.project_id #=> "tokyo-rain-123"
|
|
139
135
|
#
|
|
140
136
|
def project project_id
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
nil
|
|
146
|
-
end
|
|
137
|
+
gapi = service.get_project project_id
|
|
138
|
+
Project.from_gapi gapi, service
|
|
139
|
+
rescue NotFoundError
|
|
140
|
+
nil
|
|
147
141
|
end
|
|
148
142
|
|
|
149
143
|
##
|
|
@@ -194,14 +188,8 @@ module Gcloud
|
|
|
194
188
|
# labels: {env: :development}
|
|
195
189
|
#
|
|
196
190
|
def create_project project_id, name: nil, labels: nil
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
labels
|
|
200
|
-
if resp.success?
|
|
201
|
-
Project.from_gapi resp.data, connection
|
|
202
|
-
else
|
|
203
|
-
fail ApiError.from_response(resp)
|
|
204
|
-
end
|
|
191
|
+
gapi = service.create_project project_id, name, labels
|
|
192
|
+
Project.from_gapi gapi, service
|
|
205
193
|
end
|
|
206
194
|
|
|
207
195
|
##
|
|
@@ -233,12 +221,8 @@ module Gcloud
|
|
|
233
221
|
# resource_manager.delete "tokyo-rain-123"
|
|
234
222
|
#
|
|
235
223
|
def delete project_id
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
true
|
|
239
|
-
else
|
|
240
|
-
fail ApiError.from_response(resp)
|
|
241
|
-
end
|
|
224
|
+
service.delete_project project_id
|
|
225
|
+
true
|
|
242
226
|
end
|
|
243
227
|
|
|
244
228
|
##
|
|
@@ -259,12 +243,8 @@ module Gcloud
|
|
|
259
243
|
# resource_manager.undelete "tokyo-rain-123"
|
|
260
244
|
#
|
|
261
245
|
def undelete project_id
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
true
|
|
265
|
-
else
|
|
266
|
-
fail ApiError.from_response(resp)
|
|
267
|
-
end
|
|
246
|
+
service.undelete_project project_id
|
|
247
|
+
true
|
|
268
248
|
end
|
|
269
249
|
|
|
270
250
|
protected
|