Module: Aptible::CLI::Helpers::SecurityKey

Defined in:
lib/aptible/cli/helpers/security_key.rb

Defined Under Namespace

Classes: Authenticator, AuthenticatorParameters, Device, DeviceMapper, ThrottledAuthenticator

Constant Summary collapse

U2F_LOGGER =
Logger.new(
  ENV['U2F_DEBUG'] ? STDERR : File.open(File::NULL, 'w')
)

Class Method Summary collapse

Class Method Details

.authenticate(origin, app_id, challenge, device, device_locations) ⇒ Object



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/aptible/cli/helpers/security_key.rb', line 223

def self.authenticate(origin, app_id, challenge,
                      device, device_locations)
  procs = Hash[device_locations.map do |location|
    params = AuthenticatorParameters.new(
      origin,
      challenge,
      app_id,
      device,
      location
    )
    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 w.formatted_out(out) if out
    end
  ensure
    procs.values.map(&:pid).each { |p| Process.kill(:SIGTERM, p) }
  end
end

.device_locationsObject



208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/aptible/cli/helpers/security_key.rb', line 208

def self.device_locations
  w = DeviceMapper.spawn
  _, status = Process.wait2
  _, out = w.exited(status)
  # parse output and only log device
  matches = out.split("\n").map { |s| s.match(/^(\S+):\s/) }
  results = []
  matches.each do |m|
    capture = m.captures
    results << capture[0] if m && capture.count.positive?
  end

  results
end