gcloud 0.12.2 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
data/lib/gcloud/gce.rb DELETED
@@ -1,56 +0,0 @@
1
- # Copyright 2015 Google Inc. All rights reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
-
16
- require "faraday"
17
-
18
- module Gcloud
19
- ##
20
- # @private
21
- # Represents the Google Compute Engine environment.
22
- module GCE
23
- CHECK_URI = "http://169.254.169.254"
24
- PROJECT_URI = "#{CHECK_URI}/computeMetadata/v1/project/project-id"
25
-
26
- def self.gce? options = {}
27
- conn = options[:connection] || Faraday.default_connection
28
- resp = conn.get CHECK_URI do |req|
29
- req.options.timeout = 0.1
30
- end
31
- return false unless resp.status == 200
32
- return false unless resp.headers.key? "Metadata-Flavor"
33
- return resp.headers["Metadata-Flavor"] == "Google"
34
- rescue Faraday::TimeoutError, Faraday::ConnectionFailed
35
- return false
36
- end
37
-
38
- def self.project_id options = {}
39
- @gce ||= {}
40
- return @gce[:project_id] if @gce.key? :project_id
41
- conn = options[:connection] || Faraday.default_connection
42
- conn.headers = { "Metadata-Flavor" => "Google" }
43
- resp = conn.get PROJECT_URI do |req|
44
- req.options.timeout = 0.1
45
- end
46
- if resp.status == 200
47
- @gce[:project_id] = resp.body
48
- else
49
- @gce[:project_id] = nil
50
- end
51
- rescue Faraday::TimeoutError, Faraday::ConnectionFailed
52
- @gce ||= {}
53
- @gce[:project_id] = nil
54
- end
55
- end
56
- end
@@ -1,87 +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"
17
- require "google/protobuf/struct"
18
-
19
- module Gcloud
20
- ##
21
- # @private Conversion to/from GRPC objects.
22
- module GRPCUtils
23
- ##
24
- # @private Convert a Hash to a Google::Protobuf::Struct.
25
- def self.hash_to_struct hash
26
- # TODO: ArgumentError if hash is not a Hash
27
- Google::Protobuf::Struct.new fields:
28
- Hash[hash.map { |k, v| [String(k), object_to_value(v)] }]
29
- end
30
-
31
- ##
32
- # @private Convert a Google::Protobuf::Struct to a Hash.
33
- def self.struct_to_hash struct
34
- # TODO: ArgumentError if struct is not a Google::Protobuf::Struct
35
- Hash[struct.fields.map { |k, v| [k, value_to_object(v)] }]
36
- end
37
-
38
- ##
39
- # @private Convert a Google::Protobuf::Value to an Object.
40
- def self.value_to_object value
41
- # TODO: ArgumentError if struct is not a Google::Protobuf::Value
42
- if value.null_value
43
- nil
44
- elsif value.number_value
45
- value.number_value
46
- elsif value.struct_value
47
- struct_to_hash value.struct_value
48
- elsif value.list_value
49
- value.list_value.values.map { |v| value_to_object(v) }
50
- elsif !value.bool_value.nil? # Make sure its a bool, not nil
51
- value.bool_value
52
- else
53
- nil # just in case
54
- end
55
- end
56
-
57
- ##
58
- # @private Convert an Object to a Google::Protobuf::Value.
59
- def self.object_to_value obj
60
- case obj
61
- when String then Google::Protobuf::Value.new string_value: obj
62
- when Array then Google::Protobuf::ListValue.new(values:
63
- obj.map { |o| object_to_value(o) })
64
- when Hash then Google::Protobuf::Value.new struct_value:
65
- hash_to_struct(obj)
66
- when Numeric then Google::Protobuf::Value.new number_value: obj
67
- when TrueClass then Google::Protobuf::Value.new bool_value: true
68
- when FalseClass then Google::Protobuf::Value.new bool_value: false
69
- when NilClass then Google::Protobuf::Value.new null_value: :NULL_VALUE
70
- else
71
- # We could raise ArgumentError here, or we could convert to a string...
72
- Google::Protobuf::Value.new string_value: obj.to_s
73
- end
74
- end
75
-
76
- ##
77
- # @private Convert a Google::Protobuf::Map to a Hash
78
- def self.map_to_hash map
79
- if map.respond_to? :to_h
80
- map.to_h
81
- else
82
- # Enumerable doesn't have to_h on ruby 2.0...
83
- Hash[map.to_a]
84
- end
85
- end
86
- end
87
- end
@@ -1,29 +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/credentials"
17
-
18
- module Gcloud
19
- module Logging
20
- ##
21
- # @private Represents the OAuth 2.0 signing logic for Logging.
22
- class Credentials < Gcloud::Credentials
23
- SCOPE = ["https://www.googleapis.com/auth/logging.admin"]
24
- PATH_ENV_VARS = %w(LOGGING_KEYFILE GCLOUD_KEYFILE GOOGLE_CLOUD_KEYFILE)
25
- JSON_ENV_VARS = %w(LOGGING_KEYFILE_JSON GCLOUD_KEYFILE_JSON
26
- GOOGLE_CLOUD_KEYFILE_JSON)
27
- end
28
- end
29
- end
@@ -1,465 +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/resource"
17
- require "gcloud/logging/entry/http_request"
18
- require "gcloud/logging/entry/operation"
19
- require "gcloud/logging/entry/list"
20
- require "gcloud/grpc_utils"
21
-
22
- module Gcloud
23
- module Logging
24
- ##
25
- # # Entry
26
- #
27
- # An individual entry in a log.
28
- #
29
- # Each log entry is composed of metadata and a payload. The metadata
30
- # includes standard information used by Stackdriver Logging, such as when
31
- # the entry was created and where it came from. The payload is the event
32
- # record. Traditionally this is a message string, but in Stackdriver Logging
33
- # it can also be a JSON or protocol buffer object. A single log can have
34
- # entries with different payload types.
35
- #
36
- # A log is a named collection of entries. Logs can be produced by Google
37
- # Cloud Platform services, by third-party services, or by your applications.
38
- # For example, the log `compute.googleapis.com/activity_log` is produced by
39
- # Google Compute Engine. Logs are simply referenced by name in gcloud-ruby.
40
- # There is no `Log` type in gcloud-ruby or `Log` resource in the Cloud
41
- # Logging API.
42
- #
43
- # @see https://cloud.google.com/logging/docs/view/logs_index List of Log
44
- # Types
45
- #
46
- # @example
47
- # require "gcloud"
48
- #
49
- # gcloud = Gcloud.new
50
- # logging = gcloud.logging
51
- #
52
- # entry = logging.entry payload: "Job started.", log_name: "my_app_log"
53
- # entry.resource.type = "gae_app"
54
- # entry.resource.labels[:module_id] = "1"
55
- # entry.resource.labels[:version_id] = "20150925t173233"
56
- #
57
- # logging.write_entries entry
58
- #
59
- class Entry
60
- ##
61
- # Create a new Entry instance. The {#resource} attribute is
62
- # pre-populated with a new {Gcloud::Logging::Resource} instance. See also
63
- # {Gcloud::Logging::Project#entry}.
64
- def initialize
65
- @labels = {}
66
- @resource = Resource.new
67
- @http_request = HttpRequest.new
68
- @operation = Operation.new
69
- @severity = :DEFAULT
70
- end
71
-
72
- ##
73
- # The resource name of the log to which this log entry belongs. The format
74
- # of the name is `projects/<project-id>/logs/<log-id>`. e.g.
75
- # `projects/my-projectid/logs/my_app_log` and
76
- # `projects/1234567890/logs/library.googleapis.com%2Fbook_log`
77
- #
78
- # The log ID part of resource name must be less than 512 characters long
79
- # and can only include the following characters: upper and lower case
80
- # alphanumeric characters: `[A-Za-z0-9]`; and punctuation characters:
81
- # forward-slash (`/`), underscore (`_`), hyphen (`-`), and period (`.`).
82
- # Forward-slash (`/`) characters in the log ID must be URL-encoded.
83
- attr_accessor :log_name
84
-
85
- ##
86
- # The monitored resource associated with this log entry. Example: a log
87
- # entry that reports a database error would be associated with the
88
- # monitored resource designating the particular database that reported the
89
- # error.
90
- # @return [Gcloud::Logging::Resource]
91
- attr_accessor :resource
92
-
93
- ##
94
- # The time the event described by the log entry occurred. If omitted,
95
- # Stackdriver Logging will use the time the log entry is written.
96
- # @return [Time]
97
- attr_accessor :timestamp
98
-
99
- ##
100
- # The severity level of the log entry. The default value is `:DEFAULT`.
101
- # @return [Symbol]
102
- attr_accessor :severity
103
-
104
- ##
105
- # Returns `true` if the severity level is `:DEFAULT`.
106
- def default?
107
- severity == :DEFAULT
108
- end
109
-
110
- ##
111
- # Sets the severity level to `:DEFAULT`.
112
- #
113
- # @example
114
- # require "gcloud"
115
- #
116
- # gcloud = Gcloud.new
117
- # logging = gcloud.logging
118
- #
119
- # entry = logging.entry
120
- # entry.severity = :DEBUG
121
- # entry.default!
122
- # entry.default? #=> true
123
- # entry.severity #=> :DEFAULT
124
- #
125
- def default!
126
- self.severity = :DEFAULT
127
- end
128
-
129
- ##
130
- # Returns `true` if the severity level is `:DEBUG`.
131
- def debug?
132
- severity == :DEBUG
133
- end
134
-
135
- ##
136
- # Sets the severity level to `:DEBUG`.
137
- #
138
- # @example
139
- # require "gcloud"
140
- #
141
- # gcloud = Gcloud.new
142
- # logging = gcloud.logging
143
- #
144
- # entry = logging.entry
145
- # entry.severity #=> :DEFAULT
146
- # entry.debug!
147
- # entry.debug? #=> true
148
- # entry.severity #=> :DEBUG
149
- #
150
- def debug!
151
- self.severity = :DEBUG
152
- end
153
-
154
- ##
155
- # Returns `true` if the severity level is `:INFO`.
156
- def info?
157
- severity == :INFO
158
- end
159
-
160
- ##
161
- # Sets the severity level to `:INFO`.
162
- #
163
- # @example
164
- # require "gcloud"
165
- #
166
- # gcloud = Gcloud.new
167
- # logging = gcloud.logging
168
- #
169
- # entry = logging.entry
170
- # entry.severity #=> :DEFAULT
171
- # entry.info!
172
- # entry.info? #=> true
173
- # entry.severity #=> :INFO
174
- #
175
- def info!
176
- self.severity = :INFO
177
- end
178
-
179
- ##
180
- # Returns `true` if the severity level is `:NOTICE`.
181
- def notice?
182
- severity == :NOTICE
183
- end
184
-
185
- ##
186
- # Sets the severity level to `:NOTICE`.
187
- #
188
- # @example
189
- # require "gcloud"
190
- #
191
- # gcloud = Gcloud.new
192
- # logging = gcloud.logging
193
- #
194
- # entry = logging.entry
195
- # entry.severity #=> :DEFAULT
196
- # entry.notice!
197
- # entry.notice? #=> true
198
- # entry.severity #=> :NOTICE
199
- #
200
- def notice!
201
- self.severity = :NOTICE
202
- end
203
-
204
- ##
205
- # Returns `true` if the severity level is `:WARNING`.
206
- def warning?
207
- severity == :WARNING
208
- end
209
-
210
- ##
211
- # Sets the severity level to `:WARNING`.
212
- #
213
- # @example
214
- # require "gcloud"
215
- #
216
- # gcloud = Gcloud.new
217
- # logging = gcloud.logging
218
- #
219
- # entry = logging.entry
220
- # entry.severity #=> :DEFAULT
221
- # entry.warning!
222
- # entry.warning? #=> true
223
- # entry.severity #=> :WARNING
224
- #
225
- def warning!
226
- self.severity = :WARNING
227
- end
228
-
229
- ##
230
- # Returns `true` if the severity level is `:ERROR`.
231
- def error?
232
- severity == :ERROR
233
- end
234
-
235
- ##
236
- # Sets the severity level to `:ERROR`.
237
- #
238
- # @example
239
- # require "gcloud"
240
- #
241
- # gcloud = Gcloud.new
242
- # logging = gcloud.logging
243
- #
244
- # entry = logging.entry
245
- # entry.severity #=> :DEFAULT
246
- # entry.error!
247
- # entry.error? #=> true
248
- # entry.severity #=> :ERROR
249
- #
250
- def error!
251
- self.severity = :ERROR
252
- end
253
-
254
- ##
255
- # Returns `true` if the severity level is `:CRITICAL`.
256
- def critical?
257
- severity == :CRITICAL
258
- end
259
-
260
- ##
261
- # Sets the severity level to `:CRITICAL`.
262
- #
263
- # @example
264
- # require "gcloud"
265
- #
266
- # gcloud = Gcloud.new
267
- # logging = gcloud.logging
268
- #
269
- # entry = logging.entry
270
- # entry.severity #=> :DEFAULT
271
- # entry.critical!
272
- # entry.critical? #=> true
273
- # entry.severity #=> :CRITICAL
274
- #
275
- def critical!
276
- self.severity = :CRITICAL
277
- end
278
-
279
- ##
280
- # Returns `true` if the severity level is `:ALERT`.
281
- def alert?
282
- severity == :ALERT
283
- end
284
-
285
- ##
286
- # Sets the severity level to `:ALERT`.
287
- #
288
- # @example
289
- # require "gcloud"
290
- #
291
- # gcloud = Gcloud.new
292
- # logging = gcloud.logging
293
- #
294
- # entry = logging.entry
295
- # entry.severity #=> :DEFAULT
296
- # entry.alert!
297
- # entry.alert? #=> true
298
- # entry.severity #=> :ALERT
299
- #
300
- def alert!
301
- self.severity = :ALERT
302
- end
303
-
304
- ##
305
- # Returns `true` if the severity level is `:EMERGENCY`.
306
- def emergency?
307
- severity == :EMERGENCY
308
- end
309
-
310
- ##
311
- # Sets the severity level to `:EMERGENCY`.
312
- #
313
- # @example
314
- # require "gcloud"
315
- #
316
- # gcloud = Gcloud.new
317
- # logging = gcloud.logging
318
- #
319
- # entry = logging.entry
320
- # entry.severity #=> :DEFAULT
321
- # entry.emergency!
322
- # entry.emergency? #=> true
323
- # entry.severity #=> :EMERGENCY
324
- #
325
- def emergency!
326
- self.severity = :EMERGENCY
327
- end
328
-
329
- ##
330
- # A unique ID for the log entry. If you provide this field, the logging
331
- # service considers other log entries in the same log with the same ID as
332
- # duplicates which can be removed. If omitted, Stackdriver Logging will
333
- # generate a unique ID for this log entry.
334
- # @return [String]
335
- attr_accessor :insert_id
336
-
337
- ##
338
- # A set of user-defined data that provides additional information about
339
- # the log entry.
340
- # @return [Hash]
341
- attr_accessor :labels
342
-
343
- ##
344
- # The log entry payload, represented as either a string, a hash (JSON), or
345
- # a hash (protocol buffer).
346
- # @return [String, Hash]
347
- attr_accessor :payload
348
-
349
- ##
350
- # Information about the HTTP request associated with this log entry, if
351
- # applicable.
352
- # @return [Gcloud::Logging::Entry::HttpRequest]
353
- attr_reader :http_request
354
-
355
- ##
356
- # Information about an operation associated with the log entry, if
357
- # applicable.
358
- # @return [Gcloud::Logging::Entry::Operation]
359
- attr_reader :operation
360
-
361
- ##
362
- # @private Determines if the Entry has any data.
363
- def empty?
364
- log_name.nil? &&
365
- timestamp.nil? &&
366
- insert_id.nil? &&
367
- (labels.nil? || labels.empty?) &&
368
- payload.nil? &&
369
- resource.empty? &&
370
- http_request.empty? &&
371
- operation.empty?
372
- end
373
-
374
- ##
375
- # @private Exports the Entry to a Google::Logging::V2::LogEntry object.
376
- def to_grpc
377
- grpc = Google::Logging::V2::LogEntry.new(
378
- log_name: log_name.to_s,
379
- timestamp: timestamp_grpc,
380
- # TODO: verify severity is the correct type?
381
- severity: severity,
382
- insert_id: insert_id.to_s,
383
- labels: labels_grpc,
384
- resource: resource.to_grpc,
385
- http_request: http_request.to_grpc,
386
- operation: operation.to_grpc
387
- )
388
- # Add payload
389
- append_payload grpc
390
- grpc
391
- end
392
-
393
- ##
394
- # @private New Entry from a Google::Logging::V2::LogEntry object.
395
- def self.from_grpc grpc
396
- return new if grpc.nil?
397
- new.tap do |e|
398
- e.log_name = grpc.log_name
399
- e.timestamp = extract_timestamp(grpc)
400
- e.severity = grpc.severity
401
- e.insert_id = grpc.insert_id
402
- e.labels = GRPCUtils.map_to_hash(grpc.labels)
403
- e.payload = extract_payload(grpc)
404
- e.instance_variable_set "@resource", Resource.from_grpc(grpc.resource)
405
- e.instance_variable_set "@http_request",
406
- HttpRequest.from_grpc(grpc.http_request)
407
- e.instance_variable_set "@operation",
408
- Operation.from_grpc(grpc.operation)
409
- end
410
- end
411
-
412
- ##
413
- # @private Formats the timestamp as a Google::Protobuf::Timestamp object.
414
- def timestamp_grpc
415
- return nil if timestamp.nil?
416
- # TODO: ArgumentError if timestamp is not a Time object?
417
- Google::Protobuf::Timestamp.new(
418
- seconds: timestamp.to_i,
419
- nanos: timestamp.nsec
420
- )
421
- end
422
-
423
- ##
424
- # @private Formats the labels so they can be saved to a
425
- # Google::Logging::V2::LogEntry object.
426
- def labels_grpc
427
- # Coerce symbols to strings
428
- Hash[labels.map do |k, v|
429
- v = String(v) if v.is_a? Symbol
430
- [String(k), v]
431
- end]
432
- end
433
-
434
- ##
435
- # @private Adds the payload data to a Google::Logging::V2::LogEntry
436
- # object.
437
- def append_payload grpc
438
- grpc.proto_payload = nil
439
- grpc.json_payload = nil
440
- grpc.text_payload = nil
441
-
442
- if payload.is_a? Google::Protobuf::Any
443
- grpc.proto_payload = payload
444
- elsif payload.respond_to? :to_hash
445
- grpc.json_payload = GRPCUtils.hash_to_struct payload.to_hash
446
- else
447
- grpc.text_payload = payload.to_s
448
- end
449
- end
450
-
451
- ##
452
- # @private Extract payload data from Google API Client object.
453
- def self.extract_payload grpc
454
- grpc.proto_payload || grpc.json_payload || grpc.text_payload
455
- end
456
-
457
- ##
458
- # @private Get a Time object from a Google::Protobuf::Timestamp object.
459
- def self.extract_timestamp grpc
460
- return nil if grpc.timestamp.nil?
461
- Time.at grpc.timestamp.seconds, grpc.timestamp.nanos/1000.0
462
- end
463
- end
464
- end
465
- end