lib/conjur/authn.rb in conjur-cli-4.22.0 vs lib/conjur/authn.rb in conjur-cli-4.23.0

- old
+ new

@@ -64,11 +64,11 @@ if path = Conjur::Config[:netrc_path] args.unshift(path) else path = Netrc.default_path end - fail "netrc (#{path}) shouldn't be world-readable" if File.world_readable?(path) + fail_if_world_readable path Netrc.read(*args) end def get_credentials(options = {}) @credentials ||= (env_credentials || read_credentials || fetch_credentials(options)) @@ -123,8 +123,21 @@ require 'conjur/api' require 'conjur/base' cls = Conjur::API end cls.new_from_key(*get_credentials(options)) + end + + protected + + def fail_if_world_readable path + if !windows? && File.world_readable?(path) + fail "netrc (#{path}) shouldn't be world-readable" + end + end + + # see http://stackoverflow.com/questions/4871309/what-is-the-correct-way-to-detect-if-ruby-is-running-on-windows + def windows? + RbConfig::CONFIG["host_os"] =~ /mswin|mingw|cygwin/ end end end