Class: Wildcloud::Git::Client
- Inherits:
-
Object
- Object
- Wildcloud::Git::Client
- Defined in:
- lib/wildcloud/git/client.rb
Instance Method Summary collapse
- #authorize ⇒ Object
-
#check_command ⇒ Object
Was the right command issued?.
-
#initialize ⇒ Client
constructor
A new instance of Client.
-
#message(level, message) ⇒ Object
Message helper.
- #parse_information ⇒ Object
- #run_git ⇒ Object
- #setup_environment ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
21 22 |
# File 'lib/wildcloud/git/client.rb', line 21 def initialize end |
Instance Method Details
#authorize ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/wildcloud/git/client.rb', line 49 def (:info, 'Checking authorization') socket = UNIXSocket.new(Git.configuration['paths']['socket']) socket.write("auth|#{@user}|#{@repository}|#{@action}\n") unless socket.getc.to_s == '1' (:error, 'Invalid authorization.') end socket.close end |
#check_command ⇒ Object
Was the right command issued?
31 32 33 34 |
# File 'lib/wildcloud/git/client.rb', line 31 def check_command @command = /^git-(upload|receive)-pack '([^']*)'$/.match(ENV['SSH_ORIGINAL_COMMAND']) (:error, 'Invalid command.') unless @command end |
#message(level, message) ⇒ Object
Message helper
25 26 27 28 |
# File 'lib/wildcloud/git/client.rb', line 25 def (level, ) $stderr << "#{level.to_s.upcase}: #{}\n" exit(1) if [:error].include?(level) end |
#parse_information ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/wildcloud/git/client.rb', line 36 def parse_information (:info, 'Parsing request') @repositories = Git.configuration['paths']['repositories'] @action = @command[1] @repository = @command[2] @user = ARGV[0] end |
#run_git ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/wildcloud/git/client.rb', line 59 def run_git path = File.join(@repositories, @repository) unless File.exists?(path) (:error, 'Invalid repository.') end exec("git #{@action}-pack #{path}") end |
#setup_environment ⇒ Object
44 45 46 47 |
# File 'lib/wildcloud/git/client.rb', line 44 def setup_environment (:info, 'Setting up environment') ENV['GIT_USERNAME'] = @user end |