Class: Opsicle::SSHKey
- Inherits:
-
Object
- Object
- Opsicle::SSHKey
- Defined in:
- lib/opsicle/commands/ssh_key.rb
Instance Method Summary collapse
- #execute(options = {}) ⇒ Object
-
#initialize(environment, keyfile) ⇒ SSHKey
constructor
A new instance of SSHKey.
- #key ⇒ Object
- #public_key? ⇒ Boolean
- #update ⇒ Object
- #valid_key_file? ⇒ Boolean
- #validate! ⇒ Object
Constructor Details
Instance Method Details
#execute(options = {}) ⇒ Object
9 10 11 12 13 |
# File 'lib/opsicle/commands/ssh_key.rb', line 9 def execute(={}) validate! update Output.say "ssh-key updated successfully" end |
#key ⇒ Object
29 30 31 |
# File 'lib/opsicle/commands/ssh_key.rb', line 29 def key @key ||= File.read(@keyfile) end |
#public_key? ⇒ Boolean
25 26 27 |
# File 'lib/opsicle/commands/ssh_key.rb', line 25 def public_key? !key.match(/PRIVATE KEY/) end |
#update ⇒ Object
33 34 35 |
# File 'lib/opsicle/commands/ssh_key.rb', line 33 def update @client.api_call(:update_my_user_profile, {ssh_public_key: key}) end |
#valid_key_file? ⇒ Boolean
21 22 23 |
# File 'lib/opsicle/commands/ssh_key.rb', line 21 def valid_key_file? system("ssh-keygen -l -f #{@keyfile} > /dev/null") end |
#validate! ⇒ Object
15 16 17 18 19 |
# File 'lib/opsicle/commands/ssh_key.rb', line 15 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 |