gcloud 0.6.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/AUTHENTICATION.md +13 -9
- data/CHANGELOG.md +8 -3
- data/OVERVIEW.md +46 -8
- data/lib/gcloud.rb +123 -117
- data/lib/gcloud/backoff.rb +43 -15
- data/lib/gcloud/bigquery.rb +211 -195
- data/lib/gcloud/bigquery/connection.rb +9 -9
- data/lib/gcloud/bigquery/copy_job.rb +15 -16
- data/lib/gcloud/bigquery/credentials.rb +3 -3
- data/lib/gcloud/bigquery/data.rb +12 -11
- data/lib/gcloud/bigquery/dataset.rb +162 -216
- data/lib/gcloud/bigquery/dataset/access.rb +59 -43
- data/lib/gcloud/bigquery/dataset/list.rb +3 -3
- data/lib/gcloud/bigquery/errors.rb +9 -5
- data/lib/gcloud/bigquery/extract_job.rb +18 -18
- data/lib/gcloud/bigquery/insert_response.rb +7 -4
- data/lib/gcloud/bigquery/job.rb +48 -44
- data/lib/gcloud/bigquery/job/list.rb +3 -3
- data/lib/gcloud/bigquery/load_job.rb +24 -25
- data/lib/gcloud/bigquery/project.rb +145 -204
- data/lib/gcloud/bigquery/query_data.rb +10 -9
- data/lib/gcloud/bigquery/query_job.rb +23 -32
- data/lib/gcloud/bigquery/table.rb +238 -280
- data/lib/gcloud/bigquery/table/list.rb +3 -3
- data/lib/gcloud/bigquery/table/schema.rb +79 -87
- data/lib/gcloud/bigquery/view.rb +69 -82
- data/lib/gcloud/credentials.rb +3 -9
- data/lib/gcloud/datastore.rb +194 -170
- data/lib/gcloud/datastore/connection.rb +12 -8
- data/lib/gcloud/datastore/credentials.rb +6 -4
- data/lib/gcloud/datastore/dataset.rb +74 -141
- data/lib/gcloud/datastore/dataset/lookup_results.rb +6 -4
- data/lib/gcloud/datastore/dataset/query_results.rb +6 -4
- data/lib/gcloud/datastore/entity.rb +81 -76
- data/lib/gcloud/datastore/errors.rb +10 -8
- data/lib/gcloud/datastore/key.rb +41 -77
- data/lib/gcloud/datastore/properties.rb +3 -3
- data/lib/gcloud/datastore/proto.rb +7 -4
- data/lib/gcloud/datastore/query.rb +26 -3
- data/lib/gcloud/datastore/transaction.rb +12 -8
- data/lib/gcloud/dns.rb +180 -152
- data/lib/gcloud/dns/change.rb +16 -16
- data/lib/gcloud/dns/change/list.rb +3 -3
- data/lib/gcloud/dns/connection.rb +9 -10
- data/lib/gcloud/dns/credentials.rb +3 -3
- data/lib/gcloud/dns/errors.rb +9 -5
- data/lib/gcloud/dns/importer.rb +17 -23
- data/lib/gcloud/dns/project.rb +42 -64
- data/lib/gcloud/dns/record.rb +58 -46
- data/lib/gcloud/dns/record/list.rb +6 -7
- data/lib/gcloud/dns/zone.rb +198 -289
- data/lib/gcloud/dns/zone/list.rb +3 -3
- data/lib/gcloud/dns/zone/transaction.rb +56 -72
- data/lib/gcloud/errors.rb +174 -3
- data/lib/gcloud/gce.rb +3 -4
- data/lib/gcloud/grpc_utils.rb +76 -0
- data/lib/gcloud/logging.rb +308 -0
- data/lib/gcloud/logging/credentials.rb +29 -0
- data/lib/gcloud/logging/entry.rb +303 -0
- data/lib/gcloud/logging/entry/http_request.rb +141 -0
- data/lib/gcloud/logging/entry/list.rb +111 -0
- data/lib/gcloud/logging/entry/operation.rb +90 -0
- data/lib/gcloud/logging/logger.rb +307 -0
- data/lib/gcloud/logging/metric.rb +175 -0
- data/lib/gcloud/logging/metric/list.rb +98 -0
- data/lib/gcloud/logging/project.rb +650 -0
- data/lib/gcloud/logging/resource.rb +95 -0
- data/lib/gcloud/logging/resource_descriptor.rb +140 -0
- data/lib/gcloud/logging/resource_descriptor/list.rb +78 -0
- data/lib/gcloud/logging/service.rb +258 -0
- data/lib/gcloud/logging/sink.rb +233 -0
- data/lib/gcloud/logging/sink/list.rb +97 -0
- data/lib/gcloud/pubsub.rb +241 -199
- data/lib/gcloud/pubsub/credentials.rb +3 -3
- data/lib/gcloud/pubsub/message.rb +26 -20
- data/lib/gcloud/pubsub/project.rb +166 -233
- data/lib/gcloud/pubsub/received_message.rb +28 -38
- data/lib/gcloud/pubsub/service.rb +323 -0
- data/lib/gcloud/pubsub/subscription.rb +172 -242
- data/lib/gcloud/pubsub/subscription/list.rb +11 -9
- data/lib/gcloud/pubsub/topic.rb +152 -271
- data/lib/gcloud/pubsub/topic/batch.rb +66 -0
- data/lib/gcloud/pubsub/topic/list.rb +9 -7
- data/lib/gcloud/resource_manager.rb +158 -138
- data/lib/gcloud/resource_manager/connection.rb +6 -5
- data/lib/gcloud/resource_manager/credentials.rb +3 -3
- data/lib/gcloud/resource_manager/errors.rb +9 -5
- data/lib/gcloud/resource_manager/manager.rb +54 -86
- data/lib/gcloud/resource_manager/project.rb +69 -88
- data/lib/gcloud/resource_manager/project/list.rb +4 -5
- data/lib/gcloud/resource_manager/project/updater.rb +12 -14
- data/lib/gcloud/search.rb +158 -135
- data/lib/gcloud/search/api_client.rb +7 -7
- data/lib/gcloud/search/connection.rb +8 -8
- data/lib/gcloud/search/credentials.rb +3 -3
- data/lib/gcloud/search/document.rb +64 -87
- data/lib/gcloud/search/document/list.rb +5 -5
- data/lib/gcloud/search/errors.rb +9 -5
- data/lib/gcloud/search/field_value.rb +32 -38
- data/lib/gcloud/search/field_values.rb +50 -80
- data/lib/gcloud/search/fields.rb +44 -65
- data/lib/gcloud/search/index.rb +163 -204
- data/lib/gcloud/search/index/list.rb +5 -5
- data/lib/gcloud/search/project.rb +31 -47
- data/lib/gcloud/search/result.rb +27 -31
- data/lib/gcloud/search/result/list.rb +6 -6
- data/lib/gcloud/storage.rb +224 -190
- data/lib/gcloud/storage/bucket.rb +202 -227
- data/lib/gcloud/storage/bucket/acl.rb +83 -170
- data/lib/gcloud/storage/bucket/cors.rb +31 -34
- data/lib/gcloud/storage/bucket/list.rb +3 -3
- data/lib/gcloud/storage/connection.rb +11 -7
- data/lib/gcloud/storage/credentials.rb +3 -3
- data/lib/gcloud/storage/errors.rb +11 -8
- data/lib/gcloud/storage/file.rb +129 -171
- data/lib/gcloud/storage/file/acl.rb +51 -99
- data/lib/gcloud/storage/file/list.rb +3 -3
- data/lib/gcloud/storage/file/verifier.rb +3 -2
- data/lib/gcloud/storage/project.rb +111 -132
- data/lib/gcloud/upload.rb +4 -7
- data/lib/gcloud/version.rb +2 -4
- data/lib/google/api/annotations.rb +14 -0
- data/lib/google/api/http.rb +30 -0
- data/lib/google/api/label.rb +24 -0
- data/lib/google/api/monitored_resource.rb +25 -0
- data/lib/google/datastore/v1beta3/datastore.rb +115 -0
- data/lib/google/datastore/v1beta3/datastore_services.rb +33 -0
- data/lib/google/datastore/v1beta3/entity.rb +63 -0
- data/lib/google/datastore/v1beta3/query.rb +128 -0
- data/lib/google/devtools/cloudtrace/v1/trace.rb +78 -0
- data/lib/google/devtools/cloudtrace/v1/trace_services.rb +32 -0
- data/lib/google/example/library/v1/library.rb +91 -0
- data/lib/google/example/library/v1/library_services.rb +40 -0
- data/lib/google/iam/v1/iam_policy.rb +33 -0
- data/lib/google/iam/v1/iam_policy_services.rb +30 -0
- data/lib/google/iam/v1/policy.rb +25 -0
- data/lib/google/logging/type/http_request.rb +28 -0
- data/lib/google/logging/type/log_severity.rb +27 -0
- data/lib/google/logging/v2/log_entry.rb +44 -0
- data/lib/google/logging/v2/logging.rb +56 -0
- data/lib/google/logging/v2/logging_config.rb +59 -0
- data/lib/google/logging/v2/logging_config_services.rb +32 -0
- data/lib/google/logging/v2/logging_metrics.rb +51 -0
- data/lib/google/logging/v2/logging_metrics_services.rb +32 -0
- data/lib/google/logging/v2/logging_services.rb +31 -0
- data/lib/google/longrunning/operations.rb +50 -0
- data/lib/google/longrunning/operations_services.rb +29 -0
- data/lib/google/protobuf/any.rb +17 -0
- data/lib/google/protobuf/api.rb +31 -0
- data/lib/google/protobuf/descriptor.rb +0 -0
- data/lib/google/protobuf/duration.rb +17 -0
- data/lib/google/protobuf/empty.rb +15 -0
- data/lib/google/protobuf/field_mask.rb +16 -0
- data/lib/google/protobuf/source_context.rb +16 -0
- data/lib/google/protobuf/struct.rb +35 -0
- data/lib/google/protobuf/timestamp.rb +17 -0
- data/lib/google/protobuf/type.rb +79 -0
- data/lib/google/protobuf/wrappers.rb +48 -0
- data/lib/google/pubsub/v1/pubsub.rb +129 -0
- data/lib/google/pubsub/v1/pubsub_services.rb +56 -0
- data/lib/google/pubsub/v1beta2/pubsub.rb +126 -0
- data/lib/google/pubsub/v1beta2/pubsub_services.rb +56 -0
- data/lib/google/rpc/code.rb +32 -0
- data/lib/google/rpc/error_details.rb +61 -0
- data/lib/google/rpc/status.rb +19 -0
- data/lib/google/type/color.rb +20 -0
- data/lib/google/type/date.rb +18 -0
- data/lib/google/type/dayofweek.rb +23 -0
- data/lib/google/type/latlng.rb +17 -0
- data/lib/google/type/money.rb +18 -0
- data/lib/google/type/timeofday.rb +19 -0
- metadata +101 -4
- data/lib/gcloud/pubsub/connection.rb +0 -295
- data/lib/gcloud/pubsub/errors.rb +0 -93
@@ -1,4 +1,3 @@
|
|
1
|
-
#--
|
2
1
|
# Copyright 2015 Google Inc. All rights reserved.
|
3
2
|
#
|
4
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -13,18 +12,20 @@
|
|
13
12
|
# See the License for the specific language governing permissions and
|
14
13
|
# limitations under the License.
|
15
14
|
|
16
|
-
|
15
|
+
|
16
|
+
require "gcloud/errors"
|
17
17
|
require "gcloud/pubsub/subscription/list"
|
18
18
|
require "gcloud/pubsub/received_message"
|
19
19
|
|
20
20
|
module Gcloud
|
21
21
|
module Pubsub
|
22
22
|
##
|
23
|
-
#
|
23
|
+
# # Subscription
|
24
24
|
#
|
25
25
|
# A named resource representing the stream of messages from a single,
|
26
|
-
# specific
|
26
|
+
# specific {Topic}, to be delivered to the subscribing application.
|
27
27
|
#
|
28
|
+
# @example
|
28
29
|
# require "gcloud"
|
29
30
|
#
|
30
31
|
# gcloud = Gcloud.new
|
@@ -36,31 +37,31 @@ module Gcloud
|
|
36
37
|
#
|
37
38
|
class Subscription
|
38
39
|
##
|
39
|
-
# The
|
40
|
-
attr_accessor :
|
40
|
+
# @private The gRPC Service object.
|
41
|
+
attr_accessor :service
|
41
42
|
|
42
43
|
##
|
43
|
-
# The Google
|
44
|
-
attr_accessor :
|
44
|
+
# @private The gRPC Google::Pubsub::V1::Subscription object.
|
45
|
+
attr_accessor :grpc
|
45
46
|
|
46
47
|
##
|
47
|
-
# Create an empty Subscription object.
|
48
|
-
def initialize
|
49
|
-
@
|
50
|
-
@
|
48
|
+
# @private Create an empty {Subscription} object.
|
49
|
+
def initialize
|
50
|
+
@service = nil
|
51
|
+
@grpc = Google::Pubsub::V1::Subscription.new
|
51
52
|
@name = nil
|
52
53
|
@exists = nil
|
53
54
|
end
|
54
55
|
|
55
56
|
##
|
56
|
-
# New lazy Topic object without making an HTTP request.
|
57
|
-
def self.new_lazy name,
|
57
|
+
# @private New lazy {Topic} object without making an HTTP request.
|
58
|
+
def self.new_lazy name, service, options = {}
|
58
59
|
sub = new.tap do |f|
|
59
|
-
f.
|
60
|
-
f.
|
60
|
+
f.grpc = nil
|
61
|
+
f.service = service
|
61
62
|
end
|
62
63
|
sub.instance_eval do
|
63
|
-
@name =
|
64
|
+
@name = service.subscription_path(name, options)
|
64
65
|
end
|
65
66
|
sub
|
66
67
|
end
|
@@ -68,18 +69,15 @@ module Gcloud
|
|
68
69
|
##
|
69
70
|
# The name of the subscription.
|
70
71
|
def name
|
71
|
-
@
|
72
|
+
@grpc ? @grpc.name : @name
|
72
73
|
end
|
73
74
|
|
74
75
|
##
|
75
|
-
# The Topic from which this subscription receives messages.
|
76
|
-
#
|
77
|
-
# === Returns
|
78
|
-
#
|
79
|
-
# Topic
|
76
|
+
# The {Topic} from which this subscription receives messages.
|
80
77
|
#
|
81
|
-
#
|
78
|
+
# @return [Topic]
|
82
79
|
#
|
80
|
+
# @example
|
83
81
|
# require "gcloud"
|
84
82
|
#
|
85
83
|
# gcloud = Gcloud.new
|
@@ -89,43 +87,43 @@ module Gcloud
|
|
89
87
|
# sub.topic.name #=> "projects/my-project/topics/my-topic"
|
90
88
|
#
|
91
89
|
def topic
|
92
|
-
|
93
|
-
Topic.new_lazy @
|
90
|
+
ensure_grpc!
|
91
|
+
Topic.new_lazy @grpc.topic, service
|
94
92
|
end
|
95
93
|
|
96
94
|
##
|
97
95
|
# This value is the maximum number of seconds after a subscriber receives
|
98
96
|
# a message before the subscriber should acknowledge the message.
|
99
97
|
def deadline
|
100
|
-
|
101
|
-
@
|
98
|
+
ensure_grpc!
|
99
|
+
@grpc.ack_deadline_seconds
|
102
100
|
end
|
103
101
|
|
104
102
|
##
|
105
103
|
# Returns the URL locating the endpoint to which messages should be
|
106
104
|
# pushed.
|
107
105
|
def endpoint
|
108
|
-
|
109
|
-
@
|
106
|
+
ensure_grpc!
|
107
|
+
@grpc.push_config.push_endpoint if @grpc.push_config
|
110
108
|
end
|
111
109
|
|
112
110
|
##
|
113
111
|
# Sets the URL locating the endpoint to which messages should be pushed.
|
114
112
|
def endpoint= new_endpoint
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
113
|
+
ensure_service!
|
114
|
+
service.modify_push_config name, new_endpoint, {}
|
115
|
+
@grpc.push_config = Google::Pubsub::V1::PushConfig.new(
|
116
|
+
push_endpoint: new_endpoint,
|
117
|
+
attributes: {}
|
118
|
+
) if @grpc
|
119
|
+
rescue GRPC::BadStatus => e
|
120
|
+
raise Error.from_error(e)
|
122
121
|
end
|
123
122
|
|
124
123
|
##
|
125
124
|
# Determines whether the subscription exists in the Pub/Sub service.
|
126
125
|
#
|
127
|
-
#
|
128
|
-
#
|
126
|
+
# @example
|
129
127
|
# require "gcloud"
|
130
128
|
#
|
131
129
|
# gcloud = Gcloud.new
|
@@ -135,22 +133,22 @@ module Gcloud
|
|
135
133
|
# sub.exists? #=> true
|
136
134
|
#
|
137
135
|
def exists?
|
138
|
-
# Always true if we have a
|
139
|
-
return true unless @
|
136
|
+
# Always true if we have a grpc object
|
137
|
+
return true unless @grpc.nil?
|
140
138
|
# If we have a value, return it
|
141
139
|
return @exists unless @exists.nil?
|
142
|
-
|
143
|
-
@exists = !@
|
144
|
-
rescue NotFoundError
|
140
|
+
ensure_grpc!
|
141
|
+
@exists = !@grpc.nil?
|
142
|
+
rescue Gcloud::NotFoundError
|
145
143
|
@exists = false
|
146
144
|
end
|
147
145
|
|
148
146
|
##
|
147
|
+
# @private
|
149
148
|
# Determines whether the subscription object was created with an
|
150
149
|
# HTTP call.
|
151
150
|
#
|
152
|
-
#
|
153
|
-
#
|
151
|
+
# @example
|
154
152
|
# require "gcloud"
|
155
153
|
#
|
156
154
|
# gcloud = Gcloud.new
|
@@ -159,20 +157,17 @@ module Gcloud
|
|
159
157
|
# sub = pubsub.get_subscription "my-topic-sub"
|
160
158
|
# sub.lazy? #=> false
|
161
159
|
#
|
162
|
-
def lazy?
|
163
|
-
@
|
160
|
+
def lazy?
|
161
|
+
@grpc.nil?
|
164
162
|
end
|
165
163
|
|
166
164
|
##
|
167
165
|
# Deletes an existing subscription.
|
168
166
|
# All pending messages in the subscription are immediately dropped.
|
169
167
|
#
|
170
|
-
#
|
171
|
-
#
|
172
|
-
# +true+ if the subscription was deleted.
|
173
|
-
#
|
174
|
-
# === Example
|
168
|
+
# @return [Boolean] Returns `true` if the subscription was deleted.
|
175
169
|
#
|
170
|
+
# @example
|
176
171
|
# require "gcloud"
|
177
172
|
#
|
178
173
|
# gcloud = Gcloud.new
|
@@ -182,42 +177,33 @@ module Gcloud
|
|
182
177
|
# sub.delete
|
183
178
|
#
|
184
179
|
def delete
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
fail ApiError.from_response(resp)
|
191
|
-
end
|
180
|
+
ensure_service!
|
181
|
+
service.delete_subscription name
|
182
|
+
return true
|
183
|
+
rescue GRPC::BadStatus => e
|
184
|
+
raise Error.from_error(e)
|
192
185
|
end
|
193
186
|
|
194
187
|
##
|
195
188
|
# Pulls messages from the server. Returns an empty list if there are no
|
196
189
|
# messages available in the backlog. Raises an ApiError with status
|
197
|
-
#
|
190
|
+
# `UNAVAILABLE` if there are too many concurrent pull requests pending
|
198
191
|
# for the given subscription.
|
199
192
|
#
|
200
|
-
#
|
201
|
-
#
|
202
|
-
#
|
203
|
-
#
|
204
|
-
#
|
205
|
-
#
|
206
|
-
# request
|
207
|
-
#
|
208
|
-
#
|
209
|
-
#
|
210
|
-
# is +100+, the maximum value is +1000+. (+Integer+)
|
211
|
-
# +autoack+::
|
212
|
-
# Automatically acknowledge the message as it is pulled. The default
|
213
|
-
# value is +false+. (+Boolean+)
|
214
|
-
#
|
215
|
-
# === Returns
|
193
|
+
# @param [Boolean] immediate When `true` the system will respond
|
194
|
+
# immediately even if it is not able to return messages. When `false`
|
195
|
+
# the system is allowed to wait until it can return least one message.
|
196
|
+
# No messages are returned when a request times out. The default value
|
197
|
+
# is `true`.
|
198
|
+
# @param [Integer] max The maximum number of messages to return for this
|
199
|
+
# request. The Pub/Sub system may return fewer than the number
|
200
|
+
# specified. The default value is `100`, the maximum value is `1000`.
|
201
|
+
# @param [Boolean] autoack Automatically acknowledge the message as it is
|
202
|
+
# pulled. The default value is `false`.
|
216
203
|
#
|
217
|
-
# Array
|
218
|
-
#
|
219
|
-
# === Examples
|
204
|
+
# @return [Array<Gcloud::Pubsub::ReceivedMessage>]
|
220
205
|
#
|
206
|
+
# @example
|
221
207
|
# require "gcloud"
|
222
208
|
#
|
223
209
|
# gcloud = Gcloud.new
|
@@ -226,8 +212,7 @@ module Gcloud
|
|
226
212
|
# sub = pubsub.subscription "my-topic-sub"
|
227
213
|
# sub.pull.each { |msg| msg.acknowledge! }
|
228
214
|
#
|
229
|
-
# A maximum number of messages returned can also be specified:
|
230
|
-
#
|
215
|
+
# @example A maximum number of messages returned can also be specified:
|
231
216
|
# require "gcloud"
|
232
217
|
#
|
233
218
|
# gcloud = Gcloud.new
|
@@ -236,9 +221,7 @@ module Gcloud
|
|
236
221
|
# sub = pubsub.subscription "my-topic-sub", max: 10
|
237
222
|
# sub.pull.each { |msg| msg.acknowledge! }
|
238
223
|
#
|
239
|
-
# The call can block until messages are available
|
240
|
-
# +:immediate+ option to +false+:
|
241
|
-
#
|
224
|
+
# @example The call can block until messages are available:
|
242
225
|
# require "gcloud"
|
243
226
|
#
|
244
227
|
# gcloud = Gcloud.new
|
@@ -249,18 +232,16 @@ module Gcloud
|
|
249
232
|
# msgs.each { |msg| msg.acknowledge! }
|
250
233
|
#
|
251
234
|
def pull immediate: true, max: 100, autoack: false
|
252
|
-
|
235
|
+
ensure_service!
|
253
236
|
options = { immediate: immediate, max: max }
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
ReceivedMessage.from_gapi gapi, self
|
258
|
-
end
|
259
|
-
acknowledge messages if autoack
|
260
|
-
messages
|
261
|
-
else
|
262
|
-
fail ApiError.from_response(resp)
|
237
|
+
list_grpc = service.pull name, options
|
238
|
+
messages = Array(list_grpc.received_messages).map do |msg_grpc|
|
239
|
+
ReceivedMessage.from_grpc msg_grpc, self
|
263
240
|
end
|
241
|
+
acknowledge messages if autoack
|
242
|
+
messages
|
243
|
+
rescue GRPC::BadStatus => e
|
244
|
+
raise Error.from_error(e)
|
264
245
|
rescue Faraday::TimeoutError
|
265
246
|
[]
|
266
247
|
end
|
@@ -271,22 +252,15 @@ module Gcloud
|
|
271
252
|
#
|
272
253
|
# subscription.pull immediate: false
|
273
254
|
#
|
274
|
-
#
|
275
|
-
#
|
276
|
-
#
|
277
|
-
#
|
278
|
-
#
|
279
|
-
# is +100+, the maximum value is +1000+. (+Integer+)
|
280
|
-
# +autoack+::
|
281
|
-
# Automatically acknowledge the message as it is pulled. The default
|
282
|
-
# value is +false+. (+Boolean+)
|
283
|
-
#
|
284
|
-
# === Returns
|
255
|
+
# @param [Integer] max The maximum number of messages to return for this
|
256
|
+
# request. The Pub/Sub system may return fewer than the number
|
257
|
+
# specified. The default value is `100`, the maximum value is `1000`.
|
258
|
+
# @param [Boolean] autoack Automatically acknowledge the message as it is
|
259
|
+
# pulled. The default value is `false`.
|
285
260
|
#
|
286
|
-
# Array
|
287
|
-
#
|
288
|
-
# === Example
|
261
|
+
# @return [Array<Gcloud::Pubsub::ReceivedMessage>]
|
289
262
|
#
|
263
|
+
# @example
|
290
264
|
# require "gcloud"
|
291
265
|
#
|
292
266
|
# gcloud = Gcloud.new
|
@@ -304,22 +278,18 @@ module Gcloud
|
|
304
278
|
# Poll the backend for new messages. This runs a loop to ping the API,
|
305
279
|
# blocking indefinitely, yielding retrieved messages as they are received.
|
306
280
|
#
|
307
|
-
#
|
308
|
-
#
|
309
|
-
#
|
310
|
-
#
|
311
|
-
#
|
312
|
-
#
|
313
|
-
#
|
314
|
-
#
|
315
|
-
#
|
316
|
-
#
|
317
|
-
#
|
318
|
-
#
|
319
|
-
# (+Number+)
|
320
|
-
#
|
321
|
-
# === Examples
|
322
|
-
#
|
281
|
+
# @param [Integer] max The maximum number of messages to return for this
|
282
|
+
# request. The Pub/Sub system may return fewer than the number
|
283
|
+
# specified. The default value is `100`, the maximum value is `1000`.
|
284
|
+
# @param [Boolean] autoack Automatically acknowledge the message as it is
|
285
|
+
# pulled. The default value is `false`.
|
286
|
+
# @param [Number] delay The number of seconds to pause between requests
|
287
|
+
# when the Google Cloud service has no messages to return. The default
|
288
|
+
# value is `1`.
|
289
|
+
# @yield [msg] a block for processing new messages
|
290
|
+
# @yieldparam [ReceivedMessage] msg the newly received message
|
291
|
+
#
|
292
|
+
# @example
|
323
293
|
# require "gcloud"
|
324
294
|
#
|
325
295
|
# gcloud = Gcloud.new
|
@@ -330,9 +300,7 @@ module Gcloud
|
|
330
300
|
# # process msg
|
331
301
|
# end
|
332
302
|
#
|
333
|
-
#
|
334
|
-
# option:
|
335
|
-
#
|
303
|
+
# @example Limit the number of messages pulled per batch with `max`:
|
336
304
|
# require "gcloud"
|
337
305
|
#
|
338
306
|
# gcloud = Gcloud.new
|
@@ -343,9 +311,7 @@ module Gcloud
|
|
343
311
|
# # process msg
|
344
312
|
# end
|
345
313
|
#
|
346
|
-
#
|
347
|
-
# +autoack+ option:
|
348
|
-
#
|
314
|
+
# @example Automatically acknowledge messages with `autoack`:
|
349
315
|
# require "gcloud"
|
350
316
|
#
|
351
317
|
# gcloud = Gcloud.new
|
@@ -375,14 +341,10 @@ module Gcloud
|
|
375
341
|
# Acknowledging a message more than once will not result in an error.
|
376
342
|
# This is only used for messages received via pull.
|
377
343
|
#
|
378
|
-
#
|
379
|
-
#
|
380
|
-
# +messages+::
|
381
|
-
# One or more ReceivedMessage objects or ack_id values.
|
382
|
-
# (+ReceivedMessage+ or +ack_id+)
|
383
|
-
#
|
384
|
-
# === Example
|
344
|
+
# @param [ReceivedMessage, String] messages One or more {ReceivedMessage}
|
345
|
+
# objects or ack_id values.
|
385
346
|
#
|
347
|
+
# @example
|
386
348
|
# require "gcloud"
|
387
349
|
#
|
388
350
|
# gcloud = Gcloud.new
|
@@ -394,13 +356,11 @@ module Gcloud
|
|
394
356
|
#
|
395
357
|
def acknowledge *messages
|
396
358
|
ack_ids = coerce_ack_ids messages
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
fail ApiError.from_response(resp)
|
403
|
-
end
|
359
|
+
ensure_service!
|
360
|
+
service.acknowledge name, *ack_ids
|
361
|
+
true
|
362
|
+
rescue GRPC::BadStatus => e
|
363
|
+
raise Error.from_error(e)
|
404
364
|
end
|
405
365
|
alias_method :ack, :acknowledge
|
406
366
|
|
@@ -411,20 +371,15 @@ module Gcloud
|
|
411
371
|
# make the messages available for redelivery if the processing was
|
412
372
|
# interrupted.
|
413
373
|
#
|
414
|
-
#
|
415
|
-
#
|
416
|
-
#
|
417
|
-
#
|
418
|
-
#
|
419
|
-
#
|
420
|
-
#
|
421
|
-
# another pull request. (+Integer+)
|
422
|
-
# +messages+::
|
423
|
-
# One or more ReceivedMessage objects or ack_id values.
|
424
|
-
# (+ReceivedMessage+ or +ack_id+)
|
425
|
-
#
|
426
|
-
# === Example
|
374
|
+
# @param [Integer] new_deadline The new ack deadline in seconds from the
|
375
|
+
# time this request is sent to the Pub/Sub system. Must be >= 0. For
|
376
|
+
# example, if the value is `10`, the new ack deadline will expire 10
|
377
|
+
# seconds after the call is made. Specifying `0` may immediately make
|
378
|
+
# the message available for another pull request.
|
379
|
+
# @param [ReceivedMessage, String] messages One or more {ReceivedMessage}
|
380
|
+
# objects or ack_id values.
|
427
381
|
#
|
382
|
+
# @example
|
428
383
|
# require "gcloud"
|
429
384
|
#
|
430
385
|
# gcloud = Gcloud.new
|
@@ -436,29 +391,25 @@ module Gcloud
|
|
436
391
|
#
|
437
392
|
def delay new_deadline, *messages
|
438
393
|
ack_ids = coerce_ack_ids messages
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
fail ApiError.from_response(resp)
|
445
|
-
end
|
394
|
+
ensure_service!
|
395
|
+
service.modify_ack_deadline name, ack_ids, new_deadline
|
396
|
+
return true
|
397
|
+
rescue GRPC::BadStatus => e
|
398
|
+
raise Error.from_error(e)
|
446
399
|
end
|
447
400
|
|
448
401
|
##
|
449
402
|
# Gets the access control policy.
|
450
403
|
#
|
451
|
-
#
|
452
|
-
#
|
453
|
-
# +force+::
|
454
|
-
# Force the latest policy to be retrieved from the Pub/Sub service when
|
455
|
-
# +true. Otherwise the policy will be memoized to reduce the number of
|
456
|
-
# API calls made to the Pub/Sub service. The default is +false+.
|
457
|
-
# (+Boolean+)
|
404
|
+
# By default, the policy values are memoized to reduce the number of API
|
405
|
+
# calls to the Pub/Sub service.
|
458
406
|
#
|
459
|
-
#
|
407
|
+
# @param [Boolean] force Force the latest policy to be retrieved from the
|
408
|
+
# Pub/Sub service when `true`. Otherwise the policy will be memoized to
|
409
|
+
# reduce the number of API calls made to the Pub/Sub service. The
|
410
|
+
# default is `false`.
|
460
411
|
#
|
461
|
-
#
|
412
|
+
# @return [Hash] Returns a hash that conforms to the following structure:
|
462
413
|
#
|
463
414
|
# {
|
464
415
|
# "etag"=>"CAE=",
|
@@ -468,11 +419,7 @@ module Gcloud
|
|
468
419
|
# }]
|
469
420
|
# }
|
470
421
|
#
|
471
|
-
#
|
472
|
-
#
|
473
|
-
# By default, the policy values are memoized to reduce the number of API
|
474
|
-
# calls to the Pub/Sub service.
|
475
|
-
#
|
422
|
+
# @example Policy values are memoized to reduce the number of API calls:
|
476
423
|
# require "gcloud"
|
477
424
|
#
|
478
425
|
# gcloud = Gcloud.new
|
@@ -482,9 +429,7 @@ module Gcloud
|
|
482
429
|
# puts subscription.policy["bindings"]
|
483
430
|
# puts subscription.policy["rules"]
|
484
431
|
#
|
485
|
-
#
|
486
|
-
# flag.
|
487
|
-
#
|
432
|
+
# @example Use `force` to retrieve the latest policy from the service:
|
488
433
|
# require "gcloud"
|
489
434
|
#
|
490
435
|
# gcloud = Gcloud.new
|
@@ -496,22 +441,19 @@ module Gcloud
|
|
496
441
|
def policy force: nil
|
497
442
|
@policy = nil if force
|
498
443
|
@policy ||= begin
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
policy
|
444
|
+
ensure_service!
|
445
|
+
grpc = service.get_subscription_policy name
|
446
|
+
JSON.parse(Google::Iam::V1::Policy.encode_json(grpc))
|
447
|
+
rescue GRPC::BadStatus => e
|
448
|
+
raise Error.from_error(e)
|
505
449
|
end
|
506
450
|
end
|
507
451
|
|
508
452
|
##
|
509
453
|
# Sets the access control policy.
|
510
454
|
#
|
511
|
-
#
|
512
|
-
#
|
513
|
-
# +new_policy+::
|
514
|
-
# A hash that conforms to the following structure:
|
455
|
+
# @param [String] new_policy A hash that conforms to the following
|
456
|
+
# structure:
|
515
457
|
#
|
516
458
|
# {
|
517
459
|
# "bindings" => [{
|
@@ -520,8 +462,7 @@ module Gcloud
|
|
520
462
|
# }]
|
521
463
|
# }
|
522
464
|
#
|
523
|
-
#
|
524
|
-
#
|
465
|
+
# @example
|
525
466
|
# require "gcloud"
|
526
467
|
#
|
527
468
|
# gcloud = Gcloud.new
|
@@ -537,28 +478,23 @@ module Gcloud
|
|
537
478
|
# subscription.policy = viewer_policy
|
538
479
|
#
|
539
480
|
def policy= new_policy
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
else
|
546
|
-
fail ApiError.from_response(resp)
|
547
|
-
end
|
481
|
+
ensure_service!
|
482
|
+
grpc = service.set_subscription_policy name, new_policy
|
483
|
+
@policy = JSON.parse(Google::Iam::V1::Policy.encode_json(grpc))
|
484
|
+
rescue GRPC::BadStatus => e
|
485
|
+
raise Error.from_error(e)
|
548
486
|
end
|
549
487
|
|
550
488
|
##
|
551
|
-
# Tests the specified permissions against the
|
552
|
-
# IAM
|
553
|
-
# {Managing Policies}[https://cloud.google.com/iam/docs/managing-policies]
|
554
|
-
# for more information.
|
489
|
+
# Tests the specified permissions against the [Cloud
|
490
|
+
# IAM](https://cloud.google.com/iam/) access control policy.
|
555
491
|
#
|
556
|
-
#
|
492
|
+
# @see https://cloud.google.com/iam/docs/managing-policies Managing
|
493
|
+
# Policies
|
557
494
|
#
|
558
|
-
#
|
559
|
-
#
|
560
|
-
#
|
561
|
-
# (String or Array of Strings)
|
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.
|
562
498
|
#
|
563
499
|
# The permissions that can be checked on a subscription are:
|
564
500
|
#
|
@@ -569,12 +505,9 @@ module Gcloud
|
|
569
505
|
# * pubsub.subscriptions.getIamPolicy
|
570
506
|
# * pubsub.subscriptions.setIamPolicy
|
571
507
|
#
|
572
|
-
#
|
573
|
-
#
|
574
|
-
# The permissions that have access. (Array of Strings)
|
575
|
-
#
|
576
|
-
# === Example
|
508
|
+
# @return [Array<String>] The permissions that have access.
|
577
509
|
#
|
510
|
+
# @example
|
578
511
|
# require "gcloud"
|
579
512
|
#
|
580
513
|
# gcloud = Gcloud.new
|
@@ -587,48 +520,45 @@ module Gcloud
|
|
587
520
|
#
|
588
521
|
def test_permissions *permissions
|
589
522
|
permissions = Array(permissions).flatten
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
fail ApiError.from_response(resp)
|
596
|
-
end
|
523
|
+
ensure_service!
|
524
|
+
grpc = service.test_subscription_permissions name, permissions
|
525
|
+
grpc.permissions
|
526
|
+
rescue GRPC::BadStatus => e
|
527
|
+
raise Error.from_error(e)
|
597
528
|
end
|
598
529
|
|
599
530
|
##
|
600
|
-
# New Subscription from a Google
|
601
|
-
|
531
|
+
# @private New Subscription from a Google::Pubsub::V1::Subscription
|
532
|
+
# object.
|
533
|
+
def self.from_grpc grpc, service
|
602
534
|
new.tap do |f|
|
603
|
-
f.
|
604
|
-
f.
|
535
|
+
f.grpc = grpc
|
536
|
+
f.service = service
|
605
537
|
end
|
606
538
|
end
|
607
539
|
|
608
540
|
protected
|
609
541
|
|
610
542
|
##
|
611
|
-
# Raise an error unless an active connection is
|
612
|
-
|
613
|
-
|
543
|
+
# @private Raise an error unless an active connection to the service is
|
544
|
+
# available.
|
545
|
+
def ensure_service!
|
546
|
+
fail "Must have active connection to service" unless service
|
614
547
|
end
|
615
548
|
|
616
549
|
##
|
617
|
-
# Ensures a Google
|
618
|
-
def
|
619
|
-
|
620
|
-
return @
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
else
|
625
|
-
fail ApiError.from_response(resp)
|
626
|
-
end
|
550
|
+
# Ensures a Google::Pubsub::V1::Subscription object exists.
|
551
|
+
def ensure_grpc!
|
552
|
+
ensure_service!
|
553
|
+
return @grpc if @grpc
|
554
|
+
@grpc = service.get_subscription @name
|
555
|
+
rescue GRPC::BadStatus => e
|
556
|
+
raise Error.from_error(e)
|
627
557
|
end
|
628
558
|
|
629
559
|
##
|
630
|
-
# Makes sure the values are the
|
631
|
-
# If given several ReceivedMessage objects extract the
|
560
|
+
# Makes sure the values are the `ack_id`.
|
561
|
+
# If given several {ReceivedMessage} objects extract the `ack_id` values.
|
632
562
|
def coerce_ack_ids messages
|
633
563
|
Array(messages).flatten.map do |msg|
|
634
564
|
msg.respond_to?(:ack_id) ? msg.ack_id : msg.to_s
|