Sha256: c828472ee7352e682d1248cea8e24f42733f42cf3ad74494dfb9b9b033833e1d

Contents?: true

Size: 1.19 KB

Versions: 9

Compression:

Stored size: 1.19 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/base')


module KnifeJoyent
  class JoyentKeyAdd < Chef::Knife

    include KnifeJoyent::Base

    banner "knife joyent key add -f <keyfile> -k <name>"

    option :keyname,
      :short => '-k KEY_NAME',
      :long => '--keyname KEY_NAME',
      :description => 'Name for identifying this key'

    option :keyfile,
      :short => '-f KEY_FILE',
      :long => '--keyfile KEY_FILE',
      :description => 'Full path to location of ssh public key'

    def run
      keyfile = config[:keyfile]
      keyname = config[:keyname]

      unless File.exists?(keyfile)
        ui.error('keyfile specified does not exist')
        exit 1
      end


      key = begin
              File.read(keyfile)
            rescue
              puts ui.error('Unable to read contents of keyfile')
              exit 1
            end


      begin
        r = self.connection.create_key(
          :name => keyname,
          :key => key
        )
      rescue Excon::Errors::Conflict => e
        body = MultiJson.decode(e.response.body)
        ui.error(body["message"])
        exit 1
      end

      puts ui.color('Created key: '+keyname, :cyan)
      exit 0
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
knife-joyent-0.0.10 lib/chef/knife/joyent_key_add.rb
knife-joyent-0.0.9 lib/chef/knife/joyent_key_add.rb
knife-joyent-0.0.7 lib/chef/knife/joyent_key_add.rb
knife-joyent-0.0.6 lib/chef/knife/joyent_key_add.rb
knife-joyent-0.0.5 lib/chef/knife/joyent_key_add.rb
knife-joyent-0.0.4 lib/chef/knife/joyent_key_add.rb
knife-joyent-0.0.3 lib/chef/knife/joyent_key_add.rb
knife-joyent-0.0.2 lib/knife-joyent/joyent_key_add.rb
knife-joyent-0.0.1 lib/knife-joyent/joyent_key_add.rb