gcloud 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +8 -8
  2. data/AUTHENTICATION.md +3 -3
  3. data/CHANGELOG.md +92 -0
  4. data/OVERVIEW.md +3 -3
  5. data/lib/gcloud.rb +75 -25
  6. data/lib/gcloud/backoff.rb +5 -1
  7. data/lib/gcloud/bigquery.rb +25 -43
  8. data/lib/gcloud/bigquery/copy_job.rb +13 -13
  9. data/lib/gcloud/bigquery/data.rb +20 -16
  10. data/lib/gcloud/bigquery/dataset.rb +202 -177
  11. data/lib/gcloud/bigquery/dataset/access.rb +118 -104
  12. data/lib/gcloud/bigquery/dataset/list.rb +14 -18
  13. data/lib/gcloud/bigquery/extract_job.rb +12 -12
  14. data/lib/gcloud/bigquery/insert_response.rb +12 -14
  15. data/lib/gcloud/bigquery/job.rb +45 -57
  16. data/lib/gcloud/bigquery/job/list.rb +18 -24
  17. data/lib/gcloud/bigquery/load_job.rb +35 -27
  18. data/lib/gcloud/bigquery/project.rb +53 -73
  19. data/lib/gcloud/bigquery/query_data.rb +28 -35
  20. data/lib/gcloud/bigquery/query_job.rb +18 -18
  21. data/lib/gcloud/bigquery/schema.rb +359 -0
  22. data/lib/gcloud/bigquery/service.rb +506 -0
  23. data/lib/gcloud/bigquery/table.rb +185 -266
  24. data/lib/gcloud/bigquery/table/list.rb +15 -19
  25. data/lib/gcloud/bigquery/view.rb +126 -81
  26. data/lib/gcloud/datastore.rb +39 -27
  27. data/lib/gcloud/datastore/commit.rb +2 -2
  28. data/lib/gcloud/datastore/dataset.rb +8 -19
  29. data/lib/gcloud/datastore/dataset/lookup_results.rb +2 -4
  30. data/lib/gcloud/datastore/dataset/query_results.rb +0 -2
  31. data/lib/gcloud/datastore/entity.rb +7 -1
  32. data/lib/gcloud/datastore/errors.rb +5 -27
  33. data/lib/gcloud/datastore/grpc_utils.rb +4 -3
  34. data/lib/gcloud/datastore/key.rb +6 -0
  35. data/lib/gcloud/datastore/service.rb +18 -12
  36. data/lib/gcloud/datastore/transaction.rb +0 -10
  37. data/lib/gcloud/dns.rb +29 -19
  38. data/lib/gcloud/dns/change.rb +10 -15
  39. data/lib/gcloud/dns/change/list.rb +4 -4
  40. data/lib/gcloud/dns/importer.rb +1 -1
  41. data/lib/gcloud/dns/project.rb +32 -49
  42. data/lib/gcloud/dns/record.rb +8 -2
  43. data/lib/gcloud/dns/record/list.rb +4 -4
  44. data/lib/gcloud/dns/service.rb +167 -0
  45. data/lib/gcloud/dns/zone.rb +33 -52
  46. data/lib/gcloud/dns/zone/list.rb +12 -16
  47. data/lib/gcloud/errors.rb +31 -19
  48. data/lib/gcloud/logging.rb +50 -39
  49. data/lib/gcloud/logging/entry.rb +197 -24
  50. data/lib/gcloud/logging/entry/list.rb +0 -2
  51. data/lib/gcloud/logging/logger.rb +1 -1
  52. data/lib/gcloud/logging/metric.rb +3 -9
  53. data/lib/gcloud/logging/metric/list.rb +0 -2
  54. data/lib/gcloud/logging/project.rb +58 -54
  55. data/lib/gcloud/logging/resource_descriptor.rb +2 -2
  56. data/lib/gcloud/logging/resource_descriptor/list.rb +0 -2
  57. data/lib/gcloud/logging/service.rb +32 -23
  58. data/lib/gcloud/logging/sink.rb +8 -14
  59. data/lib/gcloud/logging/sink/list.rb +0 -2
  60. data/lib/gcloud/pubsub.rb +21 -16
  61. data/lib/gcloud/pubsub/policy.rb +204 -0
  62. data/lib/gcloud/pubsub/project.rb +26 -38
  63. data/lib/gcloud/pubsub/service.rb +39 -31
  64. data/lib/gcloud/pubsub/subscription.rb +56 -59
  65. data/lib/gcloud/pubsub/subscription/list.rb +4 -4
  66. data/lib/gcloud/pubsub/topic.rb +69 -66
  67. data/lib/gcloud/pubsub/topic/list.rb +0 -2
  68. data/lib/gcloud/pubsub/topic/{batch.rb → publisher.rb} +15 -2
  69. data/lib/gcloud/resource_manager.rb +27 -26
  70. data/lib/gcloud/resource_manager/manager.rb +19 -39
  71. data/lib/gcloud/resource_manager/policy.rb +211 -0
  72. data/lib/gcloud/resource_manager/project.rb +97 -121
  73. data/lib/gcloud/resource_manager/project/list.rb +7 -7
  74. data/lib/gcloud/resource_manager/project/updater.rb +4 -9
  75. data/lib/gcloud/resource_manager/service.rb +127 -0
  76. data/lib/gcloud/storage.rb +24 -42
  77. data/lib/gcloud/storage/bucket.rb +104 -192
  78. data/lib/gcloud/storage/bucket/acl.rb +47 -143
  79. data/lib/gcloud/storage/bucket/cors.rb +55 -11
  80. data/lib/gcloud/storage/bucket/list.rb +14 -14
  81. data/lib/gcloud/storage/errors.rb +3 -43
  82. data/lib/gcloud/storage/file.rb +114 -111
  83. data/lib/gcloud/storage/file/acl.rb +27 -113
  84. data/lib/gcloud/storage/file/list.rb +21 -21
  85. data/lib/gcloud/storage/project.rb +49 -59
  86. data/lib/gcloud/storage/service.rb +347 -0
  87. data/lib/gcloud/translate.rb +24 -14
  88. data/lib/gcloud/translate/api.rb +12 -21
  89. data/lib/gcloud/translate/detection.rb +5 -5
  90. data/lib/gcloud/translate/language.rb +1 -1
  91. data/lib/gcloud/translate/service.rb +80 -0
  92. data/lib/gcloud/translate/translation.rb +6 -6
  93. data/lib/gcloud/version.rb +1 -1
  94. data/lib/gcloud/vision.rb +24 -15
  95. data/lib/gcloud/vision/annotate.rb +24 -21
  96. data/lib/gcloud/vision/annotation.rb +9 -9
  97. data/lib/gcloud/vision/annotation/entity.rb +11 -11
  98. data/lib/gcloud/vision/annotation/face.rb +25 -25
  99. data/lib/gcloud/vision/annotation/properties.rb +8 -8
  100. data/lib/gcloud/vision/annotation/safe_search.rb +4 -4
  101. data/lib/gcloud/vision/annotation/text.rb +7 -7
  102. data/lib/gcloud/vision/annotation/vertex.rb +1 -1
  103. data/lib/gcloud/vision/image.rb +11 -11
  104. data/lib/gcloud/vision/location.rb +5 -2
  105. data/lib/gcloud/vision/project.rb +14 -16
  106. data/lib/gcloud/vision/service.rb +66 -0
  107. data/lib/google/api_client.rb +0 -0
  108. metadata +27 -24
  109. data/lib/gcloud/bigquery/connection.rb +0 -624
  110. data/lib/gcloud/bigquery/errors.rb +0 -68
  111. data/lib/gcloud/bigquery/table/schema.rb +0 -234
  112. data/lib/gcloud/dns/connection.rb +0 -173
  113. data/lib/gcloud/dns/errors.rb +0 -68
  114. data/lib/gcloud/resource_manager/connection.rb +0 -134
  115. data/lib/gcloud/resource_manager/errors.rb +0 -68
  116. data/lib/gcloud/storage/connection.rb +0 -444
  117. data/lib/gcloud/translate/connection.rb +0 -85
  118. data/lib/gcloud/translate/errors.rb +0 -68
  119. data/lib/gcloud/upload.rb +0 -95
  120. data/lib/gcloud/vision/connection.rb +0 -63
  121. data/lib/gcloud/vision/errors.rb +0 -69
