gcloud 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +8 -8
  2. data/AUTHENTICATION.md +3 -3
  3. data/CHANGELOG.md +92 -0
  4. data/OVERVIEW.md +3 -3
  5. data/lib/gcloud.rb +75 -25
  6. data/lib/gcloud/backoff.rb +5 -1
  7. data/lib/gcloud/bigquery.rb +25 -43
  8. data/lib/gcloud/bigquery/copy_job.rb +13 -13
  9. data/lib/gcloud/bigquery/data.rb +20 -16
  10. data/lib/gcloud/bigquery/dataset.rb +202 -177
  11. data/lib/gcloud/bigquery/dataset/access.rb +118 -104
  12. data/lib/gcloud/bigquery/dataset/list.rb +14 -18
  13. data/lib/gcloud/bigquery/extract_job.rb +12 -12
  14. data/lib/gcloud/bigquery/insert_response.rb +12 -14
  15. data/lib/gcloud/bigquery/job.rb +45 -57
  16. data/lib/gcloud/bigquery/job/list.rb +18 -24
  17. data/lib/gcloud/bigquery/load_job.rb +35 -27
  18. data/lib/gcloud/bigquery/project.rb +53 -73
  19. data/lib/gcloud/bigquery/query_data.rb +28 -35
  20. data/lib/gcloud/bigquery/query_job.rb +18 -18
  21. data/lib/gcloud/bigquery/schema.rb +359 -0
  22. data/lib/gcloud/bigquery/service.rb +506 -0
  23. data/lib/gcloud/bigquery/table.rb +185 -266
  24. data/lib/gcloud/bigquery/table/list.rb +15 -19
  25. data/lib/gcloud/bigquery/view.rb +126 -81
  26. data/lib/gcloud/datastore.rb +39 -27
  27. data/lib/gcloud/datastore/commit.rb +2 -2
  28. data/lib/gcloud/datastore/dataset.rb +8 -19
  29. data/lib/gcloud/datastore/dataset/lookup_results.rb +2 -4
  30. data/lib/gcloud/datastore/dataset/query_results.rb +0 -2
  31. data/lib/gcloud/datastore/entity.rb +7 -1
  32. data/lib/gcloud/datastore/errors.rb +5 -27
  33. data/lib/gcloud/datastore/grpc_utils.rb +4 -3
  34. data/lib/gcloud/datastore/key.rb +6 -0
  35. data/lib/gcloud/datastore/service.rb +18 -12
  36. data/lib/gcloud/datastore/transaction.rb +0 -10
  37. data/lib/gcloud/dns.rb +29 -19
  38. data/lib/gcloud/dns/change.rb +10 -15
  39. data/lib/gcloud/dns/change/list.rb +4 -4
  40. data/lib/gcloud/dns/importer.rb +1 -1
  41. data/lib/gcloud/dns/project.rb +32 -49
  42. data/lib/gcloud/dns/record.rb +8 -2
  43. data/lib/gcloud/dns/record/list.rb +4 -4
  44. data/lib/gcloud/dns/service.rb +167 -0
  45. data/lib/gcloud/dns/zone.rb +33 -52
  46. data/lib/gcloud/dns/zone/list.rb +12 -16
  47. data/lib/gcloud/errors.rb +31 -19
  48. data/lib/gcloud/logging.rb +50 -39
  49. data/lib/gcloud/logging/entry.rb +197 -24
  50. data/lib/gcloud/logging/entry/list.rb +0 -2
  51. data/lib/gcloud/logging/logger.rb +1 -1
  52. data/lib/gcloud/logging/metric.rb +3 -9
  53. data/lib/gcloud/logging/metric/list.rb +0 -2
  54. data/lib/gcloud/logging/project.rb +58 -54
  55. data/lib/gcloud/logging/resource_descriptor.rb +2 -2
  56. data/lib/gcloud/logging/resource_descriptor/list.rb +0 -2
  57. data/lib/gcloud/logging/service.rb +32 -23
  58. data/lib/gcloud/logging/sink.rb +8 -14
  59. data/lib/gcloud/logging/sink/list.rb +0 -2
  60. data/lib/gcloud/pubsub.rb +21 -16
  61. data/lib/gcloud/pubsub/policy.rb +204 -0
  62. data/lib/gcloud/pubsub/project.rb +26 -38
  63. data/lib/gcloud/pubsub/service.rb +39 -31
  64. data/lib/gcloud/pubsub/subscription.rb +56 -59
  65. data/lib/gcloud/pubsub/subscription/list.rb +4 -4
  66. data/lib/gcloud/pubsub/topic.rb +69 -66
  67. data/lib/gcloud/pubsub/topic/list.rb +0 -2
  68. data/lib/gcloud/pubsub/topic/{batch.rb → publisher.rb} +15 -2
  69. data/lib/gcloud/resource_manager.rb +27 -26
  70. data/lib/gcloud/resource_manager/manager.rb +19 -39
  71. data/lib/gcloud/resource_manager/policy.rb +211 -0
  72. data/lib/gcloud/resource_manager/project.rb +97 -121
  73. data/lib/gcloud/resource_manager/project/list.rb +7 -7
  74. data/lib/gcloud/resource_manager/project/updater.rb +4 -9
  75. data/lib/gcloud/resource_manager/service.rb +127 -0
  76. data/lib/gcloud/storage.rb +24 -42
  77. data/lib/gcloud/storage/bucket.rb +104 -192
  78. data/lib/gcloud/storage/bucket/acl.rb +47 -143
  79. data/lib/gcloud/storage/bucket/cors.rb +55 -11
  80. data/lib/gcloud/storage/bucket/list.rb +14 -14
  81. data/lib/gcloud/storage/errors.rb +3 -43
  82. data/lib/gcloud/storage/file.rb +114 -111
  83. data/lib/gcloud/storage/file/acl.rb +27 -113
  84. data/lib/gcloud/storage/file/list.rb +21 -21
  85. data/lib/gcloud/storage/project.rb +49 -59
  86. data/lib/gcloud/storage/service.rb +347 -0
  87. data/lib/gcloud/translate.rb +24 -14
  88. data/lib/gcloud/translate/api.rb +12 -21
  89. data/lib/gcloud/translate/detection.rb +5 -5
  90. data/lib/gcloud/translate/language.rb +1 -1
  91. data/lib/gcloud/translate/service.rb +80 -0
  92. data/lib/gcloud/translate/translation.rb +6 -6
  93. data/lib/gcloud/version.rb +1 -1
  94. data/lib/gcloud/vision.rb +24 -15
  95. data/lib/gcloud/vision/annotate.rb +24 -21
  96. data/lib/gcloud/vision/annotation.rb +9 -9
  97. data/lib/gcloud/vision/annotation/entity.rb +11 -11
  98. data/lib/gcloud/vision/annotation/face.rb +25 -25
  99. data/lib/gcloud/vision/annotation/properties.rb +8 -8
  100. data/lib/gcloud/vision/annotation/safe_search.rb +4 -4
  101. data/lib/gcloud/vision/annotation/text.rb +7 -7
  102. data/lib/gcloud/vision/annotation/vertex.rb +1 -1
  103. data/lib/gcloud/vision/image.rb +11 -11
  104. data/lib/gcloud/vision/location.rb +5 -2
  105. data/lib/gcloud/vision/project.rb +14 -16
  106. data/lib/gcloud/vision/service.rb +66 -0
  107. data/lib/google/api_client.rb +0 -0
  108. metadata +27 -24
  109. data/lib/gcloud/bigquery/connection.rb +0 -624
  110. data/lib/gcloud/bigquery/errors.rb +0 -68
  111. data/lib/gcloud/bigquery/table/schema.rb +0 -234
  112. data/lib/gcloud/dns/connection.rb +0 -173
  113. data/lib/gcloud/dns/errors.rb +0 -68
  114. data/lib/gcloud/resource_manager/connection.rb +0 -134
  115. data/lib/gcloud/resource_manager/errors.rb +0 -68
  116. data/lib/gcloud/storage/connection.rb +0 -444
  117. data/lib/gcloud/translate/connection.rb +0 -85
  118. data/lib/gcloud/translate/errors.rb +0 -68
  119. data/lib/gcloud/upload.rb +0 -95
  120. data/lib/gcloud/vision/connection.rb +0 -63
  121. data/lib/gcloud/vision/errors.rb +0 -69
