lib/geminabox-secure.rb in geminabox-secure-0.3.6 vs lib/geminabox-secure.rb in geminabox-secure-0.3.7
- old
+ new
@@ -15,14 +15,24 @@
set :public, File.join(File.dirname(__FILE__), *%w[.. public])
set :data, File.join(File.dirname(__FILE__), *%w[.. data])
set :views, File.join(File.dirname(__FILE__), *%w[.. views])
set :allow_replace, false
+ set :force_ssl, false
+
use Hostess
- use Rack::SslEnforcer
+
+ #defaults for SSL and basic HTTP Auth
+ if settings.force_ssl
+ use Rack::SslEnforcer
+ end
+ sec_user = ENV['GEMBOX_USER'].nil? ? 'admin' : ENV['GEMBOX_USER']
+ sec_pw = ENV['GEMBOX_PASSWORD'].nil? ? 's3cret' : ENV['GEMBOX_PASSWORD']
+
+ #setup HTTP Auth
use Rack::Auth::Basic, "Restricted Area" do |username, password|
- [username, password] == [ENV['GEMBOX_USER'],ENV['GEMBOX_PASSWORD']]
+ [username, password] == [sec_user,sec_pw]
end
class << self
def disallow_replace?
! allow_replace
@@ -59,13 +69,13 @@
return erb(:upload)
end
tmpfile.binmode
- Dir.mkdir(File.join(options.data, "gems")) unless File.directory? File.join(options.data, "gems")
+ Dir.mkdir(File.join(settings.data, "gems")) unless File.directory? File.join(settings.data, "gems")
- dest_filename = File.join(options.data, "gems", File.basename(name))
+ dest_filename = File.join(settings.data, "gems", File.basename(name))
if GeminaboxSecure.disallow_replace? and File.exist?(dest_filename)
existing_file_digest = Digest::SHA1.file(dest_filename).hexdigest
tmpfile_digest = Digest::SHA1.file(tmpfile.path).hexdigest
@@ -100,20 +110,20 @@
HTML
[code, html]
end
def reindex
- Gem::Indexer.new(options.data).generate_index
+ Gem::Indexer.new(settings.data).generate_index
end
def file_path
- File.expand_path(File.join(options.data, *request.path_info))
+ File.expand_path(File.join(settings.data, *request.path_info))
end
def load_gems
%w(specs prerelease_specs).inject(GemVersionCollection.new){|gems, specs_file_type|
- specs_file_path = File.join(options.data, "#{specs_file_type}.#{Gem.marshal_version}.gz")
+ specs_file_path = File.join(settings.data, "#{specs_file_type}.#{Gem.marshal_version}.gz")
if File.exists?(specs_file_path)
gems + Marshal.load(Gem.gunzip(Gem.read_binary(specs_file_path)))
else
gems
end
@@ -124,10 +134,10 @@
Set.new(gems.map{|name, _| name[0..0]})
end
helpers do
def spec_for(gem_name, version)
- spec_file = File.join(options.data, "quick", "Marshal.#{Gem.marshal_version}", "#{gem_name}-#{version}.gemspec.rz")
+ spec_file = File.join(settings.data, "quick", "Marshal.#{Gem.marshal_version}", "#{gem_name}-#{version}.gemspec.rz")
Marshal.load(Gem.inflate(File.read(spec_file))) if File.exists? spec_file
end
def url_for(path)
url = request.scheme + "://"