diff --git a/googleauth.gemspec b/googleauth.gemspec index bb52743..9a3a0fc 100755 --- a/googleauth.gemspec +++ b/googleauth.gemspec @@ -30,5 +30,6 @@ Gem::Specification.new do |s| s.add_dependency 'jwt', '~> 1.4' s.add_dependency 'memoist', '~> 0.12' s.add_dependency 'multi_json', '~> 1.11' + s.add_dependency 'os', '~> 0.9' s.add_dependency 'signet', '~> 0.7' end diff --git a/lib/googleauth/credentials_loader.rb b/lib/googleauth/credentials_loader.rb index 0e5dfdf..f8b317e 100644 --- a/lib/googleauth/credentials_loader.rb +++ b/lib/googleauth/credentials_loader.rb @@ -28,6 +28,7 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. require 'memoist' +require 'os' require 'rbconfig' module Google @@ -55,12 +56,6 @@ module Google SYSTEM_DEFAULT_ERROR = 'Unable to read the system default credential file' - # determines if the current OS is windows - def windows? - RbConfig::CONFIG['host_os'] =~ /Windows|mswin/ - end - memoize :windows? - # make_creds proxies the construction of a credentials instance # # By default, it calls #new on the current class, but this behaviour can @@ -91,10 +86,10 @@ module Google # # @param scope [string|array|nil] the scope(s) to access def from_well_known_path(scope = nil) - home_var = windows? ? 'APPDATA' : 'HOME' + home_var = OS.windows? ? 'APPDATA' : 'HOME' base = WELL_KNOWN_PATH root = ENV[home_var].nil? ? '' : ENV[home_var] - base = File.join('.config', base) unless windows? + base = File.join('.config', base) unless OS.windows? path = File.join(root, base) return nil unless File.exist?(path) File.open(path) do |f| @@ -108,7 +103,7 @@ module Google # # @param scope [string|array|nil] the scope(s) to access def from_system_default_path(scope = nil) - if windows? + if OS.windows? return nil unless ENV['ProgramData'] prefix = File.join(ENV['ProgramData'], 'Google/Auth') else