Sha256: 6c137c4db2bc78a7a90677503fbe901710a6837e81dfa7d582c729b9cfb451a8
Contents?: true
Size: 924 Bytes
Versions: 60
Compression:
Stored size: 924 Bytes
Contents
module Opsicle class SSHKey def initialize(environment, keyfile) @client = Client.new(environment) @keyfile = keyfile end def execute(options={}) validate! update Output.say "ssh-key updated successfully" end def validate! raise KeyFileNotFound, "No key file could be found" unless File.exists?(@keyfile) raise InvalidKeyFile, "Key file is invalid" unless valid_key_file? raise InvalidKeyFile, "Key file is a private key" unless public_key? end def valid_key_file? system("ssh-keygen -l -f #{@keyfile} > /dev/null") end def public_key? !key.match(/PRIVATE KEY/) end def key @key ||= File.read(@keyfile) end def update @client.api_call(:update_my_user_profile, {ssh_public_key: key}) end end KeyFileNotFound = Class.new(StandardError) InvalidKeyFile = Class.new(StandardError) end
Version data entries
60 entries across 60 versions & 1 rubygems