gcloud 0.12.2 → 0.20.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.
Files changed (169) hide show
  1. checksums.yaml +5 -13
  2. data/lib/gcloud.rb +27 -456
  3. data/lib/gcloud/bigquery.rb +2 -382
  4. data/lib/gcloud/datastore.rb +2 -576
  5. data/lib/gcloud/dns.rb +2 -321
  6. data/lib/gcloud/logging.rb +1 -322
  7. data/lib/gcloud/pubsub.rb +2 -476
  8. data/lib/gcloud/resource_manager.rb +2 -273
  9. data/lib/gcloud/storage.rb +2 -440
  10. data/lib/gcloud/translate.rb +1 -250
  11. data/lib/gcloud/version.rb +2 -2
  12. data/lib/gcloud/vision.rb +1 -501
  13. metadata +36 -332
  14. data/AUTHENTICATION.md +0 -75
  15. data/CHANGELOG.md +0 -382
  16. data/OVERVIEW.md +0 -259
  17. data/lib/gcloud/backoff.rb +0 -150
  18. data/lib/gcloud/bigquery/copy_job.rb +0 -97
  19. data/lib/gcloud/bigquery/credentials.rb +0 -29
  20. data/lib/gcloud/bigquery/data.rb +0 -239
  21. data/lib/gcloud/bigquery/dataset.rb +0 -753
  22. data/lib/gcloud/bigquery/dataset/access.rb +0 -507
  23. data/lib/gcloud/bigquery/dataset/list.rb +0 -169
  24. data/lib/gcloud/bigquery/extract_job.rb +0 -117
  25. data/lib/gcloud/bigquery/insert_response.rb +0 -81
  26. data/lib/gcloud/bigquery/job.rb +0 -299
  27. data/lib/gcloud/bigquery/job/list.rb +0 -172
  28. data/lib/gcloud/bigquery/load_job.rb +0 -202
  29. data/lib/gcloud/bigquery/project.rb +0 -475
  30. data/lib/gcloud/bigquery/query_data.rb +0 -234
  31. data/lib/gcloud/bigquery/query_job.rb +0 -137
  32. data/lib/gcloud/bigquery/schema.rb +0 -359
  33. data/lib/gcloud/bigquery/service.rb +0 -506
  34. data/lib/gcloud/bigquery/table.rb +0 -1141
  35. data/lib/gcloud/bigquery/table/list.rb +0 -180
  36. data/lib/gcloud/bigquery/view.rb +0 -475
  37. data/lib/gcloud/credentials.rb +0 -129
  38. data/lib/gcloud/datastore/commit.rb +0 -148
  39. data/lib/gcloud/datastore/credentials.rb +0 -35
  40. data/lib/gcloud/datastore/cursor.rb +0 -76
  41. data/lib/gcloud/datastore/dataset.rb +0 -660
  42. data/lib/gcloud/datastore/dataset/lookup_results.rb +0 -219
  43. data/lib/gcloud/datastore/dataset/query_results.rb +0 -386
  44. data/lib/gcloud/datastore/entity.rb +0 -449
  45. data/lib/gcloud/datastore/errors.rb +0 -41
  46. data/lib/gcloud/datastore/gql_query.rb +0 -211
  47. data/lib/gcloud/datastore/grpc_utils.rb +0 -132
  48. data/lib/gcloud/datastore/key.rb +0 -281
  49. data/lib/gcloud/datastore/properties.rb +0 -128
  50. data/lib/gcloud/datastore/query.rb +0 -348
  51. data/lib/gcloud/datastore/service.rb +0 -167
  52. data/lib/gcloud/datastore/transaction.rb +0 -362
  53. data/lib/gcloud/dns/change.rb +0 -158
  54. data/lib/gcloud/dns/change/list.rb +0 -173
  55. data/lib/gcloud/dns/credentials.rb +0 -29
  56. data/lib/gcloud/dns/importer.rb +0 -183
  57. data/lib/gcloud/dns/project.rb +0 -247
  58. data/lib/gcloud/dns/record.rb +0 -170
  59. data/lib/gcloud/dns/record/list.rb +0 -174
  60. data/lib/gcloud/dns/service.rb +0 -167
  61. data/lib/gcloud/dns/zone.rb +0 -759
  62. data/lib/gcloud/dns/zone/list.rb +0 -168
  63. data/lib/gcloud/dns/zone/transaction.rb +0 -176
  64. data/lib/gcloud/errors.rb +0 -206
  65. data/lib/gcloud/gce.rb +0 -56
  66. data/lib/gcloud/grpc_utils.rb +0 -87
  67. data/lib/gcloud/logging/credentials.rb +0 -29
  68. data/lib/gcloud/logging/entry.rb +0 -465
  69. data/lib/gcloud/logging/entry/http_request.rb +0 -141
  70. data/lib/gcloud/logging/entry/list.rb +0 -177
  71. data/lib/gcloud/logging/entry/operation.rb +0 -90
  72. data/lib/gcloud/logging/logger.rb +0 -307
  73. data/lib/gcloud/logging/metric.rb +0 -169
  74. data/lib/gcloud/logging/metric/list.rb +0 -172
  75. data/lib/gcloud/logging/project.rb +0 -642
  76. data/lib/gcloud/logging/resource.rb +0 -84
  77. data/lib/gcloud/logging/resource_descriptor.rb +0 -137
  78. data/lib/gcloud/logging/resource_descriptor/list.rb +0 -174
  79. data/lib/gcloud/logging/service.rb +0 -267
  80. data/lib/gcloud/logging/sink.rb +0 -227
  81. data/lib/gcloud/logging/sink/list.rb +0 -171
  82. data/lib/gcloud/pubsub/credentials.rb +0 -29
  83. data/lib/gcloud/pubsub/message.rb +0 -94
  84. data/lib/gcloud/pubsub/policy.rb +0 -204
  85. data/lib/gcloud/pubsub/project.rb +0 -482
  86. data/lib/gcloud/pubsub/received_message.rb +0 -160
  87. data/lib/gcloud/pubsub/service.rb +0 -334
  88. data/lib/gcloud/pubsub/subscription.rb +0 -565
  89. data/lib/gcloud/pubsub/subscription/list.rb +0 -208
  90. data/lib/gcloud/pubsub/topic.rb +0 -511
  91. data/lib/gcloud/pubsub/topic/list.rb +0 -174
  92. data/lib/gcloud/pubsub/topic/publisher.rb +0 -85
  93. data/lib/gcloud/resource_manager/credentials.rb +0 -30
  94. data/lib/gcloud/resource_manager/manager.rb +0 -266
  95. data/lib/gcloud/resource_manager/policy.rb +0 -211
  96. data/lib/gcloud/resource_manager/project.rb +0 -484
  97. data/lib/gcloud/resource_manager/project/list.rb +0 -167
  98. data/lib/gcloud/resource_manager/project/updater.rb +0 -130
  99. data/lib/gcloud/resource_manager/service.rb +0 -127
  100. data/lib/gcloud/storage/bucket.rb +0 -775
  101. data/lib/gcloud/storage/bucket/acl.rb +0 -810
  102. data/lib/gcloud/storage/bucket/cors.rb +0 -153
  103. data/lib/gcloud/storage/bucket/list.rb +0 -172
  104. data/lib/gcloud/storage/credentials.rb +0 -29
  105. data/lib/gcloud/storage/errors.rb +0 -65
  106. data/lib/gcloud/storage/file.rb +0 -842
  107. data/lib/gcloud/storage/file/acl.rb +0 -425
  108. data/lib/gcloud/storage/file/list.rb +0 -191
  109. data/lib/gcloud/storage/file/verifier.rb +0 -67
  110. data/lib/gcloud/storage/project.rb +0 -316
  111. data/lib/gcloud/storage/service.rb +0 -347
  112. data/lib/gcloud/translate/api.rb +0 -241
  113. data/lib/gcloud/translate/detection.rb +0 -137
  114. data/lib/gcloud/translate/language.rb +0 -69
  115. data/lib/gcloud/translate/service.rb +0 -80
  116. data/lib/gcloud/translate/translation.rb +0 -112
  117. data/lib/gcloud/vision/annotate.rb +0 -224
  118. data/lib/gcloud/vision/annotation.rb +0 -455
  119. data/lib/gcloud/vision/annotation/entity.rb +0 -234
  120. data/lib/gcloud/vision/annotation/face.rb +0 -1750
  121. data/lib/gcloud/vision/annotation/properties.rb +0 -245
  122. data/lib/gcloud/vision/annotation/safe_search.rb +0 -161
  123. data/lib/gcloud/vision/annotation/text.rb +0 -236
  124. data/lib/gcloud/vision/annotation/vertex.rb +0 -108
  125. data/lib/gcloud/vision/credentials.rb +0 -29
  126. data/lib/gcloud/vision/image.rb +0 -590
  127. data/lib/gcloud/vision/location.rb +0 -115
  128. data/lib/gcloud/vision/project.rb +0 -278
  129. data/lib/gcloud/vision/service.rb +0 -66
  130. data/lib/google/api/annotations.rb +0 -14
  131. data/lib/google/api/http.rb +0 -30
  132. data/lib/google/api/label.rb +0 -24
  133. data/lib/google/api/monitored_resource.rb +0 -25
  134. data/lib/google/datastore/v1beta3/datastore.rb +0 -115
  135. data/lib/google/datastore/v1beta3/datastore_services.rb +0 -33
  136. data/lib/google/datastore/v1beta3/entity.rb +0 -63
  137. data/lib/google/datastore/v1beta3/query.rb +0 -128
  138. data/lib/google/devtools/cloudtrace/v1/trace.rb +0 -78
  139. data/lib/google/devtools/cloudtrace/v1/trace_services.rb +0 -32
  140. data/lib/google/example/library/v1/library.rb +0 -91
  141. data/lib/google/example/library/v1/library_services.rb +0 -40
  142. data/lib/google/iam/v1/iam_policy.rb +0 -33
  143. data/lib/google/iam/v1/iam_policy_services.rb +0 -30
  144. data/lib/google/iam/v1/policy.rb +0 -25
  145. data/lib/google/logging/type/http_request.rb +0 -28
  146. data/lib/google/logging/type/log_severity.rb +0 -27
  147. data/lib/google/logging/v2/log_entry.rb +0 -44
  148. data/lib/google/logging/v2/logging.rb +0 -56
  149. data/lib/google/logging/v2/logging_config.rb +0 -59
  150. data/lib/google/logging/v2/logging_config_services.rb +0 -32
  151. data/lib/google/logging/v2/logging_metrics.rb +0 -51
  152. data/lib/google/logging/v2/logging_metrics_services.rb +0 -32
  153. data/lib/google/logging/v2/logging_services.rb +0 -31
  154. data/lib/google/longrunning/operations.rb +0 -50
  155. data/lib/google/longrunning/operations_services.rb +0 -29
  156. data/lib/google/protobuf/descriptor.rb +0 -0
  157. data/lib/google/pubsub/v1/pubsub.rb +0 -129
  158. data/lib/google/pubsub/v1/pubsub_services.rb +0 -56
  159. data/lib/google/pubsub/v1beta2/pubsub.rb +0 -126
  160. data/lib/google/pubsub/v1beta2/pubsub_services.rb +0 -56
  161. data/lib/google/rpc/code.rb +0 -32
  162. data/lib/google/rpc/error_details.rb +0 -61
  163. data/lib/google/rpc/status.rb +0 -19
  164. data/lib/google/type/color.rb +0 -20
  165. data/lib/google/type/date.rb +0 -18
  166. data/lib/google/type/dayofweek.rb +0 -23
  167. data/lib/google/type/latlng.rb +0 -17
  168. data/lib/google/type/money.rb +0 -18
  169. data/lib/google/type/timeofday.rb +0 -19