@@ -74,8 +74,6 @@ module Gcloud
74
74
  grpc = @service.list_entries token: token, projects: @projects,
75
75
  filter: @filter, order: @order, max: @max
76
76
  self.class.from_grpc grpc, @service
77
- rescue GRPC::BadStatus => e
78
- raise Gcloud::Error.from_error(e)
79
77
  end
80
78
 
81
79
  ##
@@ -266,7 +266,7 @@ module Gcloud
266
266
  protected
267
267
 
268
268
  ##
269
- # @private Write a log entry to Google Cloud Logging service.
269
+ # @private Write a log entry to the Stackdriver Logging service.
270
270
  def write_entry severity, message
271
271
  entry = logging.entry.tap do |e|
272
272
  e.severity = gcloud_severity(severity)
@@ -104,9 +104,7 @@ module Gcloud
104
104
  def save
105
105
  ensure_service!
106
106
  @grpc = service.update_metric name, description, filter
107
- return true
108
- rescue GRPC::BadStatus => e
109
- raise Gcloud::Error.from_error(e)
107
+ true
110
108
  end
111
109
 
112
110
  ##
@@ -126,9 +124,7 @@ module Gcloud
126
124
  def reload!
127
125
  ensure_service!
128
126
  @grpc = service.get_metric name
