Class: Aptible::CLI::Helpers::SecurityKey::DeviceMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/aptible/cli/helpers/security_key.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pid, out_read, err_read) ⇒ DeviceMapper

Returns a new instance of DeviceMapper.



71
72
73
74
75
# File 'lib/aptible/cli/helpers/security_key.rb', line 71

def initialize(pid, out_read, err_read)
  @pid = pid
  @out_read = out_read
  @err_read = err_read
end

Instance Attribute Details

#pidObject (readonly)

Returns the value of attribute pid.



69
70
71
# File 'lib/aptible/cli/helpers/security_key.rb', line 69

def pid
  @pid
end

Class Method Details

.spawnObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/aptible/cli/helpers/security_key.rb', line 91

def self.spawn
  out_read, out_write = IO.pipe
  err_read, err_write = IO.pipe

  pid = Process.spawn(
    'fido2-token -L',
    out: out_write, err: err_write,
    close_others: true
  )

  U2F_LOGGER.debug("#{self}: spawned #{pid}")

  [out_write, err_write].each(&:close)

  new(pid, out_read, err_read)
end

Instance Method Details

#exited(status) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/aptible/cli/helpers/security_key.rb', line 77

def exited(status)
  out, err = [@out_read, @err_read].map(&:read).map(&:chomp)

  if status.exitstatus == 0
    U2F_LOGGER.info("#{self.class}: ok: #{out}")
    [nil, out]
  else
    U2F_LOGGER.warn("#{self.class}: err: #{err}")
    [nil, nil]
  end
ensure
  [@out_read, @err_read].each(&:close)
end