Created
August 1, 2014 22:48
-
-
Save LEW21/39777b4fc9a831a58acc to your computer and use it in GitHub Desktop.
Gollum HTTP Basic Auth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'gollum/app' | |
class GollumAuth | |
User = Struct.new(:name, :email, :password_hash) | |
def users | |
if @_users | |
return @_users | |
end | |
all_users = YAML.load_file(File.expand_path('users.yml', File.dirname(__FILE__))) | |
@_users = all_users.map {|u| User.new(*u) } | |
end | |
def detected_user(credentials) | |
users.detect do |u| | |
[u.email, u.password_hash] == [credentials[0], Digest::SHA1.hexdigest(credentials[1])] | |
end | |
end | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
request = Rack::Request.new(env) | |
session = env['rack.session'] = {} | |
auth = Rack::Auth::Basic::Request.new(env) | |
if auth.provided? && auth.basic? && auth.credentials && user = detected_user(auth.credentials) | |
session['gollum.author'] = { | |
:name => user.name, | |
:email => user.email | |
} | |
end | |
# Require login to modify anything. | |
if request.path =~ /^\/(edit|uploadFile|rename|edit|delete|create|revert|preview)\// and not session['gollum.author'] | |
return [401, {'WWW-Authenticate' => %(Basic realm="Gollum Wiki")}, []] | |
end | |
@app.call(env) | |
end | |
end | |
use GollumAuth | |
gollum_path = File.expand_path(File.dirname(__FILE__)) + "/wikidata" | |
Precious::App.set(:gollum_path, gollum_path) | |
Precious::App.set(:default_markup, :markdown) | |
Precious::App.set(:wiki_options, {}) | |
run Precious::App |
im having this issue
undefined method `run' for main:Object (NoMethodError)
Can you give the command to start Gollum which this middleware? How can i put options fror gollum?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on https://gist.github.com/dstrelau/710627 and https://github.com/riskanalytics/gollum-rack/blob/master/config.ru