google-cloud-env 1.2.0 → 1.3.3

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
2
  SHA256:
3
- metadata.gz: 3ef4d05db69a9e9b94528892fdbc6290b465ac045b1ab140c43682d8a0c96606
4
- data.tar.gz: 76d191dc0d86415f21383217be630c81cb2ddd76cc091c65c17a72eb6e51aaaf
3
+ metadata.gz: 6cc1587d2fad1a7c47c154488e76f4441d4dbb2a4c9a56826f0a18d2027d3e5d
4
+ data.tar.gz: '0998d2e1d9568e680b87f6da44e892c3c2d800ee6e6f17e562f6855c9f5813b8'
5
5
  SHA512:
6
- metadata.gz: 331c0562ed88b3e9cb0252e01c8b6126d20f714b329a16c1afdb8d26e2902682c4b577f8f1d3721300ab27a4c223ab11720a1afc5b92862594798fcc25895686
7
- data.tar.gz: 5fdf10aa396e7d58396bc238f4888fe26f06d9dcd3254475f7bc9bf6aeb7fcf7568af0c7f46764e3dcda25c164ed9e712d8ea514ed71ca4674099f0005d9f69e
6
+ metadata.gz: f1d417ccdc7fc15e61cdc13a1493f406b0f2437738b5afd51eb00cc8b48e331a1e1145d9debb2246945a3dab38b808f478ad9499da313a901ab7358bc9c404f5
7
+ data.tar.gz: 40a8fb198fc780aa6057e4e56d420b12021f7c401a52765a591f7b761019f1f52ddcea9411659def21c9f704748f8cf69a8dadbded7d22e86cbddbf74d182cb2
@@ -1,5 +1,41 @@
1
1
  # Release History
2
2
 
3
+ ### 1.3.3 / 2020-07-10
4
+
5
+ #### Bug Fixes
6
+
7
+ * Project ID logic honors GOOGLE_CLOUD_PROJECT
8
+
9
+ ### 1.3.2 / 2020-05-28
10
+
11
+ #### Documentation
12
+
13
+ * Fix a few broken links
14
+
15
+ ### 1.3.1 / 2020-03-02
16
+
17
+ #### Bug Fixes
18
+
19
+ * support faraday 1.x
20
+
21
+ ### 1.3.0 / 2019-10-23
22
+
23
+ Now requires Ruby 2.4 or later.
24
+
25
+ #### Features
26
+
27
+ * Recognize App Engine Standard and Knative
28
+
29
+ ### 1.2.1 / 2019-08-23
30
+
31
+ #### Bug Fixes
32
+
33
+ * Send Metadata-Flavor header when testing the metadata server root
34
+
35
+ #### Documentation
36
+
37
+ * Update documentation
38
+
3
39
  ### 1.2.0 / 2019-06-19
4
40
 
5
41
  * Support separate timeout for connecting to the metadata server vs the entire request
