gcloud 0.6.3 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. checksums.yaml +8 -8
  2. data/AUTHENTICATION.md +13 -9
  3. data/CHANGELOG.md +8 -3
  4. data/OVERVIEW.md +46 -8
  5. data/lib/gcloud.rb +123 -117
  6. data/lib/gcloud/backoff.rb +43 -15
  7. data/lib/gcloud/bigquery.rb +211 -195
  8. data/lib/gcloud/bigquery/connection.rb +9 -9
  9. data/lib/gcloud/bigquery/copy_job.rb +15 -16
  10. data/lib/gcloud/bigquery/credentials.rb +3 -3
  11. data/lib/gcloud/bigquery/data.rb +12 -11
  12. data/lib/gcloud/bigquery/dataset.rb +162 -216
  13. data/lib/gcloud/bigquery/dataset/access.rb +59 -43
  14. data/lib/gcloud/bigquery/dataset/list.rb +3 -3
  15. data/lib/gcloud/bigquery/errors.rb +9 -5
  16. data/lib/gcloud/bigquery/extract_job.rb +18 -18
  17. data/lib/gcloud/bigquery/insert_response.rb +7 -4
  18. data/lib/gcloud/bigquery/job.rb +48 -44
  19. data/lib/gcloud/bigquery/job/list.rb +3 -3
  20. data/lib/gcloud/bigquery/load_job.rb +24 -25
  21. data/lib/gcloud/bigquery/project.rb +145 -204
  22. data/lib/gcloud/bigquery/query_data.rb +10 -9
  23. data/lib/gcloud/bigquery/query_job.rb +23 -32
  24. data/lib/gcloud/bigquery/table.rb +238 -280
  25. data/lib/gcloud/bigquery/table/list.rb +3 -3
  26. data/lib/gcloud/bigquery/table/schema.rb +79 -87
  27. data/lib/gcloud/bigquery/view.rb +69 -82
  28. data/lib/gcloud/credentials.rb +3 -9
  29. data/lib/gcloud/datastore.rb +194 -170
  30. data/lib/gcloud/datastore/connection.rb +12 -8
  31. data/lib/gcloud/datastore/credentials.rb +6 -4
  32. data/lib/gcloud/datastore/dataset.rb +74 -141
  33. data/lib/gcloud/datastore/dataset/lookup_results.rb +6 -4
  34. data/lib/gcloud/datastore/dataset/query_results.rb +6 -4
  35. data/lib/gcloud/datastore/entity.rb +81 -76
  36. data/lib/gcloud/datastore/errors.rb +10 -8
  37. data/lib/gcloud/datastore/key.rb +41 -77
  38. data/lib/gcloud/datastore/properties.rb +3 -3
  39. data/lib/gcloud/datastore/proto.rb +7 -4
  40. data/lib/gcloud/datastore/query.rb +26 -3
  41. data/lib/gcloud/datastore/transaction.rb +12 -8
  42. data/lib/gcloud/dns.rb +180 -152
  43. data/lib/gcloud/dns/change.rb +16 -16
  44. data/lib/gcloud/dns/change/list.rb +3 -3
  45. data/lib/gcloud/dns/connection.rb +9 -10
  46. data/lib/gcloud/dns/credentials.rb +3 -3
  47. data/lib/gcloud/dns/errors.rb +9 -5
  48. data/lib/gcloud/dns/importer.rb +17 -23
  49. data/lib/gcloud/dns/project.rb +42 -64
  50. data/lib/gcloud/dns/record.rb +58 -46
  51. data/lib/gcloud/dns/record/list.rb +6 -7
  52. data/lib/gcloud/dns/zone.rb +198 -289
  53. data/lib/gcloud/dns/zone/list.rb +3 -3
  54. data/lib/gcloud/dns/zone/transaction.rb +56 -72
  55. data/lib/gcloud/errors.rb +174 -3
  56. data/lib/gcloud/gce.rb +3 -4
  57. data/lib/gcloud/grpc_utils.rb +76 -0
  58. data/lib/gcloud/logging.rb +308 -0
  59. data/lib/gcloud/logging/credentials.rb +29 -0
  60. data/lib/gcloud/logging/entry.rb +303 -0
  61. data/lib/gcloud/logging/entry/http_request.rb +141 -0
  62. data/lib/gcloud/logging/entry/list.rb +111 -0
  63. data/lib/gcloud/logging/entry/operation.rb +90 -0
  64. data/lib/gcloud/logging/logger.rb +307 -0
  65. data/lib/gcloud/logging/metric.rb +175 -0
  66. data/lib/gcloud/logging/metric/list.rb +98 -0
  67. data/lib/gcloud/logging/project.rb +650 -0
  68. data/lib/gcloud/logging/resource.rb +95 -0
  69. data/lib/gcloud/logging/resource_descriptor.rb +140 -0
  70. data/lib/gcloud/logging/resource_descriptor/list.rb +78 -0
  71. data/lib/gcloud/logging/service.rb +258 -0
  72. data/lib/gcloud/logging/sink.rb +233 -0
  73. data/lib/gcloud/logging/sink/list.rb +97 -0
  74. data/lib/gcloud/pubsub.rb +241 -199
  75. data/lib/gcloud/pubsub/credentials.rb +3 -3
  76. data/lib/gcloud/pubsub/message.rb +26 -20
  77. data/lib/gcloud/pubsub/project.rb +166 -233
  78. data/lib/gcloud/pubsub/received_message.rb +28 -38
  79. data/lib/gcloud/pubsub/service.rb +323 -0
  80. data/lib/gcloud/pubsub/subscription.rb +172 -242
  81. data/lib/gcloud/pubsub/subscription/list.rb +11 -9
  82. data/lib/gcloud/pubsub/topic.rb +152 -271
  83. data/lib/gcloud/pubsub/topic/batch.rb +66 -0
  84. data/lib/gcloud/pubsub/topic/list.rb +9 -7
  85. data/lib/gcloud/resource_manager.rb +158 -138
  86. data/lib/gcloud/resource_manager/connection.rb +6 -5
  87. data/lib/gcloud/resource_manager/credentials.rb +3 -3
  88. data/lib/gcloud/resource_manager/errors.rb +9 -5
  89. data/lib/gcloud/resource_manager/manager.rb +54 -86
  90. data/lib/gcloud/resource_manager/project.rb +69 -88
  91. data/lib/gcloud/resource_manager/project/list.rb +4 -5
  92. data/lib/gcloud/resource_manager/project/updater.rb +12 -14
  93. data/lib/gcloud/search.rb +158 -135
  94. data/lib/gcloud/search/api_client.rb +7 -7
  95. data/lib/gcloud/search/connection.rb +8 -8
  96. data/lib/gcloud/search/credentials.rb +3 -3
  97. data/lib/gcloud/search/document.rb +64 -87
  98. data/lib/gcloud/search/document/list.rb +5 -5
  99. data/lib/gcloud/search/errors.rb +9 -5
  100. data/lib/gcloud/search/field_value.rb +32 -38
  101. data/lib/gcloud/search/field_values.rb +50 -80
  102. data/lib/gcloud/search/fields.rb +44 -65
  103. data/lib/gcloud/search/index.rb +163 -204
  104. data/lib/gcloud/search/index/list.rb +5 -5
  105. data/lib/gcloud/search/project.rb +31 -47
  106. data/lib/gcloud/search/result.rb +27 -31
  107. data/lib/gcloud/search/result/list.rb +6 -6
  108. data/lib/gcloud/storage.rb +224 -190
  109. data/lib/gcloud/storage/bucket.rb +202 -227
  110. data/lib/gcloud/storage/bucket/acl.rb +83 -170
  111. data/lib/gcloud/storage/bucket/cors.rb +31 -34
  112. data/lib/gcloud/storage/bucket/list.rb +3 -3
  113. data/lib/gcloud/storage/connection.rb +11 -7
  114. data/lib/gcloud/storage/credentials.rb +3 -3
  115. data/lib/gcloud/storage/errors.rb +11 -8
  116. data/lib/gcloud/storage/file.rb +129 -171
  117. data/lib/gcloud/storage/file/acl.rb +51 -99
  118. data/lib/gcloud/storage/file/list.rb +3 -3
  119. data/lib/gcloud/storage/file/verifier.rb +3 -2
  120. data/lib/gcloud/storage/project.rb +111 -132
  121. data/lib/gcloud/upload.rb +4 -7
  122. data/lib/gcloud/version.rb +2 -4
  123. data/lib/google/api/annotations.rb +14 -0
  124. data/lib/google/api/http.rb +30 -0
  125. data/lib/google/api/label.rb +24 -0
  126. data/lib/google/api/monitored_resource.rb +25 -0
  127. data/lib/google/datastore/v1beta3/datastore.rb +115 -0
  128. data/lib/google/datastore/v1beta3/datastore_services.rb +33 -0
  129. data/lib/google/datastore/v1beta3/entity.rb +63 -0
  130. data/lib/google/datastore/v1beta3/query.rb +128 -0
  131. data/lib/google/devtools/cloudtrace/v1/trace.rb +78 -0
  132. data/lib/google/devtools/cloudtrace/v1/trace_services.rb +32 -0
  133. data/lib/google/example/library/v1/library.rb +91 -0
  134. data/lib/google/example/library/v1/library_services.rb +40 -0
  135. data/lib/google/iam/v1/iam_policy.rb +33 -0
  136. data/lib/google/iam/v1/iam_policy_services.rb +30 -0
  137. data/lib/google/iam/v1/policy.rb +25 -0
  138. data/lib/google/logging/type/http_request.rb +28 -0
  139. data/lib/google/logging/type/log_severity.rb +27 -0
  140. data/lib/google/logging/v2/log_entry.rb +44 -0
  141. data/lib/google/logging/v2/logging.rb +56 -0
  142. data/lib/google/logging/v2/logging_config.rb +59 -0
  143. data/lib/google/logging/v2/logging_config_services.rb +32 -0
  144. data/lib/google/logging/v2/logging_metrics.rb +51 -0
  145. data/lib/google/logging/v2/logging_metrics_services.rb +32 -0
  146. data/lib/google/logging/v2/logging_services.rb +31 -0
  147. data/lib/google/longrunning/operations.rb +50 -0
  148. data/lib/google/longrunning/operations_services.rb +29 -0
  149. data/lib/google/protobuf/any.rb +17 -0
  150. data/lib/google/protobuf/api.rb +31 -0
  151. data/lib/google/protobuf/descriptor.rb +0 -0
  152. data/lib/google/protobuf/duration.rb +17 -0
  153. data/lib/google/protobuf/empty.rb +15 -0
  154. data/lib/google/protobuf/field_mask.rb +16 -0
  155. data/lib/google/protobuf/source_context.rb +16 -0
  156. data/lib/google/protobuf/struct.rb +35 -0
  157. data/lib/google/protobuf/timestamp.rb +17 -0
  158. data/lib/google/protobuf/type.rb +79 -0
  159. data/lib/google/protobuf/wrappers.rb +48 -0
  160. data/lib/google/pubsub/v1/pubsub.rb +129 -0
  161. data/lib/google/pubsub/v1/pubsub_services.rb +56 -0
  162. data/lib/google/pubsub/v1beta2/pubsub.rb +126 -0
  163. data/lib/google/pubsub/v1beta2/pubsub_services.rb +56 -0
  164. data/lib/google/rpc/code.rb +32 -0
  165. data/lib/google/rpc/error_details.rb +61 -0
  166. data/lib/google/rpc/status.rb +19 -0
  167. data/lib/google/type/color.rb +20 -0
  168. data/lib/google/type/date.rb +18 -0
  169. data/lib/google/type/dayofweek.rb +23 -0
  170. data/lib/google/type/latlng.rb +17 -0
  171. data/lib/google/type/money.rb +18 -0
  172. data/lib/google/type/timeofday.rb +19 -0
  173. metadata +101 -4
  174. data/lib/gcloud/pubsub/connection.rb +0 -295
  175. data/lib/gcloud/pubsub/errors.rb +0 -93