@@ -1,565 +0,0 @@
1
- # Copyright 2015 Google Inc. All rights reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
-
16
- require "gcloud/errors"
17
- require "gcloud/pubsub/subscription/list"
18
- require "gcloud/pubsub/received_message"
19
-
20
- module Gcloud
21
- module Pubsub
22
- ##
23
- # # Subscription
24
- #
25
- # A named resource representing the stream of messages from a single,
26
- # specific {Topic}, to be delivered to the subscribing application.
27
- #
28
- # @example
29
- # require "gcloud"
30
- #
31
- # gcloud = Gcloud.new
32
- # pubsub = gcloud.pubsub
33
- #
34
- # sub = pubsub.subscription "my-topic-sub"
35
- # msgs = sub.pull
36
- # msgs.each { |msg| msg.acknowledge! }
37
- #
38
- class Subscription
39
- ##
40
- # @private The gRPC Service object.
41
- attr_accessor :service
42
-
43
- ##
44
- # @private The gRPC Google::Pubsub::V1::Subscription object.
45
- attr_accessor :grpc
46
-
47
- ##
48
- # @private Create an empty {Subscription} object.
49
- def initialize
50
- @service = nil
51
- @grpc = Google::Pubsub::V1::Subscription.new
52
- @name = nil
53
- @exists = nil
54
- end
55
-
56
- ##
57
- # @private New lazy {Topic} object without making an HTTP request.
58
- def self.new_lazy name, service, options = {}
59
- new.tap do |s|
60
- s.grpc = nil
61
- s.service = service
62
- s.instance_variable_set "@name",
63
- service.subscription_path(name, options)
64
- end
65
- end
66
-
67
- ##
68
- # The name of the subscription.
69
- def name
70
- @grpc ? @grpc.name : @name
71
- end
72
-
73
- ##
74
- # The {Topic} from which this subscription receives messages.
75
- #
76
- # @return [Topic]
77
- #
78
- # @example
79
- # require "gcloud"
80
- #
81
- # gcloud = Gcloud.new
82
- # pubsub = gcloud.pubsub
83
- #
84
- # sub = pubsub.subscription "my-topic-sub"
85
- # sub.topic.name #=> "projects/my-project/topics/my-topic"
86
- #
87
- def topic
88
- ensure_grpc!
89
- Topic.new_lazy @grpc.topic, service
90
- end
91
-
92
- ##
93
- # This value is the maximum number of seconds after a subscriber receives
94
- # a message before the subscriber should acknowledge the message.
95
- def deadline
96
- ensure_grpc!
97
- @grpc.ack_deadline_seconds
98
- end
99
-
100
- ##
101
- # Returns the URL locating the endpoint to which messages should be
102
- # pushed.
103
- def endpoint
104
- ensure_grpc!
105
- @grpc.push_config.push_endpoint if @grpc.push_config
106
- end
107
-
108
- ##
109
- # Sets the URL locating the endpoint to which messages should be pushed.
110
- def endpoint= new_endpoint
111
- ensure_service!
112
- service.modify_push_config name, new_endpoint, {}
113
- @grpc.push_config = Google::Pubsub::V1::PushConfig.new(
114
- push_endpoint: new_endpoint,
115
- attributes: {}
116
- ) if @grpc
117
- end
118
-
119
- ##
120
- # Determines whether the subscription exists in the Pub/Sub service.
121
- #
122
- # @example
123
- # require "gcloud"
124
- #
125
- # gcloud = Gcloud.new
126
- # pubsub = gcloud.pubsub
127
- #
128
- # sub = pubsub.subscription "my-topic-sub"
129
- # sub.exists? #=> true
130
- #
131
- def exists?
132
- # Always true if we have a grpc object
133
- return true unless @grpc.nil?
134
- # If we have a value, return it
135
- return @exists unless @exists.nil?
136
- ensure_grpc!
137
- @exists = !@grpc.nil?
138
- rescue Gcloud::NotFoundError
139
- @exists = false
140
- end
141
-
142
- ##
143
- # @private
144
- # Determines whether the subscription object was created with an
145
- # HTTP call.
146
- #
147
- # @example
148
- # require "gcloud"
149
- #
150
- # gcloud = Gcloud.new
151
- # pubsub = gcloud.pubsub
152
- #
153
- # sub = pubsub.get_subscription "my-topic-sub"
154
- # sub.lazy? #=> false
155
- #
156
- def lazy?
157
- @grpc.nil?
158
- end
159
-
160
- ##
161
- # Deletes an existing subscription.
162
- # All pending messages in the subscription are immediately dropped.
163
- #
164
- # @return [Boolean] Returns `true` if the subscription was deleted.
165
- #
166
- # @example
167
- # require "gcloud"
168
- #
169
- # gcloud = Gcloud.new
170
- # pubsub = gcloud.pubsub
171
- #
172
- # sub = pubsub.subscription "my-topic-sub"
173
- # sub.delete
174
- #
175
- def delete
176
- ensure_service!
177
- service.delete_subscription name
178
- true
179
- end
180
-
181
- ##
182
- # Pulls messages from the server. Returns an empty list if there are no
183
- # messages available in the backlog. Raises an ApiError with status
184
- # `UNAVAILABLE` if there are too many concurrent pull requests pending
185
- # for the given subscription.
186
- #
187
- # @param [Boolean] immediate When `true` the system will respond
188
- # immediately even if it is not able to return messages. When `false`
189
- # the system is allowed to wait until it can return least one message.
190
- # No messages are returned when a request times out. The default value
191
- # is `true`.
192
- # @param [Integer] max The maximum number of messages to return for this
193
- # request. The Pub/Sub system may return fewer than the number
194
- # specified. The default value is `100`, the maximum value is `1000`.
195
- # @param [Boolean] autoack Automatically acknowledge the message as it is
196
- # pulled. The default value is `false`.
197
- #
198
- # @return [Array<Gcloud::Pubsub::ReceivedMessage>]
199
- #
200
- # @example
201
- # require "gcloud"
202
- #
203
- # gcloud = Gcloud.new
204
- # pubsub = gcloud.pubsub
205
- #
206
- # sub = pubsub.subscription "my-topic-sub"
207
- # sub.pull.each { |msg| msg.acknowledge! }
208
- #
209
- # @example A maximum number of messages returned can also be specified:
210
- # require "gcloud"
211
- #
212
- # gcloud = Gcloud.new
213
- # pubsub = gcloud.pubsub
214
- #
215
- # sub = pubsub.subscription "my-topic-sub", max: 10
216
- # sub.pull.each { |msg| msg.acknowledge! }
217
- #
218
- # @example The call can block until messages are available:
219
- # require "gcloud"
220
- #
221
- # gcloud = Gcloud.new
222
- # pubsub = gcloud.pubsub
223
- #
224
- # sub = pubsub.subscription "my-topic-sub"
225
- # msgs = sub.pull immediate: false
226
- # msgs.each { |msg| msg.acknowledge! }
227
- #
228
- def pull immediate: true, max: 100, autoack: false
229
- ensure_service!
230
- options = { immediate: immediate, max: max }
231
- list_grpc = service.pull name, options
232
- messages = Array(list_grpc.received_messages).map do |msg_grpc|
233
- ReceivedMessage.from_grpc msg_grpc, self
234
- end
235
- acknowledge messages if autoack
236
- messages
237
- rescue Gcloud::DeadlineExceededError
238
- []
239
- end
240
-
241
- ##
242
- # Pulls from the server while waiting for messages to become available.
243
- # This is the same as:
244
- #
245
- # subscription.pull immediate: false
246
- #
247
- # @param [Integer] max The maximum number of messages to return for this
248
- # request. The Pub/Sub system may return fewer than the number
249
- # specified. The default value is `100`, the maximum value is `1000`.
250
- # @param [Boolean] autoack Automatically acknowledge the message as it is
251
- # pulled. The default value is `false`.
252
- #
253
- # @return [Array<Gcloud::Pubsub::ReceivedMessage>]
254
- #
255
- # @example
256
- # require "gcloud"
257
- #
258
- # gcloud = Gcloud.new
259
- # pubsub = gcloud.pubsub
260
- #
261
- # sub = pubsub.subscription "my-topic-sub"
262
- # msgs = sub.wait_for_messages
263
- # msgs.each { |msg| msg.acknowledge! }
264
- #
265
- def wait_for_messages max: 100, autoack: false
266
- pull immediate: false, max: max, autoack: autoack
267
- end
268
-
269
- ##
270
- # Poll the backend for new messages. This runs a loop to ping the API,
271
- # blocking indefinitely, yielding retrieved messages as they are received.
272
- #
273
- # @param [Integer] max The maximum number of messages to return for this
274
- # request. The Pub/Sub system may return fewer than the number
275
- # specified. The default value is `100`, the maximum value is `1000`.
276
- # @param [Boolean] autoack Automatically acknowledge the message as it is
277
- # pulled. The default value is `false`.
278
- # @param [Number] delay The number of seconds to pause between requests
279
- # when the Google Cloud service has no messages to return. The default
280
- # value is `1`.
281
- # @yield [msg] a block for processing new messages
282
- # @yieldparam [ReceivedMessage] msg the newly received message
283
- #
284
- # @example
285
- # require "gcloud"
286
- #
287
- # gcloud = Gcloud.new
288
- # pubsub = gcloud.pubsub
289
- #
290
- # sub = pubsub.subscription "my-topic-sub"
291
- # sub.listen do |msg|
292
- # # process msg
293
- # end
294
- #
295
- # @example Limit the number of messages pulled per API request with `max`:
296
- # require "gcloud"
297
- #
298
- # gcloud = Gcloud.new
299
- # pubsub = gcloud.pubsub
300
- #
301
- # sub = pubsub.subscription "my-topic-sub"
302
- # sub.listen max: 20 do |msg|
303
- # # process msg
304
- # end
305
- #
306
- # @example Automatically acknowledge messages with `autoack`:
307
- # require "gcloud"
308
- #
309
- # gcloud = Gcloud.new
310
- # pubsub = gcloud.pubsub
311
- #
312
- # sub = pubsub.subscription "my-topic-sub"
313
- # sub.listen autoack: true do |msg|
314
- # # process msg
315
- # end
316
- #
317
- def listen max: 100, autoack: false, delay: 1
318
- loop do
319
- msgs = wait_for_messages max: max, autoack: autoack
320
- if msgs.any?
321
- msgs.each { |msg| yield msg }
322
- else
323
- sleep delay
324
- end
325
- end
326
- end
327
-
328
- ##
329
- # Acknowledges receipt of a message. After an ack,
330
- # the Pub/Sub system can remove the message from the subscription.
331
- # Acknowledging a message whose ack deadline has expired may succeed,
332
- # although the message may have been sent again.
333
- # Acknowledging a message more than once will not result in an error.
334
- # This is only used for messages received via pull.
335
- #
336
- # @param [ReceivedMessage, String] messages One or more {ReceivedMessage}
337
- # objects or ack_id values.
338
- #
339
- # @example
340
- # require "gcloud"
341
- #
342
- # gcloud = Gcloud.new
343
- # pubsub = gcloud.pubsub
344
- #
345
- # sub = pubsub.subscription "my-topic-sub"
346
- # messages = sub.pull
347
- # sub.acknowledge messages
348
- #
349
- def acknowledge *messages
350
- ack_ids = coerce_ack_ids messages
351
- return true if ack_ids.empty?
352
- ensure_service!
353
- service.acknowledge name, *ack_ids
354
- true
355
- end
356
- alias_method :ack, :acknowledge
357
-
358
- ##
359
- # Modifies the acknowledge deadline for messages.
360
- #
361
- # This indicates that more time is needed to process the messages, or to
362
- # make the messages available for redelivery if the processing was
363
- # interrupted.
364
- #
365
- # @param [Integer] new_deadline The new ack deadline in seconds from the
366
- # time this request is sent to the Pub/Sub system. Must be >= 0. For
367
- # example, if the value is `10`, the new ack deadline will expire 10
368
- # seconds after the call is made. Specifying `0` may immediately make
369
- # the message available for another pull request.
370
- # @param [ReceivedMessage, String] messages One or more {ReceivedMessage}
371
- # objects or ack_id values.
372
- #
373
- # @example
374
- # require "gcloud"
375
- #
376
- # gcloud = Gcloud.new
377
- # pubsub = gcloud.pubsub
378
- #
379
- # sub = pubsub.subscription "my-topic-sub"
380
- # messages = sub.pull
381
- # sub.delay 120, messages
382
- #
383
- def delay new_deadline, *messages
384
- ack_ids = coerce_ack_ids messages
385
- ensure_service!
386
- service.modify_ack_deadline name, ack_ids, new_deadline
387
- true
388
- end
389
-
390
- ##
391
- # Gets the [Cloud IAM](https://cloud.google.com/iam/) access control
392
- # policy for this subscription.
393
- #
394
- # @see https://cloud.google.com/pubsub/reference/rpc/google.iam.v1#iampolicy
395
- # google.iam.v1.IAMPolicy
396
- #
397
- # @param [Boolean] force Force the latest policy to be retrieved from the
398
- # Pub/Sub service when `true`. Otherwise the policy will be memoized to
399
- # reduce the number of API calls made to the Pub/Sub service. The
400
- # default is `false`.
401
- #
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
407
- #
408
- # @return [Policy] the current Cloud IAM Policy for this subscription
409
- #
410
- # @example Policy values are memoized to reduce the number of API calls:
411
- # require "gcloud"
412
- #
413
- # gcloud = Gcloud.new
414
- # pubsub = gcloud.pubsub
415
- # sub = pubsub.subscription "my-subscription"
416
- #
417
- # policy = sub.policy # API call
418
- # policy_2 = sub.policy # No API call
419
- #
420
- # @example Use `force` to retrieve the latest policy from the service:
421
- # require "gcloud"
422
- #
423
- # gcloud = Gcloud.new
424
- # pubsub = gcloud.pubsub
425
- # sub = pubsub.subscription "my-subscription"
426
- #
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
440
- #
441
- def policy force: nil
442
- @policy = nil if force || block_given?
443
- @policy ||= begin
444
- ensure_service!
445
- grpc = service.get_subscription_policy name
446
- Policy.from_grpc grpc
447
- end
448
- return @policy unless block_given?
449
- p = @policy.deep_dup
450
- yield p
451
- self.policy = p
452
- end
453
-
454
- ##
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.
462
- #
463
- # @see https://cloud.google.com/pubsub/reference/rpc/google.iam.v1#iampolicy
464
- # google.iam.v1.IAMPolicy
465
- #
466
- # @param [Policy] new_policy a new or modified Cloud IAM Policy for this
467
- # subscription
468
- #
469
- # @example
470
- # require "gcloud"
471
- #
472
- # gcloud = Gcloud.new
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"
479
- #
480
- # sub.policy = policy # API call
481
- #
482
- def policy= new_policy
483
- ensure_service!
484
- grpc = service.set_subscription_policy name, new_policy.to_grpc
485
- @policy = Policy.from_grpc grpc
486
- end
487
-
488
- ##
489
- # Tests the specified permissions against the [Cloud
490
- # IAM](https://cloud.google.com/iam/) access control policy.
491
- #
492
- # @see https://cloud.google.com/iam/docs/managing-policies Managing
493
- # Policies
494
- #
495
- # @param [String, Array<String>] permissions The set of permissions to
496
- # check access for. Permissions with wildcards (such as `*` or
497
- # `storage.*`) are not allowed.
498
- #
499
- # The permissions that can be checked on a subscription are:
500
- #
501
- # * pubsub.subscriptions.consume
502
- # * pubsub.subscriptions.get
503
- # * pubsub.subscriptions.delete
504
- # * pubsub.subscriptions.update
505
- # * pubsub.subscriptions.getIamPolicy
506
- # * pubsub.subscriptions.setIamPolicy
507
- #
508
- # @return [Array<String>] The permissions that have access.
509
- #
510
- # @example
511
- # require "gcloud"
512
- #
513
- # gcloud = Gcloud.new
514
- # pubsub = gcloud.pubsub
515
- # sub = pubsub.subscription "my-subscription"
516
- # perms = sub.test_permissions "pubsub.subscriptions.get",
517
- # "pubsub.subscriptions.consume"
518
- # perms.include? "pubsub.subscriptions.get" #=> true
519
- # perms.include? "pubsub.subscriptions.consume" #=> false
520
- #
521
- def test_permissions *permissions
522
- permissions = Array(permissions).flatten
523
- ensure_service!
524
- grpc = service.test_subscription_permissions name, permissions
525
- grpc.permissions
526
- end
527
-
528
- ##
529
- # @private New Subscription from a Google::Pubsub::V1::Subscription
530
- # object.
531
- def self.from_grpc grpc, service
532
- new.tap do |f|
533
- f.grpc = grpc
534
- f.service = service
535
- end
536
- end
537
-
538
- protected
539
-
540
- ##
541
- # @private Raise an error unless an active connection to the service is
542
- # available.
543
- def ensure_service!
544
- fail "Must have active connection to service" unless service
545
- end
546
-
547
- ##
548
- # Ensures a Google::Pubsub::V1::Subscription object exists.
549
- def ensure_grpc!
550
- ensure_service!
551
- return @grpc if @grpc
552
- @grpc = service.get_subscription @name
553
- end
554
-
555
- ##
556
- # Makes sure the values are the `ack_id`.
557
- # If given several {ReceivedMessage} objects extract the `ack_id` values.
558
- def coerce_ack_ids messages
559
- Array(messages).flatten.map do |msg|
560
- msg.respond_to?(:ack_id) ? msg.ack_id : msg.to_s
561
- end
562
- end
563
- end
564
- end
565
- end