googleauth 0.13.1 → 0.14.0

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: ed0edf45ba52552808e13667185f0277233c77e8d0e377d7b1924dc0fb9c1d1a
4
- data.tar.gz: db8eaf43c99d362dae906b0c1c488652201940a8b4f70ca589846a7ecf869dfa
3
+ metadata.gz: 8846e57d325ff993c15ca691e299b9c2c4b7472b1b0a9e905b36cdb99216e061
4
+ data.tar.gz: 2fcee29e36a6fd57420b9cd0106cf3ab73bf447e94e2f6bdce61a973d256cd5e
5
5
  SHA512:
6
- metadata.gz: 62c088c7997002f68a820b928ae2f1898f6efdd32d5850413d9894995fee3dce0689908427547a971884ab1673f2218e3526b20bdbea3d280995bee3fcdef202
7
- data.tar.gz: d45554051877a0cb282db279cf45df0462dcda88562cd54cf640c554d95eb43adb254821366e0b12529dc5768cbe9bf3fbbf1cb612a72b6a400b619b3ed6fbfc
6
+ metadata.gz: dd54bce055240fc1db34ccfe2850ab49f23b17f55f5336dfeccf380c2f93b8b9e29100a1c53f360564e8387805a9c4bf74d09eb2ca58b5bda666cdab3b061f45
7
+ data.tar.gz: 27dae4439e8163194604e912918709d2cd623c61856f70f7c350b08dfac010fdff50ad703934b88631c2759dcf7e5aab5b315a884cb160790c153115ee88bdfe
@@ -0,0 +1,7 @@
1
+ # Code owners file.
2
+ # This file controls who is tagged for review for any given pull request.
3
+ #
4
+ # For syntax help see:
5
+ # https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners#codeowners-syntax
6
+
7
+ * @googleapis/yoshi-ruby
@@ -1,5 +1,10 @@
1
1
  # Release History
2
2
 
3
+ ### 0.14.0 / 2020-10-09
4
+
5
+ * Honor GCE_METADATA_HOST environment variable
6
+ * Fix errors in some environments when requesting an access token for multiple scopes
7
+
3
8
  ### 0.13.1 / 2020-07-30
4
9
 
5
10
  * Support scopes when using GCE Metadata Server authentication ([@ball-hayden][])
File without changes
@@ -51,22 +51,43 @@ module Google
51
51
  class GCECredentials < Signet::OAuth2::Client
52
52
  # The IP Address is used in the URIs to speed up failures on non-GCE
53
53
  # systems.
54
+ DEFAULT_METADATA_HOST = "169.254.169.254".freeze
55
+
56
+ # @private Unused and deprecated
54
57
  COMPUTE_AUTH_TOKEN_URI =
55
58
  "http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token".freeze
59
+ # @private Unused and deprecated
56
60
  COMPUTE_ID_TOKEN_URI =
57
61
  "http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/identity".freeze
62
+ # @private Unused and deprecated
58
63
  COMPUTE_CHECK_URI = "http://169.254.169.254".freeze
59
64
 
60
65
  class << self
61
66
  extend Memoist
62
67
 
68
+ def metadata_host
69
+ ENV.fetch "GCE_METADATA_HOST", DEFAULT_METADATA_HOST
70
+ end
71
+
72
+ def compute_check_uri
73
+ "http://#{metadata_host}".freeze
74
+ end
75
+
76
+ def compute_auth_token_uri
77
+ "#{compute_check_uri}/computeMetadata/v1/instance/service-accounts/default/token".freeze
78
+ end
79
+
80
+ def compute_id_token_uri
81
+ "#{compute_check_uri}/computeMetadata/v1/instance/service-accounts/default/identity".freeze
82
+ end
83
+
63
84
  # Detect if this appear to be a GCE instance, by checking if metadata
64
85
  # is available.
65
86
  def on_gce? options = {}
66
87
  # TODO: This should use google-cloud-env instead.
67
88
  c = options[:connection] || Faraday.default_connection
68
89
  headers = { "Metadata-Flavor" => "Google" }
69
- resp = c.get COMPUTE_CHECK_URI, nil, headers do |req|
90
+ resp = c.get compute_check_uri, nil, headers do |req|
70
91
  req.options.timeout = 1.0
71
92
  req.options.open_timeout = 0.1
72
93
  end
@@ -84,9 +105,9 @@ module Google
84
105
  def fetch_access_token options = {}