129
- return true
130
- rescue GRPC::BadStatus => e
131
- raise Gcloud::Error.from_error(e)
127
+ true
132
128
  end
133
129
  alias_method :refresh!, :reload!
134
130
 
@@ -148,9 +144,7 @@ module Gcloud
148
144
  def delete
149
145
  ensure_service!
150
146
  service.delete_metric name
151
- return true
152
- rescue GRPC::BadStatus => e
153
- raise Gcloud::Error.from_error(e)
147
+ true
154
148
  end
155
149
 
156
150
  ##
@@ -73,8 +73,6 @@ module Gcloud
73
73
  ensure_service!
74
74
  grpc = @service.list_metrics token: token, max: @max
75
75
  self.class.from_grpc grpc, @service
76
- rescue GRPC::BadStatus => e
77
- raise Gcloud::Error.from_error(e)
78
76
  end
79
77
 
80
78
  ##
@@ -30,7 +30,7 @@ module Gcloud
30
30
  #
31
31
  # Projects are top-level containers in Google Cloud Platform. They store
32
32
  # information about billing and authorized users, and they control access to
33
- # Google Cloud Logging resources. Each project has a friendly name and a
33
+ # Stackdriver Logging resources. Each project has a friendly name and a
34
34
  # unique ID. Projects can be created only in the [Google Developers
35
35
  # Console](https://console.developers.google.com). See {Gcloud#logging}.
36
36
  #
@@ -49,10 +49,8 @@ module Gcloud
49
49
 
50
50
  ##
51
51
  # @private Creates a new Connection instance.
52
- def initialize project, credentials
53
- project = project.to_s # Always cast to a string
54
- fail ArgumentError, "project is missing" if project.empty?
55
- @service = Service.new project, credentials
52
+ def initialize service
53
+ @service = service
56
54
  end
57
55
 
58
56
  ##
@@ -149,16 +147,35 @@ module Gcloud
149
147
  order: order, token: token, max: max
150
148
  Entry::List.from_grpc list_grpc, service, projects: projects, max: max,
151
149
  filter: filter, order: order
