gcloud 0.12.2 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. checksums.yaml +5 -13
  2. data/lib/gcloud.rb +27 -456
  3. data/lib/gcloud/bigquery.rb +2 -382
  4. data/lib/gcloud/datastore.rb +2 -576
  5. data/lib/gcloud/dns.rb +2 -321
  6. data/lib/gcloud/logging.rb +1 -322
  7. data/lib/gcloud/pubsub.rb +2 -476
  8. data/lib/gcloud/resource_manager.rb +2 -273
  9. data/lib/gcloud/storage.rb +2 -440
  10. data/lib/gcloud/translate.rb +1 -250
  11. data/lib/gcloud/version.rb +2 -2
  12. data/lib/gcloud/vision.rb +1 -501
  13. metadata +36 -332
  14. data/AUTHENTICATION.md +0 -75
  15. data/CHANGELOG.md +0 -382
  16. data/OVERVIEW.md +0 -259
  17. data/lib/gcloud/backoff.rb +0 -150
  18. data/lib/gcloud/bigquery/copy_job.rb +0 -97
  19. data/lib/gcloud/bigquery/credentials.rb +0 -29
  20. data/lib/gcloud/bigquery/data.rb +0 -239
  21. data/lib/gcloud/bigquery/dataset.rb +0 -753
  22. data/lib/gcloud/bigquery/dataset/access.rb +0 -507
  23. data/lib/gcloud/bigquery/dataset/list.rb +0 -169
  24. data/lib/gcloud/bigquery/extract_job.rb +0 -117
  25. data/lib/gcloud/bigquery/insert_response.rb +0 -81
  26. data/lib/gcloud/bigquery/job.rb +0 -299
  27. data/lib/gcloud/bigquery/job/list.rb +0 -172
  28. data/lib/gcloud/bigquery/load_job.rb +0 -202
  29. data/lib/gcloud/bigquery/project.rb +0 -475
  30. data/lib/gcloud/bigquery/query_data.rb +0 -234
  31. data/lib/gcloud/bigquery/query_job.rb +0 -137
  32. data/lib/gcloud/bigquery/schema.rb +0 -359
  33. data/lib/gcloud/bigquery/service.rb +0 -506
  34. data/lib/gcloud/bigquery/table.rb +0 -1141
  35. data/lib/gcloud/bigquery/table/list.rb +0 -180
  36. data/lib/gcloud/bigquery/view.rb +0 -475
  37. data/lib/gcloud/credentials.rb +0 -129
  38. data/lib/gcloud/datastore/commit.rb +0 -148
  39. data/lib/gcloud/datastore/credentials.rb +0 -35
  40. data/lib/gcloud/datastore/cursor.rb +0 -76
  41. data/lib/gcloud/datastore/dataset.rb +0 -660
  42. data/lib/gcloud/datastore/dataset/lookup_results.rb +0 -219
  43. data/lib/gcloud/datastore/dataset/query_results.rb +0 -386
  44. data/lib/gcloud/datastore/entity.rb +0 -449
  45. data/lib/gcloud/datastore/errors.rb +0 -41
  46. data/lib/gcloud/datastore/gql_query.rb +0 -211
  47. data/lib/gcloud/datastore/grpc_utils.rb +0 -132
  48. data/lib/gcloud/datastore/key.rb +0 -281
  49. data/lib/gcloud/datastore/properties.rb +0 -128
  50. data/lib/gcloud/datastore/query.rb +0 -348
  51. data/lib/gcloud/datastore/service.rb +0 -167
  52. data/lib/gcloud/datastore/transaction.rb +0 -362
  53. data/lib/gcloud/dns/change.rb +0 -158
  54. data/lib/gcloud/dns/change/list.rb +0 -173
  55. data/lib/gcloud/dns/credentials.rb +0 -29
  56. data/lib/gcloud/dns/importer.rb +0 -183
  57. data/lib/gcloud/dns/project.rb +0 -247
  58. data/lib/gcloud/dns/record.rb +0 -170
  59. data/lib/gcloud/dns/record/list.rb +0 -174
  60. data/lib/gcloud/dns/service.rb +0 -167
  61. data/lib/gcloud/dns/zone.rb +0 -759
  62. data/lib/gcloud/dns/zone/list.rb +0 -168
  63. data/lib/gcloud/dns/zone/transaction.rb +0 -176
  64. data/lib/gcloud/errors.rb +0 -206
  65. data/lib/gcloud/gce.rb +0 -56
  66. data/lib/gcloud/grpc_utils.rb +0 -87
  67. data/lib/gcloud/logging/credentials.rb +0 -29
  68. data/lib/gcloud/logging/entry.rb +0 -465
  69. data/lib/gcloud/logging/entry/http_request.rb +0 -141
  70. data/lib/gcloud/logging/entry/list.rb +0 -177
  71. data/lib/gcloud/logging/entry/operation.rb +0 -90
  72. data/lib/gcloud/logging/logger.rb +0 -307
  73. data/lib/gcloud/logging/metric.rb +0 -169
  74. data/lib/gcloud/logging/metric/list.rb +0 -172
  75. data/lib/gcloud/logging/project.rb +0 -642
  76. data/lib/gcloud/logging/resource.rb +0 -84
  77. data/lib/gcloud/logging/resource_descriptor.rb +0 -137
  78. data/lib/gcloud/logging/resource_descriptor/list.rb +0 -174
  79. data/lib/gcloud/logging/service.rb +0 -267
  80. data/lib/gcloud/logging/sink.rb +0 -227
  81. data/lib/gcloud/logging/sink/list.rb +0 -171
  82. data/lib/gcloud/pubsub/credentials.rb +0 -29
  83. data/lib/gcloud/pubsub/message.rb +0 -94
  84. data/lib/gcloud/pubsub/policy.rb +0 -204
  85. data/lib/gcloud/pubsub/project.rb +0 -482
  86. data/lib/gcloud/pubsub/received_message.rb +0 -160
  87. data/lib/gcloud/pubsub/service.rb +0 -334
  88. data/lib/gcloud/pubsub/subscription.rb +0 -565
  89. data/lib/gcloud/pubsub/subscription/list.rb +0 -208
  90. data/lib/gcloud/pubsub/topic.rb +0 -511
  91. data/lib/gcloud/pubsub/topic/list.rb +0 -174
  92. data/lib/gcloud/pubsub/topic/publisher.rb +0 -85
  93. data/lib/gcloud/resource_manager/credentials.rb +0 -30
  94. data/lib/gcloud/resource_manager/manager.rb +0 -266
  95. data/lib/gcloud/resource_manager/policy.rb +0 -211
  96. data/lib/gcloud/resource_manager/project.rb +0 -484
  97. data/lib/gcloud/resource_manager/project/list.rb +0 -167
  98. data/lib/gcloud/resource_manager/project/updater.rb +0 -130
  99. data/lib/gcloud/resource_manager/service.rb +0 -127
  100. data/lib/gcloud/storage/bucket.rb +0 -775
  101. data/lib/gcloud/storage/bucket/acl.rb +0 -810
  102. data/lib/gcloud/storage/bucket/cors.rb +0 -153
  103. data/lib/gcloud/storage/bucket/list.rb +0 -172
  104. data/lib/gcloud/storage/credentials.rb +0 -29
  105. data/lib/gcloud/storage/errors.rb +0 -65
  106. data/lib/gcloud/storage/file.rb +0 -842
  107. data/lib/gcloud/storage/file/acl.rb +0 -425
  108. data/lib/gcloud/storage/file/list.rb +0 -191
  109. data/lib/gcloud/storage/file/verifier.rb +0 -67
  110. data/lib/gcloud/storage/project.rb +0 -316
  111. data/lib/gcloud/storage/service.rb +0 -347
  112. data/lib/gcloud/translate/api.rb +0 -241
  113. data/lib/gcloud/translate/detection.rb +0 -137
  114. data/lib/gcloud/translate/language.rb +0 -69
  115. data/lib/gcloud/translate/service.rb +0 -80
  116. data/lib/gcloud/translate/translation.rb +0 -112
  117. data/lib/gcloud/vision/annotate.rb +0 -224
  118. data/lib/gcloud/vision/annotation.rb +0 -455
  119. data/lib/gcloud/vision/annotation/entity.rb +0 -234
  120. data/lib/gcloud/vision/annotation/face.rb +0 -1750
  121. data/lib/gcloud/vision/annotation/properties.rb +0 -245
  122. data/lib/gcloud/vision/annotation/safe_search.rb +0 -161
  123. data/lib/gcloud/vision/annotation/text.rb +0 -236
  124. data/lib/gcloud/vision/annotation/vertex.rb +0 -108
  125. data/lib/gcloud/vision/credentials.rb +0 -29
  126. data/lib/gcloud/vision/image.rb +0 -590
  127. data/lib/gcloud/vision/location.rb +0 -115
  128. data/lib/gcloud/vision/project.rb +0 -278
  129. data/lib/gcloud/vision/service.rb +0 -66
  130. data/lib/google/api/annotations.rb +0 -14
  131. data/lib/google/api/http.rb +0 -30
  132. data/lib/google/api/label.rb +0 -24
  133. data/lib/google/api/monitored_resource.rb +0 -25
  134. data/lib/google/datastore/v1beta3/datastore.rb +0 -115
  135. data/lib/google/datastore/v1beta3/datastore_services.rb +0 -33
  136. data/lib/google/datastore/v1beta3/entity.rb +0 -63
  137. data/lib/google/datastore/v1beta3/query.rb +0 -128
  138. data/lib/google/devtools/cloudtrace/v1/trace.rb +0 -78
  139. data/lib/google/devtools/cloudtrace/v1/trace_services.rb +0 -32
  140. data/lib/google/example/library/v1/library.rb +0 -91
  141. data/lib/google/example/library/v1/library_services.rb +0 -40
  142. data/lib/google/iam/v1/iam_policy.rb +0 -33
  143. data/lib/google/iam/v1/iam_policy_services.rb +0 -30
  144. data/lib/google/iam/v1/policy.rb +0 -25
  145. data/lib/google/logging/type/http_request.rb +0 -28
  146. data/lib/google/logging/type/log_severity.rb +0 -27
  147. data/lib/google/logging/v2/log_entry.rb +0 -44
  148. data/lib/google/logging/v2/logging.rb +0 -56
  149. data/lib/google/logging/v2/logging_config.rb +0 -59
  150. data/lib/google/logging/v2/logging_config_services.rb +0 -32
  151. data/lib/google/logging/v2/logging_metrics.rb +0 -51
  152. data/lib/google/logging/v2/logging_metrics_services.rb +0 -32
  153. data/lib/google/logging/v2/logging_services.rb +0 -31
  154. data/lib/google/longrunning/operations.rb +0 -50
  155. data/lib/google/longrunning/operations_services.rb +0 -29
  156. data/lib/google/protobuf/descriptor.rb +0 -0
  157. data/lib/google/pubsub/v1/pubsub.rb +0 -129
  158. data/lib/google/pubsub/v1/pubsub_services.rb +0 -56
  159. data/lib/google/pubsub/v1beta2/pubsub.rb +0 -126
  160. data/lib/google/pubsub/v1beta2/pubsub_services.rb +0 -56
  161. data/lib/google/rpc/code.rb +0 -32
  162. data/lib/google/rpc/error_details.rb +0 -61
  163. data/lib/google/rpc/status.rb +0 -19
  164. data/lib/google/type/color.rb +0 -20
  165. data/lib/google/type/date.rb +0 -18
  166. data/lib/google/type/dayofweek.rb +0 -23
  167. data/lib/google/type/latlng.rb +0 -17
  168. data/lib/google/type/money.rb +0 -18
  169. data/lib/google/type/timeofday.rb +0 -19
