Module: Golem::Access

Defined in:
lib/golem/access.rb

Overview

Access control, implements basic control, may be overriden (see Access.check).

Class Method Summary (collapse)

Class Method Details

+ (Boolean) check(user, repo, gitcmd)

Main access control, checks if user is the owner of the repository. When overriden gitcmd may be used to determine R/W access.

Parameters:

  • user (String)

    username,

  • repo (String)

    repository name,

  • gitcmd (String)

    git command (one of upload-pack, upload-archive, receive-pack).

Returns:

  • (Boolean)

    result.



8
9
10
# File 'lib/golem/access.rb', line 8

def self.check(user, repo, gitcmd)
	Golem::DB.repositories(:user_name => user, :name => repo, :fields => :name).length > 0
end

+ (Boolean) read?(gitcmd)

Convenience method to check if requested access type is read (e.g. command was receive-pack).

Returns:

  • (Boolean)

    if read access was requested.



36
37
38
# File 'lib/golem/access.rb', line 36

def self.read?(gitcmd)
	gitcmd == "receive-pack"
end

+ (Array) repositories

Returns list of repository names.

Returns:

  • (Array)

    list of repository names.



30
31
32
# File 'lib/golem/access.rb', line 30

def self.repositories
	Golem::DB.repositories(:fields => :name, :return => :array)
end

+ (Hash) ssh_keys

Returns username => [array of keystrings] pairs.

Returns:

  • (Hash)

    username => [array of keystrings] pairs.



18
19
20
21
22
23
24
25
26
27
# File 'lib/golem/access.rb', line 18

def self.ssh_keys
	Golem::DB.ssh_keys(:fields => [:name, :key], :return => :array).inject({}) do |memo, (user, key)|
 if memo.key?(user)
		memo[user] << key
 else
		memo[user] = [key]
 end
 memo
	end
end

+ (Array) users

Returns list of usernames.

Returns:

  • (Array)

    list of usernames.



13
14
15
# File 'lib/golem/access.rb', line 13

def self.users
	Golem::DB.users(:fields => :name, :return => :array)
end

+ (Boolean) write?(gitcmd)

Convenience method to check if requested access type is write (e.g. command was upload-pack or upload-archive).

Returns:

  • (Boolean)

    if write access was requested.



42
43
44
# File 'lib/golem/access.rb', line 42

def self.write?(gitcmd)
	!!gitcmd.match(/\Aupload-(pack|archive)\z/)
end