152
- rescue GRPC::BadStatus => e
153
- raise Gcloud::Error.from_error(e)
154
150
  end
155
151
  alias_method :find_entries, :entries
156
152
 
157
153
  ##
158
154
  # Creates an new Entry instance that may be populated and written to the
159
- # Cloud Logging service. The {Entry#resource} attribute is pre-populated
160
- # with a new {Gcloud::Logging::Resource} instance. Equivalent to calling
161
- # `Gcloud::Logging::Entry.new`.
155
+ # Stackdriver Logging service. The {Entry#resource} attribute is
156
+ # pre-populated with a new {Gcloud::Logging::Resource} instance.
157
+ # Equivalent to calling `Gcloud::Logging::Entry.new`.
158
+ #
159
+ # @param [String] log_name The resource name of the log to which this log
160
+ # entry belongs. See also {Entry#log_name=}.
161
+ # @param [Resource] resource The monitored resource associated with this
162
+ # log entry. See also {Entry#resource}.
163
+ # @param [Time] timestamp The time the event described by the log entry
164
+ # occurred. If omitted, Stackdriver Logging will use the time the log
165
+ # entry is written. See also {Entry#timestamp}.
166
+ # @param [Symbol] severity The severity level of the log entry. The
167
+ # default value is `DEFAULT`. See also {Entry#severity}.
168
+ # @param [String] insert_id A unique ID for the log entry. If you provide
169
+ # this field, the logging service considers other log entries in the
170
+ # same log with the same ID as duplicates which can be removed. If
171
+ # omitted, Stackdriver Logging will generate a unique ID for this log
172
+ # entry. See also {Entry#insert_id}.
173
+ # @param [Hash{Symbol,String => String}] labels A hash of user-defined
174
+ # `key:value` pairs that provide additional information about the log
175
+ # entry. See also {Entry#labels=}.
176
+ # @param [String, Hash] payload The log entry payload, represented as
177
+ # either a string, a hash (JSON), or a hash (protocol buffer). See also
178
+ # {Entry#payload}.
162
179
  #
163
180
  # @return [Gcloud::Logging::Entry] a new Entry instance
164
181
  #
@@ -168,19 +185,26 @@ module Gcloud
168
185
  # gcloud = Gcloud.new
169
186
  # logging = gcloud.logging
170
187
  #
171
- # entry = logging.entry
172
- # entry.severity = :INFO
173
- # entry.payload = "Job started."
188
+ # entry = logging.entry severity: :INFO, payload: "Job started."
174
189
  #
175
190
  # logging.write_entries entry
176
191
  #
177
- def entry
178
- Entry.new
192
+ def entry log_name: nil, resource: nil, timestamp: nil, severity: nil,
193
+ insert_id: nil, labels: nil, payload: nil
194
+ e = Entry.new
195
+ e.log_name = log_name if log_name
196
+ e.resource = resource if resource
197
+ e.timestamp = timestamp if timestamp
198
+ e.severity = severity if severity
199
+ e.insert_id = insert_id if insert_id
200
+ e.labels = labels if labels
201
+ e.payload = payload if payload
202
+ e
179
203
  end
180
204
  alias_method :new_entry, :entry
181
205
 
182
206
  ##
183
- # Writes log entries to the Cloud Logging service.
207
+ # Writes log entries to the Stackdriver Logging service.
184
208
  #
185
209
  # If you write a collection of log entries, you can provide the log name,
186
210
  # resource, and/or labels hash to be used for all of the entries, and omit
@@ -208,9 +232,7 @@ module Gcloud
208
232
  # gcloud = Gcloud.new
209
233
  # logging = gcloud.logging
210
234
  #
211
- # entry = logging.entry
212
- # entry.payload = "Job started."
213
- # entry.log_name = "my_app_log"
235
+ # entry = logging.entry payload: "Job started.", log_name: "my_app_log"
214
236
  # entry.resource.type = "gae_app"
215
237
  # entry.resource.labels[:module_id] = "1"
