google-cloud-pubsub 0.34.1 → 0.35.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.
@@ -133,7 +133,7 @@ module Google
133
133
  def all request_limit: nil
134
134
  request_limit = request_limit.to_i if request_limit
135
135
  unless block_given?
136
- return enum_for(:all, request_limit: request_limit)
136
+ return enum_for :all, request_limit: request_limit
137
137
  end
138
138
  results = self
139
139
  loop do
@@ -0,0 +1,244 @@
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
+
16
+ require "google/pubsub/v1/pubsub_pb"
17
+
18
+ module Google
19
+ module Cloud
20
+ module PubSub
21
+ class Subscription
22
+ ##
23
+ # Configuration for a push delivery endpoint.
24
+ #
25
+ # @example
26
+ # require "google/cloud/pubsub"
27
+ #
28
+ # pubsub = Google::Cloud::PubSub.new
29
+ #
30
+ # sub = pubsub.subscription "my-topic-sub"
31
+ # sub.push_config.endpoint #=> "http://example.com/callback"
32
+ # sub.push_config.authentication.email #=> "user@example.com"
33
+ # sub.push_config.authentication.audience #=> "client-12345"
34
+ #
35
+ # @example Update the push configuration by passing a block:
36
+ # require "google/cloud/pubsub"
37
+ #
38
+ # pubsub = Google::Cloud::PubSub.new
39
+ # sub = pubsub.subscription "my-subscription"
40
+ #
41
+ # sub.push_config do |pc|
42
+ # pc.endpoint = "http://example.net/callback"
43
+ # pc.set_oidc_token "user@example.net", "client-67890"
44
+ # end
45
+ #
46
+ class PushConfig
47
+ ##
48
+ # @private
49
+ def initialize
50
+ @grpc = Google::Cloud::PubSub::V1::PushConfig.new
51
+ end
52
+
53
+ ##
54
+ # A URL locating the endpoint to which messages should be pushed. For
55
+ # example, a Webhook endpoint might use "https://example.com/push".
56
+ #
57
+ # @return [String]
58
+ def endpoint
59
+ @grpc.push_endpoint
60
+ end
61
+
62
+ ##
63
+ # Sets the URL locating the endpoint to which messages should be
64
+ # pushed. For example, a Webhook endpoint might use
65
+ # "https://example.com/push".
66
+ #
67
+ # @param [String, nil] new_endpoint New URL value
68
+ def endpoint= new_endpoint
69
+ @grpc.push_endpoint = String new_endpoint
70
+ end
71
+
72
+ ##
73
+ # The authentication method used by push endpoints to verify the
74
+ # source of push requests.
75
+ #
76
+ # @return [OidcToken, nil] An OIDC JWT token if specified, `nil`
77
+ # otherwise.
78
+ def authentication
79
+ return nil unless @grpc.authentication_method == :oidc_token
80
+
81
+ OidcToken.from_grpc @grpc.oidc_token
82
+ end
83
+
84
+ ##
85
+ # Sets the authentication method used by push endpoints to verify the
86
+ # source of push requests.
87
+ #
88
+ # @param [OidcToken, nil] new_auth An authentication value.
89
+ def authentication= new_auth
90
+ if new_auth.nil?
91
+ @grpc.oidc_token = nil
92
+ else
93
+ raise ArgumentError unless new_auth.is_a? OidcToken
94
+
95
+ @grpc.oidc_token = new_auth.to_grpc
96
+ end
97
+ end
98
+
99
+ ##
100
+ # Checks whether authentication is an {OidcToken}.
101
+ #
102
+ # @return [Boolean]
103
+ def oidc_token?
104
+ authentication.is_a? OidcToken
105
+ end
106
+
107
+ ##
108
+ # Sets the authentication method to use an {OidcToken}.
109
+ #
110
+ # @param [String] email Service account email.
111
+ # @param [String] audience Audience to be used.
112
+ def set_oidc_token email, audience
113
+ oidc_token = OidcToken.new.tap do |token|
114
+ token.email = email
115
+ token.audience = audience
116
+ end
117
+ self.authentication = oidc_token
118
+ end
119
+
120
+ ##
121
+ # The format of the pushed message. This attribute indicates the
122
+ # version of the data expected by the endpoint. This controls the
123
+ # shape of the pushed message (i.e., its fields and metadata). The
124
+ # endpoint version is based on the version of the Pub/Sub API.
125
+ #
126
+ # If not present during the Subscription creation, it will default to
127
+ # the version of the API used to make such call.
128
+ #
129
+ # The possible values for this attribute are:
130
+ #
131
+ # * `v1beta1`: uses the push format defined in the v1beta1 Pub/Sub
132
+ # API.
133
+ # * `v1` or `v1beta2`: uses the push format defined in the v1 Pub/Sub
134
+ # API.
135
+ #
136
+ # @return [String]
137
+ def version
138
+ @grpc.attributes["x-goog-version"]
139
+ end
140
+
141
+ ##
142
+ # Sets the format of the pushed message.
143
+ #
144
+ # The possible values for this attribute are:
145
+ #
146
+ # * `v1beta1`: uses the push format defined in the v1beta1 Pub/Sub
147
+ # API.
148
+ # * `v1` or `v1beta2`: uses the push format defined in the v1 Pub/Sub
149
+ # API.
150
+ #
151
+ # @param [String, nil] new_version The new version value.
152
+ def version= new_version
153
+ if new_version.nil?
154
+ @grpc.attributes.delete "x-goog-version"
155
+ else
156
+ @grpc.attributes["x-goog-version"] = new_version
157
+ end
158
+ end
159
+
160
+ ##
161
+ # @private
162
+ def to_grpc
163
+ @grpc
164
+ end
165
+
166
+ ##
167
+ # @private
168
+ def self.from_grpc grpc
169
+ new.tap do |pc|
170
+ pc.instance_variable_set :@grpc, grpc.dup if grpc
171
+ end
172
+ end
173
+
174
+ ##
175
+ # Contains information needed for generating an [OpenID Connect
176
+ # token](https://developers.google.com/identity/protocols/OpenIDConnect).
177
+ class OidcToken
178
+ ##
179
+ # @private
180
+ def initialize
181
+ @grpc = Google::Cloud::PubSub::V1::PushConfig::OidcToken.new
182
+ end
183
+
184
+ ##
185
+ # Service account email to be used for generating the OIDC token.
186
+ #
187
+ # @return [String]
188
+ def email
189
+ @grpc.service_account_email
190
+ end
191
+
192
+ ##
193
+ # Service account email to be used for generating the OIDC token.
194
+ #
195
+ # @param [String] new_email New service account email value.
196
+ def email= new_email
197
+ @grpc.service_account_email = new_email
198
+ end
199
+
200
+ ##
201
+ # Audience to be used when generating OIDC token. The audience claim
202
+ # identifies the recipients that the JWT is intended for. The
203
+ # audience value is a single case-sensitive string.
204
+ #
205
+ # Having multiple values (array) for the audience field is not
206
+ # supported.
207
+ #
208
+ # More info about the OIDC JWT token audience here:
209
+ # https://tools.ietf.org/html/rfc7519#section-4.1.3
210
+ #
211
+ # @return [String]
212
+ def audience
213
+ @grpc.audience
214
+ end
215
+
216
+ ##
217
+ # Sets the audience to be used when generating OIDC token.
218
+ #
219
+ # @param [String] new_audience New audience value.
220
+ def audience= new_audience
221
+ @grpc.audience = new_audience
222
+ end
223
+
224
+ ##
225
+ # @private
226
+ def to_grpc
227
+ @grpc
228
+ end
229
+
230
+ ##
231
+ # @private
232
+ def self.from_grpc grpc
233
+ grpc ||= Google::Cloud::PubSub::V1::PushConfig::OidcToken.new
234
+
235
+ new.tap do |pc|
236
+ pc.instance_variable_set :@grpc, grpc.dup
237
+ end
238
+ end
239
+ end
240
+ end
241
+ end
242
+ end
243
+ end
244
+ end
@@ -422,7 +422,7 @@ module Google
422
422
  def publish_async data = nil, attributes = {}, &block
