google-cloud-pubsub 0.20.1 → 0.21.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 +4 -4
- data/lib/google-cloud-pubsub.rb +13 -26
- data/lib/google/cloud/pubsub.rb +106 -86
- data/lib/google/cloud/pubsub/message.rb +2 -3
- data/lib/google/cloud/pubsub/policy.rb +13 -17
- data/lib/google/cloud/pubsub/project.rb +52 -73
- data/lib/google/cloud/pubsub/received_message.rb +6 -9
- data/lib/google/cloud/pubsub/service.rb +172 -152
- data/lib/google/cloud/pubsub/subscription.rb +41 -60
- data/lib/google/cloud/pubsub/subscription/list.rb +10 -15
- data/lib/google/cloud/pubsub/topic.rb +44 -64
- data/lib/google/cloud/pubsub/topic/list.rb +10 -15
- data/lib/google/cloud/pubsub/topic/publisher.rb +2 -3
- data/lib/google/cloud/pubsub/v1/publisher_api.rb +232 -11
- data/lib/google/cloud/pubsub/v1/publisher_client_config.json +15 -0
- data/lib/google/cloud/pubsub/v1/subscriber_api.rb +249 -17
- data/lib/google/cloud/pubsub/v1/subscriber_client_config.json +15 -0
- data/lib/google/cloud/pubsub/version.rb +1 -1
- data/lib/google/pubsub/v1/pubsub_services_pb.rb +6 -4
- metadata +36 -11
- data/lib/google/iam/v1/iam_policy.rb +0 -33
- data/lib/google/iam/v1/iam_policy_services.rb +0 -30
- data/lib/google/iam/v1/policy.rb +0 -25
@@ -40,10 +40,9 @@ module Google
|
|
40
40
|
# @return [Boolean]
|
41
41
|
#
|
42
42
|
# @example
|
43
|
-
# require "google/cloud"
|
43
|
+
# require "google/cloud/pubsub"
|
44
44
|
#
|
45
|
-
#
|
46
|
-
# pubsub = gcloud.pubsub
|
45
|
+
# pubsub = Google::Cloud::Pubsub.new
|
47
46
|
#
|
48
47
|
# topics = pubsub.topics
|
49
48
|
# if topics.next?
|
@@ -60,10 +59,9 @@ module Google
|
|
60
59
|
# @return [Topic::List]
|
61
60
|
#
|
62
61
|
# @example
|
63
|
-
# require "google/cloud"
|
62
|
+
# require "google/cloud/pubsub"
|
64
63
|
#
|
65
|
-
#
|
66
|
-
# pubsub = gcloud.pubsub
|
64
|
+
# pubsub = Google::Cloud::Pubsub.new
|
67
65
|
#
|
68
66
|
# topics = pubsub.topics
|
69
67
|
# if topics.next?
|
@@ -97,10 +95,9 @@ module Google
|
|
97
95
|
# @return [Enumerator]
|
98
96
|
#
|
99
97
|
# @example Iterating each topic by passing a block:
|
100
|
-
# require "google/cloud"
|
98
|
+
# require "google/cloud/pubsub"
|
101
99
|
#
|
102
|
-
#
|
103
|
-
# pubsub = gcloud.pubsub
|
100
|
+
# pubsub = Google::Cloud::Pubsub.new
|
104
101
|
#
|
105
102
|
# topics = pubsub.topics
|
106
103
|
# topics.all do |topic|
|
@@ -108,10 +105,9 @@ module Google
|
|
108
105
|
# end
|
109
106
|
#
|
110
107
|
# @example Using the enumerator by not passing a block:
|
111
|
-
# require "google/cloud"
|
108
|
+
# require "google/cloud/pubsub"
|
112
109
|
#
|
113
|
-
#
|
114
|
-
# pubsub = gcloud.pubsub
|
110
|
+
# pubsub = Google::Cloud::Pubsub.new
|
115
111
|
#
|
116
112
|
# topics = pubsub.topics
|
117
113
|
# all_names = topics.all.map do |topic|
|
@@ -119,10 +115,9 @@ module Google
|
|
119
115
|
# end
|
120
116
|
#
|
121
117
|
# @example Limit the number of API calls made:
|
122
|
-
# require "google/cloud"
|
118
|
+
# require "google/cloud/pubsub"
|
123
119
|
#
|
124
|
-
#
|
125
|
-
# pubsub = gcloud.pubsub
|
120
|
+
# pubsub = Google::Cloud::Pubsub.new
|
126
121
|
#
|
127
122
|
# topics = pubsub.topics
|
128
123
|
# topics.all(request_limit: 10) do |topic|
|
@@ -21,10 +21,9 @@ module Google
|
|
21
21
|
# Topic Publisher object used to publish multiple messages at once.
|
22
22
|
#
|
23
23
|
# @example
|
24
|
-
# require "google/cloud"
|
24
|
+
# require "google/cloud/pubsub"
|
25
25
|
#
|
26
|
-
#
|
27
|
-
# pubsub = gcloud.pubsub
|
26
|
+
# pubsub = Google::Cloud::Pubsub.new
|
28
27
|
#
|
29
28
|
# topic = pubsub.topic "my-topic"
|
30
29
|
# msgs = topic.publish do |t|
|
@@ -26,7 +26,8 @@ require "json"
|
|
26
26
|
require "pathname"
|
27
27
|
|
28
28
|
require "google/gax"
|
29
|
-
require "google/
|
29
|
+
require "google/iam/v1/iam_policy_pb"
|
30
|
+
require "google/pubsub/v1/pubsub_pb"
|
30
31
|
|
31
32
|
module Google
|
32
33
|
module Cloud
|
@@ -35,10 +36,12 @@ module Google
|
|
35
36
|
# The service that an application uses to manipulate topics, and to send
|
36
37
|
# messages to a topic.
|
37
38
|
#
|
38
|
-
# @!attribute [r]
|
39
|
+
# @!attribute [r] iam_policy_stub
|
40
|
+
# @return [Google::Iam::V1::IAMPolicy::Stub]
|
41
|
+
# @!attribute [r] publisher_stub
|
39
42
|
# @return [Google::Pubsub::V1::Publisher::Stub]
|
40
43
|
class PublisherApi
|
41
|
-
attr_reader :
|
44
|
+
attr_reader :iam_policy_stub, :publisher_stub
|
42
45
|
|
43
46
|
# The default address of the service.
|
44
47
|
SERVICE_ADDRESS = "pubsub.googleapis.com".freeze
|
@@ -163,8 +166,16 @@ module Google
|
|
163
166
|
timeout: DEFAULT_TIMEOUT,
|
164
167
|
app_name: "gax",
|
165
168
|
app_version: Google::Gax::VERSION
|
169
|
+
# These require statements are intentionally placed here to initialize
|
170
|
+
# the gRPC module only when it's required.
|
171
|
+
# See https://github.com/googleapis/toolkit/issues/446
|
172
|
+
require "google/gax/grpc"
|
173
|
+
require "google/iam/v1/iam_policy_services_pb"
|
174
|
+
require "google/pubsub/v1/pubsub_services_pb"
|
175
|
+
|
166
176
|
google_api_client = "#{app_name}/#{app_version} " \
|
167
|
-
"#{CODE_GEN_NAME_VERSION}
|
177
|
+
"#{CODE_GEN_NAME_VERSION} gax/#{Google::Gax::VERSION} " \
|
178
|
+
"ruby/#{RUBY_VERSION}".freeze
|
168
179
|
headers = { :"x-goog-api-client" => google_api_client }
|
169
180
|
client_config_file = Pathname.new(__dir__).join(
|
170
181
|
"publisher_client_config.json"
|
@@ -182,7 +193,15 @@ module Google
|
|
182
193
|
kwargs: headers
|
183
194
|
)
|
184
195
|
end
|
185
|
-
@
|
196
|
+
@iam_policy_stub = Google::Gax::Grpc.create_stub(
|
197
|
+
service_path,
|
198
|
+
port,
|
199
|
+
chan_creds: chan_creds,
|
200
|
+
channel: channel,
|
201
|
+
scopes: scopes,
|
202
|
+
&Google::Iam::V1::IAMPolicy::Stub.method(:new)
|
203
|
+
)
|
204
|
+
@publisher_stub = Google::Gax::Grpc.create_stub(
|
186
205
|
service_path,
|
187
206
|
port,
|
188
207
|
chan_creds: chan_creds,
|
@@ -191,28 +210,40 @@ module Google
|
|
191
210
|
&Google::Pubsub::V1::Publisher::Stub.method(:new)
|
192
211
|
)
|
193
212
|
|
213
|
+
@set_iam_policy = Google::Gax.create_api_call(
|
214
|
+
@iam_policy_stub.method(:set_iam_policy),
|
215
|
+
defaults["set_iam_policy"]
|
216
|
+
)
|
217
|
+
@get_iam_policy = Google::Gax.create_api_call(
|
218
|
+
@iam_policy_stub.method(:get_iam_policy),
|
219
|
+
defaults["get_iam_policy"]
|
220
|
+
)
|
221
|
+
@test_iam_permissions = Google::Gax.create_api_call(
|
222
|
+
@iam_policy_stub.method(:test_iam_permissions),
|
223
|
+
defaults["test_iam_permissions"]
|
224
|
+
)
|
194
225
|
@create_topic = Google::Gax.create_api_call(
|
195
|
-
@
|
226
|
+
@publisher_stub.method(:create_topic),
|
196
227
|
defaults["create_topic"]
|
197
228
|
)
|
198
229
|
@publish = Google::Gax.create_api_call(
|
199
|
-
@
|
230
|
+
@publisher_stub.method(:publish),
|
200
231
|
defaults["publish"]
|
201
232
|
)
|
202
233
|
@get_topic = Google::Gax.create_api_call(
|
203
|
-
@
|
234
|
+
@publisher_stub.method(:get_topic),
|
204
235
|
defaults["get_topic"]
|
205
236
|
)
|
206
237
|
@list_topics = Google::Gax.create_api_call(
|
207
|
-
@
|
238
|
+
@publisher_stub.method(:list_topics),
|
208
239
|
defaults["list_topics"]
|
209
240
|
)
|
210
241
|
@list_topic_subscriptions = Google::Gax.create_api_call(
|
211
|
-
@
|
242
|
+
@publisher_stub.method(:list_topic_subscriptions),
|
212
243
|
defaults["list_topic_subscriptions"]
|
213
244
|
)
|
214
245
|
@delete_topic = Google::Gax.create_api_call(
|
215
|
-
@
|
246
|
+
@publisher_stub.method(:delete_topic),
|
216
247
|
defaults["delete_topic"]
|
217
248
|
)
|
218
249
|
end
|
@@ -233,6 +264,15 @@ module Google
|
|
233
264
|
# retries, etc.
|
234
265
|
# @return [Google::Pubsub::V1::Topic]
|
235
266
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
267
|
+
# @example
|
268
|
+
# require "google/cloud/pubsub/v1/publisher_api"
|
269
|
+
#
|
270
|
+
# PublisherApi = Google::Cloud::Pubsub::V1::PublisherApi
|
271
|
+
#
|
272
|
+
# publisher_api = PublisherApi.new
|
273
|
+
# formatted_name = PublisherApi.topic_path("[PROJECT]", "[TOPIC]")
|
274
|
+
# response = publisher_api.create_topic(formatted_name)
|
275
|
+
|
236
276
|
def create_topic \
|
237
277
|
name,
|
238
278
|
options: nil
|
@@ -255,6 +295,20 @@ module Google
|
|
255
295
|
# retries, etc.
|
256
296
|
# @return [Google::Pubsub::V1::PublishResponse]
|
257
297
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
298
|
+
# @example
|
299
|
+
# require "google/cloud/pubsub/v1/publisher_api"
|
300
|
+
#
|
301
|
+
# PublisherApi = Google::Cloud::Pubsub::V1::PublisherApi
|
302
|
+
# PubsubMessage = Google::Pubsub::V1::PubsubMessage
|
303
|
+
#
|
304
|
+
# publisher_api = PublisherApi.new
|
305
|
+
# formatted_topic = PublisherApi.topic_path("[PROJECT]", "[TOPIC]")
|
306
|
+
# data = ''
|
307
|
+
# messages_element = PubsubMessage.new
|
308
|
+
# messages_element.data = data
|
309
|
+
# messages = [messages_element]
|
310
|
+
# response = publisher_api.publish(formatted_topic, messages)
|
311
|
+
|
258
312
|
def publish \
|
259
313
|
topic,
|
260
314
|
messages,
|
@@ -275,6 +329,15 @@ module Google
|
|
275
329
|
# retries, etc.
|
276
330
|
# @return [Google::Pubsub::V1::Topic]
|
277
331
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
332
|
+
# @example
|
333
|
+
# require "google/cloud/pubsub/v1/publisher_api"
|
334
|
+
#
|
335
|
+
# PublisherApi = Google::Cloud::Pubsub::V1::PublisherApi
|
336
|
+
#
|
337
|
+
# publisher_api = PublisherApi.new
|
338
|
+
# formatted_topic = PublisherApi.topic_path("[PROJECT]", "[TOPIC]")
|
339
|
+
# response = publisher_api.get_topic(formatted_topic)
|
340
|
+
|
278
341
|
def get_topic \
|
279
342
|
topic,
|
280
343
|
options: nil
|
@@ -303,6 +366,27 @@ module Google
|
|
303
366
|
# operations such as per-page iteration or access to the response
|
304
367
|
# object.
|
305
368
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
369
|
+
# @example
|
370
|
+
# require "google/cloud/pubsub/v1/publisher_api"
|
371
|
+
#
|
372
|
+
# PublisherApi = Google::Cloud::Pubsub::V1::PublisherApi
|
373
|
+
#
|
374
|
+
# publisher_api = PublisherApi.new
|
375
|
+
# formatted_project = PublisherApi.project_path("[PROJECT]")
|
376
|
+
#
|
377
|
+
# # Iterate over all results.
|
378
|
+
# publisher_api.list_topics(formatted_project).each do |element|
|
379
|
+
# # Process element.
|
380
|
+
# end
|
381
|
+
#
|
382
|
+
# # Or iterate over results one page at a time.
|
383
|
+
# publisher_api.list_topics(formatted_project).each_page do |page|
|
384
|
+
# # Process each page at a time.
|
385
|
+
# page.each do |element|
|
386
|
+
# # Process element.
|
387
|
+
# end
|
388
|
+
# end
|
389
|
+
|
306
390
|
def list_topics \
|
307
391
|
project,
|
308
392
|
page_size: nil,
|
@@ -333,6 +417,27 @@ module Google
|
|
333
417
|
# operations such as per-page iteration or access to the response
|
334
418
|
# object.
|
335
419
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
420
|
+
# @example
|
421
|
+
# require "google/cloud/pubsub/v1/publisher_api"
|
422
|
+
#
|
423
|
+
# PublisherApi = Google::Cloud::Pubsub::V1::PublisherApi
|
424
|
+
#
|
425
|
+
# publisher_api = PublisherApi.new
|
426
|
+
# formatted_topic = PublisherApi.topic_path("[PROJECT]", "[TOPIC]")
|
427
|
+
#
|
428
|
+
# # Iterate over all results.
|
429
|
+
# publisher_api.list_topic_subscriptions(formatted_topic).each do |element|
|
430
|
+
# # Process element.
|
431
|
+
# end
|
432
|
+
#
|
433
|
+
# # Or iterate over results one page at a time.
|
434
|
+
# publisher_api.list_topic_subscriptions(formatted_topic).each_page do |page|
|
435
|
+
# # Process each page at a time.
|
436
|
+
# page.each do |element|
|
437
|
+
# # Process element.
|
438
|
+
# end
|
439
|
+
# end
|
440
|
+
|
336
441
|
def list_topic_subscriptions \
|
337
442
|
topic,
|
338
443
|
page_size: nil,
|
@@ -356,6 +461,15 @@ module Google
|
|
356
461
|
# Overrides the default settings for this call, e.g, timeout,
|
357
462
|
# retries, etc.
|
358
463
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
464
|
+
# @example
|
465
|
+
# require "google/cloud/pubsub/v1/publisher_api"
|
466
|
+
#
|
467
|
+
# PublisherApi = Google::Cloud::Pubsub::V1::PublisherApi
|
468
|
+
#
|
469
|
+
# publisher_api = PublisherApi.new
|
470
|
+
# formatted_topic = PublisherApi.topic_path("[PROJECT]", "[TOPIC]")
|
471
|
+
# publisher_api.delete_topic(formatted_topic)
|
472
|
+
|
359
473
|
def delete_topic \
|
360
474
|
topic,
|
361
475
|
options: nil
|
@@ -364,6 +478,113 @@ module Google
|
|
364
478
|
)
|
365
479
|
@delete_topic.call(req, options)
|
366
480
|
end
|
481
|
+
|
482
|
+
# Sets the access control policy on the specified resource. Replaces any
|
483
|
+
# existing policy.
|
484
|
+
#
|
485
|
+
# @param resource [String]
|
486
|
+
# REQUIRED: The resource for which the policy is being specified.
|
487
|
+
# +resource+ is usually specified as a path. For example, a Project
|
488
|
+
# resource is specified as +projects/{project}+.
|
489
|
+
# @param policy [Google::Iam::V1::Policy]
|
490
|
+
# REQUIRED: The complete policy to be applied to the +resource+. The size of
|
491
|
+
# the policy is limited to a few 10s of KB. An empty policy is a
|
492
|
+
# valid policy but certain Cloud Platform services (such as Projects)
|
493
|
+
# might reject them.
|
494
|
+
# @param options [Google::Gax::CallOptions]
|
495
|
+
# Overrides the default settings for this call, e.g, timeout,
|
496
|
+
# retries, etc.
|
497
|
+
# @return [Google::Iam::V1::Policy]
|
498
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
499
|
+
# @example
|
500
|
+
# require "google/cloud/pubsub/v1/publisher_api"
|
501
|
+
#
|
502
|
+
# Policy = Google::Iam::V1::Policy
|
503
|
+
# PublisherApi = Google::Cloud::Pubsub::V1::PublisherApi
|
504
|
+
#
|
505
|
+
# publisher_api = PublisherApi.new
|
506
|
+
# formatted_resource = PublisherApi.topic_path("[PROJECT]", "[TOPIC]")
|
507
|
+
# policy = Policy.new
|
508
|
+
# response = publisher_api.set_iam_policy(formatted_resource, policy)
|
509
|
+
|
510
|
+
def set_iam_policy \
|
511
|
+
resource,
|
512
|
+
policy,
|
513
|
+
options: nil
|
514
|
+
req = Google::Iam::V1::SetIamPolicyRequest.new(
|
515
|
+
resource: resource,
|
516
|
+
policy: policy
|
517
|
+
)
|
518
|
+
@set_iam_policy.call(req, options)
|
519
|
+
end
|
520
|
+
|
521
|
+
# Gets the access control policy for a resource.
|
522
|
+
# Returns an empty policy if the resource exists and does not have a policy
|
523
|
+
# set.
|
524
|
+
#
|
525
|
+
# @param resource [String]
|
526
|
+
# REQUIRED: The resource for which the policy is being requested.
|
527
|
+
# +resource+ is usually specified as a path. For example, a Project
|
528
|
+
# resource is specified as +projects/{project}+.
|
529
|
+
# @param options [Google::Gax::CallOptions]
|
530
|
+
# Overrides the default settings for this call, e.g, timeout,
|
531
|
+
# retries, etc.
|
532
|
+
# @return [Google::Iam::V1::Policy]
|
533
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
534
|
+
# @example
|
535
|
+
# require "google/cloud/pubsub/v1/publisher_api"
|
536
|
+
#
|
537
|
+
# PublisherApi = Google::Cloud::Pubsub::V1::PublisherApi
|
538
|
+
#
|
539
|
+
# publisher_api = PublisherApi.new
|
540
|
+
# formatted_resource = PublisherApi.topic_path("[PROJECT]", "[TOPIC]")
|
541
|
+
# response = publisher_api.get_iam_policy(formatted_resource)
|
542
|
+
|
543
|
+
def get_iam_policy \
|
544
|
+
resource,
|
545
|
+
options: nil
|
546
|
+
req = Google::Iam::V1::GetIamPolicyRequest.new(
|
547
|
+
resource: resource
|
548
|
+
)
|
549
|
+
@get_iam_policy.call(req, options)
|
550
|
+
end
|
551
|
+
|
552
|
+
# Returns permissions that a caller has on the specified resource.
|
553
|
+
#
|
554
|
+
# @param resource [String]
|
555
|
+
# REQUIRED: The resource for which the policy detail is being requested.
|
556
|
+
# +resource+ is usually specified as a path. For example, a Project
|
557
|
+
# resource is specified as +projects/{project}+.
|
558
|
+
# @param permissions [Array<String>]
|
559
|
+
# The set of permissions to check for the +resource+. Permissions with
|
560
|
+
# wildcards (such as '*' or 'storage.*') are not allowed. For more
|
561
|
+
# information see
|
562
|
+
# {IAM Overview}[https://cloud.google.com/iam/docs/overview#permissions].
|
563
|
+
# @param options [Google::Gax::CallOptions]
|
564
|
+
# Overrides the default settings for this call, e.g, timeout,
|
565
|
+
# retries, etc.
|
566
|
+
# @return [Google::Iam::V1::TestIamPermissionsResponse]
|
567
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
568
|
+
# @example
|
569
|
+
# require "google/cloud/pubsub/v1/publisher_api"
|
570
|
+
#
|
571
|
+
# PublisherApi = Google::Cloud::Pubsub::V1::PublisherApi
|
572
|
+
#
|
573
|
+
# publisher_api = PublisherApi.new
|
574
|
+
# formatted_resource = PublisherApi.topic_path("[PROJECT]", "[TOPIC]")
|
575
|
+
# permissions = []
|
576
|
+
# response = publisher_api.test_iam_permissions(formatted_resource, permissions)
|
577
|
+
|
578
|
+
def test_iam_permissions \
|
579
|
+
resource,
|
580
|
+
permissions,
|
581
|
+
options: nil
|
582
|
+
req = Google::Iam::V1::TestIamPermissionsRequest.new(
|
583
|
+
resource: resource,
|
584
|
+
permissions: permissions
|
585
|
+
)
|
586
|
+
@test_iam_permissions.call(req, options)
|
587
|
+
end
|
367
588
|
end
|
368
589
|
end
|
369
590
|
end
|
@@ -71,6 +71,21 @@
|
|
71
71
|
"timeout_millis": 60000,
|
72
72
|
"retry_codes_name": "idempotent",
|
73
73
|
"retry_params_name": "default"
|
74
|
+
},
|
75
|
+
"SetIamPolicy": {
|
76
|
+
"timeout_millis": 60000,
|
77
|
+
"retry_codes_name": "non_idempotent",
|
78
|
+
"retry_params_name": "default"
|
79
|
+
},
|
80
|
+
"GetIamPolicy": {
|
81
|
+
"timeout_millis": 60000,
|
82
|
+
"retry_codes_name": "idempotent",
|
83
|
+
"retry_params_name": "default"
|
84
|
+
},
|
85
|
+
"TestIamPermissions": {
|
86
|
+
"timeout_millis": 60000,
|
87
|
+
"retry_codes_name": "non_idempotent",
|
88
|
+
"retry_params_name": "default"
|
74
89
|
}
|
75
90
|
}
|
76
91
|
}
|
@@ -26,7 +26,8 @@ require "json"
|
|
26
26
|
require "pathname"
|
27
27
|
|
28
28
|
require "google/gax"
|
29
|
-
require "google/
|
29
|
+
require "google/iam/v1/iam_policy_pb"
|
30
|
+
require "google/pubsub/v1/pubsub_pb"
|
30
31
|
|
31
32
|
module Google
|
32
33
|
module Cloud
|
@@ -35,10 +36,12 @@ module Google
|
|
35
36
|
# The service that an application uses to manipulate subscriptions and to
|
36
37
|
# consume messages from a subscription via the +Pull+ method.
|
37
38
|
#
|
38
|
-
# @!attribute [r]
|
39
|
+
# @!attribute [r] iam_policy_stub
|
40
|
+
# @return [Google::Iam::V1::IAMPolicy::Stub]
|
41
|
+
# @!attribute [r] subscriber_stub
|
39
42
|
# @return [Google::Pubsub::V1::Subscriber::Stub]
|
40
43
|
class SubscriberApi
|
41
|
-
attr_reader :
|
44
|
+
attr_reader :iam_policy_stub, :subscriber_stub
|
42
45
|
|
43
46
|
# The default address of the service.
|
44
47
|
SERVICE_ADDRESS = "pubsub.googleapis.com".freeze
|
@@ -179,8 +182,16 @@ module Google
|
|
179
182
|
timeout: DEFAULT_TIMEOUT,
|
180
183
|
app_name: "gax",
|
181
184
|
app_version: Google::Gax::VERSION
|
185
|
+
# These require statements are intentionally placed here to initialize
|
186
|
+
# the gRPC module only when it's required.
|
187
|
+
# See https://github.com/googleapis/toolkit/issues/446
|
188
|
+
require "google/gax/grpc"
|
189
|
+
require "google/iam/v1/iam_policy_services_pb"
|
190
|
+
require "google/pubsub/v1/pubsub_services_pb"
|
191
|
+
|
182
192
|
google_api_client = "#{app_name}/#{app_version} " \
|
183
|
-
"#{CODE_GEN_NAME_VERSION}
|
193
|
+
"#{CODE_GEN_NAME_VERSION} gax/#{Google::Gax::VERSION} " \
|
194
|
+
"ruby/#{RUBY_VERSION}".freeze
|
184
195
|
headers = { :"x-goog-api-client" => google_api_client }
|
185
196
|
client_config_file = Pathname.new(__dir__).join(
|
186
197
|
"subscriber_client_config.json"
|
@@ -197,7 +208,15 @@ module Google
|
|
197
208
|
kwargs: headers
|
198
209
|
)
|
199
210
|
end
|
200
|
-
@
|
211
|
+
@iam_policy_stub = Google::Gax::Grpc.create_stub(
|
212
|
+
service_path,
|
213
|
+
port,
|
214
|
+
chan_creds: chan_creds,
|
215
|
+
channel: channel,
|
216
|
+
scopes: scopes,
|
217
|
+
&Google::Iam::V1::IAMPolicy::Stub.method(:new)
|
218
|
+
)
|
219
|
+
@subscriber_stub = Google::Gax::Grpc.create_stub(
|
201
220
|
service_path,
|
202
221
|
port,
|
203
222
|
chan_creds: chan_creds,
|
@@ -206,48 +225,61 @@ module Google
|
|
206
225
|
&Google::Pubsub::V1::Subscriber::Stub.method(:new)
|
207
226
|
)
|
208
227
|
|
228
|
+
@set_iam_policy = Google::Gax.create_api_call(
|
229
|
+
@iam_policy_stub.method(:set_iam_policy),
|
230
|
+
defaults["set_iam_policy"]
|
231
|
+
)
|
232
|
+
@get_iam_policy = Google::Gax.create_api_call(
|
233
|
+
@iam_policy_stub.method(:get_iam_policy),
|
234
|
+
defaults["get_iam_policy"]
|
235
|
+
)
|
236
|
+
@test_iam_permissions = Google::Gax.create_api_call(
|
237
|
+
@iam_policy_stub.method(:test_iam_permissions),
|
238
|
+
defaults["test_iam_permissions"]
|
239
|
+
)
|
209
240
|
@create_subscription = Google::Gax.create_api_call(
|
210
|
-
@
|
241
|
+
@subscriber_stub.method(:create_subscription),
|
211
242
|
defaults["create_subscription"]
|
212
243
|
)
|
213
244
|
@get_subscription = Google::Gax.create_api_call(
|
214
|
-
@
|
245
|
+
@subscriber_stub.method(:get_subscription),
|
215
246
|
defaults["get_subscription"]
|
216
247
|
)
|
217
248
|
@list_subscriptions = Google::Gax.create_api_call(
|
218
|
-
@
|
249
|
+
@subscriber_stub.method(:list_subscriptions),
|
219
250
|
defaults["list_subscriptions"]
|
220
251
|
)
|
221
252
|
@delete_subscription = Google::Gax.create_api_call(
|
222
|
-
@
|
253
|
+
@subscriber_stub.method(:delete_subscription),
|
223
254
|
defaults["delete_subscription"]
|
224
255
|
)
|
225
256
|
@modify_ack_deadline = Google::Gax.create_api_call(
|
226
|
-
@
|
257
|
+
@subscriber_stub.method(:modify_ack_deadline),
|
227
258
|
defaults["modify_ack_deadline"]
|
228
259
|
)
|
229
260
|
@acknowledge = Google::Gax.create_api_call(
|
230
|
-
@
|
261
|
+
@subscriber_stub.method(:acknowledge),
|
231
262
|
defaults["acknowledge"]
|
232
263
|
)
|
233
264
|
@pull = Google::Gax.create_api_call(
|
234
|
-
@
|
265
|
+
@subscriber_stub.method(:pull),
|
235
266
|
defaults["pull"]
|
236
267
|
)
|
237
268
|
@modify_push_config = Google::Gax.create_api_call(
|
238
|
-
@
|
269
|
+
@subscriber_stub.method(:modify_push_config),
|
239
270
|
defaults["modify_push_config"]
|
240
271
|
)
|
241
272
|
end
|
242
273
|
|
243
274
|
# Service calls
|
244
275
|
|
245
|
-
# Creates a subscription to a given topic
|
276
|
+
# Creates a subscription to a given topic.
|
246
277
|
# If the subscription already exists, returns +ALREADY_EXISTS+.
|
247
278
|
# If the corresponding topic doesn't exist, returns +NOT_FOUND+.
|
248
279
|
#
|
249
280
|
# If the name is not provided in the request, the server will assign a random
|
250
|
-
# name for this subscription on the same project as the topic.
|
281
|
+
# name for this subscription on the same project as the topic. Note that
|
282
|
+
# for REST API requests, you must specify a name.
|
251
283
|
#
|
252
284
|
# @param name [String]
|
253
285
|
# The name of the subscription. It must have the format
|
@@ -275,6 +307,7 @@ module Google
|
|
275
307
|
# deadline. To override this value for a given message, call
|
276
308
|
# +ModifyAckDeadline+ with the corresponding +ack_id+ if using
|
277
309
|
# pull.
|
310
|
+
# The maximum custom deadline you can specify is 600 seconds (10 minutes).
|
278
311
|
#
|
279
312
|
# For push delivery, this value is also used to set the request timeout for
|
280
313
|
# the call to the push endpoint.
|
@@ -282,12 +315,22 @@ module Google
|
|
282
315
|
# If the subscriber never acknowledges the message, the Pub/Sub
|
283
316
|
# system will eventually redeliver the message.
|
284
317
|
#
|
285
|
-
# If this parameter is
|
318
|
+
# If this parameter is 0, a default value of 10 seconds is used.
|
286
319
|
# @param options [Google::Gax::CallOptions]
|
287
320
|
# Overrides the default settings for this call, e.g, timeout,
|
288
321
|
# retries, etc.
|
289
322
|
# @return [Google::Pubsub::V1::Subscription]
|
290
323
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
324
|
+
# @example
|
325
|
+
# require "google/cloud/pubsub/v1/subscriber_api"
|
326
|
+
#
|
327
|
+
# SubscriberApi = Google::Cloud::Pubsub::V1::SubscriberApi
|
328
|
+
#
|
329
|
+
# subscriber_api = SubscriberApi.new
|
330
|
+
# formatted_name = SubscriberApi.subscription_path("[PROJECT]", "[SUBSCRIPTION]")
|
331
|
+
# formatted_topic = SubscriberApi.topic_path("[PROJECT]", "[TOPIC]")
|
332
|
+
# response = subscriber_api.create_subscription(formatted_name, formatted_topic)
|
333
|
+
|
291
334
|
def create_subscription \
|
292
335
|
name,
|
293
336
|
topic,
|
@@ -312,6 +355,15 @@ module Google
|
|
312
355
|
# retries, etc.
|
313
356
|
# @return [Google::Pubsub::V1::Subscription]
|
314
357
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
358
|
+
# @example
|
359
|
+
# require "google/cloud/pubsub/v1/subscriber_api"
|
360
|
+
#
|
361
|
+
# SubscriberApi = Google::Cloud::Pubsub::V1::SubscriberApi
|
362
|
+
#
|
363
|
+
# subscriber_api = SubscriberApi.new
|
364
|
+
# formatted_subscription = SubscriberApi.subscription_path("[PROJECT]", "[SUBSCRIPTION]")
|
365
|
+
# response = subscriber_api.get_subscription(formatted_subscription)
|
366
|
+
|
315
367
|
def get_subscription \
|
316
368
|
subscription,
|
317
369
|
options: nil
|
@@ -340,6 +392,27 @@ module Google
|
|
340
392
|
# operations such as per-page iteration or access to the response
|
341
393
|
# object.
|
342
394
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
395
|
+
# @example
|
396
|
+
# require "google/cloud/pubsub/v1/subscriber_api"
|
397
|
+
#
|
398
|
+
# SubscriberApi = Google::Cloud::Pubsub::V1::SubscriberApi
|
399
|
+
#
|
400
|
+
# subscriber_api = SubscriberApi.new
|
401
|
+
# formatted_project = SubscriberApi.project_path("[PROJECT]")
|
402
|
+
#
|
403
|
+
# # Iterate over all results.
|
404
|
+
# subscriber_api.list_subscriptions(formatted_project).each do |element|
|
405
|
+
# # Process element.
|
406
|
+
# end
|
407
|
+
#
|
408
|
+
# # Or iterate over results one page at a time.
|
409
|
+
# subscriber_api.list_subscriptions(formatted_project).each_page do |page|
|
410
|
+
# # Process each page at a time.
|
411
|
+
# page.each do |element|
|
412
|
+
# # Process element.
|
413
|
+
# end
|
414
|
+
# end
|
415
|
+
|
343
416
|
def list_subscriptions \
|
344
417
|
project,
|
345
418
|
page_size: nil,
|
@@ -363,6 +436,15 @@ module Google
|
|
363
436
|
# Overrides the default settings for this call, e.g, timeout,
|
364
437
|
# retries, etc.
|
365
438
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
439
|
+
# @example
|
440
|
+
# require "google/cloud/pubsub/v1/subscriber_api"
|
441
|
+
#
|
442
|
+
# SubscriberApi = Google::Cloud::Pubsub::V1::SubscriberApi
|
443
|
+
#
|
444
|
+
# subscriber_api = SubscriberApi.new
|
445
|
+
# formatted_subscription = SubscriberApi.subscription_path("[PROJECT]", "[SUBSCRIPTION]")
|
446
|
+
# subscriber_api.delete_subscription(formatted_subscription)
|
447
|
+
|
366
448
|
def delete_subscription \
|
367
449
|
subscription,
|
368
450
|
options: nil
|
@@ -375,7 +457,8 @@ module Google
|
|
375
457
|
# Modifies the ack deadline for a specific message. This method is useful
|
376
458
|
# to indicate that more time is needed to process a message by the
|
377
459
|
# subscriber, or to make the message available for redelivery if the
|
378
|
-
# processing was interrupted.
|
460
|
+
# processing was interrupted. Note that this does not modify the
|
461
|
+
# subscription-level +ackDeadlineSeconds+ used for subsequent messages.
|
379
462
|
#
|
380
463
|
# @param subscription [String]
|
381
464
|
# The name of the subscription.
|
@@ -391,6 +474,17 @@ module Google
|
|
391
474
|
# Overrides the default settings for this call, e.g, timeout,
|
392
475
|
# retries, etc.
|
393
476
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
477
|
+
# @example
|
478
|
+
# require "google/cloud/pubsub/v1/subscriber_api"
|
479
|
+
#
|
480
|
+
# SubscriberApi = Google::Cloud::Pubsub::V1::SubscriberApi
|
481
|
+
#
|
482
|
+
# subscriber_api = SubscriberApi.new
|
483
|
+
# formatted_subscription = SubscriberApi.subscription_path("[PROJECT]", "[SUBSCRIPTION]")
|
484
|
+
# ack_ids = []
|
485
|
+
# ack_deadline_seconds = 0
|
486
|
+
# subscriber_api.modify_ack_deadline(formatted_subscription, ack_ids, ack_deadline_seconds)
|
487
|
+
|
394
488
|
def modify_ack_deadline \
|
395
489
|
subscription,
|
396
490
|
ack_ids,
|
@@ -421,6 +515,16 @@ module Google
|
|
421
515
|
# Overrides the default settings for this call, e.g, timeout,
|
422
516
|
# retries, etc.
|
423
517
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
518
|
+
# @example
|
519
|
+
# require "google/cloud/pubsub/v1/subscriber_api"
|
520
|
+
#
|
521
|
+
# SubscriberApi = Google::Cloud::Pubsub::V1::SubscriberApi
|
522
|
+
#
|
523
|
+
# subscriber_api = SubscriberApi.new
|
524
|
+
# formatted_subscription = SubscriberApi.subscription_path("[PROJECT]", "[SUBSCRIPTION]")
|
525
|
+
# ack_ids = []
|
526
|
+
# subscriber_api.acknowledge(formatted_subscription, ack_ids)
|
527
|
+
|
424
528
|
def acknowledge \
|
425
529
|
subscription,
|
426
530
|
ack_ids,
|
@@ -453,6 +557,16 @@ module Google
|
|
453
557
|
# retries, etc.
|
454
558
|
# @return [Google::Pubsub::V1::PullResponse]
|
455
559
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
560
|
+
# @example
|
561
|
+
# require "google/cloud/pubsub/v1/subscriber_api"
|
562
|
+
#
|
563
|
+
# SubscriberApi = Google::Cloud::Pubsub::V1::SubscriberApi
|
564
|
+
#
|
565
|
+
# subscriber_api = SubscriberApi.new
|
566
|
+
# formatted_subscription = SubscriberApi.subscription_path("[PROJECT]", "[SUBSCRIPTION]")
|
567
|
+
# max_messages = 0
|
568
|
+
# response = subscriber_api.pull(formatted_subscription, max_messages)
|
569
|
+
|
456
570
|
def pull \
|
457
571
|
subscription,
|
458
572
|
max_messages,
|
@@ -486,6 +600,17 @@ module Google
|
|
486
600
|
# Overrides the default settings for this call, e.g, timeout,
|
487
601
|
# retries, etc.
|
488
602
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
603
|
+
# @example
|
604
|
+
# require "google/cloud/pubsub/v1/subscriber_api"
|
605
|
+
#
|
606
|
+
# PushConfig = Google::Pubsub::V1::PushConfig
|
607
|
+
# SubscriberApi = Google::Cloud::Pubsub::V1::SubscriberApi
|
608
|
+
#
|
609
|
+
# subscriber_api = SubscriberApi.new
|
610
|
+
# formatted_subscription = SubscriberApi.subscription_path("[PROJECT]", "[SUBSCRIPTION]")
|
611
|
+
# push_config = PushConfig.new
|
612
|
+
# subscriber_api.modify_push_config(formatted_subscription, push_config)
|
613
|
+
|
489
614
|
def modify_push_config \
|
490
615
|
subscription,
|
491
616
|
push_config,
|
@@ -496,6 +621,113 @@ module Google
|
|
496
621
|
)
|
497
622
|
@modify_push_config.call(req, options)
|
498
623
|
end
|
624
|
+
|
625
|
+
# Sets the access control policy on the specified resource. Replaces any
|
626
|
+
# existing policy.
|
627
|
+
#
|
628
|
+
# @param resource [String]
|
629
|
+
# REQUIRED: The resource for which the policy is being specified.
|
630
|
+
# +resource+ is usually specified as a path. For example, a Project
|
631
|
+
# resource is specified as +projects/{project}+.
|
632
|
+
# @param policy [Google::Iam::V1::Policy]
|
633
|
+
# REQUIRED: The complete policy to be applied to the +resource+. The size of
|
634
|
+
# the policy is limited to a few 10s of KB. An empty policy is a
|
635
|
+
# valid policy but certain Cloud Platform services (such as Projects)
|
636
|
+
# might reject them.
|
637
|
+
# @param options [Google::Gax::CallOptions]
|
638
|
+
# Overrides the default settings for this call, e.g, timeout,
|
639
|
+
# retries, etc.
|
640
|
+
# @return [Google::Iam::V1::Policy]
|
641
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
642
|
+
# @example
|
643
|
+
# require "google/cloud/pubsub/v1/subscriber_api"
|
644
|
+
#
|
645
|
+
# Policy = Google::Iam::V1::Policy
|
646
|
+
# SubscriberApi = Google::Cloud::Pubsub::V1::SubscriberApi
|
647
|
+
#
|
648
|
+
# subscriber_api = SubscriberApi.new
|
649
|
+
# formatted_resource = SubscriberApi.subscription_path("[PROJECT]", "[SUBSCRIPTION]")
|
650
|
+
# policy = Policy.new
|
651
|
+
# response = subscriber_api.set_iam_policy(formatted_resource, policy)
|
652
|
+
|
653
|
+
def set_iam_policy \
|
654
|
+
resource,
|
655
|
+
policy,
|
656
|
+
options: nil
|
657
|
+
req = Google::Iam::V1::SetIamPolicyRequest.new(
|
658
|
+
resource: resource,
|
659
|
+
policy: policy
|
660
|
+
)
|
661
|
+
@set_iam_policy.call(req, options)
|
662
|
+
end
|
663
|
+
|
664
|
+
# Gets the access control policy for a resource.
|
665
|
+
# Returns an empty policy if the resource exists and does not have a policy
|
666
|
+
# set.
|
667
|
+
#
|
668
|
+
# @param resource [String]
|
669
|
+
# REQUIRED: The resource for which the policy is being requested.
|
670
|
+
# +resource+ is usually specified as a path. For example, a Project
|
671
|
+
# resource is specified as +projects/{project}+.
|
672
|
+
# @param options [Google::Gax::CallOptions]
|
673
|
+
# Overrides the default settings for this call, e.g, timeout,
|
674
|
+
# retries, etc.
|
675
|
+
# @return [Google::Iam::V1::Policy]
|
676
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
677
|
+
# @example
|
678
|
+
# require "google/cloud/pubsub/v1/subscriber_api"
|
679
|
+
#
|
680
|
+
# SubscriberApi = Google::Cloud::Pubsub::V1::SubscriberApi
|
681
|
+
#
|
682
|
+
# subscriber_api = SubscriberApi.new
|
683
|
+
# formatted_resource = SubscriberApi.subscription_path("[PROJECT]", "[SUBSCRIPTION]")
|
684
|
+
# response = subscriber_api.get_iam_policy(formatted_resource)
|
685
|
+
|
686
|
+
def get_iam_policy \
|
687
|
+
resource,
|
688
|
+
options: nil
|
689
|
+
req = Google::Iam::V1::GetIamPolicyRequest.new(
|
690
|
+
resource: resource
|
691
|
+
)
|
692
|
+
@get_iam_policy.call(req, options)
|
693
|
+
end
|
694
|
+
|
695
|
+
# Returns permissions that a caller has on the specified resource.
|
696
|
+
#
|
697
|
+
# @param resource [String]
|
698
|
+
# REQUIRED: The resource for which the policy detail is being requested.
|
699
|
+
# +resource+ is usually specified as a path. For example, a Project
|
700
|
+
# resource is specified as +projects/{project}+.
|
701
|
+
# @param permissions [Array<String>]
|
702
|
+
# The set of permissions to check for the +resource+. Permissions with
|
703
|
+
# wildcards (such as '*' or 'storage.*') are not allowed. For more
|
704
|
+
# information see
|
705
|
+
# {IAM Overview}[https://cloud.google.com/iam/docs/overview#permissions].
|
706
|
+
# @param options [Google::Gax::CallOptions]
|
707
|
+
# Overrides the default settings for this call, e.g, timeout,
|
708
|
+
# retries, etc.
|
709
|
+
# @return [Google::Iam::V1::TestIamPermissionsResponse]
|
710
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
711
|
+
# @example
|
712
|
+
# require "google/cloud/pubsub/v1/subscriber_api"
|
713
|
+
#
|
714
|
+
# SubscriberApi = Google::Cloud::Pubsub::V1::SubscriberApi
|
715
|
+
#
|
716
|
+
# subscriber_api = SubscriberApi.new
|
717
|
+
# formatted_resource = SubscriberApi.subscription_path("[PROJECT]", "[SUBSCRIPTION]")
|
718
|
+
# permissions = []
|
719
|
+
# response = subscriber_api.test_iam_permissions(formatted_resource, permissions)
|
720
|
+
|
721
|
+
def test_iam_permissions \
|
722
|
+
resource,
|
723
|
+
permissions,
|
724
|
+
options: nil
|
725
|
+
req = Google::Iam::V1::TestIamPermissionsRequest.new(
|
726
|
+
resource: resource,
|
727
|
+
permissions: permissions
|
728
|
+
)
|
729
|
+
@test_iam_permissions.call(req, options)
|
730
|
+
end
|
499
731
|
end
|
500
732
|
end
|
501
733
|
end
|