googleauth 0.17.1 → 1.8.1

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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +127 -62
  3. data/README.md +50 -15
  4. data/lib/googleauth/application_default.rb +15 -30
  5. data/lib/googleauth/base_client.rb +80 -0
  6. data/lib/googleauth/client_id.rb +35 -33
  7. data/lib/googleauth/compute_engine.rb +33 -40
  8. data/lib/googleauth/credentials.rb +12 -28
  9. data/lib/googleauth/credentials_loader.rb +21 -50
  10. data/lib/googleauth/default_credentials.rb +15 -27
  11. data/lib/googleauth/external_account/aws_credentials.rb +378 -0
  12. data/lib/googleauth/external_account/base_credentials.rb +158 -0
  13. data/lib/googleauth/external_account/external_account_utils.rb +103 -0
  14. data/lib/googleauth/external_account/identity_pool_credentials.rb +118 -0
  15. data/lib/googleauth/external_account/pluggable_credentials.rb +156 -0
  16. data/lib/googleauth/external_account.rb +93 -0
  17. data/lib/googleauth/helpers/connection.rb +35 -0
  18. data/lib/googleauth/iam.rb +10 -25
  19. data/lib/googleauth/id_tokens/errors.rb +9 -23
  20. data/lib/googleauth/id_tokens/key_sources.rb +19 -33
  21. data/lib/googleauth/id_tokens/verifier.rb +9 -23
  22. data/lib/googleauth/id_tokens.rb +11 -25
  23. data/lib/googleauth/json_key_reader.rb +10 -25
  24. data/lib/googleauth/oauth2/sts_client.rb +109 -0
  25. data/lib/googleauth/scope_util.rb +45 -27
  26. data/lib/googleauth/service_account.rb +11 -28
  27. data/lib/googleauth/signet.rb +16 -58
  28. data/lib/googleauth/stores/file_token_store.rb +10 -25
  29. data/lib/googleauth/stores/redis_token_store.rb +10 -25
  30. data/lib/googleauth/token_store.rb +10 -25
  31. data/lib/googleauth/user_authorizer.rb +22 -30
  32. data/lib/googleauth/user_refresh.rb +15 -27
  33. data/lib/googleauth/version.rb +11 -26
  34. data/lib/googleauth/web_user_authorizer.rb +14 -29
  35. data/lib/googleauth.rb +10 -25
  36. metadata +26 -25
@@ -1,82 +1,83 @@
1
- # Copyright 2014, Google Inc.
2
- # All rights reserved.
1
+ # Copyright 2014 Google, Inc.
3
2
  #
4
- # Redistribution and use in source and binary forms, with or without
5
- # modification, are permitted provided that the following conditions are
6
- # met:
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
7
6
  #
8
- # * Redistributions of source code must retain the above copyright
9
- # notice, this list of conditions and the following disclaimer.
10
- # * Redistributions in binary form must reproduce the above
11
- # copyright notice, this list of conditions and the following disclaimer
12
- # in the documentation and/or other materials provided with the
13
- # distribution.
14
- # * Neither the name of Google Inc. nor the names of its
15
- # contributors may be used to endorse or promote products derived from
16
- # this software without specific prior written permission.
7
+ # http://www.apache.org/licenses/LICENSE-2.0
17
8
  #
18
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
- # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
- # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
- # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
- # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
- # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
- # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
- # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
- # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
- # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
29
14
 
30
15
  require "multi_json"
31
16
  require "googleauth/credentials_loader"
32
17
 
33
18
  module Google
34
19
  module Auth
35
- # Representation of an application's identity for user authorization
36
- # flows.
20
+ ##
21
+ # Representation of an application's identity for user authorization flows.
22
+ #
37
23
  class ClientId
24
+ # Toplevel JSON key for the an installed app configuration.
25
+ # Must include client_id and client_secret subkeys if present.
38
26
  INSTALLED_APP = "installed".freeze
27
+ # Toplevel JSON key for the a webapp configuration.
28
+ # Must include client_id and client_secret subkeys if present.
39
29
  WEB_APP = "web".freeze
30
+ # JSON key for the client ID within an app configuration.
40
31
  CLIENT_ID = "client_id".freeze
32
+ # JSON key for the client secret within an app configuration.
41
33
  CLIENT_SECRET = "client_secret".freeze
