Merge pull request #109 from hxiong388/fix-build

Fix rubocop violations. Fix Travis build.
This commit is contained in:
Daniel Azuma 2017-07-13 08:29:23 -07:00 committed by GitHub
commit 91ecc02d86
6 changed files with 48 additions and 63 deletions

View File

@ -1,6 +1,26 @@
inherit_from: .rubocop_todo.yml AllCops:
Exclude:
- "spec/**/*"
Metrics/AbcSize:
Max: 25
Metrics/BlockLength: Metrics/BlockLength:
Exclude: Exclude:
- 'spec/**/*.rb' - "googleauth.gemspec"
- 'googleauth.gemspec' Metrics/CyclomaticComplexity:
Max: 8
Metrics/MethodLength:
Max: 20
Metrics/ClassLength:
Enabled: false
Style/IndentHeredoc:
Enabled: false
Style/FormatString:
Enabled: false
Style/GuardClause:
Enabled: false
Style/PercentLiteralDelimiters: # Contradicting rule
Enabled: false
Style/SymbolArray: # Undefined syntax in Ruby 1.9.3
Enabled: false

View File

@ -1,41 +0,0 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-02-25 23:23:21 +0900 using RuboCop version 0.46.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 5
# Configuration parameters: Include.
# Include: **/Gemfile, **/gems.rb
Bundler/OrderedGems:
Exclude:
- 'Gemfile'
# Offense count: 3
Metrics/AbcSize:
Max: 27
# Offense count: 1
Metrics/CyclomaticComplexity:
Max: 7
# Offense count: 18
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 22
# Offense count: 3
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: format, sprintf, percent
Style/FormatString:
Exclude:
- 'lib/googleauth/user_authorizer.rb'
- 'lib/googleauth/web_user_authorizer.rb'
# Offense count: 1
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'lib/googleauth/web_user_authorizer.rb'

View File

@ -1,7 +1,8 @@
sudo: false sudo: false
language: ruby language: ruby
rvm: rvm:
- 2.3.3 - 2.4
- 2.3
- 2.2 - 2.2
- 2.0.0 - 2.0.0
- 2.1 - 2.1
@ -33,6 +34,6 @@ before_install:
notifications: notifications:
email: email:
recipients: recipients:
- temiola@google.com - ruby-cloud-eng@google.com
on_success: change on_success: change
on_failure: change on_failure: change

12
Gemfile
View File

@ -5,17 +5,17 @@ gemspec
group :development do group :development do
gem 'bundler', '~> 1.9' gem 'bundler', '~> 1.9'
gem 'simplecov', '~> 0.9'
gem 'coveralls', '~> 0.7' gem 'coveralls', '~> 0.7'
gem 'fakefs', '~> 0.6' gem 'fakefs', '~> 0.6'
gem 'rake', '~> 10.0'
gem 'rubocop', '~> 0.30'
gem 'rspec', '~> 3.0'
gem 'redis', '~> 3.2'
gem 'fakeredis', '~> 0.5' gem 'fakeredis', '~> 0.5'
gem 'webmock', '~> 1.21'
gem 'rack-test', '~> 0.6' gem 'rack-test', '~> 0.6'
gem 'rake', '~> 10.0'
gem 'redis', '~> 3.2'
gem 'rspec', '~> 3.0'
gem 'rubocop', '~> 0.30'
gem 'simplecov', '~> 0.9'
gem 'sinatra' gem 'sinatra'
gem 'webmock', '~> 1.21'
end end
platforms :jruby do platforms :jruby do

View File

@ -1,5 +1,6 @@
# -*- ruby -*- # -*- ruby -*-
# encoding: utf-8 # encoding: utf-8
$LOAD_PATH.push File.expand_path('../lib', __FILE__) $LOAD_PATH.push File.expand_path('../lib', __FILE__)
require 'googleauth/version' require 'googleauth/version'

View File

@ -32,7 +32,6 @@ require 'multi_json'
require 'googleauth/signet' require 'googleauth/signet'
require 'googleauth/user_refresh' require 'googleauth/user_refresh'
# rubocop:disable ClassLength
module Google module Google
module Auth module Auth
# Handles an interactive 3-Legged-OAuth2 (3LO) user consent authorization. # Handles an interactive 3-Legged-OAuth2 (3LO) user consent authorization.
@ -125,11 +124,7 @@ module Google
# @return [Google::Auth::UserRefreshCredentials] # @return [Google::Auth::UserRefreshCredentials]
# Stored credentials, nil if none present # Stored credentials, nil if none present
def get_credentials(user_id, scope = nil) def get_credentials(user_id, scope = nil)
raise NIL_USER_ID_ERROR if user_id.nil? saved_token = stored_token(user_id)
raise NIL_TOKEN_STORE_ERROR if @token_store.nil?
scope ||= @scope
saved_token = @token_store.load(user_id)
return nil if saved_token.nil? return nil if saved_token.nil?
data = MultiJson.load(saved_token) data = MultiJson.load(saved_token)
@ -146,6 +141,7 @@ module Google
refresh_token: data['refresh_token'], refresh_token: data['refresh_token'],
expires_at: data.fetch('expiration_time_millis', 0) / 1000 expires_at: data.fetch('expiration_time_millis', 0) / 1000
) )
scope ||= @scope
if credentials.includes_scope?(scope) if credentials.includes_scope?(scope)
return monitor_credentials(user_id, credentials) return monitor_credentials(user_id, credentials)
end end
@ -245,6 +241,18 @@ module Google
private private
# @private Fetch stored token with given user_id
#
# @param [String] user_id
# Unique ID of the user for loading/storing credentials.
# @return [String] The saved token from @token_store
def stored_token(user_id)
raise NIL_USER_ID_ERROR if user_id.nil?
raise NIL_TOKEN_STORE_ERROR if @token_store.nil?
@token_store.load(user_id)
end
# Begin watching a credential for refreshes so the access token can be # Begin watching a credential for refreshes so the access token can be
# saved. # saved.
# #
@ -268,14 +276,10 @@ module Google
def redirect_uri_for(base_url) def redirect_uri_for(base_url)
return @callback_uri unless URI(@callback_uri).scheme.nil? return @callback_uri unless URI(@callback_uri).scheme.nil?
if base_url.nil? || URI(base_url).scheme.nil? if base_url.nil? || URI(base_url).scheme.nil?
raise sprintf( raise sprintf(ISSING_ABSOLUTE_URL_ERROR, @callback_uri)
MISSING_ABSOLUTE_URL_ERROR,
@callback_uri
)
end end
URI.join(base_url, @callback_uri).to_s URI.join(base_url, @callback_uri).to_s
end end
end end
end end
end end
# rubocop:enable ClassLength