216
238
  # entry.resource.labels[:version_id] = "20150925t173233"
@@ -223,12 +245,10 @@ module Gcloud
223
245
  # gcloud = Gcloud.new
224
246
  # logging = gcloud.logging
225
247
  #
226
- # entry1 = logging.entry
227
- # entry1.payload = "Job started."
228
- # entry2 = logging.entry
229
- # entry2.payload = "Job completed."
230
- # labels = { job_size: "large", job_code: "red" }
248
+ # entry1 = logging.entry payload: "Job started."
249
+ # entry2 = logging.entry payload: "Job completed."
231
250
  #
251
+ # labels = { job_size: "large", job_code: "red" }
232
252
  # resource = logging.resource "gae_app",
233
253
  # "module_id" => "1",
234
254
  # "version_id" => "20150925t173233"
@@ -243,9 +263,7 @@ module Gcloud
243
263
  service.write_entries Array(entries).map(&:to_grpc),
244
264
  log_name: log_name, resource: resource,
245
265
  labels: labels
246
- return true
247
- rescue GRPC::BadStatus => e
248
- raise Gcloud::Error.from_error(e)
266
+ true
249
267
  end
250
268
 
251
269
  ##
@@ -302,14 +320,12 @@ module Gcloud
302
320
  def delete_log name
303
321
  ensure_service!
304
322
  service.delete_log name
305
- return true
306
- rescue GRPC::BadStatus => e
307
- raise Gcloud::Error.from_error(e)
323
+ true
308
324
  end
309
325
 
310
326
  ##
311
327
  # Retrieves the list of monitored resource descriptors that are used by
312
- # Google Cloud Logging.
328
+ # Stackdriver Logging.
313
329
  #
314
330
  # @see https://cloud.google.com/logging/docs/api/introduction_v2#monitored_resources
315
331
  # Monitored Resources
@@ -347,8 +363,6 @@ module Gcloud
347
363
  ensure_service!
348
364
  list_grpc = service.list_resource_descriptors token: token, max: max
349
365
  ResourceDescriptor::List.from_grpc list_grpc, service, max
350
- rescue GRPC::BadStatus => e
351
- raise Gcloud::Error.from_error(e)
352
366
  end
353
367
  alias_method :find_resource_descriptors, :resource_descriptors
354
368
 
@@ -410,15 +424,13 @@ module Gcloud
410
424
  ensure_service!
411
425
  list_grpc = service.list_sinks token: token, max: max
412
426
  Sink::List.from_grpc list_grpc, service, max
413
- rescue GRPC::BadStatus => e
414
- raise Gcloud::Error.from_error(e)
415
427
  end
416
428
  alias_method :find_sinks, :sinks
417
429
 
418
430
  ##
419
431
  # Creates a new project sink. When you create a sink, only new log entries
420
- # that match the sink's filter are exported. Cloud Logging does not send
421
- # previously-ingested log entries to the sink's destination.
432
+ # that match the sink's filter are exported. Stackdriver Logging does not
433
+ # send previously-ingested log entries to the sink's destination.
422
434
  #
423
435
  # Before creating the sink, ensure that you have granted
424
436
  # `cloud-logs@google.com` permission to write logs to the destination. See
@@ -446,12 +458,12 @@ module Gcloud
446
458
  # that defines the log entries to be exported. The filter must be
447
459
  # consistent with the log entry format designed by the `version`
448
460
  # parameter, regardless of the format of the log entry that was
449
- # originally written to Cloud Logging.
461
+ # originally written to Stackdriver Logging.
450
462
  # @param [Symbol] version The log entry version used when exporting log
451
463
  # entries from this sink. This version does not have to correspond to
452
- # the version of the log entry when it was written to Cloud Logging.
453
- # Accepted values are `:unspecified`, `:v2`, and `:v1`. Version 2 is
454
- # currently the preferred format. An unspecified version format
464
+ # the version of the log entry when it was written to Stackdriver
465
+ # Logging. Accepted values are `:unspecified`, `:v2`, and `:v1`. Version
466
+ # 2 is currently the preferred format. An unspecified version format
455
467
  # currently defaults to V2 in the service. The default value is
