Class: Turnstyl::Client
- Inherits:
-
Object
- Object
- Turnstyl::Client
- Defined in:
- lib/turnstyl/client/client.rb
Class Method Summary collapse
Instance Method Summary collapse
- #authorized_key_missing? ⇒ Boolean
- #config_changed? ⇒ Boolean
- #config_file_missing? ⇒ Boolean
- #create_backup ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #run(force) ⇒ Object
- #update_authorized_keys ⇒ Object
- #update_authorized_keys_carefully ⇒ Object
- #update_necessary? ⇒ Boolean
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/turnstyl/client/client.rb', line 10 def initialize @config_path = File.(Client.home_folder+"/.turnstylrc") if config_file_missing? puts <<-TEXT Unable to run without a config file. Try something like this in ~/.turnstylrc userlist = [ "githubuser1", "githubuser2", "...", "githubuser99" ] TEXT exit 1 end end |
Class Method Details
.home_folder ⇒ Object
6 7 8 |
# File 'lib/turnstyl/client/client.rb', line 6 def self.home_folder Dir.home end |
Instance Method Details
#authorized_key_missing? ⇒ Boolean
72 73 74 |
# File 'lib/turnstyl/client/client.rb', line 72 def !File.exist? Client.home_folder+"/.ssh/authorized_keys" end |
#config_changed? ⇒ Boolean
80 81 82 |
# File 'lib/turnstyl/client/client.rb', line 80 def config_changed? File.mtime(@config_path) > File.mtime(Client.home_folder+"/.ssh/authorized_keys") end |
#config_file_missing? ⇒ Boolean
76 77 78 |
# File 'lib/turnstyl/client/client.rb', line 76 def config_file_missing? !File.exist? Client.home_folder+"/.turnstylrc" end |
#create_backup ⇒ Object
88 89 90 91 92 93 |
# File 'lib/turnstyl/client/client.rb', line 88 def create_backup puts "\nMaking a backup ..." number = Dir.glob(Client.home_folder+'/.ssh/authorized_keys*').count puts number FileUtils.mv(Client.home_folder+"/.ssh/authorized_keys", Client.home_folder+"/.ssh/authorized_keys.bak"+number.to_s) end |
#run(force) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/turnstyl/client/client.rb', line 26 def run(force) if force else end end |
#update_authorized_keys ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/turnstyl/client/client.rb', line 55 def settings = load_settings = settings["userlist"] keys = [] if .empty? keys << '# YOU HAVE NOT AUTHORIZED ANYONE TO LOGIN' else .each do |person| keys = keys + Communicator.new.get_keys_from(person) end end File.open(Client.home_folder+'/.ssh/authorized_keys', 'w+') do |file| file.write(keys.join("\n") << "\n") end puts "\nkeys updated..." end |
#update_authorized_keys_carefully ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/turnstyl/client/client.rb', line 34 def if elsif config_changed? print "Authorized keys file exists. Overwrite? [y/N/b/?]? " input = STDIN.gets.chomp case input when "y" when "b" create_backup when "?" display_help else puts "\nDoing nothing ..." end end end |
#update_necessary? ⇒ Boolean
84 85 86 |
# File 'lib/turnstyl/client/client.rb', line 84 def update_necessary? || config_changed? end |