Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

WIP

  • Loading branch information...
commit 8c8d84f522b689e89e08c90802986c3c6f42fe31 1 parent f94817a
@dpiddy dpiddy authored
Showing with 35 additions and 4 deletions.
  1. +35 −4 lib/gemgate/web.rb
View
39 lib/gemgate/web.rb
@@ -1,4 +1,5 @@
require "sinatra/base"
+require "tempfile"
module Gemgate
class Web < Sinatra::Base
@@ -15,10 +16,6 @@ def self.auth
env!("GEMGATE_AUTH").split(":")
end
- use Rack::Auth::Basic, "gemgate" do |username, password|
- [username, password] == auth
- end
-
configure :test do
enable :raise_errors
end
@@ -26,12 +23,46 @@ def self.auth
disable :show_exceptions
post "/" do
+ full_authorize
+
repository.add_gem(params[:file][:tempfile].path)
status 200
end
+ post "/api/v1/gems" do
+ gem_push_authorize
+
+ Tempfile.open("gem") do |f|
+ while data = request.body.read(8192)
+ f.write(data)
+ end
+ f.close
+
+ repository.add_gem(f.path)
+ end
+
+ status 200
+ end
+
helpers do
+ def full_authorize
+ unless basic_auth_credentials == self.class.auth
+ halt 401
+ end
+ end
+
+ def gem_push_authorize
+ unless request.env["HTTP_AUTHORIZATION"] == self.class.auth.last
+ halt 401
+ end
+ end
+
+ def basic_auth_credentials
+ auth = Rack::Auth::Basic::Request.new(request.env)
+ auth.provided? && auth.basic? ? auth.credentials : []
+ end
+
def repository
@repository ||= self.class.repository || Repository.new
end
Please sign in to comment.
Something went wrong with that request. Please try again.