Sha256: 919b42bf9189fd346531057f25f7979d45c060453d4b49a5d89e7d8432ac5f9f

Contents?: true

Size: 1.24 KB

Versions: 15

Compression:

Stored size: 1.24 KB

Contents

require 'chef/knife/joyent_base'

class Chef
  class Knife
    class JoyentKeyAdd < Knife

      include Knife::JoyentBase

      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
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
knife-joyent-0.4.0 lib/chef/knife/joyent_key_add.rb
knife-joyent-0.3.6 lib/chef/knife/joyent_key_add.rb
knife-joyent-0.3.5 lib/chef/knife/joyent_key_add.rb
knife-joyent-0.3.4 lib/chef/knife/joyent_key_add.rb
knife-joyent-0.3.3 lib/chef/knife/joyent_key_add.rb
knife-joyent-0.3.2 lib/chef/knife/joyent_key_add.rb
knife-joyent-0.3.1 lib/chef/knife/joyent_key_add.rb
knife-joyent-0.3.0 lib/chef/knife/joyent_key_add.rb
knife-joyent-0.2.2 lib/chef/knife/joyent_key_add.rb
knife-joyent-0.2.1 lib/chef/knife/joyent_key_add.rb
knife-joyent-0.2.0 lib/chef/knife/joyent_key_add.rb
knife-joyent-0.1.4 lib/chef/knife/joyent_key_add.rb
knife-joyent-0.1.3 lib/chef/knife/joyent_key_add.rb
knife-joyent-0.1.1 lib/chef/knife/joyent_key_add.rb
knife-joyent-0.1.0 lib/chef/knife/joyent_key_add.rb