456
468
  # `:unspecified`.
457
469
  #
@@ -466,7 +478,7 @@ module Gcloud
466
478
  #
467
479
  # bucket = storage.create_bucket "my-logs-bucket"
468
480
  #
469
- # # Grant owner permission to Cloud Logging service
481
+ # # Grant owner permission to Stackdriver Logging service
470
482
  # email = "cloud-logs@google.com"
471
483
  # bucket.acl.add_owner "group-#{email}"
472
484
  #
@@ -478,8 +490,6 @@ module Gcloud
478
490
  ensure_service!
479
491
  grpc = service.create_sink name, destination, filter, version
480
492
  Sink.from_grpc grpc, service
481
- rescue GRPC::BadStatus => e
482
- raise Gcloud::Error.from_error(e)
483
493
  end
484
494
  alias_method :new_sink, :create_sink
485
495
 
@@ -509,9 +519,8 @@ module Gcloud
509
519
  ensure_service!
510
520
  grpc = service.get_sink sink_name
511
521
  Sink.from_grpc grpc, service
512
- rescue GRPC::BadStatus => e
513
- return nil if e.code == 5
514
- raise Gcloud::Error.from_error(e)
522
+ rescue Gcloud::NotFoundError
523
+ nil
515
524
  end
516
525
  alias_method :get_sink, :sink
517
526
  alias_method :find_sink, :sink
@@ -551,8 +560,6 @@ module Gcloud
551
560
  ensure_service!
552
561
  grpc = service.list_metrics token: token, max: max
553
562
  Metric::List.from_grpc grpc, service, max
554
- rescue GRPC::BadStatus => e
555
- raise Gcloud::Error.from_error(e)
556
563
  end
557
564
  alias_method :find_metrics, :metrics
558
565
 
@@ -587,8 +594,6 @@ module Gcloud
587
594
  ensure_service!
588
595
  grpc = service.create_metric name, filter, description
589
596
  Metric.from_grpc grpc, service
590
- rescue GRPC::BadStatus => e
591
- raise Gcloud::Error.from_error(e)
592
597
  end
593
598
  alias_method :new_metric, :create_metric
594
599
 
@@ -618,9 +623,8 @@ module Gcloud
618
623
  ensure_service!
619
624
  grpc = service.get_metric name
620
625
  Metric.from_grpc grpc, service
621
- rescue GRPC::BadStatus => e
622
- return nil if e.code == 5
623
- raise Gcloud::Error.from_error(e)
626
+ rescue Gcloud::NotFoundError
627
+ nil
624
628
  end
625
629
  alias_method :get_metric, :metric
626
630
  alias_method :find_metric, :metric
@@ -20,8 +20,8 @@ module Gcloud
20
20
  ##
21
21
  # # ResourceDescriptor
22
22
  #
23
- # Describes a type of monitored resource supported by Cloud Logging. Each
24
- # ResourceDescriptor has a type name, such as `cloudsql_database`,
23
+ # Describes a type of monitored resource supported by Stackdriver Logging.
24
+ # Each ResourceDescriptor has a type name, such as `cloudsql_database`,
25
25
  # `gae_app`, or `gce_instance`. It also specifies a set of labels that must
26
26
  # all be given values in a {Resource} instance to represent an actual
27
27
  # instance of the type.
@@ -74,8 +74,6 @@ module Gcloud
74
74
  ensure_service!
75
75
  list_grpc = @service.list_resource_descriptors token: token, max: @max
76
76
  self.class.from_grpc list_grpc, @service
77
- rescue GRPC::BadStatus => e
78
- raise Gcloud::Error.from_error(e)
79
77
  end
80
78
 
81
79
  ##
@@ -13,10 +13,12 @@
13
13
  # limitations under the License.
