Class: TargetIO::TrainCompat::Shadow::Passwd
- Inherits:
-
Object
- Object
- TargetIO::TrainCompat::Shadow::Passwd
- Defined in:
- lib/chef/target_io/train/shadow.rb
Overview
Class Method Summary collapse
Class Method Details
.__parse_shadow(content) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/chef/target_io/train/shadow.rb', line 26 def __parse_shadow(content) content.to_s.split("\n").map do |line| next if line[0] == "#" __parse_shadow_line(line) end.compact end |
.__parse_shadow_line(line) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/chef/target_io/train/shadow.rb', line 34 def __parse_shadow_line(line) x = line.split(":") { # rubocop:disable Layout/AlignHash "sp_namp" => x.at(0), "sp_pwdp" => x.at(1), "sp_lstchg" => x.at(2), "sp_min" => x.at(3), "sp_max" => x.at(4), "sp_warn" => x.at(5), "sp_inact" => x.at(6), "sp_expire" => x.at(7), } end |
.getspnam(name) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/chef/target_io/train/shadow.rb', line 7 def getspnam(name) content = ::TargetIO::File.read("/etc/shadow") entries = __parse_shadow(content) data = entries.detect { |entry| entry["name"] == name } return ::TargetIO::Shadow::Entry.new unless data ::TargetIO::Shadow::Entry.new( data["sp_namp"], data["sp_pwdp"], data["sp_lstchg"], data["sp_min"], data["sp_max"], data["sp_warn"], data["sp_inact"], data["sp_expire"], data["sp_loginclass"] ) end |