google-cloud-env 1.1.0 → 1.3.2
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/CHANGELOG.md +34 -0
- data/CONTRIBUTING.md +1 -14
- data/README.md +6 -6
- data/lib/google/cloud/env.rb +70 -16
- data/lib/google/cloud/env/version.rb +1 -1
- metadata +33 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ee42ea850521061d3f1a6c8de4205c5d546a84d5e7329c6537856087e809f89
|
4
|
+
data.tar.gz: d7f27f16c341483065e6345d04138a3ae0789e650856d351e909dcef439c9e48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1d4cf238414e5cc08e3ca994a35d15b2912b0358c7de4d33f23a61d7bfeeb93d661bb2ec68d6f8a8a3178e72285a571bf2a44ea0f98ed46f72764a6ae983110
|
7
|
+
data.tar.gz: 755c1039f5af08315f5e3ce2df79942651d07a82ba059e06c29a45d19971c11c7dcf7182e4e0115b2974a14fbdb9c17f2a321bb1ca6d1bb4416fa73b261a8606
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,39 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 1.3.2 / 2020-05-28
|
4
|
+
|
5
|
+
#### Documentation
|
6
|
+
|
7
|
+
* Fix a few broken links
|
8
|
+
|
9
|
+
### 1.3.1 / 2020-03-02
|
10
|
+
|
11
|
+
#### Bug Fixes
|
12
|
+
|
13
|
+
* support faraday 1.x
|
14
|
+
|
15
|
+
### 1.3.0 / 2019-10-23
|
16
|
+
|
17
|
+
Now requires Ruby 2.4 or later.
|
18
|
+
|
19
|
+
#### Features
|
20
|
+
|
21
|
+
* Recognize App Engine Standard and Knative
|
22
|
+
|
23
|
+
### 1.2.1 / 2019-08-23
|
24
|
+
|
25
|
+
#### Bug Fixes
|
26
|
+
|
27
|
+
* Send Metadata-Flavor header when testing the metadata server root
|
28
|
+
|
29
|
+
#### Documentation
|
30
|
+
|
31
|
+
* Update documentation
|
32
|
+
|
33
|
+
### 1.2.0 / 2019-06-19
|
34
|
+
|
35
|
+
* Support separate timeout for connecting to the metadata server vs the entire request
|
36
|
+
|
3
37
|
### 1.1.0 / 2019-05-29
|
4
38
|
|
5
39
|
* Support disabling of the metadata cache
|
data/CONTRIBUTING.md
CHANGED
@@ -24,7 +24,7 @@ be able to accept your pull requests.
|
|
24
24
|
In order to use the google-cloud-env console and run the project's tests,
|
25
25
|
there is a small amount of setup:
|
26
26
|
|
27
|
-
1. Install Ruby. google-cloud-env requires Ruby 2.
|
27
|
+
1. Install Ruby. google-cloud-env requires Ruby 2.4+. You may choose to
|
28
28
|
manage your Ruby and gem installations with [RVM](https://rvm.io/),
|
29
29
|
[rbenv](https://github.com/rbenv/rbenv), or
|
30
30
|
[chruby](https://github.com/postmodern/chruby).
|
@@ -48,19 +48,6 @@ there is a small amount of setup:
|
|
48
48
|
$ bundle exec rake bundleupdate
|
49
49
|
```
|
50
50
|
|
51
|
-
## Console
|
52
|
-
|
53
|
-
In order to run code interactively, you can automatically load
|
54
|
-
google-cloud-env and its dependencies in IRB. This requires that your
|
55
|
-
developer environment has already been configured by following the steps
|
56
|
-
described in the {file:AUTHENTICATION.md Authentication Guide}. An IRB console
|
57
|
-
can be created with:
|
58
|
-
|
59
|
-
```sh
|
60
|
-
$ cd google-cloud-env/
|
61
|
-
$ bundle exec rake console
|
62
|
-
```
|
63
|
-
|
64
51
|
## hosting environment Tests
|
65
52
|
|
66
53
|
Tests are very important part of google-cloud-env. All contributions
|
data/README.md
CHANGED
@@ -3,15 +3,15 @@
|
|
3
3
|
This library provides information on the application hosting environment for
|
4
4
|
apps running on Google Cloud Platform.
|
5
5
|
|
6
|
-
- [google-cloud-env API documentation](https://googleapis.
|
6
|
+
- [google-cloud-env API documentation](https://googleapis.dev/ruby/google-cloud-env/latest)
|
7
7
|
|
8
8
|
## Supported Ruby Versions
|
9
9
|
|
10
|
-
This library is supported on Ruby 2.
|
10
|
+
This library is supported on Ruby 2.4+.
|
11
11
|
|
12
12
|
Google provides official support for Ruby versions that are actively supported
|
13
13
|
by Ruby Core—that is, Ruby versions that are either in normal maintenance or in
|
14
|
-
security maintenance, and not end of life. Currently, this means Ruby 2.
|
14
|
+
security maintenance, and not end of life. Currently, this means Ruby 2.4 and
|
15
15
|
later. Older versions of Ruby _may_ still work, but are unsupported and not
|
16
16
|
recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details
|
17
17
|
about the Ruby support schedule.
|
@@ -28,18 +28,18 @@ change at any time and the public API should not be considered stable.
|
|
28
28
|
Contributions to this library are always welcome and highly encouraged.
|
29
29
|
|
30
30
|
See the [Contributing
|
31
|
-
Guide](https://googleapis.
|
31
|
+
Guide](https://googleapis.dev/ruby/google-cloud-env/latest/file.CONTRIBUTING.html)
|
32
32
|
for more information on how to get started.
|
33
33
|
|
34
34
|
Please note that this project is released with a Contributor Code of Conduct. By
|
35
35
|
participating in this project you agree to abide by its terms. See [Code of
|
36
|
-
Conduct](https://googleapis.
|
36
|
+
Conduct](https://googleapis.dev/ruby/google-cloud-env/latest/file.CODE_OF_CONDUCT.html)
|
37
37
|
for more information.
|
38
38
|
|
39
39
|
## License
|
40
40
|
|
41
41
|
This library is licensed under Apache 2.0. Full license text is available in
|
42
|
-
[LICENSE](https://googleapis.
|
42
|
+
[LICENSE](https://googleapis.dev/ruby/google-cloud-env/latest/file.LICENSE.html).
|
43
43
|
|
44
44
|
## Support
|
45
45
|
|
data/lib/google/cloud/env.rb
CHANGED
@@ -78,14 +78,17 @@ module Google
|
|
78
78
|
# Create a new instance of the environment information.
|
79
79
|
# Most client should not need to call this directly. Obtain a singleton
|
80
80
|
# instance of the information from `Google::Cloud.env`. This constructor
|
81
|
-
# is provided
|
81
|
+
# is provided to allow customization of the timeout/retry settings, as
|
82
|
+
# well as mocking for testing.
|
82
83
|
#
|
83
84
|
# @param [Hash] env Mock environment variables.
|
84
85
|
# @param [Hash,false] metadata_cache The metadata cache. You may pass
|
85
86
|
# a prepopuated cache, an empty cache (the default) or `false` to
|
86
87
|
# disable the cache completely.
|
87
|
-
# @param [Numeric]
|
88
|
+
# @param [Numeric] open_timeout Timeout for opening http connections.
|
88
89
|
# Defaults to 0.1.
|
90
|
+
# @param [Numeric] request_timeout Timeout for entire http requests.
|
91
|
+
# Defaults to 1.0.
|
89
92
|
# @param [Integer] retry_count Number of times to retry http requests.
|
90
93
|
# Defaults to 1. Note that retry remains in effect even if a custom
|
91
94
|
# `connection` is provided.
|
@@ -96,10 +99,12 @@ module Google
|
|
96
99
|
# @param [Numeric] retry_max_interval Maximum time between retries in
|
97
100
|
# seconds. Defaults to 0.5.
|
98
101
|
# @param [Faraday::Connection] connection Faraday connection to use.
|
99
|
-
# If specified, overrides the `request_timeout`
|
102
|
+
# If specified, overrides the `request_timeout` and `open_timeout`
|
103
|
+
# settings.
|
100
104
|
#
|
101
105
|
def initialize env: nil, connection: nil, metadata_cache: nil,
|
102
|
-
|
106
|
+
open_timeout: 0.1, request_timeout: 1.0,
|
107
|
+
retry_count: 2, retry_interval: 0.1,
|
103
108
|
retry_backoff_factor: 1.5, retry_max_interval: 0.5
|
104
109
|
@disable_metadata_cache = metadata_cache == false
|
105
110
|
@metadata_cache = metadata_cache || {}
|
@@ -108,9 +113,18 @@ module Google
|
|
108
113
|
@retry_interval = retry_interval
|
109
114
|
@retry_backoff_factor = retry_backoff_factor
|
110
115
|
@retry_max_interval = retry_max_interval
|
111
|
-
|
112
|
-
|
113
|
-
|
116
|
+
request_opts = { timeout: request_timeout, open_timeout: open_timeout }
|
117
|
+
@connection = connection || ::Faraday.new(url: METADATA_HOST, request: request_opts)
|
118
|
+
end
|
119
|
+
|
120
|
+
##
|
121
|
+
# Determine whether the application is running on a Knative-based
|
122
|
+
# hosting platform, such as Cloud Run or Cloud Functions.
|
123
|
+
#
|
124
|
+
# @return [Boolean]
|
125
|
+
#
|
126
|
+
def knative?
|
127
|
+
env["K_SERVICE"] ? true : false
|
114
128
|
end
|
115
129
|
|
116
130
|
##
|
@@ -122,6 +136,26 @@ module Google
|
|
122
136
|
env["GAE_INSTANCE"] ? true : false
|
123
137
|
end
|
124
138
|
|
139
|
+
##
|
140
|
+
# Determine whether the application is running on Google App Engine
|
141
|
+
# Flexible Environment.
|
142
|
+
#
|
143
|
+
# @return [Boolean]
|
144
|
+
#
|
145
|
+
def app_engine_flexible?
|
146
|
+
app_engine? && env["GAE_ENV"] != "standard"
|
147
|
+
end
|
148
|
+
|
149
|
+
##
|
150
|
+
# Determine whether the application is running on Google App Engine
|
151
|
+
# Standard Environment.
|
152
|
+
#
|
153
|
+
# @return [Boolean]
|
154
|
+
#
|
155
|
+
def app_engine_standard?
|
156
|
+
app_engine? && env["GAE_ENV"] == "standard"
|
157
|
+
end
|
158
|
+
|
125
159
|
##
|
126
160
|
# Determine whether the application is running on Google Kubernetes
|
127
161
|
# Engine (GKE).
|
@@ -166,7 +200,7 @@ module Google
|
|
166
200
|
# @return [Boolean]
|
167
201
|
#
|
168
202
|
def raw_compute_engine?
|
169
|
-
!app_engine? && !cloud_shell? && metadata? && !kubernetes_engine?
|
203
|
+
!knative? && !app_engine? && !cloud_shell? && metadata? && !kubernetes_engine?
|
170
204
|
end
|
171
205
|
|
172
206
|
##
|
@@ -176,8 +210,7 @@ module Google
|
|
176
210
|
# @return [String,nil]
|
177
211
|
#
|
178
212
|
def project_id
|
179
|
-
env["GCLOUD_PROJECT"] || env["DEVSHELL_PROJECT_ID"] ||
|
180
|
-
lookup_metadata("project", "project-id")
|
213
|
+
env["GCLOUD_PROJECT"] || env["DEVSHELL_PROJECT_ID"] || lookup_metadata("project", "project-id")
|
181
214
|
end
|
182
215
|
|
183
216
|
##
|
@@ -279,6 +312,27 @@ module Google
|
|
279
312
|
lookup_metadata "instance", "attributes/#{key}"
|
280
313
|
end
|
281
314
|
|
315
|
+
##
|
316
|
+
# Returns the name of the running Knative service, or `nil` if the
|
317
|
+
# current code is not running on Knative.
|
318
|
+
#
|
319
|
+
# @return [String,nil]
|
320
|
+
#
|
321
|
+
def knative_service_id
|
322
|
+
env["K_SERVICE"]
|
323
|
+
end
|
324
|
+
alias knative_service_name knative_service_id
|
325
|
+
|
326
|
+
##
|
327
|
+
# Returns the revision of the running Knative service, or `nil` if the
|
328
|
+
# current code is not running on Knative.
|
329
|
+
#
|
330
|
+
# @return [String,nil]
|
331
|
+
#
|
332
|
+
def knative_service_revision
|
333
|
+
env["K_REVISION"]
|
334
|
+
end
|
335
|
+
|
282
336
|
##
|
283
337
|
# Returns the name of the running App Engine service, or `nil` if the
|
284
338
|
# current code is not running in App Engine.
|
@@ -288,6 +342,7 @@ module Google
|
|
288
342
|
def app_engine_service_id
|
289
343
|
env["GAE_SERVICE"]
|
290
344
|
end
|
345
|
+
alias app_engine_service_name app_engine_service_id
|
291
346
|
|
292
347
|
##
|
293
348
|
# Returns the version of the running App Engine service, or `nil` if the
|
@@ -335,8 +390,7 @@ module Google
|
|
335
390
|
# below is set in some older versions of GKE, and the file below is
|
336
391
|
# present in Kubernetes as of version 1.9, but it is possible that
|
337
392
|
# alternatives will need to be found in the future.
|
338
|
-
env["GKE_NAMESPACE_ID"] ||
|
339
|
-
::IO.read("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
|
393
|
+
env["GKE_NAMESPACE_ID"] || ::IO.read("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
|
340
394
|
rescue SystemCallError
|
341
395
|
nil
|
342
396
|
end
|
@@ -351,7 +405,9 @@ module Google
|
|
351
405
|
path = METADATA_ROOT_PATH
|
352
406
|
if @disable_metadata_cache || !metadata_cache.include?(path)
|
353
407
|
metadata_cache[path] = retry_or_fail_with false do
|
354
|
-
resp = connection.get path
|
408
|
+
resp = connection.get path do |req|
|
409
|
+
req.headers = { "Metadata-Flavor" => "Google" }
|
410
|
+
end
|
355
411
|
resp.status == 200 && resp.headers["Metadata-Flavor"] == "Google"
|
356
412
|
end
|
357
413
|
end
|
@@ -408,9 +464,7 @@ module Google
|
|
408
464
|
if retries_remaining >= 0
|
409
465
|
sleep retry_interval
|
410
466
|
retry_interval *= @retry_backoff_factor
|
411
|
-
if retry_interval > @retry_max_interval
|
412
|
-
retry_interval = @retry_max_interval
|
413
|
-
end
|
467
|
+
retry_interval = @retry_max_interval if retry_interval > @retry_max_interval
|
414
468
|
retry
|
415
469
|
end
|
416
470
|
error_result
|
metadata
CHANGED
@@ -1,87 +1,93 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-cloud-env
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.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: 2020-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.17.3
|
20
|
+
- - "<"
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0
|
22
|
+
version: '2.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
29
|
+
version: 0.17.3
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.0'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
34
|
+
name: autotest-suffix
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - "~>"
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
39
|
+
version: '1.1'
|
34
40
|
type: :development
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
44
|
- - "~>"
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
46
|
+
version: '1.1'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
48
|
+
name: google-style
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
51
|
- - "~>"
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
53
|
+
version: 1.24.0
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
58
|
- - "~>"
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
60
|
+
version: 1.24.0
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: minitest
|
62
|
+
name: minitest
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
65
|
- - "~>"
|
60
66
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
67
|
+
version: '5.10'
|
62
68
|
type: :development
|
63
69
|
prerelease: false
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
65
71
|
requirements:
|
66
72
|
- - "~>"
|
67
73
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
74
|
+
version: '5.10'
|
69
75
|
- !ruby/object:Gem::Dependency
|
70
|
-
name: minitest-
|
76
|
+
name: minitest-autotest
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
72
78
|
requirements:
|
73
79
|
- - "~>"
|
74
80
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
81
|
+
version: '1.0'
|
76
82
|
type: :development
|
77
83
|
prerelease: false
|
78
84
|
version_requirements: !ruby/object:Gem::Requirement
|
79
85
|
requirements:
|
80
86
|
- - "~>"
|
81
87
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
88
|
+
version: '1.0'
|
83
89
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
90
|
+
name: minitest-focus
|
85
91
|
requirement: !ruby/object:Gem::Requirement
|
86
92
|
requirements:
|
87
93
|
- - "~>"
|
@@ -95,33 +101,33 @@ dependencies:
|
|
95
101
|
- !ruby/object:Gem::Version
|
96
102
|
version: '1.1'
|
97
103
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
104
|
+
name: minitest-rg
|
99
105
|
requirement: !ruby/object:Gem::Requirement
|
100
106
|
requirements:
|
101
107
|
- - "~>"
|
102
108
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
109
|
+
version: '5.2'
|
104
110
|
type: :development
|
105
111
|
prerelease: false
|
106
112
|
version_requirements: !ruby/object:Gem::Requirement
|
107
113
|
requirements:
|
108
114
|
- - "~>"
|
109
115
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
116
|
+
version: '5.2'
|
111
117
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
118
|
+
name: redcarpet
|
113
119
|
requirement: !ruby/object:Gem::Requirement
|
114
120
|
requirements:
|
115
121
|
- - "~>"
|
116
122
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
123
|
+
version: '3.0'
|
118
124
|
type: :development
|
119
125
|
prerelease: false
|
120
126
|
version_requirements: !ruby/object:Gem::Requirement
|
121
127
|
requirements:
|
122
128
|
- - "~>"
|
123
129
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
130
|
+
version: '3.0'
|
125
131
|
- !ruby/object:Gem::Dependency
|
126
132
|
name: simplecov
|
127
133
|
requirement: !ruby/object:Gem::Requirement
|
@@ -195,14 +201,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
195
201
|
requirements:
|
196
202
|
- - ">="
|
197
203
|
- !ruby/object:Gem::Version
|
198
|
-
version: 2.
|
204
|
+
version: '2.4'
|
199
205
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
200
206
|
requirements:
|
201
207
|
- - ">="
|
202
208
|
- !ruby/object:Gem::Version
|
203
209
|
version: '0'
|
204
210
|
requirements: []
|
205
|
-
rubygems_version: 3.0.
|
211
|
+
rubygems_version: 3.0.6
|
206
212
|
signing_key:
|
207
213
|
specification_version: 4
|
208
214
|
summary: Google Cloud Platform hosting environment information.
|