@@ -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.3+. You may choose to
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.github.io/google-cloud-ruby/docs/google-cloud-env/latest)
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.3+.
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.3 and
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.github.io/google-cloud-ruby/docs/google-cloud-env/latest/file.CONTRIBUTING)
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.github.io/google-cloud-ruby/docs/google-cloud-env/latest/file.CODE_OF_CONDUCT)
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.github.io/google-cloud-ruby/docs/google-cloud-env/latest/file.LICENSE).
42
+ [LICENSE](https://googleapis.dev/ruby/google-cloud-env/latest/file.LICENSE.html).
43
43
 
44
44
  ## Support
45
45
 
@@ -114,8 +114,17 @@ module Google
114
114
  @retry_backoff_factor = retry_backoff_factor
115
115
  @retry_max_interval = retry_max_interval
116
116
  request_opts = { timeout: request_timeout, open_timeout: open_timeout }
117
- @connection = connection ||
118
- ::Faraday.new(url: METADATA_HOST, request: request_opts)
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
119
128
  end
120
129
 
121
130
  ##
@@ -127,6 +136,26 @@ module Google
127
136
  env["GAE_INSTANCE"] ? true : false
128
137
  end
129
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
+
130
159
  ##
131
160
  # Determine whether the application is running on Google Kubernetes
132
161
  # Engine (GKE).
@@ -171,7 +200,7 @@ module Google
171
200
  # @return [Boolean]
172
201
  #
173
202
  def raw_compute_engine?
174
- !app_engine? && !cloud_shell? && metadata? && !kubernetes_engine?
203
+ !knative? && !app_engine? && !cloud_shell? && metadata? && !kubernetes_engine?
175
204
  end
176
205
 
177
206
  ##
@@ -181,7 +210,9 @@ module Google
181
210
  # @return [String,nil]
182
211
  #
183
212
  def project_id
184
- env["GCLOUD_PROJECT"] || env["DEVSHELL_PROJECT_ID"] ||
213
+ env["GOOGLE_CLOUD_PROJECT"] ||
214
+ env["GCLOUD_PROJECT"] ||
215
+ env["DEVSHELL_PROJECT_ID"] ||
185
216
  lookup_metadata("project", "project-id")
186
217
  end
187
218
 
@@ -284,6 +315,27 @@ module Google
284
315
  lookup_metadata "instance", "attributes/#{key}"
285
316
  end
286
317
 
318
+ ##
319
+ # Returns the name of the running Knative service, or `nil` if the
320
+ # current code is not running on Knative.
321
+ #
322
+ # @return [String,nil]
323
+ #
324
+ def knative_service_id
325
+ env["K_SERVICE"]
326
+ end
327
+ alias knative_service_name knative_service_id
328
+
329
+ ##
330
+ # Returns the revision of the running Knative service, or `nil` if the
331
+ # current code is not running on Knative.
332
+ #
333
+ # @return [String,nil]
334
+ #
335
+ def knative_service_revision
336
+ env["K_REVISION"]
337
+ end
338
+
287
339
  ##
288
340
  # Returns the name of the running App Engine service, or `nil` if the
289
341
  # current code is not running in App Engine.
@@ -293,6 +345,7 @@ module Google
293
345
  def app_engine_service_id
294
346
  env["GAE_SERVICE"]
295
347
  end
348
+ alias app_engine_service_name app_engine_service_id
296
349
 
297
350
  ##
298
351
  # Returns the version of the running App Engine service, or `nil` if the
@@ -340,8 +393,7 @@ module Google
340
393
  # below is set in some older versions of GKE, and the file below is
341
394
  # present in Kubernetes as of version 1.9, but it is possible that
342
395
  # alternatives will need to be found in the future.
343
- env["GKE_NAMESPACE_ID"] ||
344
- ::IO.read("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
396
+ env["GKE_NAMESPACE_ID"] || ::IO.read("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
345
397
  rescue SystemCallError
346
398
  nil
347
399
  end
@@ -356,7 +408,9 @@ module Google
356
408
  path = METADATA_ROOT_PATH
357
409
  if @disable_metadata_cache || !metadata_cache.include?(path)
358
410
  metadata_cache[path] = retry_or_fail_with false do
359
- resp = connection.get path
411
+ resp = connection.get path do |req|
412
+ req.headers = { "Metadata-Flavor" => "Google" }
413
+ end
360
414
  resp.status == 200 && resp.headers["Metadata-Flavor"] == "Google"
361
415
  end
362
416
  end
@@ -413,9 +467,7 @@ module Google
413
467
  if retries_remaining >= 0
414
468
  sleep retry_interval
415
469
  retry_interval *= @retry_backoff_factor
416
- if retry_interval > @retry_max_interval
417
- retry_interval = @retry_max_interval
418
- end
470
+ retry_interval = @retry_max_interval if retry_interval > @retry_max_interval
419
471
  retry
420
472
  end
421
473
  error_result
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  class Env
19
- VERSION = "1.2.0".freeze
19
+ VERSION = "1.3.3".freeze
20
20
  end
21
21
  end
22
22
  end
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.2.0
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Azuma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-20 00:00:00.000000000 Z
11
+ date: 2020-07-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.11'
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: '0.11'
29
+ version: 0.17.3
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
27
33
  - !ruby/object:Gem::Dependency
28
- name: minitest
34
+ name: autotest-suffix
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - "~>"
32
38
  - !ruby/object:Gem::Version
33
- version: '5.10'
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: '5.10'
46
+ version: '1.1'
41
47
  - !ruby/object:Gem::Dependency
42
- name: minitest-autotest
48
+ name: google-style
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
51
  - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: '1.0'
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: '1.0'
60
+ version: 1.24.0
55
61
  - !ruby/object:Gem::Dependency
56
- name: minitest-focus
62
+ name: minitest
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
65
  - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: '1.1'
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: '1.1'
74
+ version: '5.10'
69
75
  - !ruby/object:Gem::Dependency
70
- name: minitest-rg
76
+ name: minitest-autotest
71
77
  requirement: !ruby/object:Gem::Requirement
72
78
  requirements:
73
79
  - - "~>"
74
80
  - !ruby/object:Gem::Version
75
- version: '5.2'
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: '5.2'
88
+ version: '1.0'
83
89
  - !ruby/object:Gem::Dependency
84
- name: autotest-suffix
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: redcarpet
104
+ name: minitest-rg
99
105
  requirement: !ruby/object:Gem::Requirement
100
106
  requirements:
101
107
  - - "~>"
102
108
  - !ruby/object:Gem::Version
103
- version: '3.0'
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: '3.0'
116
+ version: '5.2'
111
117
  - !ruby/object:Gem::Dependency
112
- name: rubocop
118
+ name: redcarpet
113
119
  requirement: !ruby/object:Gem::Requirement
114
120
  requirements:
115
121
  - - "~>"
116
122
  - !ruby/object:Gem::Version
117
- version: 0.64.0
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: 0.64.0
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.0.0
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.3
211
+ rubygems_version: 3.1.3
206
212
  signing_key:
207
213
  specification_version: 4
208
214
  summary: Google Cloud Platform hosting environment information.