423
423
  ensure_service!
424
424
 
425
- @async_publisher ||= AsyncPublisher.new(name, service, @async_opts)
425
+ @async_publisher ||= AsyncPublisher.new name, service, @async_opts
426
426
  @async_publisher.publish data, attributes, &block
427
427
  end
428
428
 
@@ -606,6 +606,27 @@ module Google
606
606
  !@grpc.nil?
607
607
  end
608
608
 
609
+ ##
610
+ # Reloads the topic with current data from the Pub/Sub service.
611
+ #
612
+ # @return [Google::Cloud::PubSub::Topic] Returns the reloaded topic
613
+ #
614
+ # @example
615
+ # require "google/cloud/pubsub"
616
+ #
617
+ # pubsub = Google::Cloud::PubSub.new
618
+ #
619
+ # topic = pubsub.topic "my-topic"
620
+ # topic.reload!
621
+ #
622
+ def reload!
623
+ ensure_service!
624
+ @grpc = service.get_topic name
625
+ @resource_name = nil
626
+ self
627
+ end
628
+ alias refresh! reload!
629
+
609
630
  ##
610
631
  # @private New Topic from a Google::Cloud::PubSub::V1::Topic object.
611
632
  def self.from_grpc grpc, service, async: nil
@@ -638,8 +659,7 @@ module Google
638
659
  # Ensures a Google::Cloud::PubSub::V1::Topic object exists.