85
106
  c = options[:connection] || Faraday.default_connection
86
107
  retry_with_error do
87
- uri = target_audience ? COMPUTE_ID_TOKEN_URI : COMPUTE_AUTH_TOKEN_URI
108
+ uri = target_audience ? GCECredentials.compute_id_token_uri : GCECredentials.compute_auth_token_uri
88
109
  query = target_audience ? { "audience" => target_audience, "format" => "full" } : {}
89
- query[:scopes] = Array(scope).join " " if scope
110
+ query[:scopes] = Array(scope).join "," if scope
90
111
  headers = { "Metadata-Flavor" => "Google" }
91
112
  resp = c.get uri, query, headers
92
113
  case resp.status
@@ -31,6 +31,6 @@ module Google
31
31
  # Module Auth provides classes that provide Google-specific authorization
32
32
  # used to access Google APIs.
33
33
  module Auth
34
- VERSION = "0.13.1".freeze
34
+ VERSION = "0.14.0".freeze
35
35
  end
36
36
  end
@@ -53,7 +53,7 @@ describe Google::Auth::GCECredentials do
53
53
  "expires_in" => 3600)
54
54
 
55
55
  uri = MD_ACCESS_URI
56
- uri += "?scopes=#{opts[:scope]}" if opts[:scope]
56
+ uri += "?scopes=#{Array(opts[:scope]).join ','}" if opts[:scope]
57
57
 
58
58
  stub_request(:get, uri)
59
59
  .with(headers: { "Metadata-Flavor" => "Google" })
@@ -74,9 +74,9 @@ describe Google::Auth::GCECredentials do
74
74
  context "metadata is unavailable" do
75
75
  describe "#fetch_access_token" do
76
76
  it "should pass scopes when requesting an access token" do
77
- scope = "https://www.googleapis.com/auth/drive"
78
- stub = make_auth_stubs access_token: "1/abcdef1234567890", scope: scope
79
- @client = GCECredentials.new(scope: [scope])
77
+ scopes = ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/bigtable.data"]
78
+ stub = make_auth_stubs access_token: "1/abcdef1234567890", scope: scopes
79
+ @client = GCECredentials.new(scope: scopes)
80
80
  @client.fetch_access_token!
81
81
  expect(stub).to have_been_requested
82
82
  end
@@ -142,5 +142,19 @@ describe Google::Auth::GCECredentials do
142
142
  expect(GCECredentials.on_gce?({}, true)).to eq(false)
143
143
  expect(stub).to have_been_requested
144
144
  end
145
+
146
+ it "should honor GCE_METADATA_HOST environment variable" do
147
+ ENV["GCE_METADATA_HOST"] = "mymetadata.example.com"
148
+ begin
149
+ stub = stub_request(:get, "http://mymetadata.example.com")
150
+ .with(headers: { "Metadata-Flavor" => "Google" })
151
+ .to_return(status: 200,
152
+ headers: { "Metadata-Flavor" => "Google" })
153
+ expect(GCECredentials.on_gce?({}, true)).to eq(true)
154
+ expect(stub).to have_been_requested
155
+ ensure
156
+ ENV.delete "GCE_METADATA_HOST"
157
+ end
158
+ end
145
159
  end
146
160
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: googleauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.1
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Emiola
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-30 00:00:00.000000000 Z
11
+ date: 2020-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -135,6 +135,7 @@ executables: []
135
135
  extensions: []
136
136
  extra_rdoc_files: []
137
137
  files:
138
+ - ".github/CODEOWNERS"
138
139
  - ".github/CONTRIBUTING.md"
139
140
  - ".github/ISSUE_TEMPLATE/bug_report.md"
140
141
  - ".github/ISSUE_TEMPLATE/feature_request.md"
@@ -160,8 +161,8 @@ files:
160
161
  - ".rubocop.yml"
161
162
  - CHANGELOG.md
162
163
  - CODE_OF_CONDUCT.md
163
- - COPYING
164
164
  - Gemfile
165
+ - LICENSE
165
166
  - README.md
166
167
  - Rakefile
167
168
  - googleauth.gemspec
@@ -231,7 +232,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
232
  - !ruby/object:Gem::Version
232
233
  version: '0'
233
234
  requirements: []
234
- rubygems_version: 3.1.3
235
+ rubygems_version: 3.1.4
235
236
  signing_key:
236
237
  specification_version: 4
237
238
  summary: Google Auth Library for Ruby