gcloud 0.6.3 → 0.7.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 +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,16 +12,18 @@
|
|
|
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/message"
|
|
18
18
|
|
|
19
19
|
module Gcloud
|
|
20
20
|
module Pubsub
|
|
21
21
|
##
|
|
22
|
-
#
|
|
22
|
+
# # ReceivedMessage
|
|
23
23
|
#
|
|
24
|
-
# Represents a Pub/Sub Message that can be acknowledged or delayed.
|
|
24
|
+
# Represents a Pub/Sub {Message} that can be acknowledged or delayed.
|
|
25
25
|
#
|
|
26
|
+
# @example
|
|
26
27
|
# require "gcloud"
|
|
27
28
|
#
|
|
28
29
|
# gcloud = Gcloud.new
|
|
@@ -37,30 +38,30 @@ module Gcloud
|
|
|
37
38
|
#
|
|
38
39
|
class ReceivedMessage
|
|
39
40
|
##
|
|
40
|
-
# The Subscription object.
|
|
41
|
-
attr_accessor :subscription
|
|
41
|
+
# @private The {Subscription} object.
|
|
42
|
+
attr_accessor :subscription
|
|
42
43
|
|
|
43
44
|
##
|
|
44
|
-
# The Google
|
|
45
|
-
attr_accessor :
|
|
45
|
+
# @private The gRPC Google::Pubsub::V1::ReceivedMessage object.
|
|
46
|
+
attr_accessor :grpc
|
|
46
47
|
|
|
47
48
|
##
|
|
48
|
-
# Create an empty Subscription object.
|
|
49
|
-
def initialize
|
|
49
|
+
# @private Create an empty {Subscription} object.
|
|
50
|
+
def initialize
|
|
50
51
|
@subscription = nil
|
|
51
|
-
@
|
|
52
|
+
@grpc = Google::Pubsub::V1::ReceivedMessage.new
|
|
52
53
|
end
|
|
53
54
|
|
|
54
55
|
##
|
|
55
56
|
# The acknowledgment ID for the message.
|
|
56
57
|
def ack_id
|
|
57
|
-
@
|
|
58
|
+
@grpc.ack_id
|
|
58
59
|
end
|
|
59
60
|
|
|
60
61
|
##
|
|
61
62
|
# The received message.
|
|
62
63
|
def message
|
|
63
|
-
Message.
|
|
64
|
+
Message.from_grpc @grpc.message
|
|
64
65
|
end
|
|
65
66
|
alias_method :msg, :message
|
|
66
67
|
|
|
@@ -87,8 +88,7 @@ module Gcloud
|
|
|
87
88
|
##
|
|
88
89
|
# Acknowledges receipt of the message.
|
|
89
90
|
#
|
|
90
|
-
#
|
|
91
|
-
#
|
|
91
|
+
# @example
|
|
92
92
|
# require "gcloud"
|
|
93
93
|
#
|
|
94
94
|
# gcloud = Gcloud.new
|
|
@@ -113,17 +113,13 @@ module Gcloud
|
|
|
113
113
|
# This indicates that more time is needed to process the message, or to
|
|
114
114
|
# make the message available for redelivery.
|
|
115
115
|
#
|
|
116
|
-
#
|
|
117
|
-
#
|
|
118
|
-
#
|
|
119
|
-
#
|
|
120
|
-
#
|
|
121
|
-
# +10+, the new ack deadline will expire 10 seconds after the call is
|
|
122
|
-
# made. Specifying +0+ may immediately make the message available for
|
|
123
|
-
# another pull request. (+Integer+)
|
|
124
|
-
#
|
|
125
|
-
# === Example
|
|
116
|
+
# @param [Integer] new_deadline The new ack deadline in seconds from the
|
|
117
|
+
# time this request is sent to the Pub/Sub system. Must be >= 0. For
|
|
118
|
+
# example, if the value is `10`, the new ack deadline will expire 10
|
|
119
|
+
# seconds after the call is made. Specifying `0` may immediately make
|
|
120
|
+
# the message available for another pull request.
|
|
126
121
|
#
|
|
122
|
+
# @example
|
|
127
123
|
# require "gcloud"
|
|
128
124
|
#
|
|
129
125
|
# gcloud = Gcloud.new
|
|
@@ -139,22 +135,16 @@ module Gcloud
|
|
|
139
135
|
#
|
|
140
136
|
def delay! new_deadline
|
|
141
137
|
ensure_subscription!
|
|
142
|
-
|
|
143
|
-
resp = connection.modify_ack_deadline subscription.name,
|
|
144
|
-
ack_id, new_deadline
|
|
145
|
-
if resp.success?
|
|
146
|
-
true
|
|
147
|
-
else
|
|
148
|
-
fail ApiError.from_response(resp)
|
|
149
|
-
end
|
|
138
|
+
subscription.delay new_deadline, ack_id
|
|
150
139
|
end
|
|
151
140
|
|
|
152
141
|
##
|
|
153
|
-
# New ReceivedMessage from a Google
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
142
|
+
# @private New ReceivedMessage from a Google::Pubsub::V1::ReceivedMessage
|
|
143
|
+
# object.
|
|
144
|
+
def self.from_grpc grpc, subscription
|
|
145
|
+
new.tap do |rm|
|
|
146
|
+
rm.grpc = grpc
|
|
147
|
+
rm.subscription = subscription
|
|
158
148
|
end
|
|
159
149
|
end
|
|
160
150
|
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
# Copyright 2016 Google Inc. All rights reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
require "google/pubsub/v1/pubsub_services"
|
|
17
|
+
require "google/iam/v1/iam_policy_services"
|
|
18
|
+
require "gcloud/backoff"
|
|
19
|
+
require "gcloud/grpc_utils"
|
|
20
|
+
require "json"
|
|
21
|
+
|
|
22
|
+
module Gcloud
|
|
23
|
+
module Pubsub
|
|
24
|
+
##
|
|
25
|
+
# @private Represents the gRPC Pub/Sub service, including all the API
|
|
26
|
+
# methods.
|
|
27
|
+
class Service
|
|
28
|
+
attr_accessor :project, :credentials, :host
|
|
29
|
+
|
|
30
|
+
##
|
|
31
|
+
# Creates a new Service instance.
|
|
32
|
+
def initialize project, credentials
|
|
33
|
+
@project = project
|
|
34
|
+
@credentials = credentials
|
|
35
|
+
@host = "pubsub.googleapis.com"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def creds
|
|
39
|
+
GRPC::Core::ChannelCredentials.new.compose \
|
|
40
|
+
GRPC::Core::CallCredentials.new credentials.client.updater_proc
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def subscriber
|
|
44
|
+
return mocked_subscriber if mocked_subscriber
|
|
45
|
+
@subscriber ||= Google::Pubsub::V1::Subscriber::Stub.new host, creds
|
|
46
|
+
end
|
|
47
|
+
attr_accessor :mocked_subscriber
|
|
48
|
+
|
|
49
|
+
def publisher
|
|
50
|
+
return mocked_publisher if mocked_publisher
|
|
51
|
+
@publisher ||= Google::Pubsub::V1::Publisher::Stub.new host, creds
|
|
52
|
+
end
|
|
53
|
+
attr_accessor :mocked_publisher
|
|
54
|
+
|
|
55
|
+
def iam
|
|
56
|
+
return mocked_iam if mocked_iam
|
|
57
|
+
@iam ||= Google::Iam::V1::IAMPolicy::Stub.new host, creds
|
|
58
|
+
end
|
|
59
|
+
attr_accessor :mocked_iam
|
|
60
|
+
|
|
61
|
+
##
|
|
62
|
+
# Gets the configuration of a topic.
|
|
63
|
+
# Since the topic only has the name attribute,
|
|
64
|
+
# this method is only useful to check the existence of a topic.
|
|
65
|
+
# If other attributes are added in the future,
|
|
66
|
+
# they will be returned here.
|
|
67
|
+
def get_topic topic_name, options = {}
|
|
68
|
+
topic_req = Google::Pubsub::V1::GetTopicRequest.new.tap do |r|
|
|
69
|
+
r.topic = topic_path(topic_name, options)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
backoff { publisher.get_topic topic_req }
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
##
|
|
76
|
+
# Lists matching topics.
|
|
77
|
+
def list_topics options = {}
|
|
78
|
+
topics_req = Google::Pubsub::V1::ListTopicsRequest.new.tap do |r|
|
|
79
|
+
r.project = project_path(options)
|
|
80
|
+
r.page_token = options[:token] if options[:token]
|
|
81
|
+
r.page_size = options[:max] if options[:max]
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
backoff { publisher.list_topics topics_req }
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
##
|
|
88
|
+
# Creates the given topic with the given name.
|
|
89
|
+
def create_topic topic_name, options = {}
|
|
90
|
+
topic_req = Google::Pubsub::V1::Topic.new.tap do |r|
|
|
91
|
+
r.name = topic_path(topic_name, options)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
backoff { publisher.create_topic topic_req }
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
##
|
|
98
|
+
# Deletes the topic with the given name.
|
|
99
|
+
# All subscriptions to this topic are also deleted.
|
|
100
|
+
# Raises GRPC status code 5 if the topic does not exist.
|
|
101
|
+
# After a topic is deleted, a new topic may be created with the same name.
|
|
102
|
+
def delete_topic topic_name
|
|
103
|
+
topic_req = Google::Pubsub::V1::DeleteTopicRequest.new.tap do |r|
|
|
104
|
+
r.topic = topic_path(topic_name)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
backoff { publisher.delete_topic topic_req }
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
##
|
|
111
|
+
# Adds one or more messages to the topic.
|
|
112
|
+
# Raises GRPC status code 5 if the topic does not exist.
|
|
113
|
+
# The messages parameter is an array of arrays.
|
|
114
|
+
# The first element is the data, second is attributes hash.
|
|
115
|
+
def publish topic, messages
|
|
116
|
+
publish_req = Google::Pubsub::V1::PublishRequest.new(
|
|
117
|
+
topic: topic_path(topic),
|
|
118
|
+
messages: messages.map do |data, attributes|
|
|
119
|
+
Google::Pubsub::V1::PubsubMessage.new(
|
|
120
|
+
data: [data].pack("m").encode("ASCII-8BIT"),
|
|
121
|
+
attributes: attributes
|
|
122
|
+
)
|
|
123
|
+
end
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
backoff { publisher.publish publish_req }
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
##
|
|
130
|
+
# Gets the details of a subscription.
|
|
131
|
+
def get_subscription subscription_name, options = {}
|
|
132
|
+
sub_req = Google::Pubsub::V1::GetSubscriptionRequest.new(
|
|
133
|
+
subscription: subscription_path(subscription_name, options)
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
backoff { subscriber.get_subscription sub_req }
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
##
|
|
140
|
+
# Lists matching subscriptions by project and topic.
|
|
141
|
+
def list_topics_subscriptions topic, options = {}
|
|
142
|
+
list_params = { topic: topic_path(topic, options),
|
|
143
|
+
page_token: options[:token],
|
|
144
|
+
page_size: options[:max] }.delete_if { |_, v| v.nil? }
|
|
145
|
+
list_req = Google::Pubsub::V1::ListTopicSubscriptionsRequest.new \
|
|
146
|
+
list_params
|
|
147
|
+
|
|
148
|
+
backoff { publisher.list_topic_subscriptions list_req }
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
##
|
|
152
|
+
# Lists matching subscriptions by project.
|
|
153
|
+
def list_subscriptions options = {}
|
|
154
|
+
list_params = { project: project_path(options),
|
|
155
|
+
page_token: options[:token],
|
|
156
|
+
page_size: options[:max] }.delete_if { |_, v| v.nil? }
|
|
157
|
+
list_req = Google::Pubsub::V1::ListSubscriptionsRequest.new list_params
|
|
158
|
+
|
|
159
|
+
backoff { subscriber.list_subscriptions list_req }
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
##
|
|
163
|
+
# Creates a subscription on a given topic for a given subscriber.
|
|
164
|
+
def create_subscription topic, subscription_name, options = {}
|
|
165
|
+
sub_params = { name: subscription_path(subscription_name, options),
|
|
166
|
+
topic: topic_path(topic),
|
|
167
|
+
ack_deadline_seconds: options[:deadline]
|
|
168
|
+
}.delete_if { |_, v| v.nil? }
|
|
169
|
+
sub_req = Google::Pubsub::V1::Subscription.new sub_params
|
|
170
|
+
if options[:endpoint]
|
|
171
|
+
sub_req.push_config = Google::Pubsub::V1::PushConfig.new(
|
|
172
|
+
push_endpoint: options[:endpoint],
|
|
173
|
+
attributes: (options[:attributes] || {}).to_h)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
backoff { subscriber.create_subscription sub_req }
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
##
|
|
180
|
+
# Deletes an existing subscription.
|
|
181
|
+
# All pending messages in the subscription are immediately dropped.
|
|
182
|
+
def delete_subscription subscription
|
|
183
|
+
del_req = Google::Pubsub::V1::DeleteSubscriptionRequest.new(
|
|
184
|
+
subscription: subscription_path(subscription)
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
backoff { subscriber.delete_subscription del_req }
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
##
|
|
191
|
+
# Pulls a single message from the server.
|
|
192
|
+
def pull subscription, options = {}
|
|
193
|
+
pull_req = Google::Pubsub::V1::PullRequest.new(
|
|
194
|
+
subscription: subscription_path(subscription, options),
|
|
195
|
+
return_immediately: !(!options.fetch(:immediate, true)),
|
|
196
|
+
max_messages: options.fetch(:max, 100).to_i
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
backoff { subscriber.pull pull_req }
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
##
|
|
203
|
+
# Acknowledges receipt of a message.
|
|
204
|
+
def acknowledge subscription, *ack_ids
|
|
205
|
+
ack_req = Google::Pubsub::V1::AcknowledgeRequest.new(
|
|
206
|
+
subscription: subscription_path(subscription),
|
|
207
|
+
ack_ids: ack_ids
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
backoff { subscriber.acknowledge ack_req }
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
##
|
|
214
|
+
# Modifies the PushConfig for a specified subscription.
|
|
215
|
+
def modify_push_config subscription, endpoint, attributes
|
|
216
|
+
# Convert attributes to strings to match the protobuf definition
|
|
217
|
+
attributes = Hash[attributes.map { |k, v| [String(k), String(v)] }]
|
|
218
|
+
|
|
219
|
+
mpc_req = Google::Pubsub::V1::ModifyPushConfigRequest.new(
|
|
220
|
+
subscription: subscription_path(subscription),
|
|
221
|
+
push_config: Google::Pubsub::V1::PushConfig.new(
|
|
222
|
+
push_endpoint: endpoint,
|
|
223
|
+
attributes: attributes
|
|
224
|
+
)
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
backoff { subscriber.modify_push_config mpc_req }
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
##
|
|
231
|
+
# Modifies the ack deadline for a specific message.
|
|
232
|
+
def modify_ack_deadline subscription, ids, deadline
|
|
233
|
+
mad_req = Google::Pubsub::V1::ModifyAckDeadlineRequest.new(
|
|
234
|
+
subscription: subscription_path(subscription),
|
|
235
|
+
ack_ids: Array(ids),
|
|
236
|
+
ack_deadline_seconds: deadline
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
backoff { subscriber.modify_ack_deadline mad_req }
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
def get_topic_policy topic_name, options = {}
|
|
243
|
+
get_req = Google::Iam::V1::GetIamPolicyRequest.new(
|
|
244
|
+
resource: topic_path(topic_name, options)
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
backoff { iam.get_iam_policy get_req }
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
def set_topic_policy topic_name, new_policy, options = {}
|
|
251
|
+
set_req = Google::Iam::V1::SetIamPolicyRequest.new(
|
|
252
|
+
resource: topic_path(topic_name, options),
|
|
253
|
+
policy: Google::Iam::V1::Policy.decode_json(JSON.dump(new_policy))
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
backoff { iam.set_iam_policy set_req }
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
def test_topic_permissions topic_name, permissions, options = {}
|
|
260
|
+
test_req = Google::Iam::V1::TestIamPermissionsRequest.new(
|
|
261
|
+
resource: topic_path(topic_name, options),
|
|
262
|
+
permissions: permissions
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
backoff { iam.test_iam_permissions test_req }
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
def get_subscription_policy subscription_name, options = {}
|
|
269
|
+
get_req = Google::Iam::V1::GetIamPolicyRequest.new(
|
|
270
|
+
resource: subscription_path(subscription_name, options)
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
backoff { iam.get_iam_policy get_req }
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
def set_subscription_policy subscription_name, new_policy, options = {}
|
|
277
|
+
set_req = Google::Iam::V1::SetIamPolicyRequest.new(
|
|
278
|
+
resource: subscription_path(subscription_name, options),
|
|
279
|
+
policy: Google::Iam::V1::Policy.decode_json(JSON.dump(new_policy))
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
backoff { iam.set_iam_policy set_req }
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
def test_subscription_permissions subscription_name,
|
|
286
|
+
permissions, options = {}
|
|
287
|
+
test_req = Google::Iam::V1::TestIamPermissionsRequest.new(
|
|
288
|
+
resource: subscription_path(subscription_name, options),
|
|
289
|
+
permissions: permissions
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
backoff { iam.test_iam_permissions test_req }
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
def project_path options = {}
|
|
296
|
+
project_name = options[:project] || project
|
|
297
|
+
"projects/#{project_name}"
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
def topic_path topic_name, options = {}
|
|
301
|
+
return topic_name if topic_name.to_s.include? "/"
|
|
302
|
+
"#{project_path(options)}/topics/#{topic_name}"
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
def subscription_path subscription_name, options = {}
|
|
306
|
+
return subscription_name if subscription_name.to_s.include? "/"
|
|
307
|
+
"#{project_path(options)}/subscriptions/#{subscription_name}"
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
def inspect
|
|
311
|
+
"#{self.class}(#{@project})"
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
protected
|
|
315
|
+
|
|
316
|
+
def backoff options = {}
|
|
317
|
+
Gcloud::Backoff.new(options).execute_grpc do
|
|
318
|
+
yield
|
|
319
|
+
end
|
|
320
|
+
end
|
|
321
|
+
end
|
|
322
|
+
end
|
|
323
|
+
end
|