Class: Installation::SshImporter
- Inherits:
-
Object
- Object
- Installation::SshImporter
- Includes:
- Singleton, Yast::Logger
- Defined in:
- src/lib/installation/ssh_importer.rb
Overview
Entry point for the SSH keys importing functionality.
This singleton class provides methods to hold a list of configurations found in the hard disk and to copy its files to the target system
Instance Attribute Summary collapse
-
#configurations ⇒ Hash{String => SshConfig}
readonly
name.
-
#copy_config ⇒ boolean
(also: #copy_config?)
keys.
-
#device ⇒ String
SshConfig to copy the keys from).
Instance Method Summary collapse
-
#add_config(root_dir, device) ⇒ Object
Reads ssh keys and config files from a given root directory, stores the information in #configurations and updates #device according to the default behavior.
-
#initialize ⇒ SshImporter
constructor
A new instance of SshImporter.
-
#reset ⇒ Object
Set default settings (#device and #copy_config?).
-
#set_device ⇒ Object
protected
Sets #device according to the logic implemented in the old "copy_to_system" feature, to ensure backwards compatibility.
-
#write(root_dir) ⇒ Object
Writes the SSH keys from the selected device (and also other configuration files if #copy_config? is true) in the target filesystem.
Constructor Details
#initialize ⇒ SshImporter
Returns a new instance of SshImporter.
42 43 44 45 |
# File 'src/lib/installation/ssh_importer.rb', line 42 def initialize @configurations = {} reset end |
Instance Attribute Details
#configurations ⇒ Hash{String => SshConfig} (readonly)
name
38 39 40 |
# File 'src/lib/installation/ssh_importer.rb', line 38 def configurations @configurations end |
#copy_config ⇒ boolean Also known as: copy_config?
keys
35 36 37 |
# File 'src/lib/installation/ssh_importer.rb', line 35 def copy_config @copy_config end |
#device ⇒ String
SshConfig to copy the keys from)
32 33 34 |
# File 'src/lib/installation/ssh_importer.rb', line 32 def device @device end |
Instance Method Details
#add_config(root_dir, device) ⇒ Object
Reads ssh keys and config files from a given root directory, stores the information in #configurations and updates #device according to the default behavior.
Directories without keys in /etc/ssh are ignored.
64 65 66 67 68 69 70 |
# File 'src/lib/installation/ssh_importer.rb', line 64 def add_config(root_dir, device) config = SshConfig.from_dir(root_dir) return if config.keys.empty? configurations[device] = config set_device end |
#reset ⇒ Object
Set default settings (#device and #copy_config?)
To ensure backwards compatibility, the default behavior is to copy the SSH keys, but not other config files, from the most recently accessed config
51 52 53 54 |
# File 'src/lib/installation/ssh_importer.rb', line 51 def reset set_device @copy_config = false end |
#set_device ⇒ Object (protected)
Sets #device according to the logic implemented in the old "copy_to_system" feature, to ensure backwards compatibility. That means selecting the device which contains the most recently accessed (atime) key file.
For some background, see fate#300421, fate#305019, fate#319624
94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'src/lib/installation/ssh_importer.rb', line 94 def set_device if configurations.empty? @device = nil else with_atime = configurations.to_a.select { |_dev, config| config.keys_atime } if with_atime.empty? @device = configurations.keys.first else recent = with_atime.max_by { |_dev, config| config.keys_atime } @device = recent.first end end end |
#write(root_dir) ⇒ Object
Writes the SSH keys from the selected device (and also other configuration files if #copy_config? is true) in the target filesystem
76 77 78 79 80 81 82 83 84 |
# File 'src/lib/installation/ssh_importer.rb', line 76 def write(root_dir) return unless device configurations[device].write_files( root_dir, write_keys: true, write_config_files: copy_config ) end |