@@ -1,169 +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/logging/metric/list"
17
-
18
- module Gcloud
19
- module Logging
20
- ##
21
- # # Metric
22
- #
23
- # A logs-based [Google Cloud
24
- # Monitoring](https://cloud.google.com/monitoring/docs) metric. A metric is
25
- # a measured value that can be used to assess a system. The basis of a
26
- # logs-based metric is the collection of log entries that match a logs
27
- # filter.
28
- #
29
- # @see https://cloud.google.com/logging/docs/view/logs_based_metrics
30
- # Logs-based Metrics
31
- # @see https://cloud.google.com/monitoring/docs Google Cloud Monitoring
32
- #
33
- # @example
34
- # require "gcloud"
35
- #
36
- # gcloud = Gcloud.new
37
- # logging = gcloud.logging
38
- # metric = logging.create_metric "errors", "severity>=ERROR"
39
- #
40
- class Metric
41
- ##
42
- # @private The gRPC Service object.
43
- attr_accessor :service
44
-
45
- ##
46
- # @private The gRPC Google::Logging::V2::LogMetric object.
47
- attr_accessor :grpc
48
-
49
- ##
50
- # @private Create an empty Metric object.
51
- def initialize
52
- @service = nil
53
- @grpc = Google::Logging::V2::LogMetric.new
54
- end
55
-
56
- ##
57
- # The client-assigned metric identifier. Metric identifiers are limited to
58
- # 1000 characters and can include only the following characters: `A-Z`,
59
- # `a-z`, `0-9`, and the special characters `_-.,+!*',()%/\`. The
60
- # forward-slash character (`/`) denotes a hierarchy of name pieces, and it
61
- # cannot be the first character of the name.
62
- def name
63
- grpc.name
64
- end
65
-
66
- ##
67
- # The description of this metric, which is used in documentation.
68
- def description
69
- grpc.description
70
- end
71
-
72
- ##
73
- # Updates the description of this metric, which is used in documentation.
74
- def description= description
75
- grpc.description = description
76
- end
77
-
78
- ##
79
- # An [advanced logs
80
- # filter](https://cloud.google.com/logging/docs/view/advanced_filters).
81
- def filter
82
- grpc.filter
83
- end
84
-
85
- ##
86
- # Updates the [advanced logs
87
- # filter](https://cloud.google.com/logging/docs/view/advanced_filters).
88
- def filter= filter
89
- grpc.filter = filter
90
- end
91
-
92
- ##
93
- # Updates the logs-based metric.
94
- #
95
- # @example
96
- # require "gcloud"
97
- #
98
- # gcloud = Gcloud.new
99
- # logging = gcloud.logging
100
- # metric = logging.metric "severe_errors"
101
- # metric.filter = "logName:syslog AND severity>=ERROR"
102
- # metric.save
103
- #
104
- def save
105
- ensure_service!
106
- @grpc = service.update_metric name, description, filter
107
- true
108
- end
109
-
110
- ##
111
- # Reloads the logs-based metric with current data from the Logging
112
- # service.
113
- #
114
- # @example
115
- # require "gcloud"
116
- #
117
- # gcloud = Gcloud.new
118
- # logging = gcloud.logging
119
- # metric = logging.metric "severe_errors"
120
- # metric.filter = "Unwanted value"
121
- # metric.reload!
122
- # metric.filter #=> "logName:syslog"
123
- #
124
- def reload!
125
- ensure_service!
126
- @grpc = service.get_metric name
127
- true
128
- end
129
- alias_method :refresh!, :reload!
130
-
131
- ##
132
- # Permanently deletes the logs-based metric.
133
- #
134
- # @return [Boolean] Returns `true` if the metric was deleted.
135
- #
136
- # @example
137
- # require "gcloud"
138
- #
139
- # gcloud = Gcloud.new
140
- # logging = gcloud.logging
141
- # metric = logging.metric "severe_errors"
142
- # metric.delete
143
- #
144
- def delete
145
- ensure_service!
146
- service.delete_metric name
147
- true
148
- end
149
-
150
- ##
151
- # @private New Metric from a gRPC object.
152
- def self.from_grpc grpc, service
153
- new.tap do |m|
154
- m.grpc = grpc
155
- m.service = service
156
- end
157
- end
158
-
159
- protected
160
-
161
- ##
162
- # @private Raise an error unless an active connection to the service is
163
- # available.
164
- def ensure_service!
165
- fail "Must have active connection to service" unless service
166
- end
167
- end
168
- end
169
- end
@@ -1,172 +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 "delegate"
17
-
18
- module Gcloud
19
- module Logging
20
- class Metric
21
- ##
22
- # Metric::List is a special case Array with additional values.
23
- class List < DelegateClass(::Array)
24
- ##
25
- # If not empty, indicates that there are more records that match
26
- # the request and this value should be passed to continue.
27
- attr_accessor :token
28
-
29
- ##
30
- # @private Create a new Metric::List with an array of Metric instances.
31
- def initialize arr = []
32
- super arr
33
- end
34
-
35
- ##
36
- # Whether there is a next page of metrics.
37
- #
38
- # @return [Boolean]
39
- #
40
- # @example
41
- # require "gcloud"
42
- #
43
- # gcloud = Gcloud.new
44
- # logging = gcloud.logging
45
- #
46
- # metrics = logging.metrics
47
- # if metrics.next?
48
- # next_metrics = metrics.next
49
- # end
50
- #
51
- def next?
52
- !token.nil?
53
- end
54
-
55
- ##
56
- # Retrieve the next page of metrics.
57
- #
58
- # @return [Sink::List]
59
- #
60
- # @example
61
- # require "gcloud"
62
- #
63
- # gcloud = Gcloud.new
64
- # logging = gcloud.logging
65
- #
66
- # metrics = dataset.metrics
67
- # if metrics.next?
68
- # next_metrics = metrics.next
69
- # end
70
- #
71
- def next
72
- return nil unless next?
73
- ensure_service!
74
- grpc = @service.list_metrics token: token, max: @max
75
- self.class.from_grpc grpc, @service
76
- end
77
-
78
- ##
79
- # Retrieves all metrics by repeatedly loading {#next} until {#next?}
80
- # returns `false`. Calls the given block once for each metric, which is
81
- # passed as the parameter.
82
- #
83
- # An Enumerator is returned if no block is given.
84
- #
85
- # This method may make several API calls until all metrics are
86
- # retrieved. Be sure to use as narrow a search criteria as possible.
87
- # Please use with caution.
88
- #
89
- # @param [Integer] request_limit The upper limit of API requests to make
90
- # to load all metrics. Default is no limit.
91
- # @yield [metric] The block for accessing each metric.
92
- # @yieldparam [Metric] metric The metric object.
93
- #
94
- # @return [Enumerator]
95
- #
96
- # @example Iterating each metric by passing a block:
97
- # require "gcloud"
98
- #
99
- # gcloud = Gcloud.new
100
- # logging = gcloud.logging
101
- # metrics = logging.metrics
102
- #
103
- # metrics.all do |metric|
104
- # puts "#{metric.name}: #{metric.filter}"
105
- # end
106
- #
107
- # @example Using the enumerator by not passing a block:
108
- # require "gcloud"
109
- #
110
- # gcloud = Gcloud.new
111
- # logging = gcloud.logging
112
- # metrics = logging.metrics
113
- #
114
- # all_names = metrics.all.map do |metric|
115
- # metric.name
116
- # end
117
- #
118
- # @example Limit the number of API calls made:
119
- # require "gcloud"
120
- #
121
- # gcloud = Gcloud.new
122
- # logging = gcloud.logging
123
- # metrics = logging.metrics
124
- #
125
- # metrics.all(request_limit: 10) do |metric|
126
- # puts "#{metric.name}: #{metric.filter}"
127
- # end
128
- #
129
- def all request_limit: nil
130
- request_limit = request_limit.to_i if request_limit
131
- unless block_given?
132
- return enum_for(:all, request_limit: request_limit)
133
- end
134
- results = self
135
- loop do
136
- results.each { |r| yield r }
137
- if request_limit
138
- request_limit -= 1
139
- break if request_limit < 0
140
- end
141
- break unless results.next?
142
- results = results.next
143
- end
144
- end
145
-
146
- ##
147
- # @private New Metric::List from a
148
- # Google::Logging::V2::ListLogMetricsResponse object.
149
- def self.from_grpc grpc_list, service, max = nil
150
- metrics = new(Array(grpc_list.metrics).map do |grpc_metric|
151
- Metric.from_grpc grpc_metric, service
152
- end)
153
- token = grpc_list.next_page_token
154
- token = nil if token == ""
155
- metrics.instance_variable_set "@token", token
156
- metrics.instance_variable_set "@service", service
157
- metrics.instance_variable_set "@max", max
158
- metrics
159
- end
160
-
161
- protected
162
-
163
- ##
164
- # @private Raise an error unless an active connection to the service is
165
- # available.
166
- def ensure_service!
167
- fail "Must have active connection to service" unless @service
168
- end
169
- end
170
- end
171
- end
172
- end
@@ -1,642 +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/errors"
17
- require "gcloud/gce"
18
- require "gcloud/logging/service"
19
- require "gcloud/logging/credentials"
20
- require "gcloud/logging/entry"
21
- require "gcloud/logging/resource_descriptor"
22
- require "gcloud/logging/sink"
23
- require "gcloud/logging/metric"
24
- require "gcloud/logging/logger"
25
-
26
- module Gcloud
27
- module Logging
28
- ##
29
- # # Project
30
- #
31
- # Projects are top-level containers in Google Cloud Platform. They store
32
- # information about billing and authorized users, and they control access to
33
- # Stackdriver Logging resources. Each project has a friendly name and a
34
- # unique ID. Projects can be created only in the [Google Developers
35
- # Console](https://console.developers.google.com). See {Gcloud#logging}.
36
- #
37
- # @example
38
- # require "gcloud"
39
- #
40
- # gcloud = Gcloud.new
41
- # logging = gcloud.logging
42
- # entries = logging.entries
43
- #
44
- # See Gcloud#logging
45
- class Project
46
- ##
47
- # @private The gRPC Service object.
48
- attr_accessor :service
49
-
50
- ##
51
- # @private Creates a new Connection instance.
52
- def initialize service
53
- @service = service
54
- end
55
-
56
- ##
57
- # The ID of the current project.
58
- #
59
- # @return [String] the Google Cloud project ID
60
- #
61
- # @example
62
- # require "gcloud"
63
- #
64
- # gcloud = Gcloud.new "my-project", "/path/to/keyfile.json"
65
- # logging = gcloud.logging
66
- #
67
- # logging.project #=> "my-project"
68
- #
69
- def project
70
- service.project
71
- end
72
-
73
- ##
74
- # @private Default project.
75
- def self.default_project
76
- ENV["LOGGING_PROJECT"] ||
77
- ENV["GCLOUD_PROJECT"] ||
78
- ENV["GOOGLE_CLOUD_PROJECT"] ||
79
- Gcloud::GCE.project_id
80
- end
81
-
82
- ##
83
- # Lists log entries. Use this method to retrieve log entries from Cloud
84
- # Logging.
85
- #
86
- # @param [String, Array] projects One or more project IDs or project
87
- # numbers from which to retrieve log entries. If `nil`, the ID of the
88
- # receiving project instance will be used.
89
- # @param [String] filter An [advanced logs
90
- # filter](https://cloud.google.com/logging/docs/view/advanced_filters).
91
- # The filter is compared against all log entries in the projects
92
- # specified by `projects`. Only entries that match the filter are
93
- # retrieved. An empty filter matches all log entries.
94
- # @param [String] order How the results should be sorted. Presently, the
95
- # only permitted values are "timestamp" (default) and "timestamp desc".
96
- # @param [String] token A previously-returned page token representing part
97
- # of the larger set of results to view.
98
- # @param [Integer] max Maximum number of entries to return.
99
- #
100
- # @return [Array<Gcloud::Logging::Entry>] (See
101
- # {Gcloud::Logging::Entry::List})
102
- #
103
- # @example
104
- # require "gcloud"
105
- #
106
- # gcloud = Gcloud.new
107
- # logging = gcloud.logging
108
- # entries = logging.entries
109
- # entries.each do |e|
110
- # puts "[#{e.timestamp}] #{e.log_name} #{e.payload.inspect}"
111
- # end
112
- #
113
- # @example You can use a filter to narrow results to a single log.
114
- # require "gcloud"
115
- #
116
- # gcloud = Gcloud.new
117
- # logging = gcloud.logging
118
- # entries = logging.entries filter: "log:syslog"
119
- # entries.each do |e|
120
- # puts "[#{e.timestamp}] #{e.payload.inspect}"
121
- # end
122
- #
123
- # @example You can also order the results by timestamp.
124
- # require "gcloud"
125
- #
126
- # gcloud = Gcloud.new
127
- # logging = gcloud.logging
128
- # entries = logging.entries order: "timestamp desc"
129
- # entries.each do |e|
130
- # puts "[#{e.timestamp}] #{e.log_name} #{e.payload.inspect}"
131
- # end
132
- #
133
- # @example Retrieve all log entries: (See {Entry::List#all})
134
- # require "gcloud"
135
- #
136
- # gcloud = Gcloud.new
137
- # logging = gcloud.logging
138
- # entries = logging.entries
139
- #
140
- # entries.all do |e|
141
- # puts "[#{e.timestamp}] #{e.log_name} #{e.payload.inspect}"
142
- # end
143
- #
144
- def entries projects: nil, filter: nil, order: nil, token: nil, max: nil
145
- ensure_service!
146
- list_grpc = service.list_entries projects: projects, filter: filter,
147
- order: order, token: token, max: max
148
- Entry::List.from_grpc list_grpc, service, projects: projects, max: max,
149
- filter: filter, order: order
150
- end
151
- alias_method :find_entries, :entries
152
-
153
- ##
154
- # Creates an new Entry instance that may be populated and written to the
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}.
179
- #
180
- # @return [Gcloud::Logging::Entry] a new Entry instance
181
- #
182
- # @example
183
- # require "gcloud"
184
- #
185
- # gcloud = Gcloud.new
186
- # logging = gcloud.logging
187
- #
188
- # entry = logging.entry severity: :INFO, payload: "Job started."
189
- #
190
- # logging.write_entries entry
191
- #
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
203
- end
204
- alias_method :new_entry, :entry
205
-
206
- ##
207
- # Writes log entries to the Stackdriver Logging service.
208
- #
209
- # If you write a collection of log entries, you can provide the log name,
210
- # resource, and/or labels hash to be used for all of the entries, and omit
211
- # these values from the individual entries.
212
- #
213
- # @param [Gcloud::Logging::Entry, Array<Gcloud::Logging::Entry>] entries
214
- # One or more entry objects to write. The log entries must have values
215
- # for all required fields.
216
- # @param [String] log_name A default log ID for those log entries in
217
- # `entries` that do not specify their own `log_name`. See also
218
- # {Entry#log_name=}.
219
- # @param [Resource] resource A default monitored resource for those log
220
- # entries in entries that do not specify their own resource. See also
221
- # {Entry#resource}.
222
- # @param [Hash{Symbol,String => String}] labels User-defined `key:value`
223
- # items that are added to the `labels` field of each log entry in
224
- # `entries`, except when a log entry specifies its own `key:value` item
225
- # with the same key. See also {Entry#labels=}.
226
- #
227
- # @return [Boolean] Returns `true` if the entries were written.
228
- #
229
- # @example
230
- # require "gcloud"
231
- #
232
- # gcloud = Gcloud.new
233
- # logging = gcloud.logging
234
- #
235
- # entry = logging.entry payload: "Job started.", log_name: "my_app_log"
236
- # entry.resource.type = "gae_app"
237
- # entry.resource.labels[:module_id] = "1"
238
- # entry.resource.labels[:version_id] = "20150925t173233"
239
- #
240
- # logging.write_entries entry
241
- #
242
- # @example Optionally pass log name, resource, and labels for all entries.
243
- # require "gcloud"
244
- #
245
- # gcloud = Gcloud.new
246
- # logging = gcloud.logging
247
- #
248
- # entry1 = logging.entry payload: "Job started."
249
- # entry2 = logging.entry payload: "Job completed."
250
- #
251
- # labels = { job_size: "large", job_code: "red" }
252
- # resource = logging.resource "gae_app",
253
- # "module_id" => "1",
254
- # "version_id" => "20150925t173233"
255
- #
256
- # logging.write_entries [entry1, entry2],
257
- # log_name: "my_app_log",
258
- # resource: resource,
259
- # labels: labels
260
- #
261
- def write_entries entries, log_name: nil, resource: nil, labels: nil
262
- ensure_service!
263
- service.write_entries Array(entries).map(&:to_grpc),
264
- log_name: log_name, resource: resource,
265
- labels: labels
266
- true
267
- end
268
-
269
- ##
270
- # Creates a logger instance that is API-compatible with Ruby's standard
271
- # library [Logger](http://ruby-doc.org/stdlib/libdoc/logger/rdoc).
272
- #
273
- # @param [String] log_name A log resource name to be associated with the
274
- # written log entries.
275
- # @param [Gcloud::Logging::Resource] resource The monitored resource to be
276
- # associated with written log entries.
277
- # @param [Hash] labels A set of user-defined data to be associated with
278
- # written log entries.
279
- #
280
- # @return [Gcloud::Logging::Logger] a Logger object that can be used in
281
- # place of a ruby standard library logger object.
282
- #
283
- # @example
284
- # require "gcloud"
285
- #
286
- # gcloud = Gcloud.new
287
- # logging = gcloud.logging
288
- #
289
- # resource = logging.resource "gae_app",
290
- # module_id: "1",
291
- # version_id: "20150925t173233"
292
- #
293
- # logger = logging.logger "my_app_log", resource, env: :production
294
- # logger.info "Job started."
295
- #
296
- def logger log_name, resource, labels = {}
297
- Logger.new self, log_name, resource, labels
298
- end
299
-
300
- ##
301
- # Deletes a log and all its log entries. The log will reappear if it
302
- # receives new entries.
303
- #
304
- # @param [String] name The name of the log, which may be the full path
305
- # including the project ID (`projects/<project-id>/logs/<log-id>`), or
306
- # just the short name (`<log-id>`), in which case the beginning of the
307
- # path will be automatically prepended, using the ID of the current
308
- # project.
309
- #
310
- # @return [Boolean] Returns `true` if the log and all its log entries were
311
- # deleted.
312
- #
313
- # @example
314
- # require "gcloud"
315
- #
316
- # gcloud = Gcloud.new
317
- # logging = gcloud.logging
318
- # logging.delete_log "my_app_log"
319
- #
320
- def delete_log name
321
- ensure_service!
322
- service.delete_log name
323
- true
324
- end
325
-
326
- ##
327
- # Retrieves the list of monitored resource descriptors that are used by
328
- # Stackdriver Logging.
329
- #
330
- # @see https://cloud.google.com/logging/docs/api/introduction_v2#monitored_resources
331
- # Monitored Resources
332
- #
333
- # @param [String] token A previously-returned page token representing part
334
- # of the larger set of results to view.
335
- # @param [Integer] max Maximum number of resource descriptors to return.
336
- #
337
- # @return [Array<Gcloud::Logging::ResourceDescriptor>] (See
338
- # {Gcloud::Logging::ResourceDescriptor::List})
339
- #
340
- # @example
341
- # require "gcloud"
342
- #
343
- # gcloud = Gcloud.new
344
- # logging = gcloud.logging
345
- # resource_descriptors = logging.resource_descriptors
346
- # resource_descriptors.each do |rd|
347
- # label_keys = rd.labels.map(&:key).join(", ")
348
- # puts "#{rd.type} (#{label_keys})"
349
- # end
350
- #
351
- # @example Pagination: (See {Gcloud::Logging::ResourceDescriptor::List})
352
- # require "gcloud"
353
- #
354
- # gcloud = Gcloud.new
355
- # logging = gcloud.logging
356
- # resource_descriptors = logging.resource_descriptors
357
- #
358
- # resource_descriptors.all do |rd|
359
- # puts rd.type
360
- # end
361
- #
362
- def resource_descriptors token: nil, max: nil
363
- ensure_service!
364
- list_grpc = service.list_resource_descriptors token: token, max: max
365
- ResourceDescriptor::List.from_grpc list_grpc, service, max
366
- end
367
- alias_method :find_resource_descriptors, :resource_descriptors
368
-
369
- ##
370
- # Creates a new monitored resource instance.
371
- #
372
- # @return [Gcloud::Logging::Resource]
373
- #
374
- # @example
375
- # require "gcloud"
376
- #
377
- # gcloud = Gcloud.new
378
- # logging = gcloud.logging
379
- #
380
- # resource = logging.resource "gae_app",
381
- # "module_id" => "1",
382
- # "version_id" => "20150925t173233"
383
- #
384
- def resource type, labels = {}
385
- Resource.new.tap do |r|
386
- r.type = type
387
- r.labels = labels
388
- end
389
- end
390
- alias_method :new_resource, :resource
391
-
392
- ##
393
- # Retrieves the list of sinks belonging to the project.
394
- #
395
- # @param [String] token A previously-returned page token representing part
396
- # of the larger set of results to view.
397
- # @param [Integer] max Maximum number of sinks to return.
398
- #
399
- # @return [Array<Gcloud::Logging::Sink>] (See
400
- # {Gcloud::Logging::Sink::List})
401
- #
402
- # @example
403
- # require "gcloud"
404
- #
405
- # gcloud = Gcloud.new
406
- # logging = gcloud.logging
407
- # sinks = logging.sinks
408
- # sinks.each do |s|
409
- # puts "#{s.name}: #{s.filter} -> #{s.destination}"
410
- # end
411
- #
412
- # @example Retrieve all sinks: (See {Sink::List#all})
413
- # require "gcloud"
414
- #
415
- # gcloud = Gcloud.new
416
- # logging = gcloud.logging
417
- # sinks = logging.sinks
418
- #
419
- # sinks.all do |s|
420
- # puts "#{s.name}: #{s.filter} -> #{s.destination}"
421
- # end
422
- #
423
- def sinks token: nil, max: nil
424
- ensure_service!
425
- list_grpc = service.list_sinks token: token, max: max
426
- Sink::List.from_grpc list_grpc, service, max
427
- end
428
- alias_method :find_sinks, :sinks
429
-
430
- ##
431
- # Creates a new project sink. When you create a sink, only new log entries
432
- # that match the sink's filter are exported. Stackdriver Logging does not
433
- # send previously-ingested log entries to the sink's destination.
434
- #
435
- # Before creating the sink, ensure that you have granted
436
- # `cloud-logs@google.com` permission to write logs to the destination. See
437
- # [Permissions for writing exported
438
- # logs](https://cloud.google.com/logging/docs/export/configure_export#setting_product_name_short_permissions_for_writing_exported_logs).
439
- #
440
- # @see https://cloud.google.com/logging/docs/api/tasks/exporting-logs
441
- # Exporting Logs With Sinks
442
- # @see https://cloud.google.com/logging/docs/api/introduction_v2#kinds_of_log_sinks
443
- # Kinds of log sinks (API V2)
444
- # @see https://cloud.google.com/logging/docs/api/#sinks Sinks (API V1)
445
- # @see https://cloud.google.com/logging/docs/export/configure_export#setting_product_name_short_permissions_for_writing_exported_logs
446
- # Permissions for writing exported logs
447
- #
448
- # @param [String] name The client-assigned sink identifier. Sink
449
- # identifiers are limited to 1000 characters and can include only the
450
- # following characters: `A-Z`, `a-z`, `0-9`, and the special characters
451
- # `_-.`.
452
- # @param [String] destination The resource name of the export destination.
453
- # See [About
454
- # sinks](https://cloud.google.com/logging/docs/api/tasks/exporting-logs#about_sinks)
455
- # for examples.
456
- # @param [String, nil] filter An [advanced logs
457
- # filter](https://cloud.google.com/logging/docs/view/advanced_filters)
458
- # that defines the log entries to be exported. The filter must be
459
- # consistent with the log entry format designed by the `version`
460
- # parameter, regardless of the format of the log entry that was
461
- # originally written to Stackdriver Logging.
462
- # @param [Symbol] version The log entry version used when exporting log
463
- # entries from this sink. This version does not have to correspond to
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
467
- # currently defaults to V2 in the service. The default value is
468
- # `:unspecified`.
469
- #
470
- # @return [Gcloud::Logging::Sink] a project sink
471
- #
472
- # @example
473
- # require "gcloud"
474
- #
475
- # gcloud = Gcloud.new
476
- # logging = gcloud.logging
477
- # storage = gcloud.storage
478
- #
479
- # bucket = storage.create_bucket "my-logs-bucket"
480
- #
481
- # # Grant owner permission to Stackdriver Logging service
482
- # email = "cloud-logs@google.com"
483
- # bucket.acl.add_owner "group-#{email}"
484
- #
485
- # sink = logging.create_sink "my-sink",
486
- # "storage.googleapis.com/#{bucket.id}"
487
- #
488
- def create_sink name, destination, filter: nil, version: :unspecified
489
- version = Sink.resolve_version version
490
- ensure_service!
491
- grpc = service.create_sink name, destination, filter, version
492
- Sink.from_grpc grpc, service
493
- end
494
- alias_method :new_sink, :create_sink
495
-
496
- ##
497
- # Retrieves a sink by name.
498
- #
499
- # @param [String] sink_name Name of a sink.
500
- #
501
- # @return [Gcloud::Logging::Sink, nil] Returns `nil` if the sink does not
502
- # exist.
503
- #
504
- # @example
505
- # require "gcloud"
506
- #
507
- # gcloud = Gcloud.new
508
- # logging = gcloud.logging
509
- # sink = logging.sink "existing-sink"
510
- #
511
- # @example By default `nil` will be returned if the sink does not exist.
512
- # require "gcloud"
513
- #
514
- # gcloud = Gcloud.new
515
- # logging = gcloud.logging
516
- # sink = logging.sink "non-existing-sink" #=> nil
517
- #
518
- def sink sink_name
519
- ensure_service!
520
- grpc = service.get_sink sink_name
521
- Sink.from_grpc grpc, service
522
- rescue Gcloud::NotFoundError
523
- nil
524
- end
525
- alias_method :get_sink, :sink
526
- alias_method :find_sink, :sink
527
-
528
- ##
529
- # Retrieves the list of metrics belonging to the project.
530
- #
531
- # @param [String] token A previously-returned page token representing part
532
- # of the larger set of results to view.
533
- # @param [Integer] max Maximum number of metrics to return.
534
- #
535
- # @return [Array<Gcloud::Logging::Metric>] (See
536
- # {Gcloud::Logging::Metric::List})
537
- #
538
- # @example
539
- # require "gcloud"
540
- #
541
- # gcloud = Gcloud.new
542
- # logging = gcloud.logging
543
- # metrics = logging.metrics
544
- # metrics.each do |m|
545
- # puts "#{m.name}: #{m.filter}"
546
- # end
547
- #
548
- # @example Retrieve all metrics: (See {Metric::List#all})
549
- # require "gcloud"
550
- #
551
- # gcloud = Gcloud.new
552
- # logging = gcloud.logging
553
- # metrics = logging.metrics
554
- #
555
- # metrics.all do |m|
556
- # puts "#{m.name}: #{m.filter}"
557
- # end
558
- #
559
- def metrics token: nil, max: nil
560
- ensure_service!
561
- grpc = service.list_metrics token: token, max: max
562
- Metric::List.from_grpc grpc, service, max
563
- end
564
- alias_method :find_metrics, :metrics
565
-
566
- ##
567
- # Creates a new logs-based metric for Google Cloud Monitoring.
568
- #
569
- # @see https://cloud.google.com/logging/docs/view/logs_based_metrics
570
- # Logs-based Metrics
571
- # @see https://cloud.google.com/monitoring/docs Google Cloud Monitoring
572
- #
573
- # @param [String] name The client-assigned metric identifier. Metric
574
- # identifiers are limited to 1000 characters and can include only the
575
- # following characters: `A-Z`, `a-z`, `0-9`, and the special characters
576
- # `_-.,+!*',()%/\`. The forward-slash character (`/`) denotes a
577
- # hierarchy of name pieces, and it cannot be the first character of the
578
- # name.
579
- # @param [String] filter An [advanced logs
580
- # filter](https://cloud.google.com/logging/docs/view/advanced_filters).
581
- # @param [String, nil] description A description of this metric, which is
582
- # used in documentation.
583
- #
584
- # @return [Gcloud::Logging::Metric]
585
- #
586
- # @example
587
- # require "gcloud"
588
- #
589
- # gcloud = Gcloud.new
590
- # logging = gcloud.logging
591
- # metric = logging.create_metric "errors", "severity>=ERROR"
592
- #
593
- def create_metric name, filter, description: nil
594
- ensure_service!
595
- grpc = service.create_metric name, filter, description
596
- Metric.from_grpc grpc, service
597
- end
598
- alias_method :new_metric, :create_metric
599
-
600
- ##
601
- # Retrieves metric by name.
602
- #
603
- # @param [String] name Name of a metric.
604
- #
605
- # @return [Gcloud::Logging::Metric, nil] Returns `nil` if metric does not
606
- # exist.
607
- #
608
- # @example
609
- # require "gcloud"
610
- #
611
- # gcloud = Gcloud.new
612
- # logging = gcloud.logging
613
- # metric = logging.metric "existing_metric"
614
- #
615
- # @example By default `nil` will be returned if the metric does not exist.
616
- # require "gcloud"
617
- #
618
- # gcloud = Gcloud.new
619
- # logging = gcloud.logging
620
- # metric = logging.metric "non_existing_metric" #=> nil
621
- #
622
- def metric name
623
- ensure_service!
624
- grpc = service.get_metric name
625
- Metric.from_grpc grpc, service
626
- rescue Gcloud::NotFoundError
627
- nil
628
- end
629
- alias_method :get_metric, :metric
630
- alias_method :find_metric, :metric
631
-
632
- protected
633
-
634
- ##
635
- # @private Raise an error unless an active connection to the service is
636
- # available.
637
- def ensure_service!
638
- fail "Must have active connection to service" unless service
639
- end
640
- end
641
- end
642
- end