6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/web_git/heroku.rb', line 6
def self.authenticate(email, password)
raise ArgumentError.new("Email and password cannot be blank.") if email.blank? || password.blank?
script = File.join( File.dirname(__FILE__), '/../scripts/heroku_login.exp')
command = "#{script} #{email} #{password}"
rout, wout = IO.pipe
pid = Process.spawn(command, :out => wout)
begin
status = Timeout.timeout(30) do
_, status = Process.wait2(pid)
wout.close
end
stdout = rout.readlines.join("\n")
rout.close
message = stdout.match(/Error.*\./).to_s
raise WebGit::AuthenticationError.new(message) if stdout.include?("Error")
rescue Timeout::Error
Process.kill('TERM', script_pid)
raise Timeout::Error.new("Sign in took longer than 30 seconds.")
end
end
|