gcloud 0.12.2 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/gcloud.rb +27 -456
- data/lib/gcloud/bigquery.rb +2 -382
- data/lib/gcloud/datastore.rb +2 -576
- data/lib/gcloud/dns.rb +2 -321
- data/lib/gcloud/logging.rb +1 -322
- data/lib/gcloud/pubsub.rb +2 -476
- data/lib/gcloud/resource_manager.rb +2 -273
- data/lib/gcloud/storage.rb +2 -440
- data/lib/gcloud/translate.rb +1 -250
- data/lib/gcloud/version.rb +2 -2
- data/lib/gcloud/vision.rb +1 -501
- metadata +36 -332
- data/AUTHENTICATION.md +0 -75
- data/CHANGELOG.md +0 -382
- data/OVERVIEW.md +0 -259
- data/lib/gcloud/backoff.rb +0 -150
- data/lib/gcloud/bigquery/copy_job.rb +0 -97
- data/lib/gcloud/bigquery/credentials.rb +0 -29
- data/lib/gcloud/bigquery/data.rb +0 -239
- data/lib/gcloud/bigquery/dataset.rb +0 -753
- data/lib/gcloud/bigquery/dataset/access.rb +0 -507
- data/lib/gcloud/bigquery/dataset/list.rb +0 -169
- data/lib/gcloud/bigquery/extract_job.rb +0 -117
- data/lib/gcloud/bigquery/insert_response.rb +0 -81
- data/lib/gcloud/bigquery/job.rb +0 -299
- data/lib/gcloud/bigquery/job/list.rb +0 -172
- data/lib/gcloud/bigquery/load_job.rb +0 -202
- data/lib/gcloud/bigquery/project.rb +0 -475
- data/lib/gcloud/bigquery/query_data.rb +0 -234
- data/lib/gcloud/bigquery/query_job.rb +0 -137
- data/lib/gcloud/bigquery/schema.rb +0 -359
- data/lib/gcloud/bigquery/service.rb +0 -506
- data/lib/gcloud/bigquery/table.rb +0 -1141
- data/lib/gcloud/bigquery/table/list.rb +0 -180
- data/lib/gcloud/bigquery/view.rb +0 -475
- data/lib/gcloud/credentials.rb +0 -129
- data/lib/gcloud/datastore/commit.rb +0 -148
- data/lib/gcloud/datastore/credentials.rb +0 -35
- data/lib/gcloud/datastore/cursor.rb +0 -76
- data/lib/gcloud/datastore/dataset.rb +0 -660
- data/lib/gcloud/datastore/dataset/lookup_results.rb +0 -219
- data/lib/gcloud/datastore/dataset/query_results.rb +0 -386
- data/lib/gcloud/datastore/entity.rb +0 -449
- data/lib/gcloud/datastore/errors.rb +0 -41
- data/lib/gcloud/datastore/gql_query.rb +0 -211
- data/lib/gcloud/datastore/grpc_utils.rb +0 -132
- data/lib/gcloud/datastore/key.rb +0 -281
- data/lib/gcloud/datastore/properties.rb +0 -128
- data/lib/gcloud/datastore/query.rb +0 -348
- data/lib/gcloud/datastore/service.rb +0 -167
- data/lib/gcloud/datastore/transaction.rb +0 -362
- data/lib/gcloud/dns/change.rb +0 -158
- data/lib/gcloud/dns/change/list.rb +0 -173
- data/lib/gcloud/dns/credentials.rb +0 -29
- data/lib/gcloud/dns/importer.rb +0 -183
- data/lib/gcloud/dns/project.rb +0 -247
- data/lib/gcloud/dns/record.rb +0 -170
- data/lib/gcloud/dns/record/list.rb +0 -174
- data/lib/gcloud/dns/service.rb +0 -167
- data/lib/gcloud/dns/zone.rb +0 -759
- data/lib/gcloud/dns/zone/list.rb +0 -168
- data/lib/gcloud/dns/zone/transaction.rb +0 -176
- data/lib/gcloud/errors.rb +0 -206
- data/lib/gcloud/gce.rb +0 -56
- data/lib/gcloud/grpc_utils.rb +0 -87
- data/lib/gcloud/logging/credentials.rb +0 -29
- data/lib/gcloud/logging/entry.rb +0 -465
- data/lib/gcloud/logging/entry/http_request.rb +0 -141
- data/lib/gcloud/logging/entry/list.rb +0 -177
- data/lib/gcloud/logging/entry/operation.rb +0 -90
- data/lib/gcloud/logging/logger.rb +0 -307
- data/lib/gcloud/logging/metric.rb +0 -169
- data/lib/gcloud/logging/metric/list.rb +0 -172
- data/lib/gcloud/logging/project.rb +0 -642
- data/lib/gcloud/logging/resource.rb +0 -84
- data/lib/gcloud/logging/resource_descriptor.rb +0 -137
- data/lib/gcloud/logging/resource_descriptor/list.rb +0 -174
- data/lib/gcloud/logging/service.rb +0 -267
- data/lib/gcloud/logging/sink.rb +0 -227
- data/lib/gcloud/logging/sink/list.rb +0 -171
- data/lib/gcloud/pubsub/credentials.rb +0 -29
- data/lib/gcloud/pubsub/message.rb +0 -94
- data/lib/gcloud/pubsub/policy.rb +0 -204
- data/lib/gcloud/pubsub/project.rb +0 -482
- data/lib/gcloud/pubsub/received_message.rb +0 -160
- data/lib/gcloud/pubsub/service.rb +0 -334
- data/lib/gcloud/pubsub/subscription.rb +0 -565
- data/lib/gcloud/pubsub/subscription/list.rb +0 -208
- data/lib/gcloud/pubsub/topic.rb +0 -511
- data/lib/gcloud/pubsub/topic/list.rb +0 -174
- data/lib/gcloud/pubsub/topic/publisher.rb +0 -85
- data/lib/gcloud/resource_manager/credentials.rb +0 -30
- data/lib/gcloud/resource_manager/manager.rb +0 -266
- data/lib/gcloud/resource_manager/policy.rb +0 -211
- data/lib/gcloud/resource_manager/project.rb +0 -484
- data/lib/gcloud/resource_manager/project/list.rb +0 -167
- data/lib/gcloud/resource_manager/project/updater.rb +0 -130
- data/lib/gcloud/resource_manager/service.rb +0 -127
- data/lib/gcloud/storage/bucket.rb +0 -775
- data/lib/gcloud/storage/bucket/acl.rb +0 -810
- data/lib/gcloud/storage/bucket/cors.rb +0 -153
- data/lib/gcloud/storage/bucket/list.rb +0 -172
- data/lib/gcloud/storage/credentials.rb +0 -29
- data/lib/gcloud/storage/errors.rb +0 -65
- data/lib/gcloud/storage/file.rb +0 -842
- data/lib/gcloud/storage/file/acl.rb +0 -425
- data/lib/gcloud/storage/file/list.rb +0 -191
- data/lib/gcloud/storage/file/verifier.rb +0 -67
- data/lib/gcloud/storage/project.rb +0 -316
- data/lib/gcloud/storage/service.rb +0 -347
- data/lib/gcloud/translate/api.rb +0 -241
- data/lib/gcloud/translate/detection.rb +0 -137
- data/lib/gcloud/translate/language.rb +0 -69
- data/lib/gcloud/translate/service.rb +0 -80
- data/lib/gcloud/translate/translation.rb +0 -112
- data/lib/gcloud/vision/annotate.rb +0 -224
- data/lib/gcloud/vision/annotation.rb +0 -455
- data/lib/gcloud/vision/annotation/entity.rb +0 -234
- data/lib/gcloud/vision/annotation/face.rb +0 -1750
- data/lib/gcloud/vision/annotation/properties.rb +0 -245
- data/lib/gcloud/vision/annotation/safe_search.rb +0 -161
- data/lib/gcloud/vision/annotation/text.rb +0 -236
- data/lib/gcloud/vision/annotation/vertex.rb +0 -108
- data/lib/gcloud/vision/credentials.rb +0 -29
- data/lib/gcloud/vision/image.rb +0 -590
- data/lib/gcloud/vision/location.rb +0 -115
- data/lib/gcloud/vision/project.rb +0 -278
- data/lib/gcloud/vision/service.rb +0 -66
- data/lib/google/api/annotations.rb +0 -14
- data/lib/google/api/http.rb +0 -30
- data/lib/google/api/label.rb +0 -24
- data/lib/google/api/monitored_resource.rb +0 -25
- data/lib/google/datastore/v1beta3/datastore.rb +0 -115
- data/lib/google/datastore/v1beta3/datastore_services.rb +0 -33
- data/lib/google/datastore/v1beta3/entity.rb +0 -63
- data/lib/google/datastore/v1beta3/query.rb +0 -128
- data/lib/google/devtools/cloudtrace/v1/trace.rb +0 -78
- data/lib/google/devtools/cloudtrace/v1/trace_services.rb +0 -32
- data/lib/google/example/library/v1/library.rb +0 -91
- data/lib/google/example/library/v1/library_services.rb +0 -40
- data/lib/google/iam/v1/iam_policy.rb +0 -33
- data/lib/google/iam/v1/iam_policy_services.rb +0 -30
- data/lib/google/iam/v1/policy.rb +0 -25
- data/lib/google/logging/type/http_request.rb +0 -28
- data/lib/google/logging/type/log_severity.rb +0 -27
- data/lib/google/logging/v2/log_entry.rb +0 -44
- data/lib/google/logging/v2/logging.rb +0 -56
- data/lib/google/logging/v2/logging_config.rb +0 -59
- data/lib/google/logging/v2/logging_config_services.rb +0 -32
- data/lib/google/logging/v2/logging_metrics.rb +0 -51
- data/lib/google/logging/v2/logging_metrics_services.rb +0 -32
- data/lib/google/logging/v2/logging_services.rb +0 -31
- data/lib/google/longrunning/operations.rb +0 -50
- data/lib/google/longrunning/operations_services.rb +0 -29
- data/lib/google/protobuf/descriptor.rb +0 -0
- data/lib/google/pubsub/v1/pubsub.rb +0 -129
- data/lib/google/pubsub/v1/pubsub_services.rb +0 -56
- data/lib/google/pubsub/v1beta2/pubsub.rb +0 -126
- data/lib/google/pubsub/v1beta2/pubsub_services.rb +0 -56
- data/lib/google/rpc/code.rb +0 -32
- data/lib/google/rpc/error_details.rb +0 -61
- data/lib/google/rpc/status.rb +0 -19
- data/lib/google/type/color.rb +0 -20
- data/lib/google/type/date.rb +0 -18
- data/lib/google/type/dayofweek.rb +0 -23
- data/lib/google/type/latlng.rb +0 -17
- data/lib/google/type/money.rb +0 -18
- data/lib/google/type/timeofday.rb +0 -19
@@ -1,141 +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
|
-
module Gcloud
|
17
|
-
module Logging
|
18
|
-
class Entry
|
19
|
-
##
|
20
|
-
# # Http Request
|
21
|
-
#
|
22
|
-
# HTTP request data associated with a log entry.
|
23
|
-
#
|
24
|
-
# See also {Gcloud::Logging::Entry#http_request}.
|
25
|
-
#
|
26
|
-
class HttpRequest
|
27
|
-
##
|
28
|
-
# @private Create an empty HttpRequest object.
|
29
|
-
def initialize
|
30
|
-
end
|
31
|
-
|
32
|
-
##
|
33
|
-
# The request method. Examples: `"GET"`, `"HEAD"`, `"PUT"`, `"POST"`.
|
34
|
-
# (String)
|
35
|
-
attr_accessor :method
|
36
|
-
|
37
|
-
##
|
38
|
-
# The URL. The scheme (http, https), the host name, the path and the
|
39
|
-
# query portion of the URL that was requested. Example:
|
40
|
-
# `"http://example.com/some/info?color=red"`. (String)
|
41
|
-
attr_accessor :url
|
42
|
-
|
43
|
-
##
|
44
|
-
# The size of the HTTP request message in bytes, including the request
|
45
|
-
# headers and the request body. (Integer)
|
46
|
-
attr_accessor :size
|
47
|
-
|
48
|
-
##
|
49
|
-
# The response code indicating the status of response. Examples: `200`,
|
50
|
-
# `404`. (Integer)
|
51
|
-
attr_accessor :status
|
52
|
-
|
53
|
-
##
|
54
|
-
# The size of the HTTP response message sent back to the client, in
|
55
|
-
# bytes, including the response headers and the response body. (Integer)
|
56
|
-
attr_accessor :response_size
|
57
|
-
|
58
|
-
##
|
59
|
-
# The user agent sent by the client. Example: `"Mozilla/4.0 (compatible;
|
60
|
-
# MSIE 6.0; Windows 98; Q312461; .NET CLR 1.0.3705)"`. (String)
|
61
|
-
attr_accessor :user_agent
|
62
|
-
|
63
|
-
##
|
64
|
-
# The IP address (IPv4 or IPv6) of the client that issued the HTTP
|
65
|
-
# request. Examples: `"192.168.1.1"`, `"FE80::0202:B3FF:FE1E:8329"`.
|
66
|
-
# (String)
|
67
|
-
attr_accessor :remote_ip
|
68
|
-
|
69
|
-
##
|
70
|
-
# The referer URL of the request, as defined in [HTTP/1.1 Header Field
|
71
|
-
# Definitions](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html).
|
72
|
-
# (String)
|
73
|
-
attr_accessor :referer
|
74
|
-
|
75
|
-
##
|
76
|
-
# Whether an entity was served from cache (with or without validation).
|
77
|
-
# (Boolean)
|
78
|
-
attr_accessor :cache_hit
|
79
|
-
|
80
|
-
##
|
81
|
-
# Whether the response was validated with the origin server before being
|
82
|
-
# served from cache. This field is only meaningful if `cache_hit` is
|
83
|
-
# `true`. (Boolean)
|
84
|
-
attr_accessor :validated
|
85
|
-
|
86
|
-
##
|
87
|
-
# @private Determines if the HttpRequest has any data.
|
88
|
-
def empty?
|
89
|
-
method.nil? &&
|
90
|
-
url.nil? &&
|
91
|
-
size.nil? &&
|
92
|
-
status.nil? &&
|
93
|
-
response_size.nil? &&
|
94
|
-
user_agent.nil? &&
|
95
|
-
remote_ip.nil? &&
|
96
|
-
referer.nil? &&
|
97
|
-
cache_hit.nil? &&
|
98
|
-
validated.nil?
|
99
|
-
end
|
100
|
-
|
101
|
-
##
|
102
|
-
# @private Exports the HttpRequest to a
|
103
|
-
# Google::Logging::Type::HttpRequest object.
|
104
|
-
def to_grpc
|
105
|
-
return nil if empty?
|
106
|
-
Google::Logging::Type::HttpRequest.new(
|
107
|
-
request_method: method.to_s,
|
108
|
-
request_url: url.to_s,
|
109
|
-
request_size: size.to_i,
|
110
|
-
status: status.to_i,
|
111
|
-
response_size: response_size.to_i,
|
112
|
-
user_agent: user_agent.to_s,
|
113
|
-
remote_ip: remote_ip.to_s,
|
114
|
-
referer: referer.to_s,
|
115
|
-
cache_hit: !(!cache_hit),
|
116
|
-
validated_with_origin_server: !(!validated)
|
117
|
-
)
|
118
|
-
end
|
119
|
-
|
120
|
-
##
|
121
|
-
# @private New HttpRequest from a Google::Logging::Type::HttpRequest
|
122
|
-
# object.
|
123
|
-
def self.from_grpc grpc
|
124
|
-
return new if grpc.nil?
|
125
|
-
new.tap do |h|
|
126
|
-
h.method = grpc.request_method
|
127
|
-
h.url = grpc.request_url
|
128
|
-
h.size = grpc.request_size
|
129
|
-
h.status = grpc.status
|
130
|
-
h.response_size = grpc.response_size
|
131
|
-
h.user_agent = grpc.user_agent
|
132
|
-
h.remote_ip = grpc.remote_ip
|
133
|
-
h.referer = grpc.referer
|
134
|
-
h.cache_hit = grpc.cache_hit
|
135
|
-
h.validated = grpc.validated_with_origin_server
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
@@ -1,177 +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 Entry
|
21
|
-
##
|
22
|
-
# Entry::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 Entry::List with an array of Entry instances.
|
31
|
-
def initialize arr = []
|
32
|
-
super arr
|
33
|
-
end
|
34
|
-
|
35
|
-
##
|
36
|
-
# Whether there is a next page of entries.
|
37
|
-
#
|
38
|
-
# @return [Boolean]
|
39
|
-
#
|
40
|
-
# @example
|
41
|
-
# require "gcloud"
|
42
|
-
#
|
43
|
-
# gcloud = Gcloud.new
|
44
|
-
# logging = gcloud.logging
|
45
|
-
#
|
46
|
-
# entries = logging.entries
|
47
|
-
# if entries.next?
|
48
|
-
# next_entries = entries.next
|
49
|
-
# end
|
50
|
-
#
|
51
|
-
def next?
|
52
|
-
!token.nil?
|
53
|
-
end
|
54
|
-
|
55
|
-
##
|
56
|
-
# Retrieve the next page of entries.
|
57
|
-
#
|
58
|
-
# @return [Sink::List]
|
59
|
-
#
|
60
|
-
# @example
|
61
|
-
# require "gcloud"
|
62
|
-
#
|
63
|
-
# gcloud = Gcloud.new
|
64
|
-
# logging = gcloud.logging
|
65
|
-
#
|
66
|
-
# entries = dataset.entries
|
67
|
-
# if entries.next?
|
68
|
-
# next_entries = entries.next
|
69
|
-
# end
|
70
|
-
#
|
71
|
-
def next
|
72
|
-
return nil unless next?
|
73
|
-
ensure_service!
|
74
|
-
grpc = @service.list_entries token: token, projects: @projects,
|
75
|
-
filter: @filter, order: @order, max: @max
|
76
|
-
self.class.from_grpc grpc, @service
|
77
|
-
end
|
78
|
-
|
79
|
-
##
|
80
|
-
# Retrieves all log entries by repeatedly loading {#next} until {#next?}
|
81
|
-
# returns `false`. Calls the given block once for each log entry, which
|
82
|
-
# is passed as the parameter.
|
83
|
-
#
|
84
|
-
# An Enumerator is returned if no block is given.
|
85
|
-
#
|
86
|
-
# This method may make several API calls until all log entries are
|
87
|
-
# retrieved. Be sure to use as narrow a search criteria as possible.
|
88
|
-
# Please use with caution.
|
89
|
-
#
|
90
|
-
# @param [Integer] request_limit The upper limit of API requests to make
|
91
|
-
# to load all log entries. Default is no limit.
|
92
|
-
# @yield [entry] The block for accessing each log entry.
|
93
|
-
# @yieldparam [Entry] entry The log entry object.
|
94
|
-
#
|
95
|
-
# @return [Enumerator]
|
96
|
-
#
|
97
|
-
# @example Iterating each log entry by passing a block:
|
98
|
-
# require "gcloud"
|
99
|
-
#
|
100
|
-
# gcloud = Gcloud.new
|
101
|
-
# logging = gcloud.logging
|
102
|
-
# entries = logging.entries order: "timestamp desc"
|
103
|
-
#
|
104
|
-
# entries.all do |entry|
|
105
|
-
# puts "[#{e.timestamp}] #{e.log_name} #{e.payload.inspect}"
|
106
|
-
# end
|
107
|
-
#
|
108
|
-
# @example Using the enumerator by not passing a block:
|
109
|
-
# require "gcloud"
|
110
|
-
#
|
111
|
-
# gcloud = Gcloud.new
|
112
|
-
# logging = gcloud.logging
|
113
|
-
# entries = logging.entries order: "timestamp desc"
|
114
|
-
#
|
115
|
-
# all_payloads = entries.all.map do |entry|
|
116
|
-
# entry.payload
|
117
|
-
# end
|
118
|
-
#
|
119
|
-
# @example Limit the number of API calls made:
|
120
|
-
# require "gcloud"
|
121
|
-
#
|
122
|
-
# gcloud = Gcloud.new
|
123
|
-
# logging = gcloud.logging
|
124
|
-
# entries = logging.entries order: "timestamp desc"
|
125
|
-
#
|
126
|
-
# entries.all(request_limit: 10) do |entry|
|
127
|
-
# puts "[#{e.timestamp}] #{e.log_name} #{e.payload.inspect}"
|
128
|
-
# end
|
129
|
-
#
|
130
|
-
def all request_limit: nil
|
131
|
-
request_limit = request_limit.to_i if request_limit
|
132
|
-
unless block_given?
|
133
|
-
return enum_for(:all, request_limit: request_limit)
|
134
|
-
end
|
135
|
-
results = self
|
136
|
-
loop do
|
137
|
-
results.each { |r| yield r }
|
138
|
-
if request_limit
|
139
|
-
request_limit -= 1
|
140
|
-
break if request_limit < 0
|
141
|
-
end
|
142
|
-
break unless results.next?
|
143
|
-
results = results.next
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
##
|
148
|
-
# @private New Entry::List from a
|
149
|
-
# Google::Logging::V2::ListLogEntryResponse object.
|
150
|
-
def self.from_grpc grpc_list, service, projects: nil, filter: nil,
|
151
|
-
order: nil, max: nil
|
152
|
-
entries = new(Array(grpc_list.entries).map do |grpc_entry|
|
153
|
-
Entry.from_grpc grpc_entry
|
154
|
-
end)
|
155
|
-
token = grpc_list.next_page_token
|
156
|
-
token = nil if token == ""
|
157
|
-
entries.instance_variable_set "@token", token
|
158
|
-
entries.instance_variable_set "@service", service
|
159
|
-
entries.instance_variable_set "@projects", projects
|
160
|
-
entries.instance_variable_set "@filter", filter
|
161
|
-
entries.instance_variable_set "@order", order
|
162
|
-
entries.instance_variable_set "@max", max
|
163
|
-
entries
|
164
|
-
end
|
165
|
-
|
166
|
-
protected
|
167
|
-
|
168
|
-
##
|
169
|
-
# @private Raise an error unless an active connection to the service is
|
170
|
-
# available.
|
171
|
-
def ensure_service!
|
172
|
-
fail "Must have active connection to service" unless @service
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
@@ -1,90 +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
|
-
module Gcloud
|
17
|
-
module Logging
|
18
|
-
class Entry
|
19
|
-
##
|
20
|
-
# # Operation
|
21
|
-
#
|
22
|
-
# Additional information about a potentially long-running operation with
|
23
|
-
# which a log entry is associated.
|
24
|
-
#
|
25
|
-
# See also {Gcloud::Logging::Entry#operation}.
|
26
|
-
#
|
27
|
-
class Operation
|
28
|
-
##
|
29
|
-
# @private Create an empty Operation object.
|
30
|
-
def initialize
|
31
|
-
end
|
32
|
-
|
33
|
-
##
|
34
|
-
# An arbitrary operation identifier. Log entries with the same
|
35
|
-
# identifier are assumed to be part of the same operation.
|
36
|
-
attr_accessor :id
|
37
|
-
|
38
|
-
##
|
39
|
-
# An arbitrary producer identifier. The combination of `id` and
|
40
|
-
# `producer` must be globally unique. Examples for `producer`:
|
41
|
-
# `"MyDivision.MyBigCompany.com"`,
|
42
|
-
# `"github.com/MyProject/MyApplication"`.
|
43
|
-
attr_accessor :producer
|
44
|
-
|
45
|
-
##
|
46
|
-
# Set this to `true` if this is the first log entry in the operation.
|
47
|
-
attr_accessor :first
|
48
|
-
|
49
|
-
##
|
50
|
-
# Set this to `true` if this is the last log entry in the operation.
|
51
|
-
attr_accessor :last
|
52
|
-
|
53
|
-
##
|
54
|
-
# @private Determines if the Operation has any data.
|
55
|
-
def empty?
|
56
|
-
id.nil? &&
|
57
|
-
producer.nil? &&
|
58
|
-
first.nil? &&
|
59
|
-
last.nil?
|
60
|
-
end
|
61
|
-
|
62
|
-
##
|
63
|
-
# @private Exports the Operation to a
|
64
|
-
# Google::Logging::V2::LogEntryOperation object.
|
65
|
-
def to_grpc
|
66
|
-
return nil if empty?
|
67
|
-
Google::Logging::V2::LogEntryOperation.new(
|
68
|
-
id: id.to_s,
|
69
|
-
producer: producer.to_s,
|
70
|
-
first: !(!first),
|
71
|
-
last: !(!last)
|
72
|
-
)
|
73
|
-
end
|
74
|
-
|
75
|
-
##
|
76
|
-
# @private New HttpRequest from a Google::Logging::V2::LogEntryOperation
|
77
|
-
# object.
|
78
|
-
def self.from_grpc grpc
|
79
|
-
return new if grpc.nil?
|
80
|
-
new.tap do |o|
|
81
|
-
o.id = grpc.id
|
82
|
-
o.producer = grpc.producer
|
83
|
-
o.first = grpc.first
|
84
|
-
o.last = grpc.last
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
@@ -1,307 +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
|
-
module Gcloud
|
17
|
-
module Logging
|
18
|
-
##
|
19
|
-
# # Logger
|
20
|
-
#
|
21
|
-
# A (mostly) API-compatible logger for ruby's Logger.
|
22
|
-
#
|
23
|
-
# @example
|
24
|
-
# require "gcloud"
|
25
|
-
#
|
26
|
-
# gcloud = Gcloud.new
|
27
|
-
# logging = gcloud.logging
|
28
|
-
#
|
29
|
-
# resource = logging.resource "gae_app",
|
30
|
-
# module_id: "1",
|
31
|
-
# version_id: "20150925t173233"
|
32
|
-
#
|
33
|
-
# logger = logging.logger "my_app_log", resource, env: :production
|
34
|
-
# logger.info "Job started."
|
35
|
-
#
|
36
|
-
class Logger
|
37
|
-
##
|
38
|
-
# @private The logging object.
|
39
|
-
attr_accessor :logging
|
40
|
-
|
41
|
-
##
|
42
|
-
# @private The Google Cloud log_name to write the log entry with.
|
43
|
-
attr_reader :log_name
|
44
|
-
|
45
|
-
##
|
46
|
-
# @private The Google Cloud resource to write the log entry with.
|
47
|
-
attr_reader :resource
|
48
|
-
|
49
|
-
##
|
50
|
-
# @private The Google Cloud labels to write the log entry with.
|
51
|
-
attr_reader :labels
|
52
|
-
|
53
|
-
##
|
54
|
-
# @private Creates a new Logger instance.
|
55
|
-
def initialize logging, log_name, resource, labels = nil
|
56
|
-
@logging = logging
|
57
|
-
@log_name = log_name
|
58
|
-
@resource = resource
|
59
|
-
@labels = labels
|
60
|
-
@level = 0 # DEBUG is the default behavior
|
61
|
-
end
|
62
|
-
|
63
|
-
##
|
64
|
-
# Log a `DEBUG` entry.
|
65
|
-
#
|
66
|
-
# @param [String, Hash] message The log entry payload, represented as
|
67
|
-
# either a string, a hash (JSON), or a hash (protocol buffer).
|
68
|
-
# @yield Evaluates to the message to log. This is not evaluated unless the
|
69
|
-
# logger's level is sufficient to log the message. This allows you to
|
70
|
-
# create potentially expensive logging messages that are only called
|
71
|
-
# when the logger is configured to show them.
|
72
|
-
#
|
73
|
-
def debug message = nil, &block
|
74
|
-
if block_given?
|
75
|
-
add 0, nil, message, &block
|
76
|
-
else
|
77
|
-
add 0, message, nil, &block
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
##
|
82
|
-
# Log an `INFO` entry.
|
83
|
-
#
|
84
|
-
# @param [String, Hash] message The log entry payload, represented as
|
85
|
-
# either a string, a hash (JSON), or a hash (protocol buffer).
|
86
|
-
# @yield Evaluates to the message to log. This is not evaluated unless the
|
87
|
-
# logger's level is sufficient to log the message. This allows you to
|
88
|
-
# create potentially expensive logging messages that are only called
|
89
|
-
# when the logger is configured to show them.
|
90
|
-
#
|
91
|
-
def info message = nil, &block
|
92
|
-
if block_given?
|
93
|
-
add 1, nil, message, &block
|
94
|
-
else
|
95
|
-
add 1, message, nil, &block
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
##
|
100
|
-
# Log a `WARN` entry.
|
101
|
-
#
|
102
|
-
# @param [String, Hash] message The log entry payload, represented as
|
103
|
-
# either a string, a hash (JSON), or a hash (protocol buffer).
|
104
|
-
# @yield Evaluates to the message to log. This is not evaluated unless the
|
105
|
-
# logger's level is sufficient to log the message. This allows you to
|
106
|
-
# create potentially expensive logging messages that are only called
|
107
|
-
# when the logger is configured to show them.
|
108
|
-
#
|
109
|
-
def warn message = nil, &block
|
110
|
-
if block_given?
|
111
|
-
add 2, nil, message, &block
|
112
|
-
else
|
113
|
-
add 2, message, nil, &block
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
##
|
118
|
-
# Log an `ERROR` entry.
|
119
|
-
#
|
120
|
-
# @param [String, Hash] message The log entry payload, represented as
|
121
|
-
# either a string, a hash (JSON), or a hash (protocol buffer).
|
122
|
-
# @yield Evaluates to the message to log. This is not evaluated unless the
|
123
|
-
# logger's level is sufficient to log the message. This allows you to
|
124
|
-
# create potentially expensive logging messages that are only called
|
125
|
-
# when the logger is configured to show them.
|
126
|
-
#
|
127
|
-
def error message = nil, &block
|
128
|
-
if block_given?
|
129
|
-
add 3, nil, message, &block
|
130
|
-
else
|
131
|
-
add 3, message, nil, &block
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
##
|
136
|
-
# Log a `FATAL` entry.
|
137
|
-
#
|
138
|
-
# @param [String, Hash] message The log entry payload, represented as
|
139
|
-
# either a string, a hash (JSON), or a hash (protocol buffer).
|
140
|
-
# @yield Evaluates to the message to log. This is not evaluated unless the
|
141
|
-
# logger's level is sufficient to log the message. This allows you to
|
142
|
-
# create potentially expensive logging messages that are only called
|
143
|
-
# when the logger is configured to show them.
|
144
|
-
#
|
145
|
-
def fatal message = nil, &block
|
146
|
-
if block_given?
|
147
|
-
add 4, nil, message, &block
|
148
|
-
else
|
149
|
-
add 4, message, nil, &block
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
##
|
154
|
-
# Log an `UNKNOWN` entry. This will be printed no matter what the
|
155
|
-
# logger's current severity level is.
|
156
|
-
#
|
157
|
-
# @param [String, Hash] message The log entry payload, represented as
|
158
|
-
# either a string, a hash (JSON), or a hash (protocol buffer).
|
159
|
-
# @yield Evaluates to the message to log. This is not evaluated unless the
|
160
|
-
# logger's level is sufficient to log the message. This allows you to
|
161
|
-
# create potentially expensive logging messages that are only called
|
162
|
-
# when the logger is configured to show them.
|
163
|
-
#
|
164
|
-
def unknown message = nil, &block
|
165
|
-
if block_given?
|
166
|
-
add 5, nil, message, &block
|
167
|
-
else
|
168
|
-
add 5, message, nil, &block
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
##
|
173
|
-
# Log a message if the given severity is high enough. This is the generic
|
174
|
-
# logging method. Users will be more inclined to use {#debug}, {#info},
|
175
|
-
# {#warn}, {#error}, and {#fatal}.
|
176
|
-
#
|
177
|
-
# @param [Integer, String, Symbol] severity the integer code for or the
|
178
|
-
# name of the severity level
|
179
|
-
# @param [String, Hash] message The log entry payload, represented as
|
180
|
-
# either a string, a hash (JSON), or a hash (protocol buffer).
|
181
|
-
# @yield Evaluates to the message to log. This is not evaluated unless the
|
182
|
-
# logger's level is sufficient to log the message. This allows you to
|
183
|
-
# create potentially expensive logging messages that are only called
|
184
|
-
# when the logger is configured to show them.
|
185
|
-
#
|
186
|
-
def add severity, message = nil, progname = nil
|
187
|
-
severity = derive_severity(severity) || 5 # 5 is UNKNOWN/DEFAULT
|
188
|
-
return true if severity < @level
|
189
|
-
|
190
|
-
if message.nil?
|
191
|
-
if block_given?
|
192
|
-
message = yield
|
193
|
-
else
|
194
|
-
message = progname
|
195
|
-
# progname = nil # TODO: Figure out what to do with the progname
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
write_entry severity, message
|
200
|
-
end
|
201
|
-
alias_method :log, :add
|
202
|
-
|
203
|
-
##
|
204
|
-
# Returns `true` if the current severity level allows for sending `DEBUG`
|
205
|
-
# messages.
|
206
|
-
def debug?
|
207
|
-
@level <= 0
|
208
|
-
end
|
209
|
-
|
210
|
-
##
|
211
|
-
# Returns `true` if the current severity level allows for sending `INFO`
|
212
|
-
# messages.
|
213
|
-
def info?
|
214
|
-
@level <= 1
|
215
|
-
end
|
216
|
-
|
217
|
-
##
|
218
|
-
# Returns `true` if the current severity level allows for sending `WARN`
|
219
|
-
# messages.
|
220
|
-
def warn?
|
221
|
-
@level <= 2
|
222
|
-
end
|
223
|
-
|
224
|
-
##
|
225
|
-
# Returns `true` if the current severity level allows for sending `ERROR`
|
226
|
-
# messages.
|
227
|
-
def error?
|
228
|
-
@level <= 3
|
229
|
-
end
|
230
|
-
|
231
|
-
##
|
232
|
-
# Returns `true` if the current severity level allows for sending `FATAL`
|
233
|
-
# messages.
|
234
|
-
def fatal?
|
235
|
-
@level <= 4
|
236
|
-
end
|
237
|
-
|
238
|
-
##
|
239
|
-
# Sets the logging severity level.
|
240
|
-
#
|
241
|
-
# @param [Integer, String, Symbol] severity the integer code for or the
|
242
|
-
# name of the severity level
|
243
|
-
#
|
244
|
-
# @example
|
245
|
-
# require "gcloud"
|
246
|
-
#
|
247
|
-
# gcloud = Gcloud.new
|
248
|
-
# logging = gcloud.logging
|
249
|
-
#
|
250
|
-
# resource = logging.resource "gae_app",
|
251
|
-
# module_id: "1",
|
252
|
-
# version_id: "20150925t173233"
|
253
|
-
#
|
254
|
-
# logger = logging.logger "my_app_log", resource, env: :production
|
255
|
-
#
|
256
|
-
# logger.level = "INFO"
|
257
|
-
# logger.debug "Job started." # No log entry written
|
258
|
-
#
|
259
|
-
def level= severity
|
260
|
-
new_level = derive_severity severity
|
261
|
-
fail ArgumentError, "invalid log level: #{severity}" if new_level.nil?
|
262
|
-
@level = new_level
|
263
|
-
end
|
264
|
-
alias_method :sev_threshold=, :level=
|
265
|
-
|
266
|
-
protected
|
267
|
-
|
268
|
-
##
|
269
|
-
# @private Write a log entry to the Stackdriver Logging service.
|
270
|
-
def write_entry severity, message
|
271
|
-
entry = logging.entry.tap do |e|
|
272
|
-
e.severity = gcloud_severity(severity)
|
273
|
-
e.payload = message
|
274
|
-
end
|
275
|
-
|
276
|
-
logging.write_entries entry, log_name: log_name,
|
277
|
-
resource: resource,
|
278
|
-
labels: labels
|
279
|
-
end
|
280
|
-
|
281
|
-
##
|
282
|
-
# @private Get the logger level number from severity value object.
|
283
|
-
def derive_severity severity
|
284
|
-
return severity if severity.is_a? Integer
|
285
|
-
|
286
|
-
downcase_severity = severity.to_s.downcase
|
287
|
-
case downcase_severity
|
288
|
-
when "debug".freeze then 0
|
289
|
-
when "info".freeze then 1
|
290
|
-
when "warn".freeze then 2
|
291
|
-
when "error".freeze then 3
|
292
|
-
when "fatal".freeze then 4
|
293
|
-
when "unknown".freeze then 5
|
294
|
-
else nil
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
##
|
299
|
-
# @private Get Google Cloud deverity from logger level number.
|
300
|
-
def gcloud_severity severity_int
|
301
|
-
%i(DEBUG INFO WARNING ERROR CRITICAL DEFAULT)[severity_int]
|
302
|
-
rescue
|
303
|
-
:DEFAULT
|
304
|
-
end
|
305
|
-
end
|
306
|
-
end
|
307
|
-
end
|