34
+ # An error message raised when none of the expected toplevel properties
35
+ # can be found.
42
36
  MISSING_TOP_LEVEL_ELEMENT_ERROR =
43
37
  "Expected top level property 'installed' or 'web' to be present.".freeze
44
38
 
39
+ ##
45
40
  # Text identifier of the client ID
46
41
  # @return [String]
42
+ #
47
43
  attr_reader :id
48
44
 
45
+ ##
49
46
  # Secret associated with the client ID
50
47
  # @return [String]
48
+ #
51
49
  attr_reader :secret
52
50
 
53
51
  class << self
54
52
  attr_accessor :default
55
53
  end
56
54
 
57
- # Initialize the Client ID
55
+ ##
56
+ # Initialize the Client ID. Both id and secret must be non-nil.
58
57
  #
59
58
  # @param [String] id
60
59
  # Text identifier of the client ID
61
60
  # @param [String] secret
62
61
  # Secret associated with the client ID
63
- # @note Direction instantion is discouraged to avoid embedding IDs
64
- # & secrets in source. See {#from_file} to load from
62
+ # @note Direct instantiation is discouraged to avoid embedding IDs
63
+ # and secrets in source. See {#from_file} to load from
65
64
  # `client_secrets.json` files.
65
+ #
66
66
  def initialize id, secret
67
- CredentialsLoader.warn_if_cloud_sdk_credentials id
68
67
  raise "Client id can not be nil" if id.nil?
69
68
  raise "Client secret can not be nil" if secret.nil?
70
69
  @id = id
71
70
  @secret = secret
72
71
  end
73
72
 
73
+ ##
74
74
  # Constructs a Client ID from a JSON file downloaded from the
75
75
  # Google Developers Console.
76
76
  #
77
77
  # @param [String, File] file
78
78
  # Path of file to read from
79
79
  # @return [Google::Auth::ClientID]
80
+ #
80
81
  def self.from_file file
81
82
  raise "File can not be nil." if file.nil?
82
83
  File.open file.to_s do |f|
@@ -86,13 +87,14 @@ module Google
86
87
  end
87
88
  end
88
89
 
90
+ ##
89
91
  # Constructs a Client ID from a previously loaded JSON file. The hash
90
- # structure should
91
- # match the expected JSON format.
92
+ # structure should match the expected JSON format.
92
93
  #
93
94
  # @param [hash] config
94
95
  # Parsed contents of the JSON file
95
96
  # @return [Google::Auth::ClientID]
97
+ #
96
98
  def self.from_hash config
97
99
  raise "Hash can not be nil." if config.nil?
98
100
  raw_detail = config[INSTALLED_APP] || config[WEB_APP]
@@ -1,35 +1,19 @@
1
- # Copyright 2015, Google Inc.
2
- # All rights reserved.
1
+ # Copyright 2015 Google, Inc.
3
2
  #
4
- # Redistribution and use in source and binary forms, with or without
5
- # modification, are permitted provided that the following conditions are
6
- # met:
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
7
6
  #
8
- # * Redistributions of source code must retain the above copyright
9
- # notice, this list of conditions and the following disclaimer.
10
- # * Redistributions in binary form must reproduce the above
11
- # copyright notice, this list of conditions and the following disclaimer
12
- # in the documentation and/or other materials provided with the
13
- # distribution.
14
- # * Neither the name of Google Inc. nor the names of its
15
- # contributors may be used to endorse or promote products derived from
16
- # this software without specific prior written permission.
7
+ # http://www.apache.org/licenses/LICENSE-2.0
17
8
  #
18
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
- # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
- # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
- # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
- # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
- # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
- # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
- # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
- # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
- # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
29
14
 
30
15
  require "faraday"
31
16
  require "googleauth/signet"
32
- require "memoist"
33
17
 
34
18
  module Google
35
19
  # Module Auth provides classes that provide Google-specific authorization
@@ -62,9 +46,9 @@ module Google
62
46
  # @private Unused and deprecated
63
47
  COMPUTE_CHECK_URI = "http://169.254.169.254".freeze
64
48
 
65
- class << self
66
- extend Memoist
49
+ @on_gce_cache = {}
67
50
 
51
+ class << self
68
52
  def metadata_host