@@ -1,295 +0,0 @@
1
- #--
2
- # Copyright 2015 Google Inc. All rights reserved.
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
-
16
- require "gcloud/version"
17
- require "google/api_client"
18
-
19
- module Gcloud
20
- module Pubsub
21
- ##
22
- # Represents the connection to Pub/Sub,
23
- # as well as expose the API calls.
24
- class Connection #:nodoc:
25
- API_VERSION = "v1"
26
-
27
- attr_accessor :project
28
- attr_accessor :credentials #:nodoc:
29
-
30
- ##
31
- # Creates a new Connection instance.
32
- def initialize project, credentials
33
- @project = project
34
- @credentials = credentials
35
- @client = Google::APIClient.new application_name: "gcloud-ruby",
36
- application_version: Gcloud::VERSION
37
- @client.authorization = @credentials.client
38
- @pubsub = @client.discovered_api "pubsub", API_VERSION
39
- end
40
-
41
- ##
42
- # Gets the configuration of a topic.
43
- # Since the topic only has the name attribute,
44
- # this method is only useful to check the existence of a topic.
45
- # If other attributes are added in the future,
46
- # they will be returned here.
47
- def get_topic topic_name, options = {}
48
- @client.execute(
49
- api_method: @pubsub.projects.topics.get,
50
- parameters: { topic: topic_path(topic_name, options) }
51
- )
52
- end
53
-
54
- ##
55
- # Creates the given topic with the given name.
56
- def create_topic topic_name, options = {}
57
- @client.execute(
58
- api_method: @pubsub.projects.topics.create,
59
- parameters: { name: topic_path(topic_name, options) }
60
- )
61
- end
62
-
63
- ##
64
- # Lists matching topics.
65
- def list_topics options = {}
66
- params = { project: project_path(options),
67
- pageToken: options.delete(:token),
68
- pageSize: options.delete(:max)
69
- }.delete_if { |_, v| v.nil? }
70
-
71
- @client.execute(
72
- api_method: @pubsub.projects.topics.list,
73
- parameters: params
74
- )
75
- end
76
-
77
- ##
78
- # Deletes the topic with the given name.
79
- # All subscriptions to this topic are also deleted.
80
- # Returns NOT_FOUND if the topic does not exist.
81
- # After a topic is deleted, a new topic may be created with the same name.
82
- def delete_topic topic
83
- @client.execute(
84
- api_method: @pubsub.projects.topics.delete,
85
- parameters: { topic: topic }
86
- )
87
- end
88
-
89
- def get_topic_policy topic_name, options = {}
90
- @client.execute(
91
- api_method: @pubsub.projects.topics.get_iam_policy,
92
- parameters: { resource: topic_path(topic_name, options) }
93
- )
94
- end
95
-
96
- def set_topic_policy topic_name, new_policy, options = {}
97
- @client.execute(
98
- api_method: @pubsub.projects.topics.set_iam_policy,
99
- parameters: { resource: topic_path(topic_name, options) },
100
- body_object: { policy: new_policy }
101
- )
102
- end
103
-
104
- def test_topic_permissions topic_name, permissions, options = {}
105
- @client.execute(
106
- api_method: @pubsub.projects.topics.test_iam_permissions,
107
- parameters: { resource: topic_path(topic_name, options) },
108
- body_object: { permissions: permissions }
109
- )
110
- end
111
-
112
- ##
113
- # Creates a subscription on a given topic for a given subscriber.
114
- def create_subscription topic, subscription_name, options = {}
115
- data = subscription_data topic, options
116
- @client.execute(
117
- api_method: @pubsub.projects.subscriptions.create,
118
- parameters: { name: subscription_path(subscription_name, options) },
119
- body_object: data
120
- )
121
- end
122
-
123
- ##
124
- # Gets the details of a subscription.
125
- def get_subscription subscription_name, options = {}
126
- @client.execute(
127
- api_method: @pubsub.projects.subscriptions.get,
128
- parameters: {
129
- subscription: subscription_path(subscription_name, options) }
130
- )
131
- end
132
-
133
- ##
134
- # Lists matching subscriptions by project.
135
- def list_subscriptions options = {}
136
- params = { project: project_path(options),
137
- pageToken: options.delete(:token),
138
- pageSize: options.delete(:max)
139
- }.delete_if { |_, v| v.nil? }
140
-
141
- @client.execute(
142
- api_method: @pubsub.projects.subscriptions.list,
143
- parameters: params
144
- )
145
- end
146
-
147
- ##
148
- # Lists matching subscriptions by project and topic.
149
- def list_topics_subscriptions topic, options = {}
150
- params = { topic: topic,
151
- pageToken: options.delete(:token),
152
- pageSize: options.delete(:max)
153
- }.delete_if { |_, v| v.nil? }
154
-
155
- @client.execute(
156
- api_method: @pubsub.projects.topics.subscriptions.list,
157
- parameters: params
158
- )
159
- end
160
-
161
- ##
162
- # Deletes an existing subscription.
163
- # All pending messages in the subscription are immediately dropped.
164
- def delete_subscription subscription
165
- @client.execute(
166
- api_method: @pubsub.projects.subscriptions.delete,
167
- parameters: { subscription: subscription }
168
- )
169
- end
170
-
171
- def get_subscription_policy subscription_name, options = {}
172
- @client.execute(
173
- api_method: @pubsub.projects.subscriptions.get_iam_policy,
174
- parameters: {
175
- resource: subscription_path(subscription_name, options) }
176
- )
177
- end
178
-
179
- def set_subscription_policy subscription_name, new_policy, options = {}
180
- @client.execute(
181
- api_method: @pubsub.projects.subscriptions.set_iam_policy,
182
- parameters: {
183
- resource: subscription_path(subscription_name, options) },
184
- body_object: { policy: new_policy }
185
- )
186
- end
187
-
188
- def test_subscription_permissions subscription_name,
189
- permissions, options = {}
190
- @client.execute(
191
- api_method: @pubsub.projects.subscriptions.test_iam_permissions,
192
- parameters: {
193
- resource: subscription_path(subscription_name, options) },
194
- body_object: { permissions: permissions }
195
- )
196
- end
197
-
198
- ##
199
- # Adds one or more messages to the topic.
200
- # Returns NOT_FOUND if the topic does not exist.
201
- # The messages parameter is an array of arrays.
202
- # The first element is the data, second is attributes hash.
203
- def publish topic, messages
204
- gapi_msgs = messages.map do |data, attributes|
205
- { data: [data].pack("m0"), attributes: attributes }
206
- end
207
- @client.execute(
208
- api_method: @pubsub.projects.topics.publish,
209
- parameters: { topic: topic_path(topic) },
210
- body_object: { messages: gapi_msgs }
211
- )
212
- end
213
-
214
- ##
215
- # Pulls a single message from the server.
216
- def pull subscription, options = {}
217
- body = { returnImmediately: !(!options.fetch(:immediate, true)),
218
- maxMessages: options.fetch(:max, 100).to_i }
219
-
220
- @client.execute(
221
- api_method: @pubsub.projects.subscriptions.pull,
222
- parameters: { subscription: subscription },
223
- body_object: body
224
- )
225
- end
226
-
227
- ##
228
- # Acknowledges receipt of a message.
229
- def acknowledge subscription, *ack_ids
230
- @client.execute(
231
- api_method: @pubsub.projects.subscriptions.acknowledge,
232
- parameters: { subscription: subscription },
233
- body_object: { ackIds: ack_ids }
234
- )
235
- end
236
-
237
- ##
238
- # Modifies the PushConfig for a specified subscription.
239
- def modify_push_config subscription, endpoint, attributes
240
- @client.execute(
241
- api_method: @pubsub.projects.subscriptions.modify_push_config,
242
- parameters: { subscription: subscription },
243
- body_object: { pushConfig: { pushEndpoint: endpoint,
244
- attributes: attributes } }
245
- )
246
- end
247
-
248
- ##
249
- # Modifies the ack deadline for a specific message.
250
- def modify_ack_deadline subscription, ids, deadline
251
- ids = Array ids
252
- @client.execute(
253
- api_method: @pubsub.projects.subscriptions.modify_ack_deadline,
254
- parameters: { subscription: subscription },
255
- body_object: { ackIds: ids, ackDeadlineSeconds: deadline }
256
- )
257
- end
258
-
259
- def project_path options = {}
260
- project_name = options[:project] || project
261
- "projects/#{project_name}"
262
- end
263
-
264
- def topic_path topic_name, options = {}
265
- return topic_name if topic_name.to_s.include? "/"
266
- "#{project_path(options)}/topics/#{topic_name}"
267
- end
268
-
269
- def subscription_path subscription_name, options = {}
270
- return subscription_name if subscription_name.to_s.include? "/"
271
- "#{project_path(options)}/subscriptions/#{subscription_name}"
272
- end
273
-
274
- def inspect #:nodoc:
275
- "#{self.class}(#{@project})"
276
- end
277
-
278
- protected
279
-
280
- def subscription_data topic, options = {}
281
- deadline = options[:deadline]
282
- endpoint = options[:endpoint]
283
- attributes = (options[:attributes] || {}).to_h
284
-
285
- data = { topic: topic_path(topic) }
286
- data[:ackDeadlineSeconds] = deadline if deadline
287
- if endpoint
288
- data[:pushConfig] = { pushEndpoint: endpoint,
289
- attributes: attributes }
290
- end
291
- data
292
- end
293
- end
294
- end
295
- end
@@ -1,93 +0,0 @@
1
- #--
2
- # Copyright 2015 Google Inc. All rights reserved.
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
-
16
- require "gcloud/errors"
17
-
18
- module Gcloud
19
- module Pubsub
20
- ##
21
- # = Storage Error
22
- #
23
- # Base Pub/Sub exception class.
24
- class Error < Gcloud::Error
25
- ##
26
- # The response object of the failed HTTP request.
27
- attr_reader :response
28
-
29
- def self.from_response resp #:nodoc:
30
- new.tap do |e|
31
- e.response = resp
32
- end
33
- end
34
- end
35
-
36
- ##
37
- # = ApiError
38
- #
39
- # Raised when an API call is not successful.
40
- class ApiError < Error
41
- ##
42
- # The code of the error.
43
- def code
44
- response.data["error"]["code"]
45
- rescue
46
- nil
47
- end
48
-
49
- ##
50
- # The errors encountered.
51
- def errors
52
- response.data["error"]["errors"]
53
- rescue
54
- []
55
- end
56
-
57
- def initialize message, response
58
- super message
59
- @response = response
60
- end
61
-
62
- def self.from_response resp #:nodoc:
63
- klass = klass_for resp.data["error"]["status"]
64
- klass.new resp.data["error"]["message"], resp
65
- rescue
66
- Gcloud::Pubsub::Error.from_response resp
67
- end
68
-
69
- def self.klass_for status
70
- if status == "ALREADY_EXISTS"
71
- return AlreadyExistsError
72
- elsif status == "NOT_FOUND"
73
- return NotFoundError
74
- end
75
- self
76
- end
77
- end
78
-
79
- ##
80
- # = AlreadyExistsError
81
- #
82
- # Raised when Pub/Sub returns an +ALREADY_EXISTS+ error.
83
- class AlreadyExistsError < ApiError
84
- end
85
-
86
- ##
87
- # = NotFoundError
88
- #
89
- # Raised when Pub/Sub returns a +NOT_FOUND+ error.
90
- class NotFoundError < ApiError
91
- end
92
- end
93
- end