639
660
  def ensure_grpc!
640
661
  ensure_service!
641
- @grpc = service.get_topic name if reference?
642
- @resource_name = nil
662
+ reload! if reference?
643
663
  end
644
664
 
645
665
  ##
@@ -127,7 +127,7 @@ module Google
127
127
  def all request_limit: nil
128
128
  request_limit = request_limit.to_i if request_limit
129
129
  unless block_given?
130
- return enum_for(:all, request_limit: request_limit)
130
+ return enum_for :all, request_limit: request_limit
131
131
  end
132
132
  results = self
133
133
  loop do
@@ -83,57 +83,49 @@ module Google
83
83
  # describe the updated values, the API ignores the values of all
84
84
  # fields not covered by the mask.
85
85
  #
86
- # If a repeated field is specified for an update operation, the existing
87
- # repeated values in the target resource will be overwritten by the new values.
88
- # Note that a repeated field is only allowed in the last position of a `paths`
89
- # string.
86
+ # If a repeated field is specified for an update operation, new values will
87
+ # be appended to the existing repeated field in the target resource. Note that
88
+ # a repeated field is only allowed in the last position of a `paths` string.
90
89
  #
91
90
  # If a sub-message is specified in the last position of the field mask for an
92
- # update operation, then the existing sub-message in the target resource is
93
- # overwritten. Given the target message:
91
+ # update operation, then new value will be merged into the existing sub-message
92
+ # in the target resource.
93
+ #
94
+ # For example, given the target message:
94
95
  #
95
96
  # f {
96
97
  # b {
97
- # d : 1
98
- # x : 2
98
+ # d: 1
99
+ # x: 2
99
100
  # }
100
- # c : 1
101
+ # c: [1]
101
102
  # }
102
103
  #
103
104
  # And an update message:
104
105
  #
105
106
  # f {
106
107
  # b {
107
- # d : 10
108
+ # d: 10
108
109
  # }
110
+ # c: [2]
109
111
  # }
110
112
  #
111
113
  # then if the field mask is:
112
114
  #
113
- # paths: "f.b"
115
+ # paths: ["f.b", "f.c"]
114
116
  #
115
117
  # then the result will be:
116
118
  #
117
119
  # f {
118
120
  # b {
119
- # d : 10
121
+ # d: 10
122
+ # x: 2
120
123
  # }
