Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge "Add download service"

  • Loading branch information...
commit ac562d09a239d00ebd43a1e95b88da8545474879 2 parents 385eb67 + 0366435
@alighm alighm authored Gerrit Code Review committed
Showing with 64 additions and 0 deletions.
  1. +17 −0 lib/cloud_controller/api/app_bits.rb
  2. +47 −0 spec/api/app_bits_spec.rb
View
17 lib/cloud_controller/api/app_bits.rb
@@ -48,6 +48,21 @@ def upload(id)
HTTP::CREATED
end
+ def download(id)
+ app = find_id_and_validate_access(:read, id)
+
+ package_path = AppPackage.package_path(id)
+ unless File.exist?(package_path)
+ raise Errors::AppPackageNotFound.new(id)
+ end
+
+ if config[:nginx][:use_nginx]
+ return [200, { "X-Accel-Redirect" => "/droplets/" + "app_#{id}" }, ""]
+ else
+ return send_file package_path, :filename => File.basename("#{path}.zip")
+ end
+ end
+
def json_param(name)
raw = params[name]
Yajl::Parser.parse(raw)
@@ -56,5 +71,7 @@ def json_param(name)
end
put "#{path_id}/bits", :upload
+
+ get "#{path_id}/download", :download
end
end
View
47 spec/api/app_bits_spec.rb
@@ -95,5 +95,52 @@ module VCAP::CloudController
include_examples "dev app upload", 201
end
end
+
+ describe "GET /v2/app/:id/download" do
+ let(:tmpdir) { Dir.mktmpdir }
+ let(:app_obj) { Models::App.make }
+ let(:app_obj_without_pkg) { Models::App.make }
+ let(:user) { make_user_for_space(app_obj.space) }
+ let(:developer) { make_developer_for_space(app_obj.space) }
+ let(:developer2) { make_developer_for_space(app_obj_without_pkg.space) }
+
+ before do
+ AppPackage.configure(config_override({
+ :directories => { :droplets => tmpdir }
+ }))
+
+ pkg_path = AppPackage.package_path(app_obj.guid)
+ File.open(pkg_path, "w") do |f|
+ f.write("A")
+ end
+ end
+
+ after do
+ FileUtils.rm_rf(tmpdir)
+ end
+
+ context "dev app download" do
+ it "should return 404 for an app without a package" do
+ get "/v2/apps/#{app_obj_without_pkg.guid}/download", {}, headers_for(developer2)
+ last_response.status.should == 404
+ end
+ it "should return 200 for valid packages" do
+ get "/v2/apps/#{app_obj.guid}/download", {}, headers_for(developer)
+ puts last_response.body
+ last_response.status.should == 200
+ end
+ it "should return 404 for non-existent apps" do
+ get "/v2/apps/abcd/download", {}, headers_for(developer)
+ last_response.status.should == 404
+ end
+ end
+
+ context "user app download" do
+ it "should return 403" do
+ get "/v2/apps/#{app_obj.guid}/download", {}, headers_for(user)
+ last_response.status.should == 403
+ end
+ end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.