module Golem::Access
Access
control, implements basic control, may be overriden (see {check}).
Public Class Methods
Main access control, checks if user is the owner of the repository. When overriden gitcmd
may be used to determine R/W access. @param [String] user username, @param [String] repo repository name, @param [String] gitcmd git command (one of upload-pack
, upload-archive
, receive-pack
). @return [Boolean] result.
# 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
Convenience method to check if requested access type is read (e.g. command was receive-pack
). @return [Boolean] if read access was requested.
# File lib/golem/access.rb, line 36 def self.read?(gitcmd) gitcmd == "receive-pack" end
@return [Array] list of repository names.
# File lib/golem/access.rb, line 30 def self.repositories Golem::DB.repositories(:fields => :name, :return => :array) end
@return [Hash] username => [array of keystrings] pairs.
# 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
@return [Array] list of usernames.
# File lib/golem/access.rb, line 13 def self.users Golem::DB.users(:fields => :name, :return => :array) end
Convenience method to check if requested access type is write (e.g. command was upload-pack
or upload-archive
). @return [Boolean] if write access was requested.
# File lib/golem/access.rb, line 42 def self.write?(gitcmd) !!gitcmd.match(/\Aupload-(pack|archive)\z/) end