Skip to content

Commit fb3fc46

Browse files
committed
Merge pull request googleapis#201 from tbetbetbe/ruby-auth-version-bump-and-use-latest-googleauth
Version bump, and updates the googleauth dependency
2 parents 847b483 + d21e28a commit fb3fc46

File tree

7 files changed

+41
-17
lines changed

7 files changed

+41
-17
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.8.3
2+
* Adds support for authorization via Application Default Credentials.
3+
# Adds support for tracking coverage on coveralls.io
4+
15
# 0.8.2
26
* Fixes for file storage and missing cacerts file
37

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ Credentials can be managed at the connection level, as shown, or supplied on a p
104104

105105
For server-to-server interactions, like those between a web application and Google Cloud Storage, Prediction, or BigQuery APIs, use service accounts.
106106

107+
As of version 0.8.3, service accounts can be configured using
108+
[Application Default Credentials][1], which rely on the credentials being
109+
available in a well-known location. If the credentials are not present
110+
and it's being used on a Compute Engine VM, it will use the VM's default credentials.
111+
112+
```ruby
113+
client.authorization = :google_app_default # in a later version, this will become the default
114+
client.authorization.fetch_access_token!
115+
client.execute(...)
116+
```
117+
118+
This is simpler API to use than in previous versions, although that is still available:
119+
107120
```ruby
108121
key = Google::APIClient::KeyUtils.load_from_pkcs12('client.p12', 'notasecret')
109122
client.authorization = Signet::OAuth2::Client.new(
@@ -201,3 +214,5 @@ See the full list of [samples on Github](https://github.com/google/google-api-ru
201214
## Support
202215

203216
Please [report bugs at the project on Github](https://github.com/google/google-api-ruby-client/issues). Don't hesitate to [ask questions](http://stackoverflow.com/questions/tagged/google-api-ruby-client) about the client or APIs on [StackOverflow](http://stackoverflow.com).
217+
218+
[1]: https://developers.google.com/accounts/docs/application-default-credentials

Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
# -*- ruby -*-
12
lib_dir = File.expand_path('../lib', __FILE__)
23
$LOAD_PATH.unshift(lib_dir)
34
$LOAD_PATH.uniq!
45

6+
require 'bundler/gem_tasks'
57
require 'rubygems'
68
require 'rake'
79

google-api-client.gemspec

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
2626
s.add_runtime_dependency 'addressable', '~> 2.3'
2727
s.add_runtime_dependency 'signet', '~> 0.6'
2828
s.add_runtime_dependency 'faraday', '~> 0.9'
29-
s.add_runtime_dependency 'googleauth', '~> 0.1'
29+
s.add_runtime_dependency 'googleauth', '~> 0.3'
3030
s.add_runtime_dependency 'multi_json', '~> 1.10'
3131
s.add_runtime_dependency 'autoparse', "~> 0.3"
3232
s.add_runtime_dependency 'extlib', '~> 0.9'
@@ -38,5 +38,6 @@ Gem::Specification.new do |s|
3838
s.add_development_dependency 'yard', '~> 0.8'
3939
s.add_development_dependency 'rspec', '~> 3.1'
4040
s.add_development_dependency 'kramdown', '~> 1.5'
41-
s.add_development_dependency 'simplecov', '~> 0.9'
41+
s.add_development_dependency 'simplecov', '~> 0.9.2'
42+
s.add_development_dependency 'coveralls', '~> 0.7.11'
4243
end

lib/google/api_client.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module Google
4141
# This class manages APIs communication.
4242
class APIClient
4343
include Google::APIClient::Logging
44-
44+
4545
##
4646
# Creates a new Google API client.
4747
#
@@ -58,7 +58,7 @@ class APIClient
5858
# </ul>
5959
# @option options [Boolean] :auto_refresh_token (true)
6060
# The setting that controls whether or not the api client attempts to
61-
# refresh authorization when a 401 is hit in #execute. If the token does
61+
# refresh authorization when a 401 is hit in #execute. If the token does
6262
# not support it, this option is ignored.
6363
# @option options [String] :application_name
6464
# The name of the application using the client.
@@ -86,7 +86,7 @@ class APIClient
8686
# Pass through of options to set on the Faraday connection
8787
def initialize(options={})
8888
logger.debug { "#{self.class} - Initializing client with options #{options}" }
89-
89+
9090
# Normalize key to String to allow indifferent access.
9191
options = options.inject({}) do |accu, (key, value)|
9292
accu[key.to_sym] = value
@@ -182,7 +182,7 @@ def authorization=(new_authorization)
182182
)
183183
when :google_app_default
184184
require 'googleauth'
185-
new_authorization = Google::Auth.get_application_default(nil)
185+
new_authorization = Google::Auth.get_application_default
186186

187187
when :oauth_2
188188
require 'signet/oauth_2/client'
@@ -214,7 +214,7 @@ def authorization=(new_authorization)
214214

215215
##
216216
# The setting that controls whether or not the api client attempts to
217-
# refresh authorization when a 401 is hit in #execute.
217+
# refresh authorization when a 401 is hit in #execute.
218218
#
219219
# @return [Boolean]
220220
attr_accessor :auto_refresh_token
@@ -261,7 +261,7 @@ def authorization=(new_authorization)
261261

262262
##
263263
# Number of times to retry on recoverable errors
264-
#
264+
#
265265
# @return [FixNum]
266266
# Number of retries
267267
attr_accessor :retries
@@ -471,7 +471,7 @@ def preferred_version(api)
471471
# Verifies an ID token against a server certificate. Used to ensure that
472472
# an ID token supplied by an untrusted client-side mechanism is valid.
473473
# Raises an error if the token is invalid or missing.
474-
#
474+
#
475475
# @deprecated Use the google-id-token gem for verifying JWTs
476476
def verify_id_token!
477477
require 'jwt'
@@ -580,7 +580,7 @@ def generate_request(options={})
580580
# - (TrueClass, FalseClass) :authenticated (default: true) -
581581
# `true` if the request must be signed or somehow
582582
# authenticated, `false` otherwise.
583-
# - (TrueClass, FalseClass) :gzip (default: true) -
583+
# - (TrueClass, FalseClass) :gzip (default: true) -
584584
# `true` if gzip enabled, `false` otherwise.
585585
# - (FixNum) :retries -
586586
# # of times to retry on recoverable errors
@@ -620,7 +620,7 @@ def execute!(*params)
620620
options.update(params.shift) if params.size > 0
621621
request = self.generate_request(options)
622622
end
623-
623+
624624
request.headers['User-Agent'] ||= '' + self.user_agent unless self.user_agent.nil?
625625
request.headers['Accept-Encoding'] ||= 'gzip' unless options[:gzip] == false
626626
request.headers['Content-Type'] ||= ''
@@ -629,11 +629,11 @@ def execute!(*params)
629629

630630
connection = options[:connection] || self.connection
631631
request.authorization = options[:authorization] || self.authorization unless options[:authenticated] == false
632-
632+
633633
tries = 1 + (options[:retries] || self.retries)
634634
attempt = 0
635635

636-
Retriable.retriable :tries => tries,
636+
Retriable.retriable :tries => tries,
637637
:on => [TransmissionError],
638638
:on_retry => client_error_handler,
639639
:interval => lambda {|attempts| (2 ** attempts) + rand} do
@@ -642,7 +642,7 @@ def execute!(*params)
642642
# This 2nd level retriable only catches auth errors, and supports 1 retry, which allows
643643
# auth to be re-attempted without having to retry all sorts of other failures like
644644
# NotFound, etc
645-
Retriable.retriable :tries => ((expired_auth_retry || tries > 1) && attempt == 1) ? 2 : 1,
645+
Retriable.retriable :tries => ((expired_auth_retry || tries > 1) && attempt == 1) ? 2 : 1,
646646
:on => [AuthorizationError],
647647
:on_retry => authorization_error_handler(request.authorization) do
648648
result = request.send(connection, true)
@@ -709,7 +709,7 @@ def resolve_uri(template, mapping={})
709709
end
710710
return Addressable::Template.new(@base_uri + template).expand(mapping)
711711
end
712-
712+
713713

714714
##
715715
# Returns on proc for special processing of retries for authorization errors
@@ -719,7 +719,7 @@ def resolve_uri(template, mapping={})
719719
# OAuth 2 credentials
720720
# @return [Proc]
721721
def authorization_error_handler(authorization)
722-
can_refresh = authorization.respond_to?(:refresh_token) && auto_refresh_token
722+
can_refresh = authorization.respond_to?(:refresh_token) && auto_refresh_token
723723
Proc.new do |exception, tries|
724724
next unless exception.kind_of?(AuthorizationError)
725725
if can_refresh

lib/google/api_client/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class APIClient
1818
module VERSION
1919
MAJOR = 0
2020
MINOR = 8
21-
TINY = 2
21+
TINY = 3
2222
PATCH = nil
2323
STRING = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
2424
end

spec/spec_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
begin
88
require 'simplecov'
9+
require 'coveralls'
910

11+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
1012
SimpleCov.start
1113
rescue LoadError
1214
# SimpleCov missing, so just run specs with no coverage.

0 commit comments

Comments
 (0)