69
53
  ENV.fetch "GCE_METADATA_HOST", DEFAULT_METADATA_HOST
70
54
  end
@@ -83,21 +67,30 @@ module Google
83
67
 
84
68
  # Detect if this appear to be a GCE instance, by checking if metadata
85
69
  # is available.
86
- def on_gce? options = {}
87
- # TODO: This should use google-cloud-env instead.
88
- c = options[:connection] || Faraday.default_connection
89
- headers = { "Metadata-Flavor" => "Google" }
90
- resp = c.get compute_check_uri, nil, headers do |req|
91
- req.options.timeout = 1.0
92
- req.options.open_timeout = 0.1
70
+ def on_gce? options = {}, reload = false # rubocop:disable Style/OptionalBooleanParameter
71
+ # We can follow OptionalBooleanParameter here because it's a public interface, we can't change it.
72
+ @on_gce_cache.delete options if reload
73
+ @on_gce_cache.fetch options do
74
+ @on_gce_cache[options] = begin
75
+ # TODO: This should use google-cloud-env instead.
76
+ c = options[:connection] || Faraday.default_connection
77
+ headers = { "Metadata-Flavor" => "Google" }
78
+ resp = c.get compute_check_uri, nil, headers do |req|
79
+ req.options.timeout = 1.0
80
+ req.options.open_timeout = 0.1
81
+ end
82
+ return false unless resp.status == 200
83
+ resp.headers["Metadata-Flavor"] == "Google"
84
+ rescue Faraday::TimeoutError, Faraday::ConnectionFailed
85
+ false
86
+ end
93
87
  end
94
- return false unless resp.status == 200
95
- resp.headers["Metadata-Flavor"] == "Google"
96
- rescue Faraday::TimeoutError, Faraday::ConnectionFailed
97
- false
98
88
  end
99
89
 
100
- memoize :on_gce?
90
+ def reset_cache
91
+ @on_gce_cache.clear
92
+ end
93
+ alias unmemoize_all reset_cache
101
94
  end
102
95
 
103
96
  # Overrides the super class method to change how access tokens are
@@ -1,31 +1,16 @@
1
- # Copyright 2017, Google Inc.
2
- # All rights reserved.
1
+ # Copyright 2017 Google, Inc.
3
2
  #
4
- # Redistribution and use in source and binary forms, with or without
5
- # modification, are permitted provided that the following conditions are
6
- # met:
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
7
6
  #
8
- # * Redistributions of source code must retain the above copyright
9
- # notice, this list of conditions and the following disclaimer.
10
- # * Redistributions in binary form must reproduce the above
11
- # copyright notice, this list of conditions and the following disclaimer
12
- # in the documentation and/or other materials provided with the
13
- # distribution.
14
- # * Neither the name of Google Inc. nor the names of its
15
- # contributors may be used to endorse or promote products derived from
16
- # this software without specific prior written permission.
7
+ # http://www.apache.org/licenses/LICENSE-2.0
17
8
  #
18
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
- # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
- # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
- # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
- # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
- # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
- # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
- # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
- # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
- # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
29
14
 
30
15
  require "forwardable"
31
16
  require "json"
@@ -370,16 +355,15 @@ module Google
370
355
  @project_id = options["project_id"] || options["project"]
371
356
  @quota_project_id = options["quota_project_id"]
372
357
  case keyfile
373
- when Signet::OAuth2::Client
358
+ when Google::Auth::BaseClient
374
359
  update_from_signet keyfile
375
360
  when Hash
376
361
  update_from_hash keyfile, options
377
362
  else
378
363
  update_from_filepath keyfile, options
379
364
  end
380
- CredentialsLoader.warn_if_cloud_sdk_credentials @client.client_id
381
365
  @project_id ||= CredentialsLoader.load_gcloud_project_id
382
- @client.fetch_access_token!
366
+ @client.fetch_access_token! if @client.needs_access_token?
383
367
  @env_vars = nil
384
368
  @paths = nil
385
369
  @scope = nil
@@ -1,33 +1,17 @@
1
- # Copyright 2015, Google Inc.
2
- # All rights reserved.
1
+ # Copyright 2015 Google, Inc.
3
2
  #
