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,84 +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
|
-
# # Resource
|
20
|
-
#
|
21
|
-
# A monitored resource is an abstraction used to characterize many kinds of
|
22
|
-
# objects in your cloud infrastructure, including Google Cloud SQL
|
23
|
-
# databases, Google App Engine apps, Google Compute Engine virtual machine
|
24
|
-
# instances, and so forth. Each of those kinds of objects is described by an
|
25
|
-
# instance of {ResourceDescriptor}.
|
26
|
-
#
|
27
|
-
# For use with {Gcloud::Logging::Entry#resource},
|
28
|
-
# {Gcloud::Logging::Project#resource}, and
|
29
|
-
# {Gcloud::Logging::Project#write_entries}.
|
30
|
-
#
|
31
|
-
# @example
|
32
|
-
# require "gcloud"
|
33
|
-
#
|
34
|
-
# gcloud = Gcloud.new
|
35
|
-
# logging = gcloud.logging
|
36
|
-
# resource = logging.resource "gae_app",
|
37
|
-
# "module_id" => "1",
|
38
|
-
# "version_id" => "20150925t173233"
|
39
|
-
#
|
40
|
-
class Resource
|
41
|
-
##
|
42
|
-
# Create an empty Resource object.
|
43
|
-
def initialize
|
44
|
-
@labels = {}
|
45
|
-
end
|
46
|
-
|
47
|
-
##
|
48
|
-
# The type of resource, as represented by a {ResourceDescriptor}.
|
49
|
-
attr_accessor :type
|
50
|
-
|
51
|
-
##
|
52
|
-
# A set of labels that can be used to describe instances of this monitored
|
53
|
-
# resource type.
|
54
|
-
attr_accessor :labels
|
55
|
-
|
56
|
-
##
|
57
|
-
# @private Determines if the Resource has any data.
|
58
|
-
def empty?
|
59
|
-
type.nil? && (labels.nil? || labels.empty?)
|
60
|
-
end
|
61
|
-
|
62
|
-
##
|
63
|
-
# @private Exports the Resource to a Google::Api::MonitoredResource
|
64
|
-
# object.
|
65
|
-
def to_grpc
|
66
|
-
return nil if empty?
|
67
|
-
Google::Api::MonitoredResource.new(
|
68
|
-
type: type,
|
69
|
-
labels: Hash[labels.map { |k, v| [String(k), String(v)] }]
|
70
|
-
)
|
71
|
-
end
|
72
|
-
|
73
|
-
##
|
74
|
-
# @private New Resource from a Google::Api::MonitoredResource object.
|
75
|
-
def self.from_grpc grpc
|
76
|
-
return new if grpc.nil?
|
77
|
-
new.tap do |r|
|
78
|
-
r.type = grpc.type
|
79
|
-
r.labels = GRPCUtils.map_to_hash(grpc.labels)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
@@ -1,137 +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_descriptor/list"
|
17
|
-
|
18
|
-
module Gcloud
|
19
|
-
module Logging
|
20
|
-
##
|
21
|
-
# # ResourceDescriptor
|
22
|
-
#
|
23
|
-
# Describes a type of monitored resource supported by Stackdriver Logging.
|
24
|
-
# Each ResourceDescriptor has a type name, such as `cloudsql_database`,
|
25
|
-
# `gae_app`, or `gce_instance`. It also specifies a set of labels that must
|
26
|
-
# all be given values in a {Resource} instance to represent an actual
|
27
|
-
# instance of the type.
|
28
|
-
#
|
29
|
-
# ResourceDescriptor instances are read-only. You cannot create your own
|
30
|
-
# instances, but you can list them with {Project#resource_descriptors}.
|
31
|
-
#
|
32
|
-
# @example
|
33
|
-
# require "gcloud"
|
34
|
-
#
|
35
|
-
# gcloud = Gcloud.new
|
36
|
-
# logging = gcloud.logging
|
37
|
-
# resource_descriptor = logging.resource_descriptors.first
|
38
|
-
# resource_descriptor.type #=> "cloudsql_database"
|
39
|
-
# resource_descriptor.name #=> "Cloud SQL Database"
|
40
|
-
# resource_descriptor.labels.map &:key #=> ["database_id", "region"]
|
41
|
-
#
|
42
|
-
class ResourceDescriptor
|
43
|
-
##
|
44
|
-
# @private New ResourceDescriptor from a Google API Client object.
|
45
|
-
def initialize
|
46
|
-
@labels = []
|
47
|
-
end
|
48
|
-
|
49
|
-
##
|
50
|
-
# The monitored resource type. For example, `cloudsql_database`.
|
51
|
-
attr_reader :type
|
52
|
-
|
53
|
-
##
|
54
|
-
# A display name for the monitored resource type. For example,
|
55
|
-
# `Cloud SQL Database`.
|
56
|
-
attr_reader :name
|
57
|
-
|
58
|
-
##
|
59
|
-
# A detailed description of the monitored resource type, which is used in
|
60
|
-
# documentation.
|
61
|
-
attr_reader :description
|
62
|
-
|
63
|
-
##
|
64
|
-
# A set of definitions of the labels that can be used to describe
|
65
|
-
# instances of this monitored resource type. For example, Cloud SQL
|
66
|
-
# databases must be labeled with their `database_id` and their `region`.
|
67
|
-
#
|
68
|
-
# @return [Array<LabelDescriptor>]
|
69
|
-
#
|
70
|
-
attr_reader :labels
|
71
|
-
|
72
|
-
##
|
73
|
-
# @private New ResourceDescriptor from a
|
74
|
-
# Google::Api::MonitoredResourceDescriptor object.
|
75
|
-
def self.from_grpc grpc
|
76
|
-
r = new
|
77
|
-
r.instance_variable_set "@type", grpc.type
|
78
|
-
r.instance_variable_set "@name", grpc.display_name
|
79
|
-
r.instance_variable_set "@description", grpc.description
|
80
|
-
labels = Array(grpc.labels).map do |g|
|
81
|
-
LabelDescriptor.from_grpc g
|
82
|
-
end
|
83
|
-
r.instance_variable_set "@labels", labels
|
84
|
-
r
|
85
|
-
end
|
86
|
-
|
87
|
-
##
|
88
|
-
# # LabelDescriptor
|
89
|
-
#
|
90
|
-
# A definition of a label that can be used to describe instances of a
|
91
|
-
# {Resource}. For example, Cloud SQL databases must be labeled with their
|
92
|
-
# `database_id`. See {ResourceDescriptor#labels}.
|
93
|
-
#
|
94
|
-
# @example
|
95
|
-
# require "gcloud"
|
96
|
-
#
|
97
|
-
# gcloud = Gcloud.new
|
98
|
-
# logging = gcloud.logging
|
99
|
-
# resource_descriptor = logging.resource_descriptors.first
|
100
|
-
# label_descriptor = resource_descriptor.labels.first
|
101
|
-
# label_descriptor.key #=> "database_id"
|
102
|
-
# label_descriptor.description #=> "The ID of the database."
|
103
|
-
#
|
104
|
-
class LabelDescriptor
|
105
|
-
##
|
106
|
-
# The key (name) of the label.
|
107
|
-
attr_reader :key
|
108
|
-
|
109
|
-
##
|
110
|
-
# The type of data that can be assigned to the label.
|
111
|
-
#
|
112
|
-
# @return [Symbol, nil] Returns `:string`, `:boolean`, `:integer`, or
|
113
|
-
# `nil` if there is no type.
|
114
|
-
#
|
115
|
-
attr_reader :type
|
116
|
-
|
117
|
-
##
|
118
|
-
# A human-readable description for the label.
|
119
|
-
attr_reader :description
|
120
|
-
|
121
|
-
##
|
122
|
-
# @private New LabelDescriptor from a Google::Api::LabelDescriptor
|
123
|
-
# object.
|
124
|
-
def self.from_grpc grpc
|
125
|
-
type_sym = { STRING: :string,
|
126
|
-
BOOL: :boolean,
|
127
|
-
INT64: :integer }[grpc.value_type]
|
128
|
-
l = new
|
129
|
-
l.instance_variable_set "@key", grpc.key
|
130
|
-
l.instance_variable_set "@type", type_sym
|
131
|
-
l.instance_variable_set "@description", grpc.description
|
132
|
-
l
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
@@ -1,174 +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 ResourceDescriptor
|
21
|
-
##
|
22
|
-
# ResourceDescriptor::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 ResourceDescriptor::List with an array of
|
31
|
-
# ResourceDescriptor instances.
|
32
|
-
def initialize arr = []
|
33
|
-
super arr
|
34
|
-
end
|
35
|
-
|
36
|
-
##
|
37
|
-
# Whether there is a next page of resource descriptors.
|
38
|
-
#
|
39
|
-
# @return [Boolean]
|
40
|
-
#
|
41
|
-
# @example
|
42
|
-
# require "gcloud"
|
43
|
-
#
|
44
|
-
# gcloud = Gcloud.new
|
45
|
-
# logging = gcloud.logging
|
46
|
-
#
|
47
|
-
# resource_descriptors = logging.resource_descriptors
|
48
|
-
# if resource_descriptors.next?
|
49
|
-
# next_resource_descriptors = resource_descriptors.next
|
50
|
-
# end
|
51
|
-
#
|
52
|
-
def next?
|
53
|
-
!token.nil?
|
54
|
-
end
|
55
|
-
|
56
|
-
##
|
57
|
-
# Retrieve the next page of resource descriptors.
|
58
|
-
#
|
59
|
-
# @return [Sink::List]
|
60
|
-
#
|
61
|
-
# @example
|
62
|
-
# require "gcloud"
|
63
|
-
#
|
64
|
-
# gcloud = Gcloud.new
|
65
|
-
# logging = gcloud.logging
|
66
|
-
#
|
67
|
-
# resource_descriptors = logging.resource_descriptors
|
68
|
-
# if resource_descriptors.next?
|
69
|
-
# next_resource_descriptors = resource_descriptors.next
|
70
|
-
# end
|
71
|
-
#
|
72
|
-
def next
|
73
|
-
return nil unless next?
|
74
|
-
ensure_service!
|
75
|
-
list_grpc = @service.list_resource_descriptors token: token, max: @max
|
76
|
-
self.class.from_grpc list_grpc, @service
|
77
|
-
end
|
78
|
-
|
79
|
-
##
|
80
|
-
# Retrieves all resource descriptors by repeatedly loading {#next} until
|
81
|
-
# {#next?} returns `false`. Calls the given block once for each resource
|
82
|
-
# descriptor, which 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 resource descriptors
|
87
|
-
# are 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 resource descriptors. Default is no limit.
|
92
|
-
# @yield [resource_descriptor] The block for accessing each resource
|
93
|
-
# descriptor.
|
94
|
-
# @yieldparam [ResourceDescriptor] resource_descriptor The resource
|
95
|
-
# descriptor object.
|
96
|
-
#
|
97
|
-
# @return [Enumerator]
|
98
|
-
#
|
99
|
-
# @example Iterating each resource descriptor by passing a block:
|
100
|
-
# require "gcloud"
|
101
|
-
#
|
102
|
-
# gcloud = Gcloud.new
|
103
|
-
# logging = gcloud.logging
|
104
|
-
# resource_descriptors = logging.resource_descriptors
|
105
|
-
#
|
106
|
-
# resource_descriptors.all do |rd|
|
107
|
-
# puts rd.type
|
108
|
-
# end
|
109
|
-
#
|
110
|
-
# @example Using the enumerator by not passing a block:
|
111
|
-
# require "gcloud"
|
112
|
-
#
|
113
|
-
# gcloud = Gcloud.new
|
114
|
-
# logging = gcloud.logging
|
115
|
-
# resource_descriptors = logging.resource_descriptors
|
116
|
-
#
|
117
|
-
# all_types = resource_descriptors.all.map do |rd|
|
118
|
-
# rd.type
|
119
|
-
# end
|
120
|
-
#
|
121
|
-
# @example Limit the number of API calls made:
|
122
|
-
# require "gcloud"
|
123
|
-
#
|
124
|
-
# gcloud = Gcloud.new
|
125
|
-
# logging = gcloud.logging
|
126
|
-
# resource_descriptors = logging.resource_descriptors
|
127
|
-
#
|
128
|
-
# resource_descriptors.all(request_limit: 10) do |rd|
|
129
|
-
# puts rd.type
|
130
|
-
# end
|
131
|
-
#
|
132
|
-
def all request_limit: nil
|
133
|
-
request_limit = request_limit.to_i if request_limit
|
134
|
-
unless block_given?
|
135
|
-
return enum_for(:all, request_limit: request_limit)
|
136
|
-
end
|
137
|
-
results = self
|
138
|
-
loop do
|
139
|
-
results.each { |r| yield r }
|
140
|
-
if request_limit
|
141
|
-
request_limit -= 1
|
142
|
-
break if request_limit < 0
|
143
|
-
end
|
144
|
-
break unless results.next?
|
145
|
-
results = results.next
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
##
|
150
|
-
# @private New ResourceDescriptor::List from a
|
151
|
-
# Google::Logging::V2::ListMonitoredResourceDescriptorsResponse object.
|
152
|
-
def self.from_grpc grpc_list, service, max = nil
|
153
|
-
rds = new(Array(grpc_list.resource_descriptors).map do |grpc|
|
154
|
-
ResourceDescriptor.from_grpc grpc
|
155
|
-
end)
|
156
|
-
token = grpc_list.next_page_token
|
157
|
-
token = nil if token == ""
|
158
|
-
rds.instance_variable_set "@token", token
|
159
|
-
rds.instance_variable_set "@service", service
|
160
|
-
rds.instance_variable_set "@max", max
|
161
|
-
rds
|
162
|
-
end
|
163
|
-
|
164
|
-
protected
|
165
|
-
|
166
|
-
##
|
167
|
-
# Raise an error unless an active service is available.
|
168
|
-
def ensure_service!
|
169
|
-
fail "Must have active service" unless @service
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
@@ -1,267 +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/backoff"
|
17
|
-
require "gcloud/errors"
|
18
|
-
require "google/logging/v2/logging_services"
|
19
|
-
require "google/logging/v2/logging_config_services"
|
20
|
-
require "google/logging/v2/logging_metrics_services"
|
21
|
-
|
22
|
-
|
23
|
-
module Gcloud
|
24
|
-
module Logging
|
25
|
-
##
|
26
|
-
# @private Represents the gRPC Logging service, including all the API
|
27
|
-
# methods.
|
28
|
-
class Service
|
29
|
-
attr_accessor :project, :credentials, :host, :retries, :timeout
|
30
|
-
|
31
|
-
##
|
32
|
-
# Creates a new Service instance.
|
33
|
-
def initialize project, credentials, host: nil, retries: nil, timeout: nil
|
34
|
-
@project = project
|
35
|
-
@credentials = credentials
|
36
|
-
@host = host || "logging.googleapis.com"
|
37
|
-
@retries = retries
|
38
|
-
@timeout = timeout
|
39
|
-
end
|
40
|
-
|
41
|
-
def creds
|
42
|
-
GRPC::Core::ChannelCredentials.new.compose \
|
43
|
-
GRPC::Core::CallCredentials.new credentials.client.updater_proc
|
44
|
-
end
|
45
|
-
|
46
|
-
def logging
|
47
|
-
return mocked_logging if mocked_logging
|
48
|
-
@logging ||= Google::Logging::V2::LoggingServiceV2::Stub.new(
|
49
|
-
host, creds, timeout: timeout)
|
50
|
-
end
|
51
|
-
attr_accessor :mocked_logging
|
52
|
-
|
53
|
-
def sinks
|
54
|
-
return mocked_sinks if mocked_sinks
|
55
|
-
@sinks ||= Google::Logging::V2::ConfigServiceV2::Stub.new(
|
56
|
-
host, creds, timeout: timeout)
|
57
|
-
end
|
58
|
-
attr_accessor :mocked_sinks
|
59
|
-
|
60
|
-
def metrics
|
61
|
-
return mocked_metrics if mocked_metrics
|
62
|
-
@metrics ||= Google::Logging::V2::MetricsServiceV2::Stub.new(
|
63
|
-
host, creds, timeout: timeout)
|
64
|
-
end
|
65
|
-
attr_accessor :mocked_metrics
|
66
|
-
|
67
|
-
def list_entries projects: nil, filter: nil, order: nil, token: nil,
|
68
|
-
max: nil
|
69
|
-
list_params = { project_ids: Array(projects || @project),
|
70
|
-
filter: filter,
|
71
|
-
order_by: order,
|
72
|
-
page_token: token,
|
73
|
-
page_size: max
|
74
|
-
}.delete_if { |_, v| v.nil? }
|
75
|
-
|
76
|
-
list_req = Google::Logging::V2::ListLogEntriesRequest.new(list_params)
|
77
|
-
|
78
|
-
execute { logging.list_log_entries list_req }
|
79
|
-
end
|
80
|
-
|
81
|
-
def write_entries entries, log_name: nil, resource: nil, labels: nil
|
82
|
-
# Fix log names so they are the full path
|
83
|
-
entries = Array(entries).each do |entry|
|
84
|
-
entry.log_name = log_path(entry.log_name)
|
85
|
-
end
|
86
|
-
resource = resource.to_grpc if resource
|
87
|
-
labels = Hash[labels.map { |k, v| [String(k), String(v)] }] if labels
|
88
|
-
|
89
|
-
write_params = { entries: entries,
|
90
|
-
log_name: log_path(log_name),
|
91
|
-
resource: resource, labels: labels
|
92
|
-
}.delete_if { |_, v| v.nil? }
|
93
|
-
|
94
|
-
write_req = Google::Logging::V2::WriteLogEntriesRequest.new write_params
|
95
|
-
|
96
|
-
execute { logging.write_log_entries write_req }
|
97
|
-
end
|
98
|
-
|
99
|
-
def delete_log name
|
100
|
-
delete_req = Google::Logging::V2::DeleteLogRequest.new(
|
101
|
-
log_name: log_path(name)
|
102
|
-
)
|
103
|
-
|
104
|
-
execute { logging.delete_log delete_req }
|
105
|
-
end
|
106
|
-
|
107
|
-
def list_resource_descriptors token: nil, max: nil
|
108
|
-
list_params = { page_token: token,
|
109
|
-
page_size: max
|
110
|
-
}.delete_if { |_, v| v.nil? }
|
111
|
-
|
112
|
-
list_req = \
|
113
|
-
Google::Logging::V2::ListMonitoredResourceDescriptorsRequest.new(
|
114
|
-
list_params)
|
115
|
-
|
116
|
-
execute { logging.list_monitored_resource_descriptors list_req }
|
117
|
-
end
|
118
|
-
|
119
|
-
def list_sinks token: nil, max: nil
|
120
|
-
list_params = { project_name: project_path,
|
121
|
-
page_token: token,
|
122
|
-
page_size: max
|
123
|
-
}.delete_if { |_, v| v.nil? }
|
124
|
-
|
125
|
-
list_req = Google::Logging::V2::ListSinksRequest.new(list_params)
|
126
|
-
|
127
|
-
execute { sinks.list_sinks list_req }
|
128
|
-
end
|
129
|
-
|
130
|
-
def create_sink name, destination, filter, version
|
131
|
-
sink_params = {
|
132
|
-
name: name, destination: destination,
|
133
|
-
filter: filter, output_version_format: version
|
134
|
-
}.delete_if { |_, v| v.nil? }
|
135
|
-
|
136
|
-
create_req = Google::Logging::V2::CreateSinkRequest.new(
|
137
|
-
project_name: project_path,
|
138
|
-
sink: Google::Logging::V2::LogSink.new(sink_params)
|
139
|
-
)
|
140
|
-
|
141
|
-
execute { sinks.create_sink create_req }
|
142
|
-
end
|
143
|
-
|
144
|
-
def get_sink name
|
145
|
-
get_req = Google::Logging::V2::GetSinkRequest.new(
|
146
|
-
sink_name: sink_path(name)
|
147
|
-
)
|
148
|
-
|
149
|
-
execute { sinks.get_sink get_req }
|
150
|
-
end
|
151
|
-
|
152
|
-
def update_sink name, destination, filter, version
|
153
|
-
sink_params = {
|
154
|
-
name: name, destination: destination,
|
155
|
-
filter: filter, output_version_format: version
|
156
|
-
}.delete_if { |_, v| v.nil? }
|
157
|
-
|
158
|
-
update_req = Google::Logging::V2::UpdateSinkRequest.new(
|
159
|
-
sink_name: sink_path(name),
|
160
|
-
sink: Google::Logging::V2::LogSink.new(sink_params)
|
161
|
-
)
|
162
|
-
|
163
|
-
execute { sinks.update_sink update_req }
|
164
|
-
end
|
165
|
-
|
166
|
-
def delete_sink name
|
167
|
-
delete_req = Google::Logging::V2::DeleteSinkRequest.new(
|
168
|
-
sink_name: sink_path(name)
|
169
|
-
)
|
170
|
-
|
171
|
-
execute { sinks.delete_sink delete_req }
|
172
|
-
end
|
173
|
-
|
174
|
-
def list_metrics token: nil, max: nil
|
175
|
-
list_params = { project_name: project_path,
|
176
|
-
page_token: token,
|
177
|
-
page_size: max
|
178
|
-
}.delete_if { |_, v| v.nil? }
|
179
|
-
|
180
|
-
list_req = Google::Logging::V2::ListLogMetricsRequest.new(list_params)
|
181
|
-
|
182
|
-
execute { metrics.list_log_metrics list_req }
|
183
|
-
end
|
184
|
-
|
185
|
-
def create_metric name, filter, description
|
186
|
-
metric_params = {
|
187
|
-
name: name,
|
188
|
-
description: description,
|
189
|
-
filter: filter
|
190
|
-
}.delete_if { |_, v| v.nil? }
|
191
|
-
|
192
|
-
create_req = Google::Logging::V2::CreateLogMetricRequest.new(
|
193
|
-
project_name: project_path,
|
194
|
-
metric: Google::Logging::V2::LogMetric.new(metric_params)
|
195
|
-
)
|
196
|
-
|
197
|
-
execute { metrics.create_log_metric create_req }
|
198
|
-
end
|
199
|
-
|
200
|
-
def get_metric name
|
201
|
-
get_req = Google::Logging::V2::GetLogMetricRequest.new(
|
202
|
-
metric_name: metric_path(name)
|
203
|
-
)
|
204
|
-
|
205
|
-
execute { metrics.get_log_metric get_req }
|
206
|
-
end
|
207
|
-
|
208
|
-
def update_metric name, description, filter
|
209
|
-
metric_params = {
|
210
|
-
name: name,
|
211
|
-
description: description,
|
212
|
-
filter: filter
|
213
|
-
}.delete_if { |_, v| v.nil? }
|
214
|
-
|
215
|
-
update_req = Google::Logging::V2::UpdateLogMetricRequest.new(
|
216
|
-
metric_name: metric_path(name),
|
217
|
-
metric: Google::Logging::V2::LogMetric.new(metric_params)
|
218
|
-
)
|
219
|
-
|
220
|
-
execute { metrics.update_log_metric update_req }
|
221
|
-
end
|
222
|
-
|
223
|
-
def delete_metric name
|
224
|
-
delete_req = Google::Logging::V2::DeleteLogMetricRequest.new(
|
225
|
-
metric_name: metric_path(name)
|
226
|
-
)
|
227
|
-
|
228
|
-
execute { metrics.delete_log_metric delete_req }
|
229
|
-
end
|
230
|
-
|
231
|
-
def inspect
|
232
|
-
"#{self.class}(#{@project})"
|
233
|
-
end
|
234
|
-
|
235
|
-
protected
|
236
|
-
|
237
|
-
def project_path
|
238
|
-
"projects/#{@project}"
|
239
|
-
end
|
240
|
-
|
241
|
-
def log_path log_name
|
242
|
-
return nil if log_name.nil?
|
243
|
-
return log_name if log_name.empty?
|
244
|
-
return log_name if log_name.to_s.include? "/"
|
245
|
-
"#{project_path}/logs/#{log_name}"
|
246
|
-
end
|
247
|
-
|
248
|
-
def sink_path sink_name
|
249
|
-
return sink_name if sink_name.to_s.include? "/"
|
250
|
-
"#{project_path}/sinks/#{sink_name}"
|
251
|
-
end
|
252
|
-
|
253
|
-
def metric_path metric_name
|
254
|
-
return metric_name if metric_name.to_s.include? "/"
|
255
|
-
"#{project_path}/metrics/#{metric_name}"
|
256
|
-
end
|
257
|
-
|
258
|
-
def execute
|
259
|
-
Gcloud::Backoff.new(retries: retries).execute_grpc do
|
260
|
-
yield
|
261
|
-
end
|
262
|
-
rescue GRPC::BadStatus => e
|
263
|
-
raise Gcloud::Error.from_error(e)
|
264
|
-
end
|
265
|
-
end
|
266
|
-
end
|
267
|
-
end
|