@@ -13,9 +13,10 @@
13
13
  # limitations under the License.
14
14
 
15
15
 
16
+ require "gcloud/backoff"
17
+ require "gcloud/errors"
16
18
  require "google/pubsub/v1/pubsub_services"
17
19
  require "google/iam/v1/iam_policy_services"
18
- require "gcloud/backoff"
19
20
  require "gcloud/grpc_utils"
20
21
  require "json"
21
22
 
@@ -25,14 +26,16 @@ module Gcloud
25
26
  # @private Represents the gRPC Pub/Sub service, including all the API
26
27
  # methods.
27
28
  class Service
28
- attr_accessor :project, :credentials, :host
29
+ attr_accessor :project, :credentials, :host, :retries, :timeout
29
30
 
30
31
  ##
31
32
  # Creates a new Service instance.
32
- def initialize project, credentials
33
+ def initialize project, credentials, host: nil, retries: nil, timeout: nil
33
34
  @project = project
34
35
  @credentials = credentials
35
- @host = "pubsub.googleapis.com"
36
+ @host = host || "pubsub.googleapis.com"
37
+ @retries = retries
38
+ @timeout = timeout
36
39
  end
37
40
 
38
41
  def creds
@@ -43,19 +46,22 @@ module Gcloud
43
46
 
