Class: Jiveapps::Command::Keys

Inherits:
Base
  • Object
show all
Defined in:
lib/jiveapps/commands/keys.rb

Constant Summary collapse

SSH_KEY_REGEX =
/^((?:[A-Za-z0-9-]+(?:="[^"]+")?,?)+ *)?(ssh-(?:dss|rsa)) *([^ ]*) *(.*)/

Instance Attribute Summary

Attributes inherited from Base

#args, #autodetected_app

Instance Method Summary collapse

Methods inherited from Base

#extract_app, #extract_app_from_git_config, #extract_app_in_dir, #extract_option, #git_remotes, #initialize, #jiveapps

Methods included from Helpers

#ask, #catch_args, #check_git_version, #confirm, #confirm_command, #debug, #debug_mode?, #display, #display_oauth_services, #error, #get_app_prop_with_default, #get_or_set_git_prop, #git_version, #has_program?, #home_directory, #run, #running_on_a_mac?, #running_on_windows?, #sh, #usage, #user_git_version

Constructor Details

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

Instance Method Details

#addObject

Uploads an SSH Key

  • args.first can either be a path to a key file or be nil. if nil, looks in default paths



23
24
25
26
27
28
29
30
31
# File 'lib/jiveapps/commands/keys.rb', line 23

def add
  silent = extract_option("--silent").present?
  keyfile = find_key(args.first)
  key = File.read(keyfile)
  validate_key(key, keyfile)

  display "Uploading ssh public key #{keyfile}" unless silent
  jiveapps.add_key(key)
end

#checkObject

Check to see if this machine’s SSH key (or the key passed in) has been registered with Jiveapps



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/jiveapps/commands/keys.rb', line 49

def check
  keyfile = find_key(args.first)
  key = File.read(keyfile)
  key_name = key.strip.split(/\s+/).last

  uploaded_key_names = jiveapps.keys.map{|key| key['name']}

  if uploaded_key_names.include?(key_name)
    display "This machine's SSH key \"#{key_name}\" has been registered with Jive Apps."
  else
    display "This machine's SSH key \"#{key_name}\" has not been registered with Jive Apps."
  end
end

#listObject Also known as: index

Lists uploaded SSH keys



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/jiveapps/commands/keys.rb', line 7

def list
  long = args.any? { |a| a == '--long' }
  ssh_keys = jiveapps.keys
  if ssh_keys.empty?
    display "No keys for #{jiveapps.user}"
  else
    display "=== #{ssh_keys.size} key#{'s' if ssh_keys.size > 1} for #{jiveapps.user}"
    ssh_keys.each do |ssh_key|
      display long ? ssh_key['key'].strip : format_key_for_display(ssh_key['key'])
    end
  end
end

#removeObject

Remove an SSH key

  • args.first must be the name of the key



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/jiveapps/commands/keys.rb', line 35

def remove
  if args.first == nil
    display "No key specified. Please specify key to remove, for example:\n$ jiveapps keys:remove name@host"
    return
  end
  begin
    jiveapps.remove_key(args.first)
    display "Key #{args.first} removed."
  rescue RestClient::ResourceNotFound
    display "Key #{args.first} not found."
  end
end