Class: Chef::Knife::JoyentKeyDelete

Inherits:
Chef::Knife show all
Includes:
JoyentBase
Defined in:
lib/chef/knife/joyent_key_delete.rb

Instance Method Summary collapse

Methods included from JoyentBase

#connection, #decode_time_attrs, included, #json_decode, #locate_config_value, #msg_pair, #output_error, #pricing

Instance Method Details

#runObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/chef/knife/joyent_key_delete.rb', line 11

def run
  unless name_args.size === 1
    show_usage
  end

  keyname = name_args.first

  begin
    self.connection.delete_key(keyname)
  rescue Excon::Errors::NotFound => e
    ui.error("Key [#{keyname}] does not exist.")
    exit 1
  rescue Excon::Errors::Conflict => e
    body = MultiJson.decode(e.response.body)
    ui.error(body["message"])
    exit 1
  end

  puts ui.color('Deleted key: '+keyname, :cyan)
  exit 0
rescue => e
  output_error(e)
  exit 1
end