44
47
  def subscriber
45
48
  return mocked_subscriber if mocked_subscriber
46
- @subscriber ||= Google::Pubsub::V1::Subscriber::Stub.new host, creds
49
+ @subscriber ||= Google::Pubsub::V1::Subscriber::Stub.new(
50
+ host, creds, timeout: timeout)
47
51
  end
48
52
  attr_accessor :mocked_subscriber
49
53
 
50
54
  def publisher
51
55
  return mocked_publisher if mocked_publisher
52
- @publisher ||= Google::Pubsub::V1::Publisher::Stub.new host, creds
56
+ @publisher ||= Google::Pubsub::V1::Publisher::Stub.new(
57
+ host, creds, timeout: timeout)
53
58
  end
54
59
  attr_accessor :mocked_publisher
55
60
 
56
61
  def iam
57
62
  return mocked_iam if mocked_iam
58
- @iam ||= Google::Iam::V1::IAMPolicy::Stub.new host, creds
63
+ @iam ||= Google::Iam::V1::IAMPolicy::Stub.new(
64
+ host, creds, timeout: timeout)
59
65
  end
60
66
  attr_accessor :mocked_iam
61
67
 
@@ -74,7 +80,7 @@ module Gcloud
74
80
  r.topic = topic_path(topic_name, options)
75
81
  end
76
82
 
77
- backoff { publisher.get_topic topic_req }
83
+ execute { publisher.get_topic topic_req }
78
84
  end
79
85
 
80
86
  ##
@@ -86,7 +92,7 @@ module Gcloud
86
92
  r.page_size = options[:max] if options[:max]
87
93
  end
88
94
 
89
- backoff { publisher.list_topics topics_req }
95
+ execute { publisher.list_topics topics_req }
90
96
  end
91
97
 
92
98
  ##
@@ -96,7 +102,7 @@ module Gcloud
96
102
  r.name = topic_path(topic_name, options)
97
103
  end
98
104
 
99
- backoff { publisher.create_topic topic_req }
105
+ execute { publisher.create_topic topic_req }
100
106
  end
101
107
 
102
108
  ##
@@ -109,7 +115,7 @@ module Gcloud
109
115
  r.topic = topic_path(topic_name)
110
116
  end
111
117
 
112
- backoff { publisher.delete_topic topic_req }
118
+ execute { publisher.delete_topic topic_req }
113
119
  end
114
120
 
115
121
  ##
@@ -126,7 +132,7 @@ module Gcloud
126
132
  end
127
133
  )
128
134
 
129
- backoff { publisher.publish publish_req }
135
+ execute { publisher.publish publish_req }
130
136
  end
131
137
 
132
138
  ##
@@ -136,7 +142,7 @@ module Gcloud
136
142
  subscription: subscription_path(subscription_name, options)
137
143
  )
138
144
 
139
- backoff { subscriber.get_subscription sub_req }
145
+ execute { subscriber.get_subscription sub_req }
140
146
  end
141
147
 
142
148
  ##
@@ -148,7 +154,7 @@ module Gcloud
148
154
  list_req = Google::Pubsub::V1::ListTopicSubscriptionsRequest.new \
149
155
  list_params
150
156
 
151
- backoff { publisher.list_topic_subscriptions list_req }
157
+ execute { publisher.list_topic_subscriptions list_req }
152
158
  end
153
159
 
154
160
  ##
@@ -159,7 +165,7 @@ module Gcloud
159
165
  page_size: options[:max] }.delete_if { |_, v| v.nil? }
160
166
  list_req = Google::Pubsub::V1::ListSubscriptionsRequest.new list_params
161
167
 
162
- backoff { subscriber.list_subscriptions list_req }
168
+ execute { subscriber.list_subscriptions list_req }
163
169
  end
