Module: Gas::Prompter

Included in:
Ssh
Defined in:
lib/gas/prompter.rb

Class Method Summary collapse

Class Method Details

.clean_getsObject

If the user hits ctrl+c with this, it will exit cleanly



156
157
158
159
160
161
162
163
164
165
166
# File 'lib/gas/prompter.rb', line 156

def self.clean_gets
  begin
    getit = STDIN.gets.strip
  rescue SystemExit, Interrupt           # catch if they hit ctrl+c
    puts
    puts "Safely aborting operation..."    # reassure user that ctrl+c is fine to use.  
    exit
  end
  
  return getit
end

.user_wants_gas_to_handle_rsa_keys?Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/gas/prompter.rb', line 51

def self.user_wants_gas_to_handle_rsa_keys?
  puts
  puts "Do you want gas to handle switching rsa keys for this user?"
  puts "[Y/n]"

  while true
    handle_rsa = clean_gets

    case handle_rsa
    when "y", ""
      return true
    when "n"
      return false
    else
      puts "Please use 'y' or 'n'"
    end
  end
end

.user_wants_to_delete_all_ssh_data?Boolean

This is another prompt function, but it returns a more complicated lexicon

returns “a”, “l”, “g”, or “n”

Returns:

  • (Boolean)


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/gas/prompter.rb', line 93

def self.user_wants_to_delete_all_ssh_data?
  puts "Would you like to remove all of this user's ssh keys too!?!"  
  puts "(github account keys can be removed as well!)"
  puts
  puts "a:  All, the local copy, and checks github too."
  puts "l:  Remove local key only."
  puts "g:  Removes key from github.com only."
  puts "n:  Don't remove this user's keys."
  puts "Default: l"

  while true
    delete_all_keys = clean_gets

    case delete_all_keys.downcase
    when "a"
      return "a"
    when "l", ""
      return "l"
    when "g"
      return "g"
    when "n"
      return "n"
    else
      puts "please use 'a', 'l', 'g' or 'n' for NONE."
    end
  end
end

.user_wants_to_install_key_to_github?Boolean

Returns:

  • (Boolean)


121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/gas/prompter.rb', line 121

def self.user_wants_to_install_key_to_github?
  puts "Gas can automatically install this ssh key into the github account of your choice.  Would you like gas to do this for you?  (Requires inputting github username and password)"
  puts "[Y/n]"

  while true
    upload_key = clean_gets.downcase
    case upload_key
    when "y", ""
      return true
    when "n"
      return false
    else
      puts @invalid_input_response_with_default
    end
  end
end

.user_wants_to_overwrite_existing_rsa_key?Boolean

Returns:

  • (Boolean)


138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/gas/prompter.rb', line 138

def self.user_wants_to_overwrite_existing_rsa_key?
  puts "~/.ssh/id_rsa already exists.  Overwrite?"
  puts "[y/n]"

  while true
    overwrite = clean_gets
    case overwrite
      when "y"
        return true
      when "n"
        return false
      else
        puts "please respond 'y' or 'n'"
    end
  end
end

.user_wants_to_remove_the_keys_that_already_exist_for_this_user?(uid) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/gas/prompter.rb', line 70

def self.user_wants_to_remove_the_keys_that_already_exist_for_this_user?(uid)
  puts
  puts "Well... there's already a ~/.gas/#{uid}_id_rsa configured and ready to go.  Are you sure you don't want gas to handle rsa switching?  (Clicking no will delete the key from the gas directory)"
  puts "Just let gas handle ssh key for this user? [y/n]"

  while true
    keep_file = clean_gets

    case keep_file
    when "n"
      return true
    when "y"
      puts "Excelent!  Gas will handle rsa keys for this user."
      return false
    else
      puts @invalid_input_response_with_default
    end
  end
end

.user_wants_to_use_key_already_in_gas?(uid = '') ⇒ Boolean

If the user says ‘f’, the system will

report that there isn't an id_rsa already in gas.  This causes a new key to overwrite automatically down the road.

This is for checking if a .gas/rsa file already exists for a nickname which is being registered If the rsa exists, then we’re goona need to ask if we should use it, or if we should delete it

Returns true to indicate that the user would like to use the rsa file already in .gas () Returns false when there are no naming conflicts.

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gas/prompter.rb', line 11

def self.user_wants_to_use_key_already_in_gas?(uid = '')
  puts "Gas has detected a key in its archive directory ~/.gas/#{uid}_id_rsa.  Should gas use this key or overwrite this key with a brand new one?"
  puts "Keep current key? [y/n]"

  while true
    keep_current_file = clean_gets

    case keep_current_file

    when "y"
      return true # keep the files already in .gas, skip making key.
    when "n"
      return false
    else
      puts "please respond 'y' or 'n'"
    end
  end
end

.user_wants_to_use_key_already_in_ssh?Boolean

Checks if the ~/.ssh directroy contains id_rsa and id_rsa.pub

if it does, it asks the user if they would like to use that as their ssh key, instead of generating a new key pair.

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/gas/prompter.rb', line 33

def self.user_wants_to_use_key_already_in_ssh?
  puts "Generate a brand new ssh key pair?  (Choose 'n' to use key in ~/.ssh/id_rsa)"
  puts "Default: 'y'"
  puts "[Y/n]"

  while true
    generate_new_rsa = clean_gets.downcase
    case generate_new_rsa
      when "y", ""
        return false
      when "n"
        return true # return true if we aren't generating a new key
      else
        puts @invalid_input_response_with_default
    end
  end
end