14
14
 
15
15
 
16
+ require "gcloud/backoff"
17
+ require "gcloud/errors"
16
18
  require "google/logging/v2/logging_services"
17
19
  require "google/logging/v2/logging_config_services"
18
20
  require "google/logging/v2/logging_metrics_services"
19
- require "gcloud/backoff"
21
+
20
22
 
21
23
  module Gcloud
22
24
  module Logging
@@ -24,14 +26,16 @@ module Gcloud
24
26
  # @private Represents the gRPC Logging service, including all the API
25
27
  # methods.
26
28
  class Service
27
- attr_accessor :project, :credentials, :host
29
+ attr_accessor :project, :credentials, :host, :retries, :timeout
28
30
 
29
31
  ##
30
32
  # Creates a new Service instance.
31
- def initialize project, credentials
33
+ def initialize project, credentials, host: nil, retries: nil, timeout: nil
32
34
  @project = project
33
35
  @credentials = credentials
34
- @host = "logging.googleapis.com"
36
+ @host = host || "logging.googleapis.com"
37
+ @retries = retries
38
+ @timeout = timeout
35
39
  end
36
40
 
37
41
  def creds
@@ -41,19 +45,22 @@ module Gcloud
41
45
 
42
46
  def logging
43
47
  return mocked_logging if mocked_logging
44
- @logging ||= Google::Logging::V2::LoggingServiceV2::Stub.new host, creds
48
+ @logging ||= Google::Logging::V2::LoggingServiceV2::Stub.new(
49
+ host, creds, timeout: timeout)
45
50
  end
46
51
  attr_accessor :mocked_logging
47
52
 
48
53
  def sinks
49
54
  return mocked_sinks if mocked_sinks
50
- @sinks ||= Google::Logging::V2::ConfigServiceV2::Stub.new host, creds
55
+ @sinks ||= Google::Logging::V2::ConfigServiceV2::Stub.new(
56
+ host, creds, timeout: timeout)
51
57
  end
52
58
  attr_accessor :mocked_sinks
53
59
 
54
60
  def metrics
55
61
  return mocked_metrics if mocked_metrics
56
- @metrics ||= Google::Logging::V2::MetricsServiceV2::Stub.new host, creds
62
+ @metrics ||= Google::Logging::V2::MetricsServiceV2::Stub.new(
63
+ host, creds, timeout: timeout)
57
64
  end
58
65
  attr_accessor :mocked_metrics
59
66
 
@@ -68,7 +75,7 @@ module Gcloud
68
75
 
69
76
  list_req = Google::Logging::V2::ListLogEntriesRequest.new(list_params)
70
77
 
71
- backoff { logging.list_log_entries list_req }
78
+ execute { logging.list_log_entries list_req }
72
79
  end
73
80
 
74
81
  def write_entries entries, log_name: nil, resource: nil, labels: nil
@@ -86,7 +93,7 @@ module Gcloud
86
93
 
87
94
  write_req = Google::Logging::V2::WriteLogEntriesRequest.new write_params
88
95
 
89
- backoff { logging.write_log_entries write_req }
96
+ execute { logging.write_log_entries write_req }
90
97
  end
91
98
 
92
99
  def delete_log name
@@ -94,7 +101,7 @@ module Gcloud
94
101
  log_name: log_path(name)
95
102
  )
96
103
 
97
- backoff { logging.delete_log delete_req }
104
+ execute { logging.delete_log delete_req }
98
105
  end
99
106
 
100
107
  def list_resource_descriptors token: nil, max: nil
@@ -106,7 +113,7 @@ module Gcloud
106
113
  Google::Logging::V2::ListMonitoredResourceDescriptorsRequest.new(
107
114
  list_params)
108
115
 
109
- backoff { logging.list_monitored_resource_descriptors list_req }
116
+ execute { logging.list_monitored_resource_descriptors list_req }
110
117
  end
111
118
 
112
119
  def list_sinks token: nil, max: nil
