google-cloud-core 0.21.1 → 1.0.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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/google/cloud/core/version.rb +1 -1
- data/lib/google/cloud/credentials.rb +3 -3
- metadata +21 -9
- data/lib/google/cloud/core/environment.rb +0 -149
- data/lib/google/cloud/core/grpc_utils.rb +0 -91
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3b3286a9a2e4ebe6bf7cfd228acba475b78dc40
|
4
|
+
data.tar.gz: e8d02970e3a8ba6ef1c72a046c0e6c6065f8b75f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e43a9d267eff76d96bbb39236ec953ac5d8fee64614bb2d5374f464c3d58d7faf2d94c3ee6b993525fe489532c9f1b3f68c27130e7a69705f8ac58fa0e39066
|
7
|
+
data.tar.gz: 14cf2efe270c65f98e5f668b00abaf58aa54af634a031e654bd84c9b8eae75dbc1155699bce00daf11b2ab614a59567297cf34441aa8942366e41c0462b6f3ac
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
This library contains shared types, such as error classes, for the google-cloud project. Please see the top-level project [README](../README.md) for general information.
|
4
4
|
|
5
|
-
- [google-cloud-core API documentation](http://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-core/
|
5
|
+
- [google-cloud-core API documentation](http://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-core/latest)
|
6
6
|
|
7
7
|
## Supported Ruby Versions
|
8
8
|
|
@@ -68,12 +68,12 @@ module Google
|
|
68
68
|
path = ->(p) { ::File.file? p }
|
69
69
|
|
70
70
|
# First try to find keyfile file from environment variables.
|
71
|
-
self::PATH_ENV_VARS.map(&env).
|
71
|
+
self::PATH_ENV_VARS.map(&env).compact.select(&path)
|
72
72
|
.each do |file|
|
73
73
|
return new file, scope: scope
|
74
74
|
end
|
75
75
|
# Second try to find keyfile json from environment variables.
|
76
|
-
self::JSON_ENV_VARS.map(&json).
|
76
|
+
self::JSON_ENV_VARS.map(&json).compact.each do |hash|
|
77
77
|
return new hash, scope: scope
|
78
78
|
end
|
79
79
|
# Third try to find keyfile file from known file paths.
|
@@ -111,7 +111,7 @@ module Google
|
|
111
111
|
##
|
112
112
|
# returns a new Hash with string keys instead of symbol keys.
|
113
113
|
def stringify_hash_keys hash
|
114
|
-
Hash[hash.map { |
|
114
|
+
Hash[hash.map { |k, v| [k.to_s, v] }]
|
115
115
|
end
|
116
116
|
|
117
117
|
def client_options options
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-cloud-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Moore
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-04-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: googleauth
|
@@ -25,20 +25,34 @@ dependencies:
|
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 0.5.1
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: google-cloud-env
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.0'
|
28
42
|
- !ruby/object:Gem::Dependency
|
29
43
|
name: minitest
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|
31
45
|
requirements:
|
32
46
|
- - "~>"
|
33
47
|
- !ruby/object:Gem::Version
|
34
|
-
version: '5.
|
48
|
+
version: '5.10'
|
35
49
|
type: :development
|
36
50
|
prerelease: false
|
37
51
|
version_requirements: !ruby/object:Gem::Requirement
|
38
52
|
requirements:
|
39
53
|
- - "~>"
|
40
54
|
- !ruby/object:Gem::Version
|
41
|
-
version: '5.
|
55
|
+
version: '5.10'
|
42
56
|
- !ruby/object:Gem::Dependency
|
43
57
|
name: minitest-autotest
|
44
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -141,14 +155,14 @@ dependencies:
|
|
141
155
|
name: yard-doctest
|
142
156
|
requirement: !ruby/object:Gem::Requirement
|
143
157
|
requirements:
|
144
|
-
- - "
|
158
|
+
- - "<="
|
145
159
|
- !ruby/object:Gem::Version
|
146
160
|
version: 0.1.8
|
147
161
|
type: :development
|
148
162
|
prerelease: false
|
149
163
|
version_requirements: !ruby/object:Gem::Requirement
|
150
164
|
requirements:
|
151
|
-
- - "
|
165
|
+
- - "<="
|
152
166
|
- !ruby/object:Gem::Version
|
153
167
|
version: 0.1.8
|
154
168
|
description: google-cloud-core is the internal shared library for google-cloud-ruby.
|
@@ -163,8 +177,6 @@ files:
|
|
163
177
|
- LICENSE
|
164
178
|
- README.md
|
165
179
|
- lib/google/cloud.rb
|
166
|
-
- lib/google/cloud/core/environment.rb
|
167
|
-
- lib/google/cloud/core/grpc_utils.rb
|
168
180
|
- lib/google/cloud/core/version.rb
|
169
181
|
- lib/google/cloud/credentials.rb
|
170
182
|
- lib/google/cloud/errors.rb
|
@@ -188,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
200
|
version: '0'
|
189
201
|
requirements: []
|
190
202
|
rubyforge_project:
|
191
|
-
rubygems_version: 2.
|
203
|
+
rubygems_version: 2.6.11
|
192
204
|
signing_key:
|
193
205
|
specification_version: 4
|
194
206
|
summary: Internal shared library for google-cloud-ruby
|
@@ -1,149 +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 Google
|
19
|
-
module Cloud
|
20
|
-
module Core
|
21
|
-
##
|
22
|
-
# @private
|
23
|
-
# Represents the Google Cloud Platform environments.
|
24
|
-
module Environment
|
25
|
-
CHECK_URI = "http://169.254.169.254"
|
26
|
-
PROJECT_URI = "#{CHECK_URI}/computeMetadata/v1/project"
|
27
|
-
INSTANCE_METADATA_URI = "#{CHECK_URI}/computeMetadata/v1/instance"
|
28
|
-
|
29
|
-
##
|
30
|
-
# Check if running from a gce vm, which actually hosts GCE, GKE, and
|
31
|
-
# GAE environments.
|
32
|
-
def self.gce_vm? connection: nil
|
33
|
-
@metadata ||= {}
|
34
|
-
return @metadata[:gce_vm] if @metadata.key? :gce_vm
|
35
|
-
|
36
|
-
conn = connection || Faraday.default_connection
|
37
|
-
resp = conn.get CHECK_URI do |req|
|
38
|
-
req.options.timeout = 0.1
|
39
|
-
end
|
40
|
-
@metadata[:gce_vm] = if resp.status != 200 ||
|
41
|
-
!resp.headers.key?("Metadata-Flavor")
|
42
|
-
false
|
43
|
-
else
|
44
|
-
resp.headers["Metadata-Flavor"] == "Google"
|
45
|
-
end
|
46
|
-
rescue Faraday::TimeoutError, Faraday::ConnectionFailed
|
47
|
-
@metadata ||= {}
|
48
|
-
@metadata[:gce_vm] = false
|
49
|
-
end
|
50
|
-
|
51
|
-
##
|
52
|
-
# Check if running from Google Compute Engine, and not using GAE or GKE
|
53
|
-
#
|
54
|
-
# @return [Boolean] True if running from GCE and not GAE or GKE
|
55
|
-
def self.gce?
|
56
|
-
gce_vm? && !gae? && !gke?
|
57
|
-
end
|
58
|
-
|
59
|
-
##
|
60
|
-
# Check if running from Google Container Engine by querying for
|
61
|
-
# GKE cluster name and VM instance_zone
|
62
|
-
#
|
63
|
-
# @return [Boolean] True if self.gke_cluster_name() and
|
64
|
-
# self.instance_zone() both return true values
|
65
|
-
def self.gke?
|
66
|
-
gke_cluster_name && instance_zone
|
67
|
-
end
|
68
|
-
|
69
|
-
##
|
70
|
-
# Check if running from Google App Engine by checking existance of
|
71
|
-
# GAE_VM, GAE_MODULE_NAME, GAE_MODULE_VERSION environment variables.
|
72
|
-
#
|
73
|
-
# @return [Boolean] True if all three GAE environment variables are
|
74
|
-
# defined
|
75
|
-
def self.gae?
|
76
|
-
# TODO: Remove ENV["GAE_VM"] when GAE Flex goes GA
|
77
|
-
(ENV["GAE_VM"] || ENV["GAE_INSTANCE"]) &&
|
78
|
-
gae_module_id && gae_module_version
|
79
|
-
end
|
80
|
-
|
81
|
-
def self.project_id
|
82
|
-
uri = "#{PROJECT_URI}/project-id"
|
83
|
-
get_metadata_attribute uri, :project_id
|
84
|
-
end
|
85
|
-
|
86
|
-
##
|
87
|
-
# Retrieve GAE module name
|
88
|
-
def self.gae_module_id
|
89
|
-
# TODO: Remove ENV["GAE_MODULE_NAME"] when GAE Flex goes GA
|
90
|
-
ENV["GAE_MODULE_NAME"] || ENV["GAE_SERVICE"]
|
91
|
-
end
|
92
|
-
|
93
|
-
##
|
94
|
-
# Retrieve GAE module version
|
95
|
-
def self.gae_module_version
|
96
|
-
# TODO: Remove ENV["GAE_MODULE_VERSION"] when GAE Flex goes GA
|
97
|
-
ENV["GAE_MODULE_VERSION"] || ENV["GAE_VERSION"]
|
98
|
-
end
|
99
|
-
|
100
|
-
##
|
101
|
-
# Retrieve GKE cluster name
|
102
|
-
def self.gke_cluster_name
|
103
|
-
uri = "#{INSTANCE_METADATA_URI}/attributes/cluster-name"
|
104
|
-
get_metadata_attribute uri, :cluster_name
|
105
|
-
end
|
106
|
-
|
107
|
-
##
|
108
|
-
# Retrieve GKE namespace id
|
109
|
-
def self.gke_namespace_id
|
110
|
-
ENV["GKE_NAMESPACE_ID"]
|
111
|
-
end
|
112
|
-
|
113
|
-
##
|
114
|
-
# Retrieve GCE VM zone
|
115
|
-
def self.instance_zone
|
116
|
-
uri = "#{INSTANCE_METADATA_URI}/zone"
|
117
|
-
full_zone = get_metadata_attribute uri, :zone
|
118
|
-
full_zone.nil? ? nil : full_zone.split(%r{/}).last
|
119
|
-
end
|
120
|
-
|
121
|
-
##
|
122
|
-
# Retrieve GCE VM instance_id
|
123
|
-
def self.instance_id
|
124
|
-
uri = "#{INSTANCE_METADATA_URI}/id"
|
125
|
-
get_metadata_attribute uri, :instance_id
|
126
|
-
end
|
127
|
-
|
128
|
-
##
|
129
|
-
# Helper method to send HTTP request to GCP metadata service and
|
130
|
-
# retrieve environment information
|
131
|
-
def self.get_metadata_attribute uri, attr_name, connection: nil
|
132
|
-
@metadata ||= {}
|
133
|
-
return @metadata[attr_name] if @metadata.key? attr_name
|
134
|
-
|
135
|
-
conn = connection || Faraday.default_connection
|
136
|
-
conn.headers = { "Metadata-Flavor" => "Google" }
|
137
|
-
resp = conn.get uri do |req|
|
138
|
-
req.options.timeout = 0.1
|
139
|
-
end
|
140
|
-
|
141
|
-
@metadata[attr_name] = resp.status == 200 ? resp.body : nil
|
142
|
-
rescue Faraday::TimeoutError, Faraday::ConnectionFailed
|
143
|
-
@metadata ||= {}
|
144
|
-
@metadata[attr_name] = nil
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
@@ -1,91 +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 "google/cloud"
|
17
|
-
require "google/protobuf/struct_pb"
|
18
|
-
|
19
|
-
module Google
|
20
|
-
module Cloud
|
21
|
-
module Core
|
22
|
-
##
|
23
|
-
# @private Conversion to/from GRPC objects.
|
24
|
-
module GRPCUtils
|
25
|
-
##
|
26
|
-
# @private Convert a Hash to a Google::Protobuf::Struct.
|
27
|
-
def self.hash_to_struct hash
|
28
|
-
# TODO: ArgumentError if hash is not a Hash
|
29
|
-
Google::Protobuf::Struct.new fields:
|
30
|
-
Hash[hash.map { |k, v| [String(k), object_to_value(v)] }]
|
31
|
-
end
|
32
|
-
|
33
|
-
##
|
34
|
-
# @private Convert a Google::Protobuf::Struct to a Hash.
|
35
|
-
def self.struct_to_hash struct
|
36
|
-
# TODO: ArgumentError if struct is not a Google::Protobuf::Struct
|
37
|
-
Hash[struct.fields.map { |k, v| [k, value_to_object(v)] }]
|
38
|
-
end
|
39
|
-
|
40
|
-
##
|
41
|
-
# @private Convert a Google::Protobuf::Value to an Object.
|
42
|
-
def self.value_to_object value
|
43
|
-
# TODO: ArgumentError if struct is not a Google::Protobuf::Value
|
44
|
-
if value.null_value
|
45
|
-
nil
|
46
|
-
elsif value.number_value
|
47
|
-
value.number_value
|
48
|
-
elsif value.struct_value
|
49
|
-
struct_to_hash value.struct_value
|
50
|
-
elsif value.list_value
|
51
|
-
value.list_value.values.map { |v| value_to_object(v) }
|
52
|
-
elsif !value.bool_value.nil? # Make sure its a bool, not nil
|
53
|
-
value.bool_value
|
54
|
-
else
|
55
|
-
nil # just in case
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
##
|
60
|
-
# @private Convert an Object to a Google::Protobuf::Value.
|
61
|
-
def self.object_to_value obj
|
62
|
-
case obj
|
63
|
-
when String then Google::Protobuf::Value.new string_value: obj
|
64
|
-
when Array then Google::Protobuf::ListValue.new(values:
|
65
|
-
obj.map { |o| object_to_value(o) })
|
66
|
-
when Hash then Google::Protobuf::Value.new struct_value:
|
67
|
-
hash_to_struct(obj)
|
68
|
-
when Numeric then Google::Protobuf::Value.new number_value: obj
|
69
|
-
when TrueClass then Google::Protobuf::Value.new bool_value: true
|
70
|
-
when FalseClass then Google::Protobuf::Value.new bool_value: false
|
71
|
-
when NilClass then Google::Protobuf::Value.new null_value: :NULL_VALUE
|
72
|
-
else
|
73
|
-
# We could raise ArgumentError here, or we could convert to a string
|
74
|
-
Google::Protobuf::Value.new string_value: obj.to_s
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
##
|
79
|
-
# @private Convert a Google::Protobuf::Map to a Hash
|
80
|
-
def self.map_to_hash map
|
81
|
-
if map.respond_to? :to_h
|
82
|
-
map.to_h
|
83
|
-
else
|
84
|
-
# Enumerable doesn't have to_h on ruby 2.0...
|
85
|
-
Hash[map.to_a]
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|