1

我正在尝试为 gollum 配置基本的 http 身份验证,但我希望将登录的用户名用于 git 提交。

我已经修改了 config.ru 以便基本身份验证工作,现在我只需要弄清楚如何实现等效的:

session['gollum.author'] => "%s" % loggedIn

然后我可以删除“John Smith”字符串。

顺便说一句 - 请原谅这个愚蠢的问题,我以前从未接触过 Ruby,而且它已经很晚了。

#!/usr/bin/env ruby
#--------------------------------------------------------------------
# - example custom rack for the Gollum wiki engine
# - file should be placed in wiki root
# - RACK_APP environment variable should be set to the filename
# - entrypoint.sh script will run this app using:
#   $ rackup $RACK_APP -p 4567
#--------------------------------------------------------------------
require 'rubygems'
require 'gollum/app'

gollum_path = File.expand_path(File.dirname(__FILE__))
wiki_options = {
    :live_preview => false,
    :allow_editing => true,
    :allow_uploads => true,
    :universal_toc => false,
}

users = {'user' => 'password'}
loggedIn = "anonymous"

use Rack::Auth::Basic, 'realm' do |username, password|
    users.key?(username) && users[username] == password
    loggedIn = username
end

Precious::App.set(:gollum_path, gollum_path)
Precious::App.set(:default_markup, :markdown)
Precious::App.set(:wiki_options, wiki_options)
run Precious::App

#set author
class Precious::App
    before do
        session['gollum.author'] = {
            :name => "%s" % "john smith",   # => "%s" % loggedIn
            :email => "jsmith@example.com",
        }
    end
end

所以我可以看到 session 只存在于 Precious Class 命名空间中,所以我不能直接从我的身份验证方法中设置它:

use Rack::Auth::Basic, 'realm' do |username, password|
    users.key?(username) && users[username] == password
    session['gollum.author'] = {
        :name => "%s" % "john smith",   # => "%s" % username
        :email => "jsmith@example.com",
    }
end

我也试过:

use Rack::Auth::Basic, 'realm' do |username, password|
    users.key?(username) && users[username] == password
    loggedIn = {
        :name => "%s" % username,
        :email => "jsmith@example.com",
    }
end

Precious::App.set(:session['gollum.author'], loggedIn)
4

2 回答 2

2

这是一个解决方案,它允许您定义一系列用户,启用基本的 http 身份验证并使用登录的用户名进行 fit 提交。

require 'rubygems'
require 'gollum/app'

gollum_path = File.expand_path(File.dirname(__FILE__))
wiki_options = {
    :live_preview => false,
    :allow_editing => true,
    :allow_uploads => true,
    :universal_toc => false,
}

users = {'user' => 'password',
         'user2' => 'password2'}

use Rack::Auth::Basic, 'realm' do |username, password|
    if users.key?(username) && users[username] == password
        Precious::App.set(:loggedInUser, username)
    end
end

Precious::App.set(:gollum_path, gollum_path)
Precious::App.set(:default_markup, :markdown)
Precious::App.set(:wiki_options, wiki_options)
run Precious::App

#set author
class Precious::App
    before do
        session['gollum.author'] = {
            :name => "%s" % settings.loggedInUser,
            :email => "%s@example.com" % settings.loggedInUser,
        }
    end
end
于 2016-11-19T19:03:15.387 回答
1

您可以简单地使用 ruby​​gem gollum-auth将基本身份验证添加到 Gollum 4 和 5:

https://github.com/bjoernalbers/gollum-auth

只需使用gem install gollum-auth或 Bundler 安装它并在 gollum 之前加载它。这是一个完成此任务的示例机架config.ru(取自项目的自述文件):

#!/usr/bin/env ruby
require 'rubygems'
require 'gollum/auth' # Don't forget to load the gem!
require 'gollum/app'

# Define list of authorized users.
# Each user must have a username, password, name and email.
#
# Instead of a password you can also define a password_digest, which is the
# SHA-256 hash of a password.
#
# Example:
users = YAML.load %q{
---
- username: rick
  password: asdf754&1129-@lUZw
  name: Rick Sanchez
  email: rick@example.com
- username: morty
  password_digest: 5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5
  name: Morty Smith
  email: morty@example.com
}

# Allow unauthenticated users to read the wiki (disabled by default).
options = { allow_unauthenticated_readonly: true }

# Allow only authenticated users to change the wiki.
# (NOTE: This must be loaded *before* Precious::App!)
use Gollum::Auth, users, options

# That's it. The rest is for gollum only.
gollum_path = File.expand_path(File.dirname(__FILE__)) # CHANGE THIS TO POINT TO YOUR OWN WIKI REPO
wiki_options = {:universal_toc => false}
Precious::App.set(:gollum_path, gollum_path)
Precious::App.set(:wiki_options, wiki_options)
run Precious::App

免责声明:我是 gollum-auth 的作者 :-)

于 2018-11-14T11:41:48.157 回答