@@ -117,7 +124,7 @@ module Gcloud
117
124
 
118
125
  list_req = Google::Logging::V2::ListSinksRequest.new(list_params)
119
126
 
120
- backoff { sinks.list_sinks list_req }
127
+ execute { sinks.list_sinks list_req }
121
128
  end
122
129
 
123
130
  def create_sink name, destination, filter, version
@@ -131,7 +138,7 @@ module Gcloud
131
138
  sink: Google::Logging::V2::LogSink.new(sink_params)
132
139
  )
133
140
 
134
- backoff { sinks.create_sink create_req }
141
+ execute { sinks.create_sink create_req }
135
142
  end
136
143
 
137
144
  def get_sink name
@@ -139,7 +146,7 @@ module Gcloud
139
146
  sink_name: sink_path(name)
140
147
  )
141
148
 
142
- backoff { sinks.get_sink get_req }
149
+ execute { sinks.get_sink get_req }
143
150
  end
144
151
 
145
152
  def update_sink name, destination, filter, version
@@ -153,7 +160,7 @@ module Gcloud
153
160
  sink: Google::Logging::V2::LogSink.new(sink_params)
154
161
  )
155
162
 
156
- backoff { sinks.update_sink update_req }
163
+ execute { sinks.update_sink update_req }
157
164
  end
158
165
 
159
166
  def delete_sink name
@@ -161,7 +168,7 @@ module Gcloud
161
168
  sink_name: sink_path(name)
162
169
  )
163
170
 
164
- backoff { sinks.delete_sink delete_req }
171
+ execute { sinks.delete_sink delete_req }
165
172
  end
166
173
 
167
174
  def list_metrics token: nil, max: nil
@@ -172,7 +179,7 @@ module Gcloud
172
179
 
173
180
  list_req = Google::Logging::V2::ListLogMetricsRequest.new(list_params)
174
181
 
175
- backoff { metrics.list_log_metrics list_req }
182
+ execute { metrics.list_log_metrics list_req }
176
183
  end
177
184
 
178
185
  def create_metric name, filter, description
@@ -187,7 +194,7 @@ module Gcloud
187
194
  metric: Google::Logging::V2::LogMetric.new(metric_params)
188
195
  )
189
196
 
190
- backoff { metrics.create_log_metric create_req }
197
+ execute { metrics.create_log_metric create_req }
191
198
  end
192
199
 
193
200
  def get_metric name
@@ -195,7 +202,7 @@ module Gcloud
195
202
  metric_name: metric_path(name)
196
203
  )
197
204
 
198
- backoff { metrics.get_log_metric get_req }
205
+ execute { metrics.get_log_metric get_req }
199
206
  end
200
207
 
201
208
  def update_metric name, description, filter
@@ -210,7 +217,7 @@ module Gcloud
210
217
  metric: Google::Logging::V2::LogMetric.new(metric_params)
211
218
  )
212
219
 
213
- backoff { metrics.update_log_metric update_req }
220
+ execute { metrics.update_log_metric update_req }
214
221
  end
215
222
 
216
223
  def delete_metric name
@@ -218,7 +225,7 @@ module Gcloud
218
225
  metric_name: metric_path(name)
219
226
  )
220
227
 
221
- backoff { metrics.delete_log_metric delete_req }
228
+ execute { metrics.delete_log_metric delete_req }
222
229
  end
223
230
 
224
231
  def inspect
@@ -248,10 +255,12 @@ module Gcloud
248
255
  "#{project_path}/metrics/#{metric_name}"
249
256
  end
250
257
 
251
- def backoff options = {}
252
- Gcloud::Backoff.new(options).execute_grpc do
258
+ def execute
259
+ Gcloud::Backoff.new(retries: retries).execute_grpc do
253
260
  yield
254
261
  end
262
+ rescue GRPC::BadStatus => e
263
+ raise Gcloud::Error.from_error(e)
255
264
  end
256
265
  end
257
266
  end