google-cloud-pubsub 1.1.3 → 2.0.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 (38) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHENTICATION.md +2 -1
  3. data/CHANGELOG.md +145 -0
  4. data/EMULATOR.md +1 -1
  5. data/TROUBLESHOOTING.md +2 -8
  6. data/lib/google/cloud/pubsub/async_publisher.rb +16 -21
  7. data/lib/google/cloud/pubsub/credentials.rb +2 -2
  8. data/lib/google/cloud/pubsub/project.rb +18 -26
  9. data/lib/google/cloud/pubsub/received_message.rb +38 -0
  10. data/lib/google/cloud/pubsub/retry_policy.rb +90 -0
  11. data/lib/google/cloud/pubsub/service.rb +125 -252
  12. data/lib/google/cloud/pubsub/subscriber/inventory.rb +43 -15
  13. data/lib/google/cloud/pubsub/subscriber/stream.rb +8 -10
  14. data/lib/google/cloud/pubsub/subscriber.rb +86 -15
  15. data/lib/google/cloud/pubsub/subscription/push_config.rb +2 -2
  16. data/lib/google/cloud/pubsub/subscription.rb +297 -7
  17. data/lib/google/cloud/pubsub/topic.rb +65 -2
  18. data/lib/google/cloud/pubsub/version.rb +1 -1
  19. data/lib/google/cloud/pubsub.rb +15 -18
  20. data/lib/google-cloud-pubsub.rb +13 -13
  21. metadata +11 -81
  22. data/lib/google/cloud/pubsub/v1/credentials.rb +0 -41
  23. data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/iam_policy.rb +0 -21
  24. data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/options.rb +0 -21
  25. data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/policy.rb +0 -21
  26. data/lib/google/cloud/pubsub/v1/doc/google/protobuf/duration.rb +0 -91
  27. data/lib/google/cloud/pubsub/v1/doc/google/protobuf/empty.rb +0 -29
  28. data/lib/google/cloud/pubsub/v1/doc/google/protobuf/field_mask.rb +0 -222
  29. data/lib/google/cloud/pubsub/v1/doc/google/protobuf/timestamp.rb +0 -113
  30. data/lib/google/cloud/pubsub/v1/doc/google/pubsub/v1/pubsub.rb +0 -744
  31. data/lib/google/cloud/pubsub/v1/doc/google/type/expr.rb +0 -19
  32. data/lib/google/cloud/pubsub/v1/publisher_client.rb +0 -786
  33. data/lib/google/cloud/pubsub/v1/publisher_client_config.json +0 -105
  34. data/lib/google/cloud/pubsub/v1/subscriber_client.rb +0 -1385
  35. data/lib/google/cloud/pubsub/v1/subscriber_client_config.json +0 -144
  36. data/lib/google/cloud/pubsub/v1.rb +0 -17
  37. data/lib/google/pubsub/v1/pubsub_pb.rb +0 -249
  38. data/lib/google/pubsub/v1/pubsub_services_pb.rb +0 -211