4
- # Redistribution and use in source and binary forms, with or without
5
- # modification, are permitted provided that the following conditions are
6
- # met:
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
7
6
  #
8
- # * Redistributions of source code must retain the above copyright
9
- # notice, this list of conditions and the following disclaimer.
10
- # * Redistributions in binary form must reproduce the above
11
- # copyright notice, this list of conditions and the following disclaimer
12
- # in the documentation and/or other materials provided with the
13
- # distribution.
14
- # * Neither the name of Google Inc. nor the names of its
15
- # contributors may be used to endorse or promote products derived from
16
- # this software without specific prior written permission.
7
+ # http://www.apache.org/licenses/LICENSE-2.0
17
8
  #
18
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
- # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
- # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
- # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
- # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
- # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
- # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
- # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
- # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
- # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
29
14
 
30
- require "memoist"
31
15
  require "os"
32
16
  require "rbconfig"
33
17
 
@@ -38,7 +22,6 @@ module Google
38
22
  # CredentialsLoader contains the behaviour used to locate and find default
39
23
  # credentials files on the file system.
40
24
  module CredentialsLoader
41
- extend Memoist
42
25
  ENV_VAR = "GOOGLE_APPLICATION_CREDENTIALS".freeze
43
26
  PRIVATE_KEY_VAR = "GOOGLE_PRIVATE_KEY".freeze
44
27
  CLIENT_EMAIL_VAR = "GOOGLE_CLIENT_EMAIL".freeze
@@ -47,30 +30,24 @@ module Google
47
30
  REFRESH_TOKEN_VAR = "GOOGLE_REFRESH_TOKEN".freeze
48
31
  ACCOUNT_TYPE_VAR = "GOOGLE_ACCOUNT_TYPE".freeze
49
32
  PROJECT_ID_VAR = "GOOGLE_PROJECT_ID".freeze
33
+ AWS_REGION_VAR = "AWS_REGION".freeze
34
+ AWS_DEFAULT_REGION_VAR = "AWS_DEFAULT_REGION".freeze
35
+ AWS_ACCESS_KEY_ID_VAR = "AWS_ACCESS_KEY_ID".freeze
36
+ AWS_SECRET_ACCESS_KEY_VAR = "AWS_SECRET_ACCESS_KEY".freeze
37
+ AWS_SESSION_TOKEN_VAR = "AWS_SESSION_TOKEN".freeze
50
38
  GCLOUD_POSIX_COMMAND = "gcloud".freeze
51
39
  GCLOUD_WINDOWS_COMMAND = "gcloud.cmd".freeze
52
- GCLOUD_CONFIG_COMMAND =
53
- "config config-helper --format json --verbosity none".freeze
40
+ GCLOUD_CONFIG_COMMAND = "config config-helper --format json --verbosity none".freeze
54
41
 
55
42
  CREDENTIALS_FILE_NAME = "application_default_credentials.json".freeze
56
- NOT_FOUND_ERROR =
57
- "Unable to read the credential file specified by #{ENV_VAR}".freeze
43
+ NOT_FOUND_ERROR = "Unable to read the credential file specified by #{ENV_VAR}".freeze
58
44
  WELL_KNOWN_PATH = "gcloud/#{CREDENTIALS_FILE_NAME}".freeze
59
45
  WELL_KNOWN_ERROR = "Unable to read the default credential file".freeze
60
46
 
61
- SYSTEM_DEFAULT_ERROR =
62
- "Unable to read the system default credential file".freeze
47
+ SYSTEM_DEFAULT_ERROR = "Unable to read the system default credential file".freeze
63
48
 
64
- CLOUD_SDK_CLIENT_ID = "764086051850-6qr4p6gpi6hn506pt8ejuq83di341hur.app"\
65
- "s.googleusercontent.com".freeze
66
-
67
- CLOUD_SDK_CREDENTIALS_WARNING = "Your application has authenticated using end user "\
68
- "credentials from Google Cloud SDK. We recommend that most server applications use "\
69
- "service accounts instead. If your application continues to use end user credentials "\
70
- 'from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For '\
71
- "more information about service accounts, see "\
72
- "https://cloud.google.com/docs/authentication/. To suppress this message, set the "\
73
- "GOOGLE_AUTH_SUPPRESS_CREDENTIALS_WARNINGS environment variable.".freeze
49
+ CLOUD_SDK_CLIENT_ID = "764086051850-6qr4p6gpi6hn506pt8ejuq83di341hur.app" \
50
+ "s.googleusercontent.com".freeze
74
51
 
