module Aptible::CLI::Helpers::SecurityKey

Constants

U2F_LOGGER

Public Class Methods

authenticate(origin, app_id, challenge, devices) click to toggle source
# File lib/aptible/cli/helpers/security_key.rb, line 109
def self.authenticate(origin, app_id, challenge, devices)
  procs = Hash[devices.map do |device|
    params = AuthenticatorParameters.new(
      origin, challenge, app_id, device
    )
    w = Authenticator.spawn(params)
    [w.pid, w]
  end]

  begin
    loop do
      pid, status = Process.wait2
      w = procs.delete(pid)
      raise "waited unknown pid: #{pid}" if w.nil?

      r, out = w.exited(status)

      procs[r.pid] = r if r
      return out if out
    end
  ensure
    procs.values.map(&:pid).each { |p| Process.kill(:SIGTERM, p) }
  end
end