google-cloud-env 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE +2 -2
- data/README.md +7 -0
- data/lib/google-cloud-env.rb +2 -2
- data/lib/google/cloud/env.rb +35 -20
- data/lib/google/cloud/env/version.rb +3 -3
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 13df693b9c86c79c889db27da633337603ee581f5f9735ed7760ee659832351d
|
4
|
+
data.tar.gz: 828a46811e472363e9d860451b0dc7424f50ab0c884fb31650ecc086fd0cd8ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60161c4e104e8759ad896f3f434f619b71b51eb2609928128e61e77098f1700174272837a54d8aa38e1f6d6a192e9c107eb88328991d1d72684e3195e635b27d
|
7
|
+
data.tar.gz: 66bfccc4ee66d9ad9df65e2211c9578e0c30c4aed9958a5c586d9a773dca101f1cdd45970e33db17c7350dda593e4eff513b61362fae25102feabd92817d8967
|
data/LICENSE
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Apache License
|
2
2
|
Version 2.0, January 2004
|
3
|
-
|
3
|
+
https://www.apache.org/licenses/
|
4
4
|
|
5
5
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
6
|
|
@@ -192,7 +192,7 @@
|
|
192
192
|
you may not use this file except in compliance with the License.
|
193
193
|
You may obtain a copy of the License at
|
194
194
|
|
195
|
-
|
195
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
196
196
|
|
197
197
|
Unless required by applicable law or agreed to in writing, software
|
198
198
|
distributed under the License is distributed on an "AS IS" BASIS,
|
data/README.md
CHANGED
@@ -8,6 +8,13 @@ This library provides information on the application hosting environment for app
|
|
8
8
|
|
9
9
|
This library is supported on Ruby 2.0+.
|
10
10
|
|
11
|
+
However, Ruby 2.3 or later is strongly recommended, as earlier releases have
|
12
|
+
reached or are nearing end-of-life. After June 1, 2018, Google will provide
|
13
|
+
official support only for Ruby versions that are considered current and
|
14
|
+
supported by Ruby Core (that is, Ruby versions that are either in normal
|
15
|
+
maintenance or in security maintenance).
|
16
|
+
See https://www.ruby-lang.org/en/downloads/branches/ for further details.
|
17
|
+
|
11
18
|
## Versioning
|
12
19
|
|
13
20
|
This library follows [Semantic Versioning](http://semver.org/).
|
data/lib/google-cloud-env.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# Copyright 2017 Google
|
1
|
+
# Copyright 2017 Google LLC
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
5
5
|
# You may obtain a copy of the License at
|
6
6
|
#
|
7
|
-
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
8
|
#
|
9
9
|
# Unless required by applicable law or agreed to in writing, software
|
10
10
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
data/lib/google/cloud/env.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# Copyright 2017 Google
|
1
|
+
# Copyright 2017 Google LLC
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
5
5
|
# You may obtain a copy of the License at
|
6
6
|
#
|
7
|
-
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
8
|
#
|
9
9
|
# Unless required by applicable law or agreed to in writing, software
|
10
10
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
@@ -25,7 +25,7 @@ module Google
|
|
25
25
|
# This library provides access to information about the application's
|
26
26
|
# hosting environment if it is running on Google Cloud Platform. You may
|
27
27
|
# use this library to determine which Google Cloud product is hosting your
|
28
|
-
# application (e.g.
|
28
|
+
# application (e.g. App Engine, Kubernetes Engine), information about the
|
29
29
|
# Google Cloud project hosting the application, information about the
|
30
30
|
# virtual machine instance, authentication information, and so forth.
|
31
31
|
#
|
@@ -67,9 +67,10 @@ module Google
|
|
67
67
|
#
|
68
68
|
# @param [Hash] env Mock environment variables.
|
69
69
|
# @param [Faraday::Connection] connection Faraday connection to use.
|
70
|
+
# @param [Hash] metadata_cache Mock cache.
|
70
71
|
#
|
71
|
-
def initialize env: nil, connection: nil
|
72
|
-
@metadata_cache = {}
|
72
|
+
def initialize env: nil, connection: nil, metadata_cache: nil
|
73
|
+
@metadata_cache = metadata_cache || {}
|
73
74
|
@env = env || ::ENV
|
74
75
|
@connection = connection ||
|
75
76
|
::Faraday.new(url: METADATA_HOST,
|
@@ -86,13 +87,15 @@ module Google
|
|
86
87
|
end
|
87
88
|
|
88
89
|
##
|
89
|
-
# Determine whether the application is running on Google
|
90
|
+
# Determine whether the application is running on Google Kubernetes
|
91
|
+
# Engine (GKE).
|
90
92
|
#
|
91
93
|
# @return [Boolean]
|
92
94
|
#
|
93
|
-
def
|
94
|
-
|
95
|
+
def kubernetes_engine?
|
96
|
+
kubernetes_engine_cluster_name ? true : false
|
95
97
|
end
|
98
|
+
alias container_engine? kubernetes_engine?
|
96
99
|
|
97
100
|
##
|
98
101
|
# Determine whether the application is running on Google Cloud Shell.
|
@@ -106,7 +109,7 @@ module Google
|
|
106
109
|
##
|
107
110
|
# Determine whether the application is running on Google Compute Engine.
|
108
111
|
#
|
109
|
-
# Note that most other products (e.g. App Engine,
|
112
|
+
# Note that most other products (e.g. App Engine, Kubernetes Engine,
|
110
113
|
# Cloud Shell) themselves use Compute Engine under the hood, so this
|
111
114
|
# method will return true for all the above products. If you want to
|
112
115
|
# determine whether the application is running on a "raw" Compute Engine
|
@@ -122,12 +125,12 @@ module Google
|
|
122
125
|
##
|
123
126
|
# Determine whether the application is running on "raw" Google Compute
|
124
127
|
# Engine without using a higher level hosting product such as App
|
125
|
-
# Engine or
|
128
|
+
# Engine or Kubernetes Engine.
|
126
129
|
#
|
127
130
|
# @return [Boolean]
|
128
131
|
#
|
129
132
|
def raw_compute_engine?
|
130
|
-
!app_engine? && !cloud_shell? && metadata? && !
|
133
|
+
!app_engine? && !cloud_shell? && metadata? && !kubernetes_engine?
|
131
134
|
end
|
132
135
|
|
133
136
|
##
|
@@ -272,26 +275,36 @@ module Google
|
|
272
275
|
end
|
273
276
|
|
274
277
|
##
|
275
|
-
# Returns the name of the
|
278
|
+
# Returns the name of the Kubernetes Engine cluster hosting the
|
276
279
|
# application, or `nil` if the current code is not running in
|
277
|
-
#
|
280
|
+
# Kubernetes Engine.
|
278
281
|
#
|
279
282
|
# @return [String,nil]
|
280
283
|
#
|
281
|
-
def
|
284
|
+
def kubernetes_engine_cluster_name
|
282
285
|
instance_attribute "cluster-name"
|
283
286
|
end
|
287
|
+
alias container_engine_cluster_name kubernetes_engine_cluster_name
|
284
288
|
|
285
289
|
##
|
286
|
-
# Returns the name of the
|
290
|
+
# Returns the name of the Kubernetes Engine namespace hosting the
|
287
291
|
# application, or `nil` if the current code is not running in
|
288
|
-
#
|
292
|
+
# Kubernetes Engine.
|
289
293
|
#
|
290
294
|
# @return [String,nil]
|
291
295
|
#
|
292
|
-
def
|
293
|
-
|
296
|
+
def kubernetes_engine_namespace_id
|
297
|
+
# The Kubernetes namespace is difficult to obtain without help from
|
298
|
+
# the application using the Downward API. The environment variable
|
299
|
+
# below is set in some older versions of GKE, and the file below is
|
300
|
+
# present in Kubernetes as of version 1.9, but it is possible that
|
301
|
+
# alternatives will need to be found in the future.
|
302
|
+
env["GKE_NAMESPACE_ID"] ||
|
303
|
+
::IO.read("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
|
304
|
+
rescue SystemCallError
|
305
|
+
nil
|
294
306
|
end
|
307
|
+
alias container_engine_namespace_id kubernetes_engine_namespace_id
|
295
308
|
|
296
309
|
##
|
297
310
|
# Determine whether the Google Compute Engine Metadata Service is running.
|
@@ -304,7 +317,8 @@ module Google
|
|
304
317
|
resp = connection.get METADATA_ROOT_PATH
|
305
318
|
metadata_cache[METADATA_ROOT_PATH] = \
|
306
319
|
resp.status == 200 && resp.headers["Metadata-Flavor"] == "Google"
|
307
|
-
rescue ::Faraday::TimeoutError, ::Faraday::ConnectionFailed
|
320
|
+
rescue ::Faraday::TimeoutError, ::Faraday::ConnectionFailed,
|
321
|
+
Errno::EHOSTDOWN
|
308
322
|
metadata_cache[METADATA_ROOT_PATH] = false
|
309
323
|
end
|
310
324
|
end
|
@@ -329,7 +343,8 @@ module Google
|
|
329
343
|
req.headers = { "Metadata-Flavor" => "Google" }
|
330
344
|
end
|
331
345
|
metadata_cache[path] = resp.status == 200 ? resp.body.strip : nil
|
332
|
-
rescue ::Faraday::TimeoutError, ::Faraday::ConnectionFailed
|
346
|
+
rescue ::Faraday::TimeoutError, ::Faraday::ConnectionFailed,
|
347
|
+
Errno::EHOSTDOWN
|
333
348
|
metadata_cache[path] = nil
|
334
349
|
end
|
335
350
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# Copyright 2017 Google
|
1
|
+
# Copyright 2017 Google LLC
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
5
5
|
# You may obtain a copy of the License at
|
6
6
|
#
|
7
|
-
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
8
|
#
|
9
9
|
# Unless required by applicable law or agreed to in writing, software
|
10
10
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
@@ -16,7 +16,7 @@
|
|
16
16
|
module Google
|
17
17
|
module Cloud
|
18
18
|
class Env
|
19
|
-
VERSION = "1.0.
|
19
|
+
VERSION = "1.0.2".freeze
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-cloud-env
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Azuma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -98,16 +98,16 @@ dependencies:
|
|
98
98
|
name: rubocop
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.
|
103
|
+
version: 0.50.0
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.
|
110
|
+
version: 0.50.0
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: simplecov
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
186
|
version: '0'
|
187
187
|
requirements: []
|
188
188
|
rubyforge_project:
|
189
|
-
rubygems_version: 2.
|
189
|
+
rubygems_version: 2.7.7
|
190
190
|
signing_key:
|
191
191
|
specification_version: 4
|
192
192
|
summary: Google Cloud Platform hosting environment information.
|