75
52
  # make_creds proxies the construction of a credentials instance
76
53
  #
@@ -165,17 +142,11 @@ module Google
165
142
 
166
143
  module_function
167
144
 
168
- # Issues warning if cloud sdk client id is used
169
- def warn_if_cloud_sdk_credentials client_id
170
- return if ENV["GOOGLE_AUTH_SUPPRESS_CREDENTIALS_WARNINGS"]
171
- warn CLOUD_SDK_CREDENTIALS_WARNING if client_id == CLOUD_SDK_CLIENT_ID
172
- end
173
-
174
145
  # Finds project_id from gcloud CLI configuration
175
146
  def load_gcloud_project_id
176
147
  gcloud = GCLOUD_WINDOWS_COMMAND if OS.windows?
177
148
  gcloud = GCLOUD_POSIX_COMMAND unless OS.windows?
178
- gcloud_json = IO.popen("#{gcloud} #{GCLOUD_CONFIG_COMMAND}", &:read)
149
+ gcloud_json = IO.popen("#{gcloud} #{GCLOUD_CONFIG_COMMAND}", in: :close, err: :close, &:read)
179
150
  config = MultiJson.load gcloud_json
180
151
  config["configuration"]["properties"]["core"]["project"]
181
152
  rescue StandardError
@@ -1,31 +1,16 @@
1
- # Copyright 2015, Google Inc.
2
- # All rights reserved.
1
+ # Copyright 2015 Google, Inc.
3
2
  #
4
- # Redistribution and use in source and binary forms, with or without
5
- # modification, are permitted provided that the following conditions are
6
- # met:
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
7
6
  #
8
- # * Redistributions of source code must retain the above copyright
9
- # notice, this list of conditions and the following disclaimer.
10
- # * Redistributions in binary form must reproduce the above
11
- # copyright notice, this list of conditions and the following disclaimer
12
- # in the documentation and/or other materials provided with the
13
- # distribution.
14
- # * Neither the name of Google Inc. nor the names of its
15
- # contributors may be used to endorse or promote products derived from
16
- # this software without specific prior written permission.
7
+ # http://www.apache.org/licenses/LICENSE-2.0
17
8
  #
18
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
- # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
- # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
- # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
- # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
- # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
- # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
- # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
- # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
- # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
29
14
 
30
15
  require "multi_json"
31
16
  require "stringio"
@@ -33,6 +18,7 @@ require "stringio"
33
18
  require "googleauth/credentials_loader"
34
19
  require "googleauth/service_account"
35
20
  require "googleauth/user_refresh"
21
+ require "googleauth/external_account"
36
22
 
37
23
  module Google
38
24
  # Module Auth provides classes that provide Google-specific authorization
@@ -49,11 +35,9 @@ module Google
49
35
  json_key_io = options[:json_key_io]
50
36
  if json_key_io
51
37
  json_key, clz = determine_creds_class json_key_io
52
- warn_if_cloud_sdk_credentials json_key["client_id"]
53
38
  io = StringIO.new MultiJson.dump(json_key)
54
39
  clz.make_creds options.merge(json_key_io: io)
55
40
  else
56
- warn_if_cloud_sdk_credentials ENV[CredentialsLoader::CLIENT_ID_VAR]
57
41
  clz = read_creds
58
42
  clz.make_creds options
59
43
  end
@@ -68,6 +52,8 @@ module Google
68
52
  ServiceAccountCredentials
69
53
  when "authorized_user"
70
54
  UserRefreshCredentials
55
+ when "external_account"
56
+ ExternalAccount::Credentials
71
57
  else
72
58
  raise "credentials type '#{type}' is not supported"
73
59
  end
@@ -84,6 +70,8 @@ module Google
84
70
  [json_key, ServiceAccountCredentials]
85
71
  when "authorized_user"
86
72
  [json_key, UserRefreshCredentials]
73
+ when "external_account"
74
+ [json_key, ExternalAccount::Credentials]
87
75
  else
88
76
  raise "credentials type '#{type}' is not supported"
89
77
  end