Class: Azuki::Command::Keys

Inherits:
Base
  • Object
show all
Defined in:
lib/azuki/command/keys.rb

Overview

manage authentication keys

Instance Attribute Summary

Attributes inherited from Base

#args, #options

Instance Method Summary collapse

Methods inherited from Base

#api, #app, #azuki, #initialize, namespace

Methods included from Helpers

#action, #ask, #confirm, #confirm_billing, #confirm_command, #create_git_remote, #deprecate, #display, #display_header, #display_object, #display_row, #display_table, #error, error_with_failure, error_with_failure=, extended, extended_into, #fail, #format_bytes, #format_date, #format_error, #format_with_bang, #get_terminal_environment, #git, #has_git?, #home_directory, #hprint, #hputs, included, included_into, #json_decode, #json_encode, #launchy, #line_formatter, #longest, #output_with_bang, #quantify, #redisplay, #retry_on_exception, #run_command, #running_on_a_mac?, #running_on_windows?, #set_buffer, #shell, #spinner, #status, #string_distance, #styled_array, #styled_error, #styled_hash, #styled_header, #suggestion, #time_ago, #truncate, #with_tty

Constructor Details

This class inherits a constructor from Azuki::Command::Base

Instance Method Details

#addObject

keys:add [KEY]

add a key for the current user

if no KEY is specified, will try to find ~/.ssh/id_sa.pub

Examples:

$ azuki keys:add Could not find an existing public key. Would you like to generate one? [Yn] y Generating new SSH public key. Uploading SSH public key /.ssh/id_rsa.pub… done

$ azuki keys:add /my/key.pub Uploading SSH public key /my/key.pub… done



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/azuki/command/keys.rb', line 58

def add
  keyfile = shift_argument
  validate_arguments!

  if keyfile
    Azuki::Auth.associate_key(keyfile)
  else
    # make sure we have credentials
    Azuki::Auth.get_credentials
    Azuki::Auth.associate_or_generate_ssh_key
  end
end

#clearObject

keys:clear

remove all authentication keys from the current user

Examples:

$ azuki keys:clear Removing all SSH keys… done



101
102
103
104
105
106
107
# File 'lib/azuki/command/keys.rb', line 101

def clear
  validate_arguments!

  action("Removing all SSH keys") do
    api.delete_keys
  end
end

#indexObject

keys

display keys for the current user

-l, –long # display extended information for each key

Examples:

$ azuki keys

[email protected] Keys

ssh-rsa ABCDEFGHIJK…OPQRSTUV== [email protected]

$ azuki keys –long

[email protected] Keys

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAp9AJD5QABmOcrkHm6SINuQkDefaR0MUrfgZ1Pxir3a4fM1fwa00dsUwbUaRuR7FEFD8n1E9WwDf8SwQTHtyZsJg09G9myNqUzkYXCmydN7oGr5IdVhRyv5ixcdiE0hj7dRnOJg2poSQ3Qi+Ka8SVJzF7nIw1YhuicHPSbNIFKi5s0D5a+nZb/E6MNGvhxoFCQX2IcNxaJMqhzy1ESwlixz45aT72mXYq0LIxTTpoTqma1HuKdRY8HxoREiivjmMQulYP+CxXFcMyV9kxTKIUZ/FXqlC6G5vSm3J4YScSatPOj9ID5HowpdlIx8F6y4p1/28r2tTl4CY40FFyoke4MQ== [email protected]



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/azuki/command/keys.rb', line 25

def index
  validate_arguments!
  keys = api.get_keys.body
  if keys.length > 0
    styled_header("#{Azuki::Auth.user} Keys")
    keys = if options[:long]
      keys.map {|key| key["contents"].strip}
    else
      keys.map {|key| format_key_for_display(key["contents"])}
    end
    styled_array(keys)
  else
    display("You have no keys.")
  end
end

#removeObject

keys:remove KEY

remove a key from the current user

Examples:

$ azuki keys:remove [email protected] Removing [email protected] SSH key… done



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/azuki/command/keys.rb', line 80

def remove
  key = shift_argument
  if key.nil? || key.empty?
    error("Usage: azuki keys:remove KEY\nMust specify KEY to remove.")
  end
  validate_arguments!

  action("Removing #{key} SSH key") do
    api.delete_key(key)
  end
end