@@ -1,786 +0,0 @@
1
- # Copyright 2019 Google LLC
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
- # https://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
- # EDITING INSTRUCTIONS
16
- # This file was generated from the file
17
- # https://github.com/googleapis/googleapis/blob/master/google/pubsub/v1/pubsub.proto,
18
- # and updates to that file get reflected here through a refresh process.
19
- # For the short term, the refresh process will only be runnable by Google
20
- # engineers.
21
-
22
-
23
- require "json"
24
- require "pathname"
25
-
26
- require "google/gax"
27
-
28
- require "google/iam/v1/iam_policy_pb"
29
- require "google/pubsub/v1/pubsub_pb"
30
- require "google/cloud/pubsub/v1/credentials"
31
- require "google/cloud/pubsub/version"
32
-
33
- module Google
34
- module Cloud
35
- module PubSub
36
- module V1
37
- # The service that an application uses to manipulate topics, and to send
38
- # messages to a topic.
39
- #
40
- # @!attribute [r] iam_policy_stub
41
- # @return [Google::Iam::V1::IAMPolicy::Stub]
42
- # @!attribute [r] publisher_stub
43
- # @return [Google::Cloud::PubSub::V1::Publisher::Stub]
44
- class PublisherClient
45
- # @private
46
- attr_reader :iam_policy_stub, :publisher_stub
47
-
48
- # The default address of the service.
49
- SERVICE_ADDRESS = "pubsub.googleapis.com".freeze
50
-
51
- # The default port of the service.
52
- DEFAULT_SERVICE_PORT = 443
53
-
54
- # The default set of gRPC interceptors.
55
- GRPC_INTERCEPTORS = []
56
-
57
- DEFAULT_TIMEOUT = 30
58
-
59
- PAGE_DESCRIPTORS = {
60
- "list_topics" => Google::Gax::PageDescriptor.new(
61
- "page_token",
62
- "next_page_token",
63
- "topics"),
64
- "list_topic_subscriptions" => Google::Gax::PageDescriptor.new(
65
- "page_token",
66
- "next_page_token",
67
- "subscriptions")
68
- }.freeze
69
-
70
- private_constant :PAGE_DESCRIPTORS
71
-
72
- BUNDLE_DESCRIPTORS = {
73
- "publish" => Google::Gax::BundleDescriptor.new(
74
- "messages",
75
- [
76
- "topic"
77
- ],
78
- subresponse_field: "message_ids")
79
- }.freeze
80
-
81
- private_constant :BUNDLE_DESCRIPTORS
82
-
83
- # The scopes needed to make gRPC calls to all of the methods defined in
84
- # this service.
85
- ALL_SCOPES = [
86
- "https://www.googleapis.com/auth/cloud-platform",
87
- "https://www.googleapis.com/auth/pubsub"
88
- ].freeze
89
-
90
-
91
- PROJECT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
92
- "projects/{project}"
93
- )
94
-
95
- private_constant :PROJECT_PATH_TEMPLATE
96
-
97
- TOPIC_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
98
- "projects/{project}/topics/{topic}"
99
- )
100
-
101
- private_constant :TOPIC_PATH_TEMPLATE
102
-
103
- # Returns a fully-qualified project resource name string.
104
- # @param project [String]
105
- # @return [String]
106
- def self.project_path project
107
- PROJECT_PATH_TEMPLATE.render(
108
- :"project" => project
109
- )
110
- end
111
-
112
- # Returns a fully-qualified topic resource name string.
113
- # @param project [String]
114
- # @param topic [String]
115
- # @return [String]
116
- def self.topic_path project, topic
117
- TOPIC_PATH_TEMPLATE.render(
118
- :"project" => project,
119
- :"topic" => topic
120
- )
121
- end
122
-
123
- # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
124
- # Provides the means for authenticating requests made by the client. This parameter can
125
- # be many types.
126
- # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
127
- # authenticating requests made by this client.
128
- # A `String` will be treated as the path to the keyfile to be used for the construction of
129
- # credentials for this client.
130
- # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
131
- # credentials for this client.
132
- # A `GRPC::Core::Channel` will be used to make calls through.
133
- # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
134
- # should already be composed with a `GRPC::Core::CallCredentials` object.
135
- # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
136
- # metadata for requests, generally, to give OAuth credentials.
137
- # @param scopes [Array<String>]
138
- # The OAuth scopes for this service. This parameter is ignored if
139
- # an updater_proc is supplied.
140
- # @param client_config [Hash]
141
- # A Hash for call options for each method. See
142
- # Google::Gax#construct_settings for the structure of
143
- # this data. Falls back to the default config if not specified
144
- # or the specified config is missing data points.
145
- # @param timeout [Numeric]
146
- # The default timeout, in seconds, for calls made through this client.
147
- # @param metadata [Hash]
148
- # Default metadata to be sent with each request. This can be overridden on a per call basis.
149
- # @param service_address [String]
150
- # Override for the service hostname, or `nil` to leave as the default.
151
- # @param service_port [Integer]
152
- # Override for the service port, or `nil` to leave as the default.
153
- # @param exception_transformer [Proc]
154
- # An optional proc that intercepts any exceptions raised during an API call to inject
155
- # custom error handling.
156
- def initialize \
157
- credentials: nil,
158
- scopes: ALL_SCOPES,
159
- client_config: {},
160
- timeout: DEFAULT_TIMEOUT,
161
- metadata: nil,
162
- service_address: nil,
163
- service_port: nil,
164
- exception_transformer: nil,
165
- lib_name: nil,
166
- lib_version: ""
167
- # These require statements are intentionally placed here to initialize
168
- # the gRPC module only when it's required.
169
- # See https://github.com/googleapis/toolkit/issues/446
170
- require "google/gax/grpc"
171
- require "google/iam/v1/iam_policy_services_pb"
172
- require "google/pubsub/v1/pubsub_services_pb"
173
-
174
- credentials ||= Google::Cloud::PubSub::V1::Credentials.default
175
-
176
- if credentials.is_a?(String) || credentials.is_a?(Hash)
177
- updater_proc = Google::Cloud::PubSub::V1::Credentials.new(credentials).updater_proc
178
- end
179
- if credentials.is_a?(GRPC::Core::Channel)
180
- channel = credentials
181
- end
182
- if credentials.is_a?(GRPC::Core::ChannelCredentials)
183
- chan_creds = credentials
184
- end
185
- if credentials.is_a?(Proc)
186
- updater_proc = credentials
187
- end
188
- if credentials.is_a?(Google::Auth::Credentials)
189
- updater_proc = credentials.updater_proc
190
- end
191
-
192
- package_version = Google::Cloud::PubSub::VERSION
193
-
194
- google_api_client = "gl-ruby/#{RUBY_VERSION}"
195
- google_api_client << " #{lib_name}/#{lib_version}" if lib_name
196
- google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
197
- google_api_client << " grpc/#{GRPC::VERSION}"
198
- google_api_client.freeze
199
-
200
- headers = { :"x-goog-api-client" => google_api_client }
201
- headers.merge!(metadata) unless metadata.nil?
202
- client_config_file = Pathname.new(__dir__).join(
203
- "publisher_client_config.json"
204
- )
205
- defaults = client_config_file.open do |f|
206
- Google::Gax.construct_settings(
207
- "google.pubsub.v1.Publisher",
208
- JSON.parse(f.read),
209
- client_config,
210
- Google::Gax::Grpc::STATUS_CODE_NAMES,
211
- timeout,
212
- bundle_descriptors: BUNDLE_DESCRIPTORS,
213
- page_descriptors: PAGE_DESCRIPTORS,
214
- errors: Google::Gax::Grpc::API_ERRORS,
215
- metadata: headers
216
- )
217
- end
218
-
219
- # Allow overriding the service path/port in subclasses.
220
- service_path = service_address || self.class::SERVICE_ADDRESS
221
- port = service_port || self.class::DEFAULT_SERVICE_PORT
222
- interceptors = self.class::GRPC_INTERCEPTORS
223
- @iam_policy_stub = Google::Gax::Grpc.create_stub(
224
- service_path,
225
- port,
226
- chan_creds: chan_creds,
227
- channel: channel,
228
- updater_proc: updater_proc,
229
- scopes: scopes,
230
- interceptors: interceptors,
231
- &Google::Iam::V1::IAMPolicy::Stub.method(:new)
232
- )
233
- @publisher_stub = Google::Gax::Grpc.create_stub(
234
- service_path,
235
- port,
236
- chan_creds: chan_creds,
237
- channel: channel,
238
- updater_proc: updater_proc,
239
- scopes: scopes,
240
- interceptors: interceptors,
241
- &Google::Cloud::PubSub::V1::Publisher::Stub.method(:new)
242
- )
243
-
244
- @create_topic = Google::Gax.create_api_call(
245
- @publisher_stub.method(:create_topic),
246
- defaults["create_topic"],
247
- exception_transformer: exception_transformer,
248
- params_extractor: proc do |request|
249
- {'name' => request.name}
250
- end
251
- )
252
- @update_topic = Google::Gax.create_api_call(
253
- @publisher_stub.method(:update_topic),
254
- defaults["update_topic"],
255
- exception_transformer: exception_transformer,
256
- params_extractor: proc do |request|
257
- {'topic.name' => request.topic.name}
258
- end
259
- )
260
- @publish = Google::Gax.create_api_call(
261
- @publisher_stub.method(:publish),
262
- defaults["publish"],
263
- exception_transformer: exception_transformer,
264
- params_extractor: proc do |request|
265
- {'topic' => request.topic}
266
- end
267
- )
268
- @get_topic = Google::Gax.create_api_call(
269
- @publisher_stub.method(:get_topic),
270
- defaults["get_topic"],
271
- exception_transformer: exception_transformer,
272
- params_extractor: proc do |request|
273
- {'topic' => request.topic}
274
- end
275
- )
276
- @list_topics = Google::Gax.create_api_call(
277
- @publisher_stub.method(:list_topics),
278
- defaults["list_topics"],
279
- exception_transformer: exception_transformer,
280
- params_extractor: proc do |request|
281
- {'project' => request.project}
282
- end
283
- )
284
- @list_topic_subscriptions = Google::Gax.create_api_call(
285
- @publisher_stub.method(:list_topic_subscriptions),
286
- defaults["list_topic_subscriptions"],
287
- exception_transformer: exception_transformer,
288
- params_extractor: proc do |request|
289
- {'topic' => request.topic}
290
- end
291
- )
292
- @delete_topic = Google::Gax.create_api_call(
293
- @publisher_stub.method(:delete_topic),
294
- defaults["delete_topic"],
295
- exception_transformer: exception_transformer,
296
- params_extractor: proc do |request|
297
- {'topic' => request.topic}
298
- end
299
- )
300
- @set_iam_policy = Google::Gax.create_api_call(
301
- @iam_policy_stub.method(:set_iam_policy),
302
- defaults["set_iam_policy"],
303
- exception_transformer: exception_transformer,
304
- params_extractor: proc do |request|
305
- {'resource' => request.resource}
306
- end
307
- )
308
- @get_iam_policy = Google::Gax.create_api_call(
309
- @iam_policy_stub.method(:get_iam_policy),
310
- defaults["get_iam_policy"],
311
- exception_transformer: exception_transformer,
312
- params_extractor: proc do |request|
313
- {'resource' => request.resource}
314
- end
315
- )
316
- @test_iam_permissions = Google::Gax.create_api_call(
317
- @iam_policy_stub.method(:test_iam_permissions),
318
- defaults["test_iam_permissions"],
319
- exception_transformer: exception_transformer,
320
- params_extractor: proc do |request|
321
- {'resource' => request.resource}
322
- end
323
- )
324
- end
325
-
326
- # Service calls
327
-
328
- # Creates the given topic with the given name. See the
329
- # <a href="https://cloud.google.com/pubsub/docs/admin#resource_names">
330
- # resource name rules</a>.
331
- #
332
- # @param name [String]
333
- # The name of the topic. It must have the format
334
- # `"projects/{project}/topics/{topic}"`. `{topic}` must start with a letter,
335
- # and contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`),
336
- # underscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent
337
- # signs (`%`). It must be between 3 and 255 characters in length, and it
338
- # must not start with `"goog"`.
339
- # @param labels [Hash{String => String}]
340
- # See <a href="https://cloud.google.com/pubsub/docs/labels"> Creating and
341
- # managing labels</a>.
342
- # @param message_storage_policy [Google::Cloud::PubSub::V1::MessageStoragePolicy | Hash]
343
- # Policy constraining the set of Google Cloud Platform regions where messages
344
- # published to the topic may be stored. If not present, then no constraints
345
- # are in effect.
346
- # A hash of the same form as `Google::Cloud::PubSub::V1::MessageStoragePolicy`
347
- # can also be provided.
348
- # @param kms_key_name [String]
349
- # The resource name of the Cloud KMS CryptoKey to be used to protect access
350
- # to messages published on this topic.
351
- #
352
- # The expected format is `projects/*/locations/*/keyRings/*/cryptoKeys/*`.
353
- # @param options [Google::Gax::CallOptions]
354
- # Overrides the default settings for this call, e.g, timeout,
355
- # retries, etc.
356
- # @yield [result, operation] Access the result along with the RPC operation
357
- # @yieldparam result [Google::Cloud::PubSub::V1::Topic]
358
- # @yieldparam operation [GRPC::ActiveCall::Operation]
359
- # @return [Google::Cloud::PubSub::V1::Topic]
360
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
361
- # @example
362
- # require "google/cloud/pubsub"
363
- #
364
- # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
365
- # formatted_name = Google::Cloud::PubSub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
366
- # response = publisher_client.create_topic(formatted_name)
367
-
368
- def create_topic \
369
- name,
370
- labels: nil,
371
- message_storage_policy: nil,
372
- kms_key_name: nil,
373
- options: nil,
374
- &block
375
- req = {
376
- name: name,
377
- labels: labels,
378
- message_storage_policy: message_storage_policy,
379
- kms_key_name: kms_key_name
380
- }.delete_if { |_, v| v.nil? }
381
- req = Google::Gax::to_proto(req, Google::Cloud::PubSub::V1::Topic)
382
- @create_topic.call(req, options, &block)
383
- end
384
-
385
- # Updates an existing topic. Note that certain properties of a
386
- # topic are not modifiable.
387
- #
388
- # @param topic [Google::Cloud::PubSub::V1::Topic | Hash]
389
- # The updated topic object.
390
- # A hash of the same form as `Google::Cloud::PubSub::V1::Topic`
391
- # can also be provided.
392
- # @param update_mask [Google::Protobuf::FieldMask | Hash]
393
- # Indicates which fields in the provided topic to update. Must be specified
394
- # and non-empty. Note that if `update_mask` contains
395
- # "message_storage_policy" then the new value will be determined based on the
396
- # policy configured at the project or organization level. The
397
- # `message_storage_policy` must not be set in the `topic` provided above.
398
- # A hash of the same form as `Google::Protobuf::FieldMask`
399
- # can also be provided.
400
- # @param options [Google::Gax::CallOptions]
401
- # Overrides the default settings for this call, e.g, timeout,
402
- # retries, etc.
403
- # @yield [result, operation] Access the result along with the RPC operation
404
- # @yieldparam result [Google::Cloud::PubSub::V1::Topic]
405
- # @yieldparam operation [GRPC::ActiveCall::Operation]
406
- # @return [Google::Cloud::PubSub::V1::Topic]
407
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
408
- # @example
409
- # require "google/cloud/pubsub"
410
- #
411
- # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
412
- #
413
- # # TODO: Initialize `topic`:
414
- # topic = {}
415
- #
416
- # # TODO: Initialize `update_mask`:
417
- # update_mask = {}
418
- # response = publisher_client.update_topic(topic, update_mask)
419
-
420
- def update_topic \
421
- topic,
422
- update_mask,
423
- options: nil,
424
- &block
425
- req = {
426
- topic: topic,
427
- update_mask: update_mask
428
- }.delete_if { |_, v| v.nil? }
429
- req = Google::Gax::to_proto(req, Google::Cloud::PubSub::V1::UpdateTopicRequest)
430
- @update_topic.call(req, options, &block)
431
- end
432
-
433
- # Adds one or more messages to the topic. Returns `NOT_FOUND` if the topic
434
- # does not exist.
435
- #
436
- # @param topic [String]
437
- # The messages in the request will be published on this topic.
438
- # Format is `projects/{project}/topics/{topic}`.
439
- # @param messages [Array<Google::Cloud::PubSub::V1::PubsubMessage | Hash>]
440
- # The messages to publish.
441
- # A hash of the same form as `Google::Cloud::PubSub::V1::PubsubMessage`
442
- # can also be provided.
443
- # @param options [Google::Gax::CallOptions]
444
- # Overrides the default settings for this call, e.g, timeout,
445
- # retries, etc.
446
- # @yield [result, operation] Access the result along with the RPC operation
447
- # @yieldparam result [Google::Cloud::PubSub::V1::PublishResponse]
448
- # @yieldparam operation [GRPC::ActiveCall::Operation]
449
- # @return [Google::Cloud::PubSub::V1::PublishResponse]
450
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
451
- # @example
452
- # require "google/cloud/pubsub"
453
- #
454
- # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
455
- # formatted_topic = Google::Cloud::PubSub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
456
- # data = ''
457
- # messages_element = { data: data }
458
- # messages = [messages_element]
459
- # response = publisher_client.publish(formatted_topic, messages)
460
-
461
- def publish \
462
- topic,
463
- messages,
464
- options: nil,
465
- &block
466
- req = {
467
- topic: topic,
468
- messages: messages
469
- }.delete_if { |_, v| v.nil? }
470
- req = Google::Gax::to_proto(req, Google::Cloud::PubSub::V1::PublishRequest)
471
- @publish.call(req, options, &block)
472
- end
473
-
474
- # Gets the configuration of a topic.
475
- #
476
- # @param topic [String]
477
- # The name of the topic to get.
478
- # Format is `projects/{project}/topics/{topic}`.
479
- # @param options [Google::Gax::CallOptions]
480
- # Overrides the default settings for this call, e.g, timeout,
481
- # retries, etc.
482
- # @yield [result, operation] Access the result along with the RPC operation
483
- # @yieldparam result [Google::Cloud::PubSub::V1::Topic]
484
- # @yieldparam operation [GRPC::ActiveCall::Operation]
485
- # @return [Google::Cloud::PubSub::V1::Topic]
486
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
487
- # @example
488
- # require "google/cloud/pubsub"
489
- #
490
- # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
491
- # formatted_topic = Google::Cloud::PubSub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
492
- # response = publisher_client.get_topic(formatted_topic)
493
-
494
- def get_topic \
495
- topic,
496
- options: nil,
497
- &block
498
- req = {
499
- topic: topic
500
- }.delete_if { |_, v| v.nil? }
501
- req = Google::Gax::to_proto(req, Google::Cloud::PubSub::V1::GetTopicRequest)
502
- @get_topic.call(req, options, &block)
503
- end
504
-
505
- # Lists matching topics.
506
- #
507
- # @param project [String]
508
- # The name of the project in which to list topics.
509
- # Format is `projects/{project-id}`.
510
- # @param page_size [Integer]
511
- # The maximum number of resources contained in the underlying API
512
- # response. If page streaming is performed per-resource, this
513
- # parameter does not affect the return value. If page streaming is
514
- # performed per-page, this determines the maximum number of
515
- # resources in a page.
516
- # @param options [Google::Gax::CallOptions]
517
- # Overrides the default settings for this call, e.g, timeout,
518
- # retries, etc.
519
- # @yield [result, operation] Access the result along with the RPC operation
520
- # @yieldparam result [Google::Gax::PagedEnumerable<Google::Cloud::PubSub::V1::Topic>]
521
- # @yieldparam operation [GRPC::ActiveCall::Operation]
522
- # @return [Google::Gax::PagedEnumerable<Google::Cloud::PubSub::V1::Topic>]
523
- # An enumerable of Google::Cloud::PubSub::V1::Topic instances.
524
- # See Google::Gax::PagedEnumerable documentation for other
525
- # operations such as per-page iteration or access to the response
526
- # object.
527
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
528
- # @example
529
- # require "google/cloud/pubsub"
530
- #
531
- # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
532
- # formatted_project = Google::Cloud::PubSub::V1::PublisherClient.project_path("[PROJECT]")
533
- #
534
- # # Iterate over all results.
535
- # publisher_client.list_topics(formatted_project).each do |element|
536
- # # Process element.
537
- # end
538
- #
539
- # # Or iterate over results one page at a time.
540
- # publisher_client.list_topics(formatted_project).each_page do |page|
541
- # # Process each page at a time.
542
- # page.each do |element|
543
- # # Process element.
544
- # end
545
- # end
546
-
547
- def list_topics \
548
- project,
549
- page_size: nil,
550
- options: nil,
551
- &block
552
- req = {
553
- project: project,
554
- page_size: page_size
555
- }.delete_if { |_, v| v.nil? }
556
- req = Google::Gax::to_proto(req, Google::Cloud::PubSub::V1::ListTopicsRequest)
557
- @list_topics.call(req, options, &block)
558
- end
559
-
560
- # Lists the names of the subscriptions on this topic.
561
- #
562
- # @param topic [String]
563
- # The name of the topic that subscriptions are attached to.
564
- # Format is `projects/{project}/topics/{topic}`.
565
- # @param page_size [Integer]
566
- # The maximum number of resources contained in the underlying API
567
- # response. If page streaming is performed per-resource, this
568
- # parameter does not affect the return value. If page streaming is
569
- # performed per-page, this determines the maximum number of
570
- # resources in a page.
571
- # @param options [Google::Gax::CallOptions]
572
- # Overrides the default settings for this call, e.g, timeout,
573
- # retries, etc.
574
- # @yield [result, operation] Access the result along with the RPC operation
575
- # @yieldparam result [Google::Gax::PagedEnumerable<String>]
576
- # @yieldparam operation [GRPC::ActiveCall::Operation]
577
- # @return [Google::Gax::PagedEnumerable<String>]
578
- # An enumerable of String instances.
579
- # See Google::Gax::PagedEnumerable documentation for other
580
- # operations such as per-page iteration or access to the response
581
- # object.
582
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
583
- # @example
584
- # require "google/cloud/pubsub"
585
- #
586
- # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
587
- # formatted_topic = Google::Cloud::PubSub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
588
- #
589
- # # Iterate over all results.
590
- # publisher_client.list_topic_subscriptions(formatted_topic).each do |element|
591
- # # Process element.
592
- # end
593
- #
594
- # # Or iterate over results one page at a time.
595
- # publisher_client.list_topic_subscriptions(formatted_topic).each_page do |page|
596
- # # Process each page at a time.
597
- # page.each do |element|
598
- # # Process element.
599
- # end
600
- # end
601
-
602
- def list_topic_subscriptions \
603
- topic,
604
- page_size: nil,
605
- options: nil,
606
- &block
607
- req = {
608
- topic: topic,
609
- page_size: page_size
610
- }.delete_if { |_, v| v.nil? }
611
- req = Google::Gax::to_proto(req, Google::Cloud::PubSub::V1::ListTopicSubscriptionsRequest)
612
- @list_topic_subscriptions.call(req, options, &block)
613
- end
614
-
615
- # Deletes the topic with the given name. Returns `NOT_FOUND` if the topic
616
- # does not exist. After a topic is deleted, a new topic may be created with
617
- # the same name; this is an entirely new topic with none of the old
618
- # configuration or subscriptions. Existing subscriptions to this topic are
619
- # not deleted, but their `topic` field is set to `_deleted-topic_`.
620
- #
621
- # @param topic [String]
622
- # Name of the topic to delete.
623
- # Format is `projects/{project}/topics/{topic}`.
624
- # @param options [Google::Gax::CallOptions]
625
- # Overrides the default settings for this call, e.g, timeout,
626
- # retries, etc.
627
- # @yield [result, operation] Access the result along with the RPC operation
628
- # @yieldparam result []
629
- # @yieldparam operation [GRPC::ActiveCall::Operation]
630
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
631
- # @example
632
- # require "google/cloud/pubsub"
633
- #
634
- # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
635
- # formatted_topic = Google::Cloud::PubSub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
636
- # publisher_client.delete_topic(formatted_topic)
637
-
638
- def delete_topic \
639
- topic,
640
- options: nil,
641
- &block
642
- req = {
643
- topic: topic
644
- }.delete_if { |_, v| v.nil? }
645
- req = Google::Gax::to_proto(req, Google::Cloud::PubSub::V1::DeleteTopicRequest)
646
- @delete_topic.call(req, options, &block)
647
- nil
648
- end
649
-
650
- # Sets the access control policy on the specified resource. Replaces any
651
- # existing policy.
652
- #
653
- # @param resource [String]
654
- # REQUIRED: The resource for which the policy is being specified.
655
- # See the operation documentation for the appropriate value for this field.
656
- # @param policy [Google::Iam::V1::Policy | Hash]
657
- # REQUIRED: The complete policy to be applied to the `resource`. The size of
658
- # the policy is limited to a few 10s of KB. An empty policy is a
659
- # valid policy but certain Cloud Platform services (such as Projects)
660
- # might reject them.
661
- # A hash of the same form as `Google::Iam::V1::Policy`
662
- # can also be provided.
663
- # @param options [Google::Gax::CallOptions]
664
- # Overrides the default settings for this call, e.g, timeout,
665
- # retries, etc.
666
- # @yield [result, operation] Access the result along with the RPC operation
667
- # @yieldparam result [Google::Iam::V1::Policy]
668
- # @yieldparam operation [GRPC::ActiveCall::Operation]
669
- # @return [Google::Iam::V1::Policy]
670
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
671
- # @example
672
- # require "google/cloud/pubsub"
673
- #
674
- # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
675
- # formatted_resource = Google::Cloud::PubSub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
676
- #
677
- # # TODO: Initialize `policy`:
678
- # policy = {}
679
- # response = publisher_client.set_iam_policy(formatted_resource, policy)
680
-
681
- def set_iam_policy \
682
- resource,
683
- policy,
684
- options: nil,
685
- &block
686
- req = {
687
- resource: resource,
688
- policy: policy
689
- }.delete_if { |_, v| v.nil? }
690
- req = Google::Gax::to_proto(req, Google::Iam::V1::SetIamPolicyRequest)
691
- @set_iam_policy.call(req, options, &block)
692
- end
693
-
694
- # Gets the access control policy for a resource.
695
- # Returns an empty policy if the resource exists and does not have a policy
696
- # set.
697
- #
698
- # @param resource [String]
699
- # REQUIRED: The resource for which the policy is being requested.
700
- # See the operation documentation for the appropriate value for this field.
701
- # @param options_ [Google::Iam::V1::GetPolicyOptions | Hash]
702
- # OPTIONAL: A `GetPolicyOptions` object for specifying options to
703
- # `GetIamPolicy`. This field is only used by Cloud IAM.
704
- # A hash of the same form as `Google::Iam::V1::GetPolicyOptions`
705
- # can also be provided.
706
- # @param options [Google::Gax::CallOptions]
707
- # Overrides the default settings for this call, e.g, timeout,
708
- # retries, etc.
709
- # @yield [result, operation] Access the result along with the RPC operation
710
- # @yieldparam result [Google::Iam::V1::Policy]
711
- # @yieldparam operation [GRPC::ActiveCall::Operation]
712
- # @return [Google::Iam::V1::Policy]
713
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
714
- # @example
715
- # require "google/cloud/pubsub"
716
- #
717
- # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
718
- # formatted_resource = Google::Cloud::PubSub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
719
- # response = publisher_client.get_iam_policy(formatted_resource)
720
-
721
- def get_iam_policy \
722
- resource,
723
- options_: nil,
724
- options: nil,
725
- &block
726
- req = {
727
- resource: resource,
728
- options: options_
729
- }.delete_if { |_, v| v.nil? }
730
- req = Google::Gax::to_proto(req, Google::Iam::V1::GetIamPolicyRequest)
731
- @get_iam_policy.call(req, options, &block)
732
- end
733
-
734
- # Returns permissions that a caller has on the specified resource.
735
- # If the resource does not exist, this will return an empty set of
736
- # permissions, not a NOT_FOUND error.
737
- #
738
- # Note: This operation is designed to be used for building permission-aware
739
- # UIs and command-line tools, not for authorization checking. This operation
740
- # may "fail open" without warning.
741
- #
742
- # @param resource [String]
743
- # REQUIRED: The resource for which the policy detail is being requested.
744
- # See the operation documentation for the appropriate value for this field.
745
- # @param permissions [Array<String>]
746
- # The set of permissions to check for the `resource`. Permissions with
747
- # wildcards (such as '*' or 'storage.*') are not allowed. For more
748
- # information see
749
- # [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).
750
- # @param options [Google::Gax::CallOptions]
751
- # Overrides the default settings for this call, e.g, timeout,
752
- # retries, etc.
753
- # @yield [result, operation] Access the result along with the RPC operation
754
- # @yieldparam result [Google::Iam::V1::TestIamPermissionsResponse]
755
- # @yieldparam operation [GRPC::ActiveCall::Operation]
756
- # @return [Google::Iam::V1::TestIamPermissionsResponse]
757
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
758
- # @example
759
- # require "google/cloud/pubsub"
760
- #
761
- # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
762
- # formatted_resource = Google::Cloud::PubSub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
763
- #
764
- # # TODO: Initialize `permissions`:
765
- # permissions = []
766
- # response = publisher_client.test_iam_permissions(formatted_resource, permissions)
767
-
768
- def test_iam_permissions \
769
- resource,
770
- permissions,
771
- options: nil,
772
- &block
773
- req = {
774
- resource: resource,
775
- permissions: permissions
776
- }.delete_if { |_, v| v.nil? }
777
- req = Google::Gax::to_proto(req, Google::Iam::V1::TestIamPermissionsRequest)
778
- @test_iam_permissions.call(req, options, &block)
779
- end
780
- end
781
- end
782
- end
783
-
784
- Pubsub = PubSub unless const_defined? :Pubsub
785
- end
786
- end