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
-
.check(user, repo, gitcmd) ⇒ Boolean
Main access control, checks if user is the owner of the repository.
-
.read?(gitcmd) ⇒ Boolean
Convenience method to check if requested access type is read (e.g. command was
receive-pack
). -
.repositories ⇒ Array
List of repository names.
-
.ssh_keys ⇒ Hash
Username => [array of keystrings] pairs.
-
.users ⇒ Array
List of usernames.
-
.write?(gitcmd) ⇒ Boolean
Convenience method to check if requested access type is write (e.g. command was
upload-pack
orupload-archive
).
Class Method Details
.check(user, repo, gitcmd) ⇒ Boolean
Main access control, checks if user is the owner of the repository. When overriden gitcmd
may be used to determine R/W access.
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 |
.read?(gitcmd) ⇒ Boolean
Convenience method to check if requested access type is read (e.g. command was receive-pack
).
36 37 38 |
# File 'lib/golem/access.rb', line 36 def self.read?(gitcmd) gitcmd == "receive-pack" end |
.repositories ⇒ Array
Returns 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 |
.ssh_keys ⇒ Hash
Returns 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 |
.users ⇒ Array
Returns list of usernames.
13 14 15 |
# File 'lib/golem/access.rb', line 13 def self.users Golem::DB.users(:fields => :name, :return => :array) end |
.write?(gitcmd) ⇒ Boolean
Convenience method to check if requested access type is write (e.g. command was upload-pack
or upload-archive
).
42 43 44 |
# File 'lib/golem/access.rb', line 42 def self.write?(gitcmd) !!gitcmd.match(/\Aupload-(pack|archive)\z/) end |