Class: Installation::SshKey
- Inherits:
-
Object
- Object
- Installation::SshKey
- Includes:
- Yast::Logger
- Defined in:
- src/lib/installation/ssh_key.rb
Overview
Class that allows to memorize a particular SSH keys found in a partition.
Used to implement the SSH keys importing functionality.
Defined Under Namespace
Classes: KeyFile
Constant Summary collapse
- PUBLIC_FILE_SUFFIX =
".pub".freeze
Instance Attribute Summary collapse
-
#atime ⇒ Time
Access time of the most recently accessed file.
-
#files ⇒ Array<Keyfile>
List of files associated to the key.
-
#name ⇒ String
Name for the user to identify the key.
Instance Method Summary collapse
- #add_file(path) ⇒ Object protected
-
#initialize(name) ⇒ SshKey
constructor
A new instance of SshKey.
- #read_files(priv_filename) ⇒ Object
-
#to_s ⇒ Object
Override to_s method for logging.
- #write_files(dir) ⇒ Object
Constructor Details
#initialize(name) ⇒ SshKey
Returns a new instance of SshKey.
34 35 36 37 |
# File 'src/lib/installation/ssh_key.rb', line 34 def initialize(name) @name = name @files = [] end |
Instance Attribute Details
#atime ⇒ Time
Returns access time of the most recently accessed file.
30 31 32 |
# File 'src/lib/installation/ssh_key.rb', line 30 def atime @atime end |
#files ⇒ Array<Keyfile>
Returns list of files associated to the key.
32 33 34 |
# File 'src/lib/installation/ssh_key.rb', line 32 def files @files end |
#name ⇒ String
Returns name for the user to identify the key.
28 29 30 |
# File 'src/lib/installation/ssh_key.rb', line 28 def name @name end |
Instance Method Details
#add_file(path) ⇒ Object (protected)
73 74 75 76 77 78 79 |
# File 'src/lib/installation/ssh_key.rb', line 73 def add_file(path) content = File.read(path) = File.stat(path).mode files << KeyFile.new(File.basename(path), content, ) atime = File.atime(path) self.atime = atime unless self.atime && self.atime > atime end |
#read_files(priv_filename) ⇒ Object
39 40 41 42 43 |
# File 'src/lib/installation/ssh_key.rb', line 39 def read_files(priv_filename) add_file(priv_filename) if File.exist?(priv_filename) pub_filename = priv_filename + PUBLIC_FILE_SUFFIX add_file(pub_filename) if File.exist?(pub_filename) end |
#to_s ⇒ Object
Override to_s method for logging.
64 65 66 67 |
# File 'src/lib/installation/ssh_key.rb', line 64 def to_s "#{name}:\n" + files.collect { |file| " #{file.filename}" }.join("\n") end |
#write_files(dir) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'src/lib/installation/ssh_key.rb', line 45 def write_files(dir) log.info "Write SSH keys to #{dir}:\n#{self}" files.each do |file| path = File.join(dir, file.filename) File.write(path, file.content) if file.filename =~ /^ssh_host_.*key$/ # ssh deamon accepts only private keys with restricted # file permissions. log.info("Set permissions of #{file.filename} to 0o600") File.chmod(0o600, path) else # Taking already given permissions log.info("Set permissions of #{file.filename} to 0o#{file..to_s(8)}") File.chmod(file., path) end end end |