Class: CivoCLI::SSHKey

Inherits:
Thor
  • Object
show all
Defined in:
lib/sshkey.rb

Instance Method Summary collapse

Instance Method Details

#listObject



4
5
6
7
8
9
10
11
# File 'lib/sshkey.rb', line 4

def list
  CivoCLI::Config.set_api_auth
  rows = []
  Civo::SshKey.all.items.each do |key|
    rows << [key.id, key.name, key.fingerprint]
  end
  puts Terminal::Table.new headings: ['ID', 'Name', 'Fingerprint'], rows: rows
end

#remove(id) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/sshkey.rb', line 27

def remove(id)
  CivoCLI::Config.set_api_auth
  ssh_key = Civo::SshKey.all.items.detect {|key| key.id == id}
  Civo::SshKey.remove(id: id)
  puts "Removed SSH key #{ssh_key.name.colorize(:green)} with ID #{ssh_key.id.colorize(:green)}"
rescue Flexirest::HTTPException => e
  puts e.result.reason.colorize(:red)
  exit 1
end

#upload(name, filename) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/sshkey.rb', line 16

def upload(name, filename)
  CivoCLI::Config.set_api_auth
  ssh_key = Civo::SshKey.create(name: name, public_key: File.read(filename))
  puts "Uploaded SSH key #{name.colorize(:green)} with ID #{ssh_key.id.colorize(:green)}"
rescue Flexirest::HTTPException => e
  puts e.result.reason.colorize(:red)
  exit 1
end