gcloud 0.12.2 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/gcloud.rb +27 -456
- data/lib/gcloud/bigquery.rb +2 -382
- data/lib/gcloud/datastore.rb +2 -576
- data/lib/gcloud/dns.rb +2 -321
- data/lib/gcloud/logging.rb +1 -322
- data/lib/gcloud/pubsub.rb +2 -476
- data/lib/gcloud/resource_manager.rb +2 -273
- data/lib/gcloud/storage.rb +2 -440
- data/lib/gcloud/translate.rb +1 -250
- data/lib/gcloud/version.rb +2 -2
- data/lib/gcloud/vision.rb +1 -501
- metadata +36 -332
- data/AUTHENTICATION.md +0 -75
- data/CHANGELOG.md +0 -382
- data/OVERVIEW.md +0 -259
- data/lib/gcloud/backoff.rb +0 -150
- data/lib/gcloud/bigquery/copy_job.rb +0 -97
- data/lib/gcloud/bigquery/credentials.rb +0 -29
- data/lib/gcloud/bigquery/data.rb +0 -239
- data/lib/gcloud/bigquery/dataset.rb +0 -753
- data/lib/gcloud/bigquery/dataset/access.rb +0 -507
- data/lib/gcloud/bigquery/dataset/list.rb +0 -169
- data/lib/gcloud/bigquery/extract_job.rb +0 -117
- data/lib/gcloud/bigquery/insert_response.rb +0 -81
- data/lib/gcloud/bigquery/job.rb +0 -299
- data/lib/gcloud/bigquery/job/list.rb +0 -172
- data/lib/gcloud/bigquery/load_job.rb +0 -202
- data/lib/gcloud/bigquery/project.rb +0 -475
- data/lib/gcloud/bigquery/query_data.rb +0 -234
- data/lib/gcloud/bigquery/query_job.rb +0 -137
- data/lib/gcloud/bigquery/schema.rb +0 -359
- data/lib/gcloud/bigquery/service.rb +0 -506
- data/lib/gcloud/bigquery/table.rb +0 -1141
- data/lib/gcloud/bigquery/table/list.rb +0 -180
- data/lib/gcloud/bigquery/view.rb +0 -475
- data/lib/gcloud/credentials.rb +0 -129
- data/lib/gcloud/datastore/commit.rb +0 -148
- data/lib/gcloud/datastore/credentials.rb +0 -35
- data/lib/gcloud/datastore/cursor.rb +0 -76
- data/lib/gcloud/datastore/dataset.rb +0 -660
- data/lib/gcloud/datastore/dataset/lookup_results.rb +0 -219
- data/lib/gcloud/datastore/dataset/query_results.rb +0 -386
- data/lib/gcloud/datastore/entity.rb +0 -449
- data/lib/gcloud/datastore/errors.rb +0 -41
- data/lib/gcloud/datastore/gql_query.rb +0 -211
- data/lib/gcloud/datastore/grpc_utils.rb +0 -132
- data/lib/gcloud/datastore/key.rb +0 -281
- data/lib/gcloud/datastore/properties.rb +0 -128
- data/lib/gcloud/datastore/query.rb +0 -348
- data/lib/gcloud/datastore/service.rb +0 -167
- data/lib/gcloud/datastore/transaction.rb +0 -362
- data/lib/gcloud/dns/change.rb +0 -158
- data/lib/gcloud/dns/change/list.rb +0 -173
- data/lib/gcloud/dns/credentials.rb +0 -29
- data/lib/gcloud/dns/importer.rb +0 -183
- data/lib/gcloud/dns/project.rb +0 -247
- data/lib/gcloud/dns/record.rb +0 -170
- data/lib/gcloud/dns/record/list.rb +0 -174
- data/lib/gcloud/dns/service.rb +0 -167
- data/lib/gcloud/dns/zone.rb +0 -759
- data/lib/gcloud/dns/zone/list.rb +0 -168
- data/lib/gcloud/dns/zone/transaction.rb +0 -176
- data/lib/gcloud/errors.rb +0 -206
- data/lib/gcloud/gce.rb +0 -56
- data/lib/gcloud/grpc_utils.rb +0 -87
- data/lib/gcloud/logging/credentials.rb +0 -29
- data/lib/gcloud/logging/entry.rb +0 -465
- data/lib/gcloud/logging/entry/http_request.rb +0 -141
- data/lib/gcloud/logging/entry/list.rb +0 -177
- data/lib/gcloud/logging/entry/operation.rb +0 -90
- data/lib/gcloud/logging/logger.rb +0 -307
- data/lib/gcloud/logging/metric.rb +0 -169
- data/lib/gcloud/logging/metric/list.rb +0 -172
- data/lib/gcloud/logging/project.rb +0 -642
- data/lib/gcloud/logging/resource.rb +0 -84
- data/lib/gcloud/logging/resource_descriptor.rb +0 -137
- data/lib/gcloud/logging/resource_descriptor/list.rb +0 -174
- data/lib/gcloud/logging/service.rb +0 -267
- data/lib/gcloud/logging/sink.rb +0 -227
- data/lib/gcloud/logging/sink/list.rb +0 -171
- data/lib/gcloud/pubsub/credentials.rb +0 -29
- data/lib/gcloud/pubsub/message.rb +0 -94
- data/lib/gcloud/pubsub/policy.rb +0 -204
- data/lib/gcloud/pubsub/project.rb +0 -482
- data/lib/gcloud/pubsub/received_message.rb +0 -160
- data/lib/gcloud/pubsub/service.rb +0 -334
- data/lib/gcloud/pubsub/subscription.rb +0 -565
- data/lib/gcloud/pubsub/subscription/list.rb +0 -208
- data/lib/gcloud/pubsub/topic.rb +0 -511
- data/lib/gcloud/pubsub/topic/list.rb +0 -174
- data/lib/gcloud/pubsub/topic/publisher.rb +0 -85
- data/lib/gcloud/resource_manager/credentials.rb +0 -30
- data/lib/gcloud/resource_manager/manager.rb +0 -266
- data/lib/gcloud/resource_manager/policy.rb +0 -211
- data/lib/gcloud/resource_manager/project.rb +0 -484
- data/lib/gcloud/resource_manager/project/list.rb +0 -167
- data/lib/gcloud/resource_manager/project/updater.rb +0 -130
- data/lib/gcloud/resource_manager/service.rb +0 -127
- data/lib/gcloud/storage/bucket.rb +0 -775
- data/lib/gcloud/storage/bucket/acl.rb +0 -810
- data/lib/gcloud/storage/bucket/cors.rb +0 -153
- data/lib/gcloud/storage/bucket/list.rb +0 -172
- data/lib/gcloud/storage/credentials.rb +0 -29
- data/lib/gcloud/storage/errors.rb +0 -65
- data/lib/gcloud/storage/file.rb +0 -842
- data/lib/gcloud/storage/file/acl.rb +0 -425
- data/lib/gcloud/storage/file/list.rb +0 -191
- data/lib/gcloud/storage/file/verifier.rb +0 -67
- data/lib/gcloud/storage/project.rb +0 -316
- data/lib/gcloud/storage/service.rb +0 -347
- data/lib/gcloud/translate/api.rb +0 -241
- data/lib/gcloud/translate/detection.rb +0 -137
- data/lib/gcloud/translate/language.rb +0 -69
- data/lib/gcloud/translate/service.rb +0 -80
- data/lib/gcloud/translate/translation.rb +0 -112
- data/lib/gcloud/vision/annotate.rb +0 -224
- data/lib/gcloud/vision/annotation.rb +0 -455
- data/lib/gcloud/vision/annotation/entity.rb +0 -234
- data/lib/gcloud/vision/annotation/face.rb +0 -1750
- data/lib/gcloud/vision/annotation/properties.rb +0 -245
- data/lib/gcloud/vision/annotation/safe_search.rb +0 -161
- data/lib/gcloud/vision/annotation/text.rb +0 -236
- data/lib/gcloud/vision/annotation/vertex.rb +0 -108
- data/lib/gcloud/vision/credentials.rb +0 -29
- data/lib/gcloud/vision/image.rb +0 -590
- data/lib/gcloud/vision/location.rb +0 -115
- data/lib/gcloud/vision/project.rb +0 -278
- data/lib/gcloud/vision/service.rb +0 -66
- data/lib/google/api/annotations.rb +0 -14
- data/lib/google/api/http.rb +0 -30
- data/lib/google/api/label.rb +0 -24
- data/lib/google/api/monitored_resource.rb +0 -25
- data/lib/google/datastore/v1beta3/datastore.rb +0 -115
- data/lib/google/datastore/v1beta3/datastore_services.rb +0 -33
- data/lib/google/datastore/v1beta3/entity.rb +0 -63
- data/lib/google/datastore/v1beta3/query.rb +0 -128
- data/lib/google/devtools/cloudtrace/v1/trace.rb +0 -78
- data/lib/google/devtools/cloudtrace/v1/trace_services.rb +0 -32
- data/lib/google/example/library/v1/library.rb +0 -91
- data/lib/google/example/library/v1/library_services.rb +0 -40
- 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
- data/lib/google/logging/type/http_request.rb +0 -28
- data/lib/google/logging/type/log_severity.rb +0 -27
- data/lib/google/logging/v2/log_entry.rb +0 -44
- data/lib/google/logging/v2/logging.rb +0 -56
- data/lib/google/logging/v2/logging_config.rb +0 -59
- data/lib/google/logging/v2/logging_config_services.rb +0 -32
- data/lib/google/logging/v2/logging_metrics.rb +0 -51
- data/lib/google/logging/v2/logging_metrics_services.rb +0 -32
- data/lib/google/logging/v2/logging_services.rb +0 -31
- data/lib/google/longrunning/operations.rb +0 -50
- data/lib/google/longrunning/operations_services.rb +0 -29
- data/lib/google/protobuf/descriptor.rb +0 -0
- data/lib/google/pubsub/v1/pubsub.rb +0 -129
- data/lib/google/pubsub/v1/pubsub_services.rb +0 -56
- data/lib/google/pubsub/v1beta2/pubsub.rb +0 -126
- data/lib/google/pubsub/v1beta2/pubsub_services.rb +0 -56
- data/lib/google/rpc/code.rb +0 -32
- data/lib/google/rpc/error_details.rb +0 -61
- data/lib/google/rpc/status.rb +0 -19
- data/lib/google/type/color.rb +0 -20
- data/lib/google/type/date.rb +0 -18
- data/lib/google/type/dayofweek.rb +0 -23
- data/lib/google/type/latlng.rb +0 -17
- data/lib/google/type/money.rb +0 -18
- data/lib/google/type/timeofday.rb +0 -19
@@ -1,160 +0,0 @@
|
|
1
|
-
# Copyright 2015 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 "gcloud/errors"
|
17
|
-
require "gcloud/pubsub/message"
|
18
|
-
|
19
|
-
module Gcloud
|
20
|
-
module Pubsub
|
21
|
-
##
|
22
|
-
# # ReceivedMessage
|
23
|
-
#
|
24
|
-
# Represents a Pub/Sub {Message} that can be acknowledged or delayed.
|
25
|
-
#
|
26
|
-
# @example
|
27
|
-
# require "gcloud"
|
28
|
-
#
|
29
|
-
# gcloud = Gcloud.new
|
30
|
-
# pubsub = gcloud.pubsub
|
31
|
-
#
|
32
|
-
# sub = pubsub.subscription "my-topic-sub"
|
33
|
-
# received_message = sub.pull.first
|
34
|
-
# if received_message
|
35
|
-
# puts received_message.message.data
|
36
|
-
# received_message.acknowledge!
|
37
|
-
# end
|
38
|
-
#
|
39
|
-
class ReceivedMessage
|
40
|
-
##
|
41
|
-
# @private The {Subscription} object.
|
42
|
-
attr_accessor :subscription
|
43
|
-
|
44
|
-
##
|
45
|
-
# @private The gRPC Google::Pubsub::V1::ReceivedMessage object.
|
46
|
-
attr_accessor :grpc
|
47
|
-
|
48
|
-
##
|
49
|
-
# @private Create an empty {Subscription} object.
|
50
|
-
def initialize
|
51
|
-
@subscription = nil
|
52
|
-
@grpc = Google::Pubsub::V1::ReceivedMessage.new
|
53
|
-
end
|
54
|
-
|
55
|
-
##
|
56
|
-
# The acknowledgment ID for the message.
|
57
|
-
def ack_id
|
58
|
-
@grpc.ack_id
|
59
|
-
end
|
60
|
-
|
61
|
-
##
|
62
|
-
# The received message.
|
63
|
-
def message
|
64
|
-
Message.from_grpc @grpc.message
|
65
|
-
end
|
66
|
-
alias_method :msg, :message
|
67
|
-
|
68
|
-
##
|
69
|
-
# The received message's data.
|
70
|
-
def data
|
71
|
-
message.data
|
72
|
-
end
|
73
|
-
|
74
|
-
##
|
75
|
-
# The received message's attributes.
|
76
|
-
def attributes
|
77
|
-
message.attributes
|
78
|
-
end
|
79
|
-
|
80
|
-
##
|
81
|
-
# The ID of the received message, assigned by the server at publication
|
82
|
-
# time. Guaranteed to be unique within the topic.
|
83
|
-
def message_id
|
84
|
-
message.message_id
|
85
|
-
end
|
86
|
-
alias_method :msg_id, :message_id
|
87
|
-
|
88
|
-
##
|
89
|
-
# Acknowledges receipt of the message.
|
90
|
-
#
|
91
|
-
# @example
|
92
|
-
# require "gcloud"
|
93
|
-
#
|
94
|
-
# gcloud = Gcloud.new
|
95
|
-
# pubsub = gcloud.pubsub
|
96
|
-
#
|
97
|
-
# sub = pubsub.subscription "my-topic-sub"
|
98
|
-
# received_message = sub.pull.first
|
99
|
-
# if received_message
|
100
|
-
# puts received_message.message.data
|
101
|
-
# received_message.acknowledge!
|
102
|
-
# end
|
103
|
-
#
|
104
|
-
def acknowledge!
|
105
|
-
ensure_subscription!
|
106
|
-
subscription.acknowledge ack_id
|
107
|
-
end
|
108
|
-
alias_method :ack!, :acknowledge!
|
109
|
-
|
110
|
-
##
|
111
|
-
# Modifies the acknowledge deadline for the message.
|
112
|
-
#
|
113
|
-
# This indicates that more time is needed to process the message, or to
|
114
|
-
# make the message available for redelivery.
|
115
|
-
#
|
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.
|
121
|
-
#
|
122
|
-
# @example
|
123
|
-
# require "gcloud"
|
124
|
-
#
|
125
|
-
# gcloud = Gcloud.new
|
126
|
-
# pubsub = gcloud.pubsub
|
127
|
-
#
|
128
|
-
# sub = pubsub.subscription "my-topic-sub"
|
129
|
-
# received_message = sub.pull.first
|
130
|
-
# if received_message
|
131
|
-
# puts received_message.message.data
|
132
|
-
# # Delay for 2 minutes
|
133
|
-
# received_message.delay! 120
|
134
|
-
# end
|
135
|
-
#
|
136
|
-
def delay! new_deadline
|
137
|
-
ensure_subscription!
|
138
|
-
subscription.delay new_deadline, ack_id
|
139
|
-
end
|
140
|
-
|
141
|
-
##
|
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
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
protected
|
152
|
-
|
153
|
-
##
|
154
|
-
# Raise an error unless an active subscription is available.
|
155
|
-
def ensure_subscription!
|
156
|
-
fail "Must have active subscription" unless subscription
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
@@ -1,334 +0,0 @@
|
|
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 "gcloud/backoff"
|
17
|
-
require "gcloud/errors"
|
18
|
-
require "google/pubsub/v1/pubsub_services"
|
19
|
-
require "google/iam/v1/iam_policy_services"
|
20
|
-
require "gcloud/grpc_utils"
|
21
|
-
require "json"
|
22
|
-
|
23
|
-
module Gcloud
|
24
|
-
module Pubsub
|
25
|
-
##
|
26
|
-
# @private Represents the gRPC Pub/Sub service, including all the API
|
27
|
-
# methods.
|
28
|
-
class Service
|
29
|
-
attr_accessor :project, :credentials, :host, :retries, :timeout
|
30
|
-
|
31
|
-
##
|
32
|
-
# Creates a new Service instance.
|
33
|
-
def initialize project, credentials, host: nil, retries: nil, timeout: nil
|
34
|
-
@project = project
|
35
|
-
@credentials = credentials
|
36
|
-
@host = host || "pubsub.googleapis.com"
|
37
|
-
@retries = retries
|
38
|
-
@timeout = timeout
|
39
|
-
end
|
40
|
-
|
41
|
-
def creds
|
42
|
-
return credentials if insecure?
|
43
|
-
GRPC::Core::ChannelCredentials.new.compose \
|
44
|
-
GRPC::Core::CallCredentials.new credentials.client.updater_proc
|
45
|
-
end
|
46
|
-
|
47
|
-
def subscriber
|
48
|
-
return mocked_subscriber if mocked_subscriber
|
49
|
-
@subscriber ||= Google::Pubsub::V1::Subscriber::Stub.new(
|
50
|
-
host, creds, timeout: timeout)
|
51
|
-
end
|
52
|
-
attr_accessor :mocked_subscriber
|
53
|
-
|
54
|
-
def publisher
|
55
|
-
return mocked_publisher if mocked_publisher
|
56
|
-
@publisher ||= Google::Pubsub::V1::Publisher::Stub.new(
|
57
|
-
host, creds, timeout: timeout)
|
58
|
-
end
|
59
|
-
attr_accessor :mocked_publisher
|
60
|
-
|
61
|
-
def iam
|
62
|
-
return mocked_iam if mocked_iam
|
63
|
-
@iam ||= Google::Iam::V1::IAMPolicy::Stub.new(
|
64
|
-
host, creds, timeout: timeout)
|
65
|
-
end
|
66
|
-
attr_accessor :mocked_iam
|
67
|
-
|
68
|
-
def insecure?
|
69
|
-
credentials == :this_channel_is_insecure
|
70
|
-
end
|
71
|
-
|
72
|
-
##
|
73
|
-
# Gets the configuration of a topic.
|
74
|
-
# Since the topic only has the name attribute,
|
75
|
-
# this method is only useful to check the existence of a topic.
|
76
|
-
# If other attributes are added in the future,
|
77
|
-
# they will be returned here.
|
78
|
-
def get_topic topic_name, options = {}
|
79
|
-
topic_req = Google::Pubsub::V1::GetTopicRequest.new.tap do |r|
|
80
|
-
r.topic = topic_path(topic_name, options)
|
81
|
-
end
|
82
|
-
|
83
|
-
execute { publisher.get_topic topic_req }
|
84
|
-
end
|
85
|
-
|
86
|
-
##
|
87
|
-
# Lists matching topics.
|
88
|
-
def list_topics options = {}
|
89
|
-
topics_req = Google::Pubsub::V1::ListTopicsRequest.new.tap do |r|
|
90
|
-
r.project = project_path(options)
|
91
|
-
r.page_token = options[:token] if options[:token]
|
92
|
-
r.page_size = options[:max] if options[:max]
|
93
|
-
end
|
94
|
-
|
95
|
-
execute { publisher.list_topics topics_req }
|
96
|
-
end
|
97
|
-
|
98
|
-
##
|
99
|
-
# Creates the given topic with the given name.
|
100
|
-
def create_topic topic_name, options = {}
|
101
|
-
topic_req = Google::Pubsub::V1::Topic.new.tap do |r|
|
102
|
-
r.name = topic_path(topic_name, options)
|
103
|
-
end
|
104
|
-
|
105
|
-
execute { publisher.create_topic topic_req }
|
106
|
-
end
|
107
|
-
|
108
|
-
##
|
109
|
-
# Deletes the topic with the given name.
|
110
|
-
# All subscriptions to this topic are also deleted.
|
111
|
-
# Raises GRPC status code 5 if the topic does not exist.
|
112
|
-
# After a topic is deleted, a new topic may be created with the same name.
|
113
|
-
def delete_topic topic_name
|
114
|
-
topic_req = Google::Pubsub::V1::DeleteTopicRequest.new.tap do |r|
|
115
|
-
r.topic = topic_path(topic_name)
|
116
|
-
end
|
117
|
-
|
118
|
-
execute { publisher.delete_topic topic_req }
|
119
|
-
end
|
120
|
-
|
121
|
-
##
|
122
|
-
# Adds one or more messages to the topic.
|
123
|
-
# Raises GRPC status code 5 if the topic does not exist.
|
124
|
-
# The messages parameter is an array of arrays.
|
125
|
-
# The first element is the data, second is attributes hash.
|
126
|
-
def publish topic, messages
|
127
|
-
publish_req = Google::Pubsub::V1::PublishRequest.new(
|
128
|
-
topic: topic_path(topic),
|
129
|
-
messages: messages.map do |data, attributes|
|
130
|
-
Google::Pubsub::V1::PubsubMessage.new(
|
131
|
-
data: data, attributes: attributes)
|
132
|
-
end
|
133
|
-
)
|
134
|
-
|
135
|
-
execute { publisher.publish publish_req }
|
136
|
-
end
|
137
|
-
|
138
|
-
##
|
139
|
-
# Gets the details of a subscription.
|
140
|
-
def get_subscription subscription_name, options = {}
|
141
|
-
sub_req = Google::Pubsub::V1::GetSubscriptionRequest.new(
|
142
|
-
subscription: subscription_path(subscription_name, options)
|
143
|
-
)
|
144
|
-
|
145
|
-
execute { subscriber.get_subscription sub_req }
|
146
|
-
end
|
147
|
-
|
148
|
-
##
|
149
|
-
# Lists matching subscriptions by project and topic.
|
150
|
-
def list_topics_subscriptions topic, options = {}
|
151
|
-
list_params = { topic: topic_path(topic, options),
|
152
|
-
page_token: options[:token],
|
153
|
-
page_size: options[:max] }.delete_if { |_, v| v.nil? }
|
154
|
-
list_req = Google::Pubsub::V1::ListTopicSubscriptionsRequest.new \
|
155
|
-
list_params
|
156
|
-
|
157
|
-
execute { publisher.list_topic_subscriptions list_req }
|
158
|
-
end
|
159
|
-
|
160
|
-
##
|
161
|
-
# Lists matching subscriptions by project.
|
162
|
-
def list_subscriptions options = {}
|
163
|
-
list_params = { project: project_path(options),
|
164
|
-
page_token: options[:token],
|
165
|
-
page_size: options[:max] }.delete_if { |_, v| v.nil? }
|
166
|
-
list_req = Google::Pubsub::V1::ListSubscriptionsRequest.new list_params
|
167
|
-
|
168
|
-
execute { subscriber.list_subscriptions list_req }
|
169
|
-
end
|
170
|
-
|
171
|
-
##
|
172
|
-
# Creates a subscription on a given topic for a given subscriber.
|
173
|
-
def create_subscription topic, subscription_name, options = {}
|
174
|
-
sub_params = { name: subscription_path(subscription_name, options),
|
175
|
-
topic: topic_path(topic),
|
176
|
-
ack_deadline_seconds: options[:deadline]
|
177
|
-
}.delete_if { |_, v| v.nil? }
|
178
|
-
sub_req = Google::Pubsub::V1::Subscription.new sub_params
|
179
|
-
if options[:endpoint]
|
180
|
-
sub_req.push_config = Google::Pubsub::V1::PushConfig.new(
|
181
|
-
push_endpoint: options[:endpoint],
|
182
|
-
attributes: (options[:attributes] || {}).to_h)
|
183
|
-
end
|
184
|
-
|
185
|
-
execute { subscriber.create_subscription sub_req }
|
186
|
-
end
|
187
|
-
|
188
|
-
##
|
189
|
-
# Deletes an existing subscription.
|
190
|
-
# All pending messages in the subscription are immediately dropped.
|
191
|
-
def delete_subscription subscription
|
192
|
-
del_req = Google::Pubsub::V1::DeleteSubscriptionRequest.new(
|
193
|
-
subscription: subscription_path(subscription)
|
194
|
-
)
|
195
|
-
|
196
|
-
execute { subscriber.delete_subscription del_req }
|
197
|
-
end
|
198
|
-
|
199
|
-
##
|
200
|
-
# Pulls a single message from the server.
|
201
|
-
def pull subscription, options = {}
|
202
|
-
pull_req = Google::Pubsub::V1::PullRequest.new(
|
203
|
-
subscription: subscription_path(subscription, options),
|
204
|
-
return_immediately: !(!options.fetch(:immediate, true)),
|
205
|
-
max_messages: options.fetch(:max, 100).to_i
|
206
|
-
)
|
207
|
-
|
208
|
-
execute { subscriber.pull pull_req }
|
209
|
-
end
|
210
|
-
|
211
|
-
##
|
212
|
-
# Acknowledges receipt of a message.
|
213
|
-
def acknowledge subscription, *ack_ids
|
214
|
-
ack_req = Google::Pubsub::V1::AcknowledgeRequest.new(
|
215
|
-
subscription: subscription_path(subscription),
|
216
|
-
ack_ids: ack_ids
|
217
|
-
)
|
218
|
-
|
219
|
-
execute { subscriber.acknowledge ack_req }
|
220
|
-
end
|
221
|
-
|
222
|
-
##
|
223
|
-
# Modifies the PushConfig for a specified subscription.
|
224
|
-
def modify_push_config subscription, endpoint, attributes
|
225
|
-
# Convert attributes to strings to match the protobuf definition
|
226
|
-
attributes = Hash[attributes.map { |k, v| [String(k), String(v)] }]
|
227
|
-
|
228
|
-
mpc_req = Google::Pubsub::V1::ModifyPushConfigRequest.new(
|
229
|
-
subscription: subscription_path(subscription),
|
230
|
-
push_config: Google::Pubsub::V1::PushConfig.new(
|
231
|
-
push_endpoint: endpoint,
|
232
|
-
attributes: attributes
|
233
|
-
)
|
234
|
-
)
|
235
|
-
|
236
|
-
execute { subscriber.modify_push_config mpc_req }
|
237
|
-
end
|
238
|
-
|
239
|
-
##
|
240
|
-
# Modifies the ack deadline for a specific message.
|
241
|
-
def modify_ack_deadline subscription, ids, deadline
|
242
|
-
mad_req = Google::Pubsub::V1::ModifyAckDeadlineRequest.new(
|
243
|
-
subscription: subscription_path(subscription),
|
244
|
-
ack_ids: Array(ids),
|
245
|
-
ack_deadline_seconds: deadline
|
246
|
-
)
|
247
|
-
|
248
|
-
execute { subscriber.modify_ack_deadline mad_req }
|
249
|
-
end
|
250
|
-
|
251
|
-
def get_topic_policy topic_name, options = {}
|
252
|
-
get_req = Google::Iam::V1::GetIamPolicyRequest.new(
|
253
|
-
resource: topic_path(topic_name, options)
|
254
|
-
)
|
255
|
-
|
256
|
-
execute { iam.get_iam_policy get_req }
|
257
|
-
end
|
258
|
-
|
259
|
-
def set_topic_policy topic_name, new_policy, options = {}
|
260
|
-
set_req = Google::Iam::V1::SetIamPolicyRequest.new(
|
261
|
-
resource: topic_path(topic_name, options),
|
262
|
-
policy: new_policy
|
263
|
-
)
|
264
|
-
|
265
|
-
execute { iam.set_iam_policy set_req }
|
266
|
-
end
|
267
|
-
|
268
|
-
def test_topic_permissions topic_name, permissions, options = {}
|
269
|
-
test_req = Google::Iam::V1::TestIamPermissionsRequest.new(
|
270
|
-
resource: topic_path(topic_name, options),
|
271
|
-
permissions: permissions
|
272
|
-
)
|
273
|
-
|
274
|
-
execute { iam.test_iam_permissions test_req }
|
275
|
-
end
|
276
|
-
|
277
|
-
def get_subscription_policy subscription_name, options = {}
|
278
|
-
get_req = Google::Iam::V1::GetIamPolicyRequest.new(
|
279
|
-
resource: subscription_path(subscription_name, options)
|
280
|
-
)
|
281
|
-
|
282
|
-
execute { iam.get_iam_policy get_req }
|
283
|
-
end
|
284
|
-
|
285
|
-
def set_subscription_policy subscription_name, new_policy, options = {}
|
286
|
-
set_req = Google::Iam::V1::SetIamPolicyRequest.new(
|
287
|
-
resource: subscription_path(subscription_name, options),
|
288
|
-
policy: new_policy
|
289
|
-
)
|
290
|
-
|
291
|
-
execute { iam.set_iam_policy set_req }
|
292
|
-
end
|
293
|
-
|
294
|
-
def test_subscription_permissions subscription_name,
|
295
|
-
permissions, options = {}
|
296
|
-
test_req = Google::Iam::V1::TestIamPermissionsRequest.new(
|
297
|
-
resource: subscription_path(subscription_name, options),
|
298
|
-
permissions: permissions
|
299
|
-
)
|
300
|
-
|
301
|
-
execute { iam.test_iam_permissions test_req }
|
302
|
-
end
|
303
|
-
|
304
|
-
def project_path options = {}
|
305
|
-
project_name = options[:project] || project
|
306
|
-
"projects/#{project_name}"
|
307
|
-
end
|
308
|
-
|
309
|
-
def topic_path topic_name, options = {}
|
310
|
-
return topic_name if topic_name.to_s.include? "/"
|
311
|
-
"#{project_path(options)}/topics/#{topic_name}"
|
312
|
-
end
|
313
|
-
|
314
|
-
def subscription_path subscription_name, options = {}
|
315
|
-
return subscription_name if subscription_name.to_s.include? "/"
|
316
|
-
"#{project_path(options)}/subscriptions/#{subscription_name}"
|
317
|
-
end
|
318
|
-
|
319
|
-
def inspect
|
320
|
-
"#{self.class}(#{@project})"
|
321
|
-
end
|
322
|
-
|
323
|
-
protected
|
324
|
-
|
325
|
-
def execute
|
326
|
-
Gcloud::Backoff.new(retries: retries).execute_grpc do
|
327
|
-
yield
|
328
|
-
end
|
329
|
-
rescue GRPC::BadStatus => e
|
330
|
-
raise Error.from_error(e)
|
331
|
-
end
|
332
|
-
end
|
333
|
-
end
|
334
|
-
end
|