121
- # c : 1
124
+ # c: [1, 2]
122
125
  # }
123
126
  #
124
- # However, if the update mask was:
125
- #
126
- # paths: "f.b.d"
127
- #
128
- # then the result would be:
129
- #
130
- # f {
131
- # b {
132
- # d : 10
133
- # x : 2
134
- # }
135
- # c : 1
136
- # }
127
+ # An implementation may provide options to override this default behavior for
128
+ # repeated and message fields.
137
129
  #
138
130
  # In order to reset a field's value to the default, the field must
139
131
  # be in the mask and set to the default value in the provided resource.
@@ -15,17 +15,19 @@
15
15
 
16
16
  module Google
17
17
  module Protobuf
18
- # A Timestamp represents a point in time independent of any time zone
19
- # or calendar, represented as seconds and fractions of seconds at
20
- # nanosecond resolution in UTC Epoch time. It is encoded using the
21
- # Proleptic Gregorian Calendar which extends the Gregorian calendar
22
- # backwards to year one. It is encoded assuming all minutes are 60
23
- # seconds long, i.e. leap seconds are "smeared" so that no leap second
24
- # table is needed for interpretation. Range is from
25
- # 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z.
26
- # By restricting to that range, we ensure that we can convert to
27
- # and from RFC 3339 date strings.
28
- # See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt).
18
+ # A Timestamp represents a point in time independent of any time zone or local
19
+ # calendar, encoded as a count of seconds and fractions of seconds at
20
+ # nanosecond resolution. The count is relative to an epoch at UTC midnight on
21
+ # January 1, 1970, in the proleptic Gregorian calendar which extends the
22
+ # Gregorian calendar backwards to year one.
23
+ #
24
+ # All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap
25
+ # second table is needed for interpretation, using a [24-hour linear
26
+ # smear](https://developers.google.com/time/smear).
27
+ #
28
+ # The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By
29
+ # restricting to that range, we ensure that we can convert to and from [RFC
30
+ # 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings.
29
31
  #
30
32
  # = Examples
31
33
  #
@@ -86,12 +88,12 @@ module Google
86
88
  # 01:30 UTC on January 15, 2017.
87
89
  #
88
90
  # In JavaScript, one can convert a Date object to this format using the
89
- # standard [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString]
91
+ # standard [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
90
92
  # method. In Python, a standard `datetime.datetime` object can be converted
91
93
  # to this format using [`strftime`](https://docs.python.org/2/library/time.html#time.strftime)
92
94
  # with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one
93
95
  # can use the Joda Time's [`ISODateTimeFormat.dateTime()`](
94
- # http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime--
96
+ # http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D
95
97
  # ) to obtain a formatter capable of generating timestamps in this format.
96
98
  # @!attribute [rw] seconds
97
99
  # @return [Integer]
@@ -76,6 +76,15 @@ module Google
76
76
  # The time at which the message was published, populated by the server when
77
77
  # it receives the `Publish` call. It must not be populated by the
78
78
  # publisher in a `Publish` call.
79
+ # @!attribute [rw] ordering_key
80
+ # @return [String]
81
+ # Identifies related messages for which publish order should be respected.
82
+ # If a `Subscription` has `enable_message_ordering` set to `true`, messages
83
+ # published with the same `ordering_key` value will be delivered to
84
+ # subscribers in the order in which they are received by the Pub/Sub system.
85
+ # <b>EXPERIMENTAL:</b> This feature is part of a closed alpha release. This
86
+ # API might be changed in backward-incompatible ways and is not recommended
87
+ # for production use. It is not subject to any SLA or deprecation policy.
79
88
  class PubsubMessage; end
80
89
 
81
90
  # Request for the GetTopic method.
@@ -254,7 +263,8 @@ module Google
254
263
  # messages are not expunged from the subscription's backlog, even if they are
255
264
  # acknowledged, until they fall out of the `message_retention_duration`
256
265
  # window. This must be true if you would like to
