google-cloud-env 1.2.1 → 1.4.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/CHANGELOG.md +32 -0
- data/CONTRIBUTING.md +1 -14
- data/README.md +2 -2
- data/lib/google/cloud/env.rb +65 -10
- 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: 98da1b266783f22f91d9f220cb311a35d3955d7f638e67aaa77d60e3ace6e58e
|
4
|
+
data.tar.gz: 39386abb55069149c081132808a85fc14a2b23285e3371b7632bbb1e7337815f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40ed7fab707ea30a4fa993d3c0560ef05ee9362c666191a5fe3f47a0edbac5e770fec6b5941be1c33d92b068e31fb1a094a3d34009b17b186ff60aaaf3707641
|
7
|
+
data.tar.gz: 7a4165816c410b2d8f0bf044b4d8c65f9bb4960dc8a976a97621ac7bcb424795b58863a2a8668b81a87b4081c82adf74e51e8c5705ef7f5c0094ced2de411028
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,37 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 1.4.0 / 2020-10-12
|
4
|
+
|
5
|
+
#### Features
|
6
|
+
|
7
|
+
* Honor GCE_METADATA_HOST environment variable
|
8
|
+
|
9
|
+
### 1.3.3 / 2020-07-10
|
10
|
+
|
11
|
+
#### Bug Fixes
|
12
|
+
|
13
|
+
* Project ID logic honors GOOGLE_CLOUD_PROJECT
|
14
|
+
|
15
|
+
### 1.3.2 / 2020-05-28
|
16
|
+
|
17
|
+
#### Documentation
|
18
|
+
|
19
|
+
* Fix a few broken links
|
20
|
+
|
21
|
+
### 1.3.1 / 2020-03-02
|
22
|
+
|
23
|
+
#### Bug Fixes
|
24
|
+
|
25
|
+
* support faraday 1.x
|
26
|
+
|
27
|
+
### 1.3.0 / 2019-10-23
|
28
|
+
|
29
|
+
Now requires Ruby 2.4 or later.
|
30
|
+
|
31
|
+
#### Features
|
32
|
+
|
33
|
+
* Recognize App Engine Standard and Knative
|
34
|
+
|
3
35
|
### 1.2.1 / 2019-08-23
|
4
36
|
|
5
37
|
#### Bug Fixes
|
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
@@ -7,11 +7,11 @@ apps running on Google Cloud Platform.
|
|
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.
|
data/lib/google/cloud/env.rb
CHANGED
@@ -82,6 +82,9 @@ module Google
|
|
82
82
|
# well as mocking for testing.
|
83
83
|
#
|
84
84
|
# @param [Hash] env Mock environment variables.
|
85
|
+
# @param [String] host The hostname or IP address of the metadata server.
|
86
|
+
# Optional. If not specified, uses the `GCE_METADATA_HOST`,
|
87
|
+
# environment variable or falls back to `169.254.167.254`.
|
85
88
|
# @param [Hash,false] metadata_cache The metadata cache. You may pass
|
86
89
|
# a prepopuated cache, an empty cache (the default) or `false` to
|
87
90
|
# disable the cache completely.
|
@@ -102,7 +105,7 @@ module Google
|
|
102
105
|
# If specified, overrides the `request_timeout` and `open_timeout`
|
103
106
|
# settings.
|
104
107
|
#
|
105
|
-
def initialize env: nil, connection: nil, metadata_cache: nil,
|
108
|
+
def initialize env: nil, host: nil, connection: nil, metadata_cache: nil,
|
106
109
|
open_timeout: 0.1, request_timeout: 1.0,
|
107
110
|
retry_count: 2, retry_interval: 0.1,
|
108
111
|
retry_backoff_factor: 1.5, retry_max_interval: 0.5
|
@@ -114,8 +117,19 @@ module Google
|
|
114
117
|
@retry_backoff_factor = retry_backoff_factor
|
115
118
|
@retry_max_interval = retry_max_interval
|
116
119
|
request_opts = { timeout: request_timeout, open_timeout: open_timeout }
|
117
|
-
|
118
|
-
|
120
|
+
host ||= @env["GCE_METADATA_HOST"] || METADATA_HOST
|
121
|
+
host = "http://#{host}" unless host.start_with? "http://"
|
122
|
+
@connection = connection || ::Faraday.new(url: host, request: request_opts)
|
123
|
+
end
|
124
|
+
|
125
|
+
##
|
126
|
+
# Determine whether the application is running on a Knative-based
|
127
|
+
# hosting platform, such as Cloud Run or Cloud Functions.
|
128
|
+
#
|
129
|
+
# @return [Boolean]
|
130
|
+
#
|
131
|
+
def knative?
|
132
|
+
env["K_SERVICE"] ? true : false
|
119
133
|
end
|
120
134
|
|
121
135
|
##
|
@@ -127,6 +141,26 @@ module Google
|
|
127
141
|
env["GAE_INSTANCE"] ? true : false
|
128
142
|
end
|
129
143
|
|
144
|
+
##
|
145
|
+
# Determine whether the application is running on Google App Engine
|
146
|
+
# Flexible Environment.
|
147
|
+
#
|
148
|
+
# @return [Boolean]
|
149
|
+
#
|
150
|
+
def app_engine_flexible?
|
151
|
+
app_engine? && env["GAE_ENV"] != "standard"
|
152
|
+
end
|
153
|
+
|
154
|
+
##
|
155
|
+
# Determine whether the application is running on Google App Engine
|
156
|
+
# Standard Environment.
|
157
|
+
#
|
158
|
+
# @return [Boolean]
|
159
|
+
#
|
160
|
+
def app_engine_standard?
|
161
|
+
app_engine? && env["GAE_ENV"] == "standard"
|
162
|
+
end
|
163
|
+
|
130
164
|
##
|
131
165
|
# Determine whether the application is running on Google Kubernetes
|
132
166
|
# Engine (GKE).
|
@@ -171,7 +205,7 @@ module Google
|
|
171
205
|
# @return [Boolean]
|
172
206
|
#
|
173
207
|
def raw_compute_engine?
|
174
|
-
!app_engine? && !cloud_shell? && metadata? && !kubernetes_engine?
|
208
|
+
!knative? && !app_engine? && !cloud_shell? && metadata? && !kubernetes_engine?
|
175
209
|
end
|
176
210
|
|
177
211
|
##
|
@@ -181,7 +215,9 @@ module Google
|
|
181
215
|
# @return [String,nil]
|
182
216
|
#
|
183
217
|
def project_id
|
184
|
-
env["
|
218
|
+
env["GOOGLE_CLOUD_PROJECT"] ||
|
219
|
+
env["GCLOUD_PROJECT"] ||
|
220
|
+
env["DEVSHELL_PROJECT_ID"] ||
|
185
221
|
lookup_metadata("project", "project-id")
|
186
222
|
end
|
187
223
|
|
@@ -284,6 +320,27 @@ module Google
|
|
284
320
|
lookup_metadata "instance", "attributes/#{key}"
|
285
321
|
end
|
286
322
|
|
323
|
+
##
|
324
|
+
# Returns the name of the running Knative service, or `nil` if the
|
325
|
+
# current code is not running on Knative.
|
326
|
+
#
|
327
|
+
# @return [String,nil]
|
328
|
+
#
|
329
|
+
def knative_service_id
|
330
|
+
env["K_SERVICE"]
|
331
|
+
end
|
332
|
+
alias knative_service_name knative_service_id
|
333
|
+
|
334
|
+
##
|
335
|
+
# Returns the revision of the running Knative service, or `nil` if the
|
336
|
+
# current code is not running on Knative.
|
337
|
+
#
|
338
|
+
# @return [String,nil]
|
339
|
+
#
|
340
|
+
def knative_service_revision
|
341
|
+
env["K_REVISION"]
|
342
|
+
end
|
343
|
+
|
287
344
|
##
|
288
345
|
# Returns the name of the running App Engine service, or `nil` if the
|
289
346
|
# current code is not running in App Engine.
|
@@ -293,6 +350,7 @@ module Google
|
|
293
350
|
def app_engine_service_id
|
294
351
|
env["GAE_SERVICE"]
|
295
352
|
end
|
353
|
+
alias app_engine_service_name app_engine_service_id
|
296
354
|
|
297
355
|
##
|
298
356
|
# Returns the version of the running App Engine service, or `nil` if the
|
@@ -340,8 +398,7 @@ module Google
|
|
340
398
|
# below is set in some older versions of GKE, and the file below is
|
341
399
|
# present in Kubernetes as of version 1.9, but it is possible that
|
342
400
|
# alternatives will need to be found in the future.
|
343
|
-
env["GKE_NAMESPACE_ID"] ||
|
344
|
-
::IO.read("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
|
401
|
+
env["GKE_NAMESPACE_ID"] || ::IO.read("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
|
345
402
|
rescue SystemCallError
|
346
403
|
nil
|
347
404
|
end
|
@@ -415,9 +472,7 @@ module Google
|
|
415
472
|
if retries_remaining >= 0
|
416
473
|
sleep retry_interval
|
417
474
|
retry_interval *= @retry_backoff_factor
|
418
|
-
if retry_interval > @retry_max_interval
|
419
|
-
retry_interval = @retry_max_interval
|
420
|
-
end
|
475
|
+
retry_interval = @retry_max_interval if retry_interval > @retry_max_interval
|
421
476
|
retry
|
422
477
|
end
|
423
478
|
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.4.0
|
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-10-13 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.
|
211
|
+
rubygems_version: 3.1.4
|
206
212
|
signing_key:
|
207
213
|
specification_version: 4
|
208
214
|
summary: Google Cloud Platform hosting environment information.
|