Skip to content

Commit

Permalink
Merge pull request #1782 from xeron/fix-github-enterprise
Browse files Browse the repository at this point in the history
Use Strings to access options in try_download. Fixes #1764.
  • Loading branch information
lamont-granquist committed Aug 6, 2018
2 parents 527ae74 + 3c0ef7b commit 29864cc
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/berkshelf/downloader.rb
Expand Up @@ -109,9 +109,11 @@ def try_download(source, name, version)
raise ConfigurationError.new "Missing github endpoint configuration for #{cookbook_uri.scheme}://#{cookbook_uri.host}" if options.nil?
end

github_client = Octokit::Client.new(access_token: options[:access_token],
api_endpoint: options[:api_endpoint], web_endpoint: options[:web_endpoint],
connection_options: { ssl: { verify: options[:ssl_verify].nil? ? true : options[:ssl_verify] } })
github_client = Octokit::Client.new(
access_token: options["access_token"],
api_endpoint: options["api_endpoint"], web_endpoint: options["web_endpoint"],
connection_options: { ssl: { verify: options["ssl_verify"].nil? ? true : options["ssl_verify"] } }
)

begin
url = URI(github_client.archive_link(cookbook_uri.path.gsub(/^\//, ""), ref: "v#{version}"))
Expand All @@ -122,7 +124,7 @@ def try_download(source, name, version)
# We use Net::HTTP.new and then get here, because Net::HTTP.get does not support proxy settings.
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = url.scheme == "https"
http.verify_mode = (options[:ssl_verify].nil? || options[:ssl_verify]) ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
http.verify_mode = (options["ssl_verify"].nil? || options["ssl_verify"]) ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
resp = http.get(url.request_uri)
return nil unless resp.is_a?(Net::HTTPSuccess)
open(archive_path, "wb") { |file| file.write(resp.body) }
Expand Down Expand Up @@ -169,13 +171,13 @@ def try_download(source, name, version)
raise ConfigurationError.new "Missing github endpoint configuration for #{cookbook_uri.scheme}://#{cookbook_uri.host}" if options.nil?
end

connection ||= Faraday.new(url: options[:web_endpoint]) do |faraday|
connection ||= Faraday.new(url: options["web_endpoint"]) do |faraday|
faraday.headers[:accept] = "application/x-tar"
faraday.response :logger, @logger unless @logger.nil?
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
end

resp = connection.get(cookbook_uri.request_uri + "&private_token=" + options[:private_token])
resp = connection.get(cookbook_uri.request_uri + "&private_token=" + options["private_token"])
return nil unless resp.status == 200
open(archive_path, "wb") { |file| file.write(resp.body) }

Expand Down

0 comments on commit 29864cc

Please sign in to comment.