164
170
 
165
171
  ##
@@ -176,7 +182,7 @@ module Gcloud
176
182
  attributes: (options[:attributes] || {}).to_h)
177
183
  end
178
184
 
179
- backoff { subscriber.create_subscription sub_req }
185
+ execute { subscriber.create_subscription sub_req }
180
186
  end
181
187
 
182
188
  ##
@@ -187,7 +193,7 @@ module Gcloud
187
193
  subscription: subscription_path(subscription)
188
194
  )
189
195
 
190
- backoff { subscriber.delete_subscription del_req }
196
+ execute { subscriber.delete_subscription del_req }
191
197
  end
192
198
 
193
199
  ##
@@ -199,7 +205,7 @@ module Gcloud
199
205
  max_messages: options.fetch(:max, 100).to_i
200
206
  )
201
207
 
202
- backoff { subscriber.pull pull_req }
208
+ execute { subscriber.pull pull_req }
203
209
  end
204
210
 
205
211
  ##
@@ -210,7 +216,7 @@ module Gcloud
210
216
  ack_ids: ack_ids
211
217
  )
212
218
 
213
- backoff { subscriber.acknowledge ack_req }
219
+ execute { subscriber.acknowledge ack_req }
214
220
  end
215
221
 
216
222
  ##
@@ -227,7 +233,7 @@ module Gcloud
227
233
  )
228
234
  )
229
235
 
230
- backoff { subscriber.modify_push_config mpc_req }
236
+ execute { subscriber.modify_push_config mpc_req }
231
237
  end
232
238
 
233
239
  ##
@@ -239,7 +245,7 @@ module Gcloud
239
245
  ack_deadline_seconds: deadline
240
246
  )
241
247
 
242
- backoff { subscriber.modify_ack_deadline mad_req }
248
+ execute { subscriber.modify_ack_deadline mad_req }
243
249
  end
244
250
 
245
251
  def get_topic_policy topic_name, options = {}
@@ -247,16 +253,16 @@ module Gcloud
247
253
  resource: topic_path(topic_name, options)
248
254
  )
249
255
 
250
- backoff { iam.get_iam_policy get_req }
256
+ execute { iam.get_iam_policy get_req }
251
257
  end
252
258
 
253
259
  def set_topic_policy topic_name, new_policy, options = {}
254
260
  set_req = Google::Iam::V1::SetIamPolicyRequest.new(
255
261
  resource: topic_path(topic_name, options),
256
- policy: Google::Iam::V1::Policy.decode_json(JSON.dump(new_policy))
262
+ policy: new_policy
257
263
  )
258
264
 
259
- backoff { iam.set_iam_policy set_req }
265
+ execute { iam.set_iam_policy set_req }
260
266
  end
261
267
 
262
268
  def test_topic_permissions topic_name, permissions, options = {}
@@ -265,7 +271,7 @@ module Gcloud
265
271
  permissions: permissions
266
272
  )
267
273
 
268
- backoff { iam.test_iam_permissions test_req }
274
+ execute { iam.test_iam_permissions test_req }
269
275
  end
270
276
 
271
277
  def get_subscription_policy subscription_name, options = {}
@@ -273,16 +279,16 @@ module Gcloud
273
279
  resource: subscription_path(subscription_name, options)
274
280
  )
275
281
 
276
- backoff { iam.get_iam_policy get_req }
282
+ execute { iam.get_iam_policy get_req }
277
283
  end
278
284
 
279
285
  def set_subscription_policy subscription_name, new_policy, options = {}
280
286
  set_req = Google::Iam::V1::SetIamPolicyRequest.new(
281
287
  resource: subscription_path(subscription_name, options),
282
- policy: Google::Iam::V1::Policy.decode_json(JSON.dump(new_policy))
288
+ policy: new_policy
283
289
  )
284
290
 
285
- backoff { iam.set_iam_policy set_req }
291
+ execute { iam.set_iam_policy set_req }
286
292
  end
287
293
 
288
294
  def test_subscription_permissions subscription_name,
@@ -292,7 +298,7 @@ module Gcloud
292
298
  permissions: permissions
293
299
  )
294
300
 
295
- backoff { iam.test_iam_permissions test_req }
301
+ execute { iam.test_iam_permissions test_req }
296
302
  end
297
303
 
298
304
  def project_path options = {}
@@ -316,10 +322,12 @@ module Gcloud
316
322
 
317
323
  protected
318
324
 
