Class: Wildcloud::Git::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/wildcloud/git/client.rb

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



21
22
# File 'lib/wildcloud/git/client.rb', line 21

def initialize
end

Instance Method Details

#authorizeObject



49
50
51
52
53
54
55
56
57
# File 'lib/wildcloud/git/client.rb', line 49

def authorize
  message(:info, 'Checking authorization')
  socket = UNIXSocket.new(Git.configuration['paths']['socket'])
  socket.write("auth|#{@user}|#{@repository}|#{@action}\n")
  unless socket.getc.to_s == '1'
    message(:error, 'Invalid authorization.')
  end
  socket.close
end

#check_commandObject

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'])
  message(: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 message(level, message)
  $stderr << "#{level.to_s.upcase}: #{message}\n"
  exit(1) if [:error].include?(level)
end

#parse_informationObject



36
37
38
39
40
41
42
# File 'lib/wildcloud/git/client.rb', line 36

def parse_information
  message(:info, 'Parsing request')
  @repositories = Git.configuration['paths']['repositories']
  @action = @command[1]
  @repository = @command[2]
  @user = ARGV[0]
end

#run_gitObject



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)
    message(:error, 'Invalid repository.')
  end
  exec("git #{@action}-pack #{path}")
end

#setup_environmentObject



44
45
46
47
# File 'lib/wildcloud/git/client.rb', line 44

def setup_environment
  message(:info, 'Setting up environment')
  ENV['GIT_USERNAME'] = @user
end