Class: SSHKeyHub::Exporter::AuthorizedKeysUsers
- Inherits:
-
Object
- Object
- SSHKeyHub::Exporter::AuthorizedKeysUsers
- Defined in:
- lib/ssh_key_hub/exporter/authorized_keys_users.rb
Overview
Simple key exporter with home directory like subfolders
Instance Method Summary collapse
- #add(new_creds) ⇒ Object
- #export(dir_name = 'home') ⇒ Object
-
#initialize ⇒ AuthorizedKeysUsers
constructor
A new instance of AuthorizedKeysUsers.
Constructor Details
#initialize ⇒ AuthorizedKeysUsers
Returns a new instance of AuthorizedKeysUsers
4 5 6 |
# File 'lib/ssh_key_hub/exporter/authorized_keys_users.rb', line 4 def initialize @credentials = {} end |
Instance Method Details
#add(new_creds) ⇒ Object
8 9 10 |
# File 'lib/ssh_key_hub/exporter/authorized_keys_users.rb', line 8 def add(new_creds) @credentials.merge!(new_creds) { |_, old_val, new_val| old_val + new_val } end |
#export(dir_name = 'home') ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ssh_key_hub/exporter/authorized_keys_users.rb', line 12 def export(dir_name = 'home') Dir.mkdir dir_name Dir.chdir dir_name do @credentials.each do |user, keys| Dir.mkdir user ssh_dir = File.join(user, '.ssh') Dir.mkdir ssh_dir Dir.chdir ssh_dir do File.open('authorized_keys', 'w') do |file| keys.each { |key| file.puts key } end end end end end |