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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6d375b8826aef95a69318b7eef8fdc66b804d955
4
- data.tar.gz: f2c8e7c5f719745949b7266ca1f84c3bde18dff5
2
+ SHA256:
3
+ metadata.gz: 13df693b9c86c79c889db27da633337603ee581f5f9735ed7760ee659832351d
4
+ data.tar.gz: 828a46811e472363e9d860451b0dc7424f50ab0c884fb31650ecc086fd0cd8ff
5
5
  SHA512:
6
- metadata.gz: 4fa3202316e7253e2ed46141da48174c6747644533be409755fc12e4b66c8a80fee34ee4ef06b5e3a0194e49ca2c8f41b9b9777196f7edc82e022fcb4b40c579
7
- data.tar.gz: e874658ba8ec008575ee65a7dc2c655eb6d4e0803b9627a3a0edd9a5417a0ac6a6d8bfb9cb93dad5d33451cc42d16fcadee8d4b09380ea97e603c0200a3e9efb
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
- http://www.apache.org/licenses/
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
- http://www.apache.org/licenses/LICENSE-2.0
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/).
@@ -1,10 +1,10 @@
1
- # Copyright 2017 Google Inc. All rights reserved.
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
- # http://www.apache.org/licenses/LICENSE-2.0
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,
@@ -1,10 +1,10 @@
1
- # Copyright 2017 Google Inc. All rights reserved.
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
- # http://www.apache.org/licenses/LICENSE-2.0
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. app engine, container engine), information about the
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 Container Engine.
90
+ # Determine whether the application is running on Google Kubernetes
91
+ # Engine (GKE).
90
92
  #
91
93
  # @return [Boolean]
92
94
  #
93
- def container_engine?
94
- container_engine_cluster_name ? true : false
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, Container 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 Container Engine.
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? && !container_engine?
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 Container Engine cluster hosting 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
- # Container Engine.
280
+ # Kubernetes Engine.
278
281
  #
279
282
  # @return [String,nil]
280
283
  #
281
- def container_engine_cluster_name
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 Container Engine namespace hosting 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
- # Container Engine.
292
+ # Kubernetes Engine.
289
293
  #
290
294
  # @return [String,nil]
291
295
  #
292
- def container_engine_namespace_id
293
- env["GKE_NAMESPACE_ID"]
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 Inc. All rights reserved.
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
- # http://www.apache.org/licenses/LICENSE-2.0
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.1".freeze
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.1
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: 2017-07-11 00:00:00.000000000 Z
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.35.1
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.35.1
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.6.12
189
+ rubygems_version: 2.7.7
190
190
  signing_key:
191
191
  specification_version: 4
192
192
  summary: Google Cloud Platform hosting environment information.