319
- def backoff options = {}
320
- Gcloud::Backoff.new(options).execute_grpc do
325
+ def execute
326
+ Gcloud::Backoff.new(retries: retries).execute_grpc do
321
327
  yield
322
328
  end
329
+ rescue GRPC::BadStatus => e
330
+ raise Error.from_error(e)
323
331
  end
324
332
  end
325
333
  end
@@ -114,8 +114,6 @@ module Gcloud
114
114
  push_endpoint: new_endpoint,
115
115
  attributes: {}
116
116
  ) if @grpc
117
- rescue GRPC::BadStatus => e
118
- raise Error.from_error(e)
119
117
  end
120
118
 
121
119
  ##
@@ -177,9 +175,7 @@ module Gcloud
177
175
  def delete
178
176
  ensure_service!
179
177
  service.delete_subscription name
180
- return true
181
- rescue GRPC::BadStatus => e
182
- raise Error.from_error(e)
178
+ true
183
179
  end
184
180
 
185
181
  ##
@@ -238,9 +234,7 @@ module Gcloud
238
234
  end
239
235
  acknowledge messages if autoack
240
236
  messages
241
- rescue GRPC::BadStatus => e
242
- raise Error.from_error(e)
243
- rescue Faraday::TimeoutError
237
+ rescue Hurley::Timeout
244
238
  []
245
239
  end
246
240
 
@@ -298,7 +292,7 @@ module Gcloud
298
292
  # # process msg
299
293
  # end
300
294
  #
301
- # @example Limit the number of messages pulled per batch with `max`:
295
+ # @example Limit the number of messages pulled per API request with `max`:
302
296
  # require "gcloud"
303
297
  #
304
298
  # gcloud = Gcloud.new
@@ -358,8 +352,6 @@ module Gcloud
358
352
  ensure_service!
359
353
  service.acknowledge name, *ack_ids
360
354
  true
361
- rescue GRPC::BadStatus => e
362
- raise Error.from_error(e)
363
355
  end
364
356
  alias_method :ack, :acknowledge
365
357
 
@@ -392,96 +384,105 @@ module Gcloud
392
384
  ack_ids = coerce_ack_ids messages
393
385
  ensure_service!
394
386
  service.modify_ack_deadline name, ack_ids, new_deadline
395
- return true
396
- rescue GRPC::BadStatus => e
397
- raise Error.from_error(e)
387
+ true
398
388
  end
399
389
 
400
390
  ##
401
- # Gets the access control policy.
391
+ # Gets the [Cloud IAM](https://cloud.google.com/iam/) access control
392
+ # policy for this subscription.
402
393
  #
403
- # By default, the policy values are memoized to reduce the number of API
404
- # calls to the Pub/Sub service.
394
+ # @see https://cloud.google.com/pubsub/reference/rpc/google.iam.v1#iampolicy
395
+ # google.iam.v1.IAMPolicy
405
396
  #
406
397
  # @param [Boolean] force Force the latest policy to be retrieved from the
407
398
  # Pub/Sub service when `true`. Otherwise the policy will be memoized to
408
399
  # reduce the number of API calls made to the Pub/Sub service. The
409
400
  # default is `false`.
410
401
  #
411
- # @return [Hash] Returns a hash that conforms to the following structure:
402
+ # @yield [policy] A block for updating the policy. The latest policy will
403
+ # be read from the Pub/Sub service and passed to the block. After the
404
+ # block completes, the modified policy will be written to the service.
405
+ # @yieldparam [Policy] policy the current Cloud IAM Policy for this
406
+ # subscription
412
407
  #
413
- # {
414
- # "etag"=>"CAE=",
415
- # "bindings" => [{
416
- # "role" => "roles/viewer",
417
- # "members" => ["serviceAccount:your-service-account"]
418
- # }]
419
- # }
408
+ # @return [Policy] the current Cloud IAM Policy for this subscription
420
409
  #
421
410
  # @example Policy values are memoized to reduce the number of API calls:
422
411
  # require "gcloud"
423
412
  #
424
413
  # gcloud = Gcloud.new
425
414
  # pubsub = gcloud.pubsub
415
+ # sub = pubsub.subscription "my-subscription"
426
416
  #
427
- # subscription = pubsub.subscription "my-subscription"
428
- # puts subscription.policy["bindings"]
429
- # puts subscription.policy["rules"]
417
+ # policy = sub.policy # API call
418
+ # policy_2 = sub.policy # No API call
430
419
  #
431
420
  # @example Use `force` to retrieve the latest policy from the service:
