Class: Pagoda::Command::Key

Inherits:
Base show all
Defined in:
lib/pagoda/cli/helpers/key.rb

Constant Summary

Constants included from Helpers

Helpers::INDENT

Instance Attribute Summary

Attributes inherited from Base

#args, #client, #globals, #options

Instance Method Summary collapse

Methods inherited from Base

#app, ask_for_credentials, #branch, #commit, #extract_app_from_git_config, #extract_app_from_remote, #extract_git_clone_url, #find_branch, #find_commit, #git_remotes, #home_dir, #initialize, #locate_app_root, #loop_transaction, #password, #remote, #shell, #user

Methods included from Helpers

#build_indent, #confirm, #create_git_remote, #display, #display_name, #error, #format_date, #git, #has_git?, #home_directory, #remove_app, #remove_git_remote, #running_on_a_mac?, #running_on_windows?

Constructor Details

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

Instance Method Details

#generate_key_and_pushObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/pagoda/cli/helpers/key.rb', line 7

def generate_key_and_push
  display 
  display "+ Generating a ssh key pair"
  display 
  if running_on_windows?
    display "It appears you are running on windows"
    display "the best way to generate a key is with an external tool"
    display "We suggest using 'PuTTY'"
  else
    (options[:file] ?  `ssh-keygen -f #{options[:file]}` : `ssh-keygen`)
    display
    push_existing_key
  end
end

#push_existing_keyObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/pagoda/cli/helpers/key.rb', line 22

def push_existing_key
  if file_path = options[:file] || args.first
    unless file_path[0] == '/'
      file_path = Dir.pwd << '/' << file_path
    end
    unless file_path.end_with?(".pub")
      file_path << ".pub"
    end
    if File.exists?(file_path)
      send_key_file(file_path)
    else
      error "file given '#{file_path}' does not exist"
    end
  else
    if File.exists?("#{home_dir}/.ssh/id_rsa.pub") || File.exists?("~/.ssh/id_dsa.pub")
      if File.exists?("#{home_dir}/.ssh/id_rsa.pub")
        send_key_file("#{home_dir}/.ssh/id_rsa.pub")
      end

      if File.exists?("#{home_dir}/.ssh/id_dsa.pub")
        send_key_file("#{home_dir}/.ssh/id_dsa.pub")
      end
    else
      display "It appears you do not have a public key."
      display "One should be generated with either id-rsa.pub or id-rsa.pub"
      display "in the #{home_dir}/.ssh folder."
      display "Or you could specify the file 'pagoda key:gen ~/.ssh/my_awesome_key.pub"
    end
  end
end

#send_key_file(file) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/pagoda/cli/helpers/key.rb', line 53

def send_key_file(file)
  key = File.read(file).strip
  if key =~ /^ssh-(?:dss|rsa) [A-Za-z0-9+\/]+/
    client.user_add_key(key)
    display "+ Pushing ssh key to Pagoda Box"
    display "+ done"
  else
    error "that key is not the correct format"
  end
rescue RestClient::UnprocessableEntity
  error "It Appears this key is already in use"
end