class Sshhub::PortAuthority

Public Class Methods

authorize(keys) click to toggle source
# File lib/sshhub/port_authority.rb, line 3
def self.authorize(keys)
  system('mkdir', '-p', "/Users/#{whoami}/.ssh")

  [*keys].each do |key|
    File.open(filename, 'a'){|f| f.write("#{key}\n") }
  end
end
present?(keys) click to toggle source
# File lib/sshhub/port_authority.rb, line 17
def self.present?(keys)
  ([*keys].map(&:key) & authorized_keys).any?
end
revoke(keys) click to toggle source
# File lib/sshhub/port_authority.rb, line 11
def self.revoke(keys)
  system('mkdir', '-p', "/Users/#{whoami}/.ssh")
  revoked = authorized_keys - [*keys].map(&:key)
  File.open(filename, "w"){|f| f.puts revoked }
end

Private Class Methods

authorized_keys() click to toggle source
# File lib/sshhub/port_authority.rb, line 23
def self.authorized_keys
  File.open(filename, 'r').read.split("\n")
rescue Errno::ENOENT => e
  []
end
filename() click to toggle source
# File lib/sshhub/port_authority.rb, line 29
def self.filename
  "/Users/#{whoami}/.ssh/authorized_keys"
end
whoami() click to toggle source
# File lib/sshhub/port_authority.rb, line 33
def self.whoami
  @whoami ||= `whoami`.rstrip
end