257
- # <a href="https://cloud.google.com/pubsub/docs/replay-overview#seek_to_a_time">
266
+ # <a
267
+ # href="https://cloud.google.com/pubsub/docs/replay-overview#seek_to_a_time">
258
268
  # Seek to a timestamp</a>.
259
269
  # <br><br>
260
270
  # <b>BETA:</b> This feature is part of a beta release. This API might be
@@ -275,6 +285,15 @@ module Google
275
285
  # @return [Hash{String => String}]
276
286
  # See <a href="https://cloud.google.com/pubsub/docs/labels"> Creating and
277
287
  # managing labels</a>.
288
+ # @!attribute [rw] enable_message_ordering
289
+ # @return [true, false]
290
+ # If true, messages published with the same `ordering_key` in `PubsubMessage`
291
+ # will be delivered to the subscribers in the order in which they
292
+ # are received by the Pub/Sub system. Otherwise, they may be delivered in
293
+ # any order.
294
+ # <b>EXPERIMENTAL:</b> This feature is part of a closed alpha release. This
295
+ # API might be changed in backward-incompatible ways and is not recommended
296
+ # for production use. It is not subject to any SLA or deprecation policy.
278
297
  # @!attribute [rw] expiration_policy
279
298
  # @return [Google::Cloud::PubSub::V1::ExpirationPolicy]
280
299
  # A policy that specifies the conditions for this subscription's expiration.
@@ -328,7 +347,32 @@ module Google
328
347
  #
329
348
  # * `v1beta1`: uses the push format defined in the v1beta1 Pub/Sub API.
330
349
  # * `v1` or `v1beta2`: uses the push format defined in the v1 Pub/Sub API.
331
- class PushConfig; end
350
+ # @!attribute [rw] oidc_token
351
+ # @return [Google::Cloud::PubSub::V1::PushConfig::OidcToken]
352
+ # If specified, Pub/Sub will generate and attach an OIDC JWT token as an
353
+ # `Authorization` header in the HTTP request for every pushed message.
354
+ class PushConfig
355
+ # Contains information needed for generating an
356
+ # [OpenID Connect
357
+ # token](https://developers.google.com/identity/protocols/OpenIDConnect).
358
+ # @!attribute [rw] service_account_email
359
+ # @return [String]
360
+ # [Service account
361
+ # email](https://cloud.google.com/iam/docs/service-accounts)
362
+ # to be used for generating the OIDC token. The caller (for
363
+ # CreateSubscription, UpdateSubscription, and ModifyPushConfig calls) must
364
+ # have the iam.serviceAccounts.actAs permission for the service account.
365
+ # See https://cloud.google.com/iam/docs/understanding-roles#service-accounts-roles.
366
+ # @!attribute [rw] audience
367
+ # @return [String]
368
+ # Audience to be used when generating OIDC token. The audience claim
369
+ # identifies the recipients that the JWT is intended for. The audience
370
+ # value is a single case-sensitive string. Having multiple values (array)
371
+ # for the audience field is not supported. More info about the OIDC JWT
372
+ # token audience here: https://tools.ietf.org/html/rfc7519#section-4.1.3
373
+ # Note: if not specified, the Push endpoint URL will be used.
374
+ class OidcToken; end
375
+ end
332
376
 
333
377
  # A message and its corresponding acknowledgment ID.
334
378
  # @!attribute [rw] ack_id
@@ -513,9 +557,9 @@ module Google
513
557
  class StreamingPullResponse; end
514
558
 
515
559
  # Request for the `CreateSnapshot` method.<br><br>
516
- # <b>BETA:</b> This feature is part of a beta release. This API might be changed in
517
- # backward-incompatible ways and is not recommended for production use.
518
- # It is not subject to any SLA or deprecation policy.
560
+ # <b>BETA:</b> This feature is part of a beta release. This API might be
561
+ # changed in backward-incompatible ways and is not recommended for production
562
+ # use. It is not subject to any SLA or deprecation policy.
519
563
  # @!attribute [rw] name
520
564
  # @return [String]
521
565
  # Optional user-provided name for this snapshot.