Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow relative urls in location_path for downloader #1799

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/berkshelf/downloader.rb
Expand Up @@ -68,7 +68,11 @@ def try_download(source, name, version)
if source.type == :artifactory
options[:headers] = { "X-Jfrog-Art-Api" => source.options[:api_key] }
end
CommunityREST.new(remote_cookbook.location_path, options).download(name, version)

# Allow Berkshelf install to function if a relative url exists in location_path
path = URI.parse(remote_cookbook.location_path).absolute? ? remote_cookbook.location_path : "#{source.uri_string}#{remote_cookbook.location_path}"

CommunityREST.new(path, options).download(name, version)
when :chef_server
tmp_dir = Dir.mktmpdir
unpack_dir = Pathname.new(tmp_dir) + "#{name}-#{version}"
Expand Down
25 changes: 25 additions & 0 deletions spec/unit/berkshelf/downloader_spec.rb
Expand Up @@ -59,6 +59,31 @@ module Berkshelf
subject.try_download(source, name, version)
end

context "supports location paths" do
before(:each) do
allow(source).to receive(:type) { :supermarket }
allow(source).to receive(:options) { { ssl: {} } }
allow(source).to receive(:uri_string).and_return("http://localhost:8081/repository/chef-proxy")
allow(remote_cookbook).to receive(:location_type) { :opscode }
end

let(:rest) { double("community-rest") }

it "that are relative and prepends the source URI for the download" do
allow(remote_cookbook).to receive(:location_path) { "/api/v1" }
expect(CommunityREST).to receive(:new).with("http://localhost:8081/repository/chef-proxy/api/v1", { ssl: {} }) { rest }
expect(rest).to receive(:download).with(name, version)
subject.try_download(source, name, version)
end

it "that are absolute and uses the given absolute URI" do
allow(remote_cookbook).to receive(:location_path) { "http://localhost:8081/repository/chef-proxy/api/v1" }
expect(CommunityREST).to receive(:new).with("http://localhost:8081/repository/chef-proxy/api/v1", { ssl: {} }) { rest }
expect(rest).to receive(:download).with(name, version)
subject.try_download(source, name, version)
end
end

context "with an artifactory source" do
it "supports the 'opscode' location type" do
allow(source).to receive(:type) { :artifactory }
Expand Down