Module: GitWit

Includes:
ActiveSupport::Configurable
Defined in:
lib/git_wit.rb,
lib/git_wit/auth.rb,
lib/git_wit/shell.rb,
lib/git_wit/engine.rb,
lib/git_wit/errors.rb,
lib/git_wit/version.rb,
lib/git_wit/authorized_keys.rb,
app/controllers/git_wit/git_controller.rb,
app/controllers/git_wit/application_controller.rb

Defined Under Namespace

Modules: AuthorizedKeys, Shell Classes: ApplicationController, Engine, ForbiddenError, GitController, GitError, InstallGenerator, NotFoundError, UnauthorizedError

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.add_authorized_key(username, key) ⇒ Object



16
17
18
# File 'lib/git_wit/authorized_keys.rb', line 16

def self.add_authorized_key(username, key)
  authorized_keys_file.add AuthorizedKeys::Key.shell_key_for_username(username, key)
end

.authenticate(user, password) ⇒ Object



9
10
11
12
13
14
# File 'lib/git_wit/auth.rb', line 9

def self.authenticate(user, password)
  if config.authenticate.respond_to?(:call)
    return config.authenticate.call(user, password)
  end
  false
end

.authorize(operation, user, repository) ⇒ Object



24
25
26
27
# File 'lib/git_wit/auth.rb', line 24

def self.authorize(operation, user, repository)
  cfg = config.send "authorize_#{operation}".to_sym
  cfg.respond_to?(:call) ? cfg.call(user, repository) : false
end

.authorize_read(user, repository) ⇒ Object



20
21
22
# File 'lib/git_wit/auth.rb', line 20

def self.authorize_read(user, repository)
  authorize :read, user, repository
end

.authorize_write(user, repository) ⇒ Object



16
17
18
# File 'lib/git_wit/auth.rb', line 16

def self.authorize_write(user, repository)
  authorize :write, user, repository
end

.authorized_keys_fileObject



24
25
26
# File 'lib/git_wit/authorized_keys.rb', line 24

def self.authorized_keys_file
  AuthorizedKeys::File.new authorized_keys_path
end

.authorized_keys_pathObject



28
29
30
# File 'lib/git_wit/authorized_keys.rb', line 28

def self.authorized_keys_path
  config.authorized_keys_path || File.expand_path("~#{ssh_user}/.ssh/authorized_keys")
end

.default_config!Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/git_wit.rb', line 27

def self.default_config!
  reset_config!
  configure do |config|
    config.realm = "GitWit"
    config.repositories_path = "/var/git"
    config.ssh_user = "git"
    config.git_http_backend_path = "/usr/libexec/git-core/git-http-backend"
    config.insecure_write = false
    config.insecure_auth = false
  end
end

.regenerate_authorized_keys(keymap) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/git_wit/authorized_keys.rb', line 5

def self.regenerate_authorized_keys(keymap)
  key_file = authorized_keys_file
  key_file.clear do |file|
    keymap.each do |username, keys|
      keys.each do |key|
        key_file.add AuthorizedKeys::Key.shell_key_for_username(username, key)
      end
    end
  end
end

.remove_authorized_key(key) ⇒ Object



20
21
22
# File 'lib/git_wit/authorized_keys.rb', line 20

def self.remove_authorized_key(key)
  authorized_keys_file.remove key
end

.reset_config!Object



14
15
16
# File 'lib/git_wit.rb', line 14

def self.reset_config!
  @_config = nil
end

.restore_configObject



22
23
24
25
# File 'lib/git_wit.rb', line 22

def self.restore_config
  @_config = @_stashed
  @_stashed = nil
end

.stash_configObject



18
19
20
# File 'lib/git_wit.rb', line 18

def self.stash_config
  @_stashed = @_config.dup
end

.user_for_authentication(username) ⇒ Object



2
3
4
5
6
7
# File 'lib/git_wit/auth.rb', line 2

def self.user_for_authentication(username)
  if config.user_for_authentication.respond_to?(:call)
    return config.user_for_authentication.call(username)
  end
  username
end