Class: Qtc::Cli::Platform::SshKeys

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/qtc/cli/platform/ssh_keys.rb

Instance Method Summary collapse

Methods included from Common

#base_url, #client, #extract_app_in_dir, #ini_filename, #inifile, #instance_info, #platform_base_url, #platform_client

Instance Method Details

#create(options) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/qtc/cli/platform/ssh_keys.rb', line 15

def create(options)
  raise ArgumentError.new('--name is required') if options.name.nil?
  raise ArgumentError.new('--key is required') if options.key.nil?
  unless File.exists?(options.key)
    raise ArgumentError.new("#{options.key} does not exist")
  end

  data = {
    name: options.name,
    key: File.read(options.key)
  }

  platform_client.post('/user/ssh_keys', data)
end

#destroy(options) ⇒ Object

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
37
38
39
# File 'lib/qtc/cli/platform/ssh_keys.rb', line 30

def destroy(options)
  raise ArgumentError.new('--name is required') if options.name.nil?
  response = platform_client.get('/user/ssh_keys')
  matches = response['results'].select{|r| r['name'] == options.name}
  if matches.size == 0
    raise ArgumentError.new("SSH key with name #{options.name} does not exist")
  else
    platform_client.delete("/user/ssh_keys/#{matches[0]['id']}")
  end
end

#listObject



8
9
10
11
12
13
# File 'lib/qtc/cli/platform/ssh_keys.rb', line 8

def list
  response = platform_client.get('/user/ssh_keys')
  response['results'].each do |ssh_key|
    say "~ #{ssh_key['name']}"
  end
end