432
421
  # require "gcloud"
433
422
  #
434
423
  # gcloud = Gcloud.new
435
424
  # pubsub = gcloud.pubsub
425
+ # sub = pubsub.subscription "my-subscription"
436
426
  #
437
- # subscription = pubsub.subscription "my-subscription"
438
- # policy = subscription.policy force: true
427
+ # policy = sub.policy force: true # API call
428
+ # policy_2 = sub.policy force: true # API call
429
+ #
430
+ # @example Update the policy by passing a block:
431
+ # require "gcloud"
432
+ #
433
+ # gcloud = Gcloud.new
434
+ # pubsub = gcloud.pubsub
435
+ # sub = pubsub.subscription "my-subscription"
436
+ #
437
+ # policy = sub.policy do |p|
438
+ # p.add "roles/owner", "user:owner@example.com"
439
+ # end # 2 API calls
439
440
  #
440
441
  def policy force: nil
441
- @policy = nil if force
442
+ @policy = nil if force || block_given?
442
443
  @policy ||= begin
443
444
  ensure_service!
444
445
  grpc = service.get_subscription_policy name
445
- JSON.parse(Google::Iam::V1::Policy.encode_json(grpc))
446
- rescue GRPC::BadStatus => e
447
- raise Error.from_error(e)
446
+ Policy.from_grpc grpc
448
447
  end
448
+ return @policy unless block_given?
449
+ p = @policy.deep_dup
450
+ yield p
451
+ self.policy = p
449
452
  end
450
453
 
451
454
  ##
452
- # Sets the access control policy.
455
+ # Updates the [Cloud IAM](https://cloud.google.com/iam/) access control
456
+ # policy for this subscription. The policy should be read from {#policy}.
457
+ # See {Gcloud::Pubsub::Policy} for an explanation of the policy `etag`
458
+ # property and how to modify policies.
459
+ #
460
+ # You can also update the policy by passing a block to {#policy}, which
461
+ # will call this method internally after the block completes.
453
462
  #
454
- # @param [String] new_policy A hash that conforms to the following
455
- # structure:
463
+ # @see https://cloud.google.com/pubsub/reference/rpc/google.iam.v1#iampolicy
464
+ # google.iam.v1.IAMPolicy
456
465
  #
457
- # {
458
- # "bindings" => [{
459
- # "role" => "roles/viewer",
460
- # "members" => ["serviceAccount:your-service-account"]
461
- # }]
462
- # }
466
+ # @param [Policy] new_policy a new or modified Cloud IAM Policy for this
467
+ # subscription
463
468
  #
464
469
  # @example
465
470
  # require "gcloud"
466
471
  #
467
472
  # gcloud = Gcloud.new
468
473
  # pubsub = gcloud.pubsub
474
+ # sub = pubsub.subscription "my-subscription"
475
+ #
476
+ # policy = sub.policy # API call
477
+ #
478
+ # policy.add "roles/owner", "user:owner@example.com"
469
479
  #
470
- # viewer_policy = {
471
- # "bindings" => [{
472
- # "role" => "roles/viewer",
473
- # "members" => ["serviceAccount:your-service-account"]
474
- # }]
475
- # }
476
- # subscription = pubsub.subscription "my-subscription"
477
- # subscription.policy = viewer_policy
480
+ # sub.policy = policy # API call
478
481
  #
479
482
  def policy= new_policy
480
483
  ensure_service!
481
- grpc = service.set_subscription_policy name, new_policy
482
- @policy = JSON.parse(Google::Iam::V1::Policy.encode_json(grpc))
483
- rescue GRPC::BadStatus => e
484
- raise Error.from_error(e)
484
+ grpc = service.set_subscription_policy name, new_policy.to_grpc
485
+ @policy = Policy.from_grpc grpc
485
486
  end
486
487
 
487
488
  ##
@@ -522,8 +523,6 @@ module Gcloud
522
523
  ensure_service!
523
524
  grpc = service.test_subscription_permissions name, permissions
524
525
  grpc.permissions
525
- rescue GRPC::BadStatus => e
526
- raise Error.from_error(e)
527
526
  end
528
527
 
529
528
  ##
@@ -551,8 +550,6 @@ module Gcloud
551
550
  ensure_service!
552
551
  return @grpc if @grpc
553
552
  @grpc = service.get_subscription @name
554
- rescue GRPC::BadStatus => e
555
- raise Error.from_error(e)
556
553
  end
557
554
 
558
555
  ##