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,6 +12,7 @@
|
|
13
12
|
# See the License for the specific language governing permissions and
|
14
13
|
# limitations under the License.
|
15
14
|
|
15
|
+
|
16
16
|
require "delegate"
|
17
17
|
|
18
18
|
module Gcloud
|
@@ -24,7 +24,7 @@ module Gcloud
|
|
24
24
|
##
|
25
25
|
# If not empty, indicates that there are more subscriptions
|
26
26
|
# that match the request and this value should be passed to
|
27
|
-
# the next Gcloud::
|
27
|
+
# the next {Gcloud::Pubsub::Topic#subscriptions} to continue.
|
28
28
|
attr_accessor :token
|
29
29
|
|
30
30
|
##
|
@@ -32,19 +32,21 @@ module Gcloud
|
|
32
32
|
def initialize arr = [], token = nil
|
33
33
|
super arr
|
34
34
|
@token = token
|
35
|
+
@token = nil if @token == ""
|
35
36
|
end
|
36
37
|
|
37
38
|
##
|
38
|
-
# New
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
# @private New Subscriptions::List from a
|
40
|
+
# Google::Pubsub::V1::ListSubscriptionsRequest object.
|
41
|
+
def self.from_grpc grpc_list, service
|
42
|
+
subs = Array(grpc_list.subscriptions).map do |grpc|
|
43
|
+
if grpc.is_a? String
|
44
|
+
Subscription.new_lazy grpc, service
|
43
45
|
else
|
44
|
-
Subscription.
|
46
|
+
Subscription.from_grpc grpc, service
|
45
47
|
end
|
46
48
|
end
|
47
|
-
new subs,
|
49
|
+
new subs, grpc_list.next_page_token
|
48
50
|
end
|
49
51
|
end
|
50
52
|
end
|
data/lib/gcloud/pubsub/topic.rb
CHANGED
@@ -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
|
-
|
17
|
-
require "gcloud/
|
15
|
+
|
16
|
+
require "gcloud/errors"
|
17
|
+
require "gcloud/pubsub/topic/batch"
|
18
18
|
require "gcloud/pubsub/topic/list"
|
19
19
|
require "gcloud/pubsub/subscription"
|
20
20
|
|
21
21
|
module Gcloud
|
22
22
|
module Pubsub
|
23
23
|
##
|
24
|
-
#
|
24
|
+
# # Topic
|
25
25
|
#
|
26
26
|
# A named resource to which messages are published.
|
27
27
|
#
|
28
|
+
# @example
|
28
29
|
# require "gcloud"
|
29
30
|
#
|
30
31
|
# gcloud = Gcloud.new
|
@@ -35,30 +36,30 @@ module Gcloud
|
|
35
36
|
#
|
36
37
|
class Topic
|
37
38
|
##
|
38
|
-
# The
|
39
|
-
attr_accessor :
|
39
|
+
# @private The gRPC Service object.
|
40
|
+
attr_accessor :service
|
40
41
|
|
41
42
|
##
|
42
|
-
# The Google
|
43
|
-
attr_accessor :
|
43
|
+
# @private The gRPC Google::Pubsub::V1::Topic object.
|
44
|
+
attr_accessor :grpc
|
44
45
|
|
45
46
|
##
|
46
|
-
# Create an empty Topic object.
|
47
|
-
def initialize
|
48
|
-
@
|
49
|
-
@
|
47
|
+
# @private Create an empty {Topic} object.
|
48
|
+
def initialize
|
49
|
+
@service = nil
|
50
|
+
@grpc = Google::Pubsub::V1::Topic.new
|
50
51
|
@name = nil
|
51
52
|
@exists = nil
|
52
53
|
end
|
53
54
|
|
54
55
|
##
|
55
|
-
# New lazy Topic object without making an HTTP request.
|
56
|
-
def self.new_lazy name,
|
56
|
+
# @private New lazy {Topic} object without making an HTTP request.
|
57
|
+
def self.new_lazy name, service, options = {}
|
57
58
|
new.tap do |t|
|
58
|
-
t.
|
59
|
-
t.
|
59
|
+
t.grpc = nil
|
60
|
+
t.service = service
|
60
61
|
t.instance_eval do
|
61
|
-
@name =
|
62
|
+
@name = service.topic_path(name, options)
|
62
63
|
end
|
63
64
|
end
|
64
65
|
end
|
@@ -67,18 +68,15 @@ module Gcloud
|
|
67
68
|
# The name of the topic in the form of
|
68
69
|
# "/projects/project-identifier/topics/topic-name".
|
69
70
|
def name
|
70
|
-
@
|
71
|
+
@grpc ? @grpc.name : @name
|
71
72
|
end
|
72
73
|
|
73
74
|
##
|
74
75
|
# Permanently deletes the topic.
|
75
76
|
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
# +true+ if the topic was deleted.
|
79
|
-
#
|
80
|
-
# === Example
|
77
|
+
# @return [Boolean] Returns `true` if the topic was deleted.
|
81
78
|
#
|
79
|
+
# @example
|
82
80
|
# require "gcloud"
|
83
81
|
#
|
84
82
|
# gcloud = Gcloud.new
|
@@ -88,39 +86,30 @@ module Gcloud
|
|
88
86
|
# topic.delete
|
89
87
|
#
|
90
88
|
def delete
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
fail ApiError.from_response(resp)
|
97
|
-
end
|
89
|
+
ensure_service!
|
90
|
+
service.delete_topic name
|
91
|
+
return true
|
92
|
+
rescue GRPC::BadStatus => e
|
93
|
+
raise Error.from_error(e)
|
98
94
|
end
|
99
95
|
|
100
96
|
##
|
101
|
-
# Creates a new Subscription object on the current Topic.
|
102
|
-
#
|
103
|
-
#
|
104
|
-
#
|
105
|
-
# +
|
106
|
-
#
|
107
|
-
#
|
108
|
-
#
|
109
|
-
#
|
110
|
-
#
|
111
|
-
#
|
112
|
-
#
|
113
|
-
#
|
114
|
-
#
|
115
|
-
#
|
116
|
-
#
|
117
|
-
#
|
118
|
-
# === Returns
|
119
|
-
#
|
120
|
-
# Gcloud::Pubsub::Subscription
|
121
|
-
#
|
122
|
-
# === Examples
|
123
|
-
#
|
97
|
+
# Creates a new {Subscription} object on the current Topic.
|
98
|
+
#
|
99
|
+
# @param [String] subscription_name Name of the new subscription. Must
|
100
|
+
# start with a letter, and contain only letters ([A-Za-z]), numbers
|
101
|
+
# ([0-9], dashes (-), underscores (_), periods (.), tildes (~), plus (+)
|
102
|
+
# or percent signs (%). It must be between 3 and 255 characters in
|
103
|
+
# length, and it must not start with "goog".
|
104
|
+
# @param [Integer] deadline The maximum number of seconds after a
|
105
|
+
# subscriber receives a message before the subscriber should acknowledge
|
106
|
+
# the message.
|
107
|
+
# @param [String] endpoint A URL locating the endpoint to which messages
|
108
|
+
# should be pushed.
|
109
|
+
#
|
110
|
+
# @return [Gcloud::Pubsub::Subscription]
|
111
|
+
#
|
112
|
+
# @example
|
124
113
|
# require "gcloud"
|
125
114
|
#
|
126
115
|
# gcloud = Gcloud.new
|
@@ -130,8 +119,7 @@ module Gcloud
|
|
130
119
|
# sub = topic.subscribe "my-topic-sub"
|
131
120
|
# puts sub.name # => "my-topic-sub"
|
132
121
|
#
|
133
|
-
# The name is optional, and will be generated if not given
|
134
|
-
#
|
122
|
+
# @example The name is optional, and will be generated if not given:
|
135
123
|
# require "gcloud"
|
136
124
|
#
|
137
125
|
# gcloud = Gcloud.new
|
@@ -141,9 +129,7 @@ module Gcloud
|
|
141
129
|
# sub = topic.subscribe "my-topic-sub"
|
142
130
|
# puts sub.name # => "generated-sub-name"
|
143
131
|
#
|
144
|
-
#
|
145
|
-
# acknowledgement and pushed all messages to an endpoint
|
146
|
-
#
|
132
|
+
# @example Wait 2 minutes for acknowledgement and push all to an endpoint:
|
147
133
|
# require "gcloud"
|
148
134
|
#
|
149
135
|
# gcloud = Gcloud.new
|
@@ -155,14 +141,12 @@ module Gcloud
|
|
155
141
|
# endpoint: "https://example.com/push"
|
156
142
|
#
|
157
143
|
def subscribe subscription_name, deadline: nil, endpoint: nil
|
158
|
-
|
144
|
+
ensure_service!
|
159
145
|
options = { deadline: deadline, endpoint: endpoint }
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
fail ApiError.from_response(resp)
|
165
|
-
end
|
146
|
+
grpc = service.create_subscription name, subscription_name, options
|
147
|
+
Subscription.from_grpc grpc, service
|
148
|
+
rescue GRPC::BadStatus => e
|
149
|
+
raise Error.from_error(e)
|
166
150
|
end
|
167
151
|
alias_method :create_subscription, :subscribe
|
168
152
|
alias_method :new_subscription, :subscribe
|
@@ -170,22 +154,16 @@ module Gcloud
|
|
170
154
|
##
|
171
155
|
# Retrieves subscription by name.
|
172
156
|
#
|
173
|
-
#
|
174
|
-
#
|
175
|
-
#
|
176
|
-
#
|
177
|
-
#
|
178
|
-
# Optionally create a Subscription object without verifying the
|
179
|
-
# subscription resource exists on the Pub/Sub service. Calls made on
|
180
|
-
# this object will raise errors if the service resource does not exist.
|
181
|
-
# Default is +false+. (+Boolean+)
|
182
|
-
#
|
183
|
-
# === Returns
|
157
|
+
# @param [String] subscription_name Name of a subscription.
|
158
|
+
# @param [Boolean] skip_lookup Optionally create a {Subscription} object
|
159
|
+
# without verifying the subscription resource exists on the Pub/Sub
|
160
|
+
# service. Calls made on this object will raise errors if the service
|
161
|
+
# resource does not exist. Default is `false`.
|
184
162
|
#
|
185
|
-
# Gcloud::Pubsub::Subscription
|
186
|
-
#
|
187
|
-
# === Example
|
163
|
+
# @return [Gcloud::Pubsub::Subscription, nil] Returns `nil` if
|
164
|
+
# the subscription does not exist.
|
188
165
|
#
|
166
|
+
# @example
|
189
167
|
# require "gcloud"
|
190
168
|
#
|
191
169
|
# gcloud = Gcloud.new
|
@@ -195,9 +173,7 @@ module Gcloud
|
|
195
173
|
# subscription = topic.subscription "my-topic-subscription"
|
196
174
|
# puts subscription.name
|
197
175
|
#
|
198
|
-
#
|
199
|
-
# +skip_lookup+ option:
|
200
|
-
#
|
176
|
+
# @example Skip the lookup against the service with `skip_lookup`:
|
201
177
|
# require "gcloud"
|
202
178
|
#
|
203
179
|
# gcloud = Gcloud.new
|
@@ -208,14 +184,13 @@ module Gcloud
|
|
208
184
|
# puts subscription.name
|
209
185
|
#
|
210
186
|
def subscription subscription_name, skip_lookup: nil
|
211
|
-
|
212
|
-
if skip_lookup
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
return
|
217
|
-
|
218
|
-
fail ApiError.from_response(resp)
|
187
|
+
ensure_service!
|
188
|
+
return Subscription.new_lazy subscription_name, service if skip_lookup
|
189
|
+
grpc = service.get_subscription subscription_name
|
190
|
+
Subscription.from_grpc grpc, service
|
191
|
+
rescue GRPC::BadStatus => e
|
192
|
+
return nil if e.code == 5
|
193
|
+
raise Error.from_error(e)
|
219
194
|
end
|
220
195
|
alias_method :get_subscription, :subscription
|
221
196
|
alias_method :find_subscription, :subscription
|
@@ -223,21 +198,14 @@ module Gcloud
|
|
223
198
|
##
|
224
199
|
# Retrieves a list of subscription names for the given project.
|
225
200
|
#
|
226
|
-
#
|
227
|
-
#
|
228
|
-
#
|
229
|
-
#
|
230
|
-
# indicates that this is a continuation of a call, and that the system
|
231
|
-
# should return the next page of data. (+String+)
|
232
|
-
# +max+::
|
233
|
-
# Maximum number of subscriptions to return. (+Integer+)
|
201
|
+
# @param [String] token The `token` value returned by the last call to
|
202
|
+
# `subscriptions`; indicates that this is a continuation of a call, and
|
203
|
+
# that the system should return the next page of data.
|
204
|
+
# @param [Integer] max Maximum number of subscriptions to return.
|
234
205
|
#
|
235
|
-
#
|
236
|
-
#
|
237
|
-
# Array of Subscription objects (See Subscription::List)
|
238
|
-
#
|
239
|
-
# === Examples
|
206
|
+
# @return [Array<Subscription>] (See {Subscription::List})
|
240
207
|
#
|
208
|
+
# @example
|
241
209
|
# require "gcloud"
|
242
210
|
#
|
243
211
|
# gcloud = Gcloud.new
|
@@ -249,9 +217,7 @@ module Gcloud
|
|
249
217
|
# puts subscription.name
|
250
218
|
# end
|
251
219
|
#
|
252
|
-
#
|
253
|
-
# paginate through them: (See Subscription::List#token)
|
254
|
-
#
|
220
|
+
# @example With pagination: (See {Subscription::List#token})
|
255
221
|
# require "gcloud"
|
256
222
|
#
|
257
223
|
# gcloud = Gcloud.new
|
@@ -271,14 +237,12 @@ module Gcloud
|
|
271
237
|
# end
|
272
238
|
#
|
273
239
|
def subscriptions token: nil, max: nil
|
274
|
-
|
240
|
+
ensure_service!
|
275
241
|
options = { token: token, max: max }
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
fail ApiError.from_response(resp)
|
281
|
-
end
|
242
|
+
grpc = service.list_topics_subscriptions name, options
|
243
|
+
Subscription::List.from_grpc grpc, service
|
244
|
+
rescue GRPC::BadStatus => e
|
245
|
+
raise Error.from_error(e)
|
282
246
|
end
|
283
247
|
alias_method :find_subscriptions, :subscriptions
|
284
248
|
alias_method :list_subscriptions, :subscriptions
|
@@ -286,20 +250,16 @@ module Gcloud
|
|
286
250
|
##
|
287
251
|
# Publishes one or more messages to the topic.
|
288
252
|
#
|
289
|
-
#
|
290
|
-
#
|
291
|
-
#
|
292
|
-
#
|
293
|
-
# +attributes+::
|
294
|
-
# Optional attributes for the message. (+Hash+)
|
295
|
-
#
|
296
|
-
# === Returns
|
297
|
-
#
|
298
|
-
# Message object when called without a block,
|
299
|
-
# Array of Message objects when called with a block
|
253
|
+
# @param [String] data The message data.
|
254
|
+
# @param [Hash] attributes Optional attributes for the message.
|
255
|
+
# @yield [batch] a block for publishing multiple messages in one request
|
256
|
+
# @yieldparam [Topic::Batch] batch the batch object
|
300
257
|
#
|
301
|
-
#
|
258
|
+
# @return [Message, Array<Message>] Returns the published message when
|
259
|
+
# called without a block, or an array of messages when called with a
|
260
|
+
# block.
|
302
261
|
#
|
262
|
+
# @example
|
303
263
|
# require "gcloud"
|
304
264
|
#
|
305
265
|
# gcloud = Gcloud.new
|
@@ -308,8 +268,7 @@ module Gcloud
|
|
308
268
|
# topic = pubsub.topic "my-topic"
|
309
269
|
# msg = topic.publish "new-message"
|
310
270
|
#
|
311
|
-
# Additionally, a message can be published with attributes:
|
312
|
-
#
|
271
|
+
# @example Additionally, a message can be published with attributes:
|
313
272
|
# require "gcloud"
|
314
273
|
#
|
315
274
|
# gcloud = Gcloud.new
|
@@ -320,8 +279,7 @@ module Gcloud
|
|
320
279
|
# foo: :bar,
|
321
280
|
# this: :that
|
322
281
|
#
|
323
|
-
# Multiple messages can be
|
324
|
-
#
|
282
|
+
# @example Multiple messages can be sent at the same time using a block:
|
325
283
|
# require "gcloud"
|
326
284
|
#
|
327
285
|
# gcloud = Gcloud.new
|
@@ -335,7 +293,7 @@ module Gcloud
|
|
335
293
|
# end
|
336
294
|
#
|
337
295
|
def publish data = nil, attributes = {}
|
338
|
-
|
296
|
+
ensure_service!
|
339
297
|
batch = Batch.new data, attributes
|
340
298
|
yield batch if block_given?
|
341
299
|
return nil if batch.messages.count.zero?
|
@@ -345,17 +303,12 @@ module Gcloud
|
|
345
303
|
##
|
346
304
|
# Gets the access control policy.
|
347
305
|
#
|
348
|
-
#
|
349
|
-
#
|
350
|
-
#
|
351
|
-
#
|
352
|
-
# +true. Otherwise the policy will be memoized to reduce the number of
|
353
|
-
# API calls made to the Pub/Sub service. The default is +false+.
|
354
|
-
# (+Boolean+)
|
306
|
+
# @param [Boolean] force Force the latest policy to be retrieved from the
|
307
|
+
# Pub/Sub service when `true`. Otherwise the policy will be memoized to
|
308
|
+
# reduce the number of API calls made to the Pub/Sub service. The
|
309
|
+
# default is `false`.
|
355
310
|
#
|
356
|
-
#
|
357
|
-
#
|
358
|
-
# A hash that conforms to the following structure:
|
311
|
+
# @return [Hash] Returns a hash that conforms to the following structure:
|
359
312
|
#
|
360
313
|
# {
|
361
314
|
# "etag"=>"CAE=",
|
@@ -365,11 +318,7 @@ module Gcloud
|
|
365
318
|
# }]
|
366
319
|
# }
|
367
320
|
#
|
368
|
-
#
|
369
|
-
#
|
370
|
-
# By default, the policy values are memoized to reduce the number of API
|
371
|
-
# calls to the Pub/Sub service.
|
372
|
-
#
|
321
|
+
# @example Policy values are memoized to reduce the number of API calls:
|
373
322
|
# require "gcloud"
|
374
323
|
#
|
375
324
|
# gcloud = Gcloud.new
|
@@ -379,9 +328,7 @@ module Gcloud
|
|
379
328
|
# puts topic.policy["bindings"]
|
380
329
|
# puts topic.policy["rules"]
|
381
330
|
#
|
382
|
-
#
|
383
|
-
# flag.
|
384
|
-
#
|
331
|
+
# @example Use `force` to retrieve the latest policy from the service:
|
385
332
|
# require "gcloud"
|
386
333
|
#
|
387
334
|
# gcloud = Gcloud.new
|
@@ -393,22 +340,19 @@ module Gcloud
|
|
393
340
|
def policy force: nil
|
394
341
|
@policy = nil if force
|
395
342
|
@policy ||= begin
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
policy
|
343
|
+
ensure_service!
|
344
|
+
grpc = service.get_topic_policy name
|
345
|
+
JSON.parse(Google::Iam::V1::Policy.encode_json(grpc))
|
346
|
+
rescue GRPC::BadStatus => e
|
347
|
+
raise Error.from_error(e)
|
402
348
|
end
|
403
349
|
end
|
404
350
|
|
405
351
|
##
|
406
352
|
# Sets the access control policy.
|
407
353
|
#
|
408
|
-
#
|
409
|
-
#
|
410
|
-
# +new_policy+::
|
411
|
-
# A hash that conforms to the following structure:
|
354
|
+
# @param [String] new_policy A hash that conforms to the following
|
355
|
+
# structure:
|
412
356
|
#
|
413
357
|
# {
|
414
358
|
# "bindings" => [{
|
@@ -417,8 +361,7 @@ module Gcloud
|
|
417
361
|
# }]
|
418
362
|
# }
|
419
363
|
#
|
420
|
-
#
|
421
|
-
#
|
364
|
+
# @example
|
422
365
|
# require "gcloud"
|
423
366
|
#
|
424
367
|
# gcloud = Gcloud.new
|
@@ -434,28 +377,23 @@ module Gcloud
|
|
434
377
|
# topic.policy = viewer_policy
|
435
378
|
#
|
436
379
|
def policy= new_policy
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
else
|
443
|
-
fail ApiError.from_response(resp)
|
444
|
-
end
|
380
|
+
ensure_service!
|
381
|
+
grpc = service.set_topic_policy name, new_policy
|
382
|
+
@policy = JSON.parse(Google::Iam::V1::Policy.encode_json(grpc))
|
383
|
+
rescue GRPC::BadStatus => e
|
384
|
+
raise Error.from_error(e)
|
445
385
|
end
|
446
386
|
|
447
387
|
##
|
448
|
-
# Tests the specified permissions against the
|
449
|
-
# IAM
|
450
|
-
# {Managing Policies}[https://cloud.google.com/iam/docs/managing-policies]
|
451
|
-
# for more information.
|
388
|
+
# Tests the specified permissions against the [Cloud
|
389
|
+
# IAM](https://cloud.google.com/iam/) access control policy.
|
452
390
|
#
|
453
|
-
#
|
391
|
+
# @see https://cloud.google.com/iam/docs/managing-policies Managing
|
392
|
+
# Policies
|
454
393
|
#
|
455
|
-
#
|
456
|
-
#
|
457
|
-
#
|
458
|
-
# (String or Array of Strings)
|
394
|
+
# @param [String, Array<String>] permissions The set of permissions to
|
395
|
+
# check access for. Permissions with wildcards (such as `*` or
|
396
|
+
# `storage.*`) are not allowed.
|
459
397
|
#
|
460
398
|
# The permissions that can be checked on a topic are:
|
461
399
|
#
|
@@ -467,12 +405,9 @@ module Gcloud
|
|
467
405
|
# * pubsub.topics.getIamPolicy
|
468
406
|
# * pubsub.topics.setIamPolicy
|
469
407
|
#
|
470
|
-
#
|
471
|
-
#
|
472
|
-
# The permissions that have access. (Array of Strings)
|
473
|
-
#
|
474
|
-
# === Example
|
408
|
+
# @return [Array<Strings>] The permissions that have access.
|
475
409
|
#
|
410
|
+
# @example
|
476
411
|
# require "gcloud"
|
477
412
|
#
|
478
413
|
# gcloud = Gcloud.new
|
@@ -485,20 +420,18 @@ module Gcloud
|
|
485
420
|
#
|
486
421
|
def test_permissions *permissions
|
487
422
|
permissions = Array(permissions).flatten
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
end
|
423
|
+
permissions = Array(permissions).flatten
|
424
|
+
ensure_service!
|
425
|
+
grpc = service.test_topic_permissions name, permissions
|
426
|
+
grpc.permissions
|
427
|
+
rescue GRPC::BadStatus => e
|
428
|
+
raise Error.from_error(e)
|
495
429
|
end
|
496
430
|
|
497
431
|
##
|
498
432
|
# Determines whether the topic exists in the Pub/Sub service.
|
499
433
|
#
|
500
|
-
#
|
501
|
-
#
|
434
|
+
# @example
|
502
435
|
# require "gcloud"
|
503
436
|
#
|
504
437
|
# gcloud = Gcloud.new
|
@@ -508,19 +441,19 @@ module Gcloud
|
|
508
441
|
# topic.exists? #=> true
|
509
442
|
#
|
510
443
|
def exists?
|
511
|
-
# Always true if we have a
|
512
|
-
return true unless @
|
444
|
+
# Always true if we have a grpc object
|
445
|
+
return true unless @grpc.nil?
|
513
446
|
# If we have a value, return it
|
514
447
|
return @exists unless @exists.nil?
|
515
|
-
|
516
|
-
@exists = !@
|
448
|
+
ensure_grpc!
|
449
|
+
@exists = !@grpc.nil?
|
517
450
|
end
|
518
451
|
|
519
452
|
##
|
453
|
+
# @private
|
520
454
|
# Determines whether the topic object was created with an HTTP call.
|
521
455
|
#
|
522
|
-
#
|
523
|
-
#
|
456
|
+
# @example
|
524
457
|
# require "gcloud"
|
525
458
|
#
|
526
459
|
# gcloud = Gcloud.new
|
@@ -529,98 +462,46 @@ module Gcloud
|
|
529
462
|
# topic = pubsub.topic "my-topic"
|
530
463
|
# topic.lazy? #=> false
|
531
464
|
#
|
532
|
-
def lazy?
|
533
|
-
@
|
465
|
+
def lazy?
|
466
|
+
@grpc.nil?
|
534
467
|
end
|
535
468
|
|
536
469
|
##
|
537
|
-
# New Topic from a Google
|
538
|
-
def self.
|
470
|
+
# @private New Topic from a Google::Pubsub::V1::Topic object.
|
471
|
+
def self.from_grpc grpc, service
|
539
472
|
new.tap do |f|
|
540
|
-
f.
|
541
|
-
f.
|
473
|
+
f.grpc = grpc
|
474
|
+
f.service = service
|
542
475
|
end
|
543
476
|
end
|
544
477
|
|
545
478
|
protected
|
546
479
|
|
547
480
|
##
|
548
|
-
# Raise an error unless an active connection is
|
549
|
-
|
550
|
-
|
481
|
+
# @private Raise an error unless an active connection to the service is
|
482
|
+
# available.
|
483
|
+
def ensure_service!
|
484
|
+
fail "Must have active connection to service" unless service
|
551
485
|
end
|
552
486
|
|
553
487
|
##
|
554
|
-
# Ensures a Google
|
555
|
-
def
|
556
|
-
|
557
|
-
return @
|
558
|
-
|
559
|
-
|
488
|
+
# Ensures a Google::Pubsub::V1::Topic object exists.
|
489
|
+
def ensure_grpc!
|
490
|
+
ensure_service!
|
491
|
+
return @grpc if @grpc
|
492
|
+
@grpc = service.get_topic @name
|
493
|
+
rescue GRPC::BadStatus => e
|
494
|
+
return nil if e.code == 5
|
495
|
+
raise Error.from_error(e)
|
560
496
|
end
|
561
497
|
|
562
498
|
##
|
563
499
|
# Call the publish API with arrays of data data and attrs.
|
564
500
|
def publish_batch_messages batch
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
fail ApiError.from_response(resp)
|
570
|
-
end
|
571
|
-
end
|
572
|
-
|
573
|
-
##
|
574
|
-
# Batch object used to publish multiple messages at once.
|
575
|
-
class Batch
|
576
|
-
##
|
577
|
-
# The messages to publish
|
578
|
-
attr_reader :messages #:nodoc:
|
579
|
-
|
580
|
-
##
|
581
|
-
# Create a new instance of the object.
|
582
|
-
def initialize data = nil, attributes = {} #:nodoc:
|
583
|
-
@messages = []
|
584
|
-
@mode = :batch
|
585
|
-
return if data.nil?
|
586
|
-
@mode = :single
|
587
|
-
publish data, attributes
|
588
|
-
end
|
589
|
-
|
590
|
-
##
|
591
|
-
# Add multiple messages to the topic.
|
592
|
-
# All messages added will be published at once.
|
593
|
-
# See Gcloud::Pubsub::Topic#publish
|
594
|
-
def publish data, attributes = {}
|
595
|
-
@messages << [data, attributes]
|
596
|
-
end
|
597
|
-
|
598
|
-
##
|
599
|
-
# Create Message objects with message ids.
|
600
|
-
def to_gcloud_messages message_ids #:nodoc:
|
601
|
-
msgs = @messages.zip(Array(message_ids)).map do |arr, id|
|
602
|
-
Message.from_gapi "data" => arr[0],
|
603
|
-
"attributes" => jsonify_hash(arr[1]),
|
604
|
-
"messageId" => id
|
605
|
-
end
|
606
|
-
# Return just one Message if a single publish,
|
607
|
-
# otherwise return the array of Messages.
|
608
|
-
if @mode == :single && msgs.count <= 1
|
609
|
-
msgs.first
|
610
|
-
else
|
611
|
-
msgs
|
612
|
-
end
|
613
|
-
end
|
614
|
-
|
615
|
-
protected
|
616
|
-
|
617
|
-
##
|
618
|
-
# Make the hash look like it was returned from the Cloud API.
|
619
|
-
def jsonify_hash hash
|
620
|
-
hash = (hash || {}).to_h
|
621
|
-
return hash if hash.empty?
|
622
|
-
JSON.parse(JSON.dump(hash))
|
623
|
-
end
|
501
|
+
grpc = service.publish name, batch.messages
|
502
|
+
batch.to_gcloud_messages Array(grpc.message_ids)
|
503
|
+
rescue GRPC::BadStatus => e
|
504
|
+
raise Error.from_error(e)
|
624
505
|
end
|
625
506
|
end
|
626
507
|
end
|