Class: CFA::LoginDefs
- Inherits:
-
BaseModel
- Object
- BaseModel
- CFA::LoginDefs
- Includes:
- Yast::Logger
- Defined in:
- library/general/src/lib/cfa/login_defs.rb
Overview
Model to handle login.defs configuration files
Constant Summary collapse
- KNOWN_ATTRIBUTES =
Returns List of known login.defs attributes.
[ :character_class, :create_home, :encrypt_method, :fail_delay, :gid_max, :gid_min, :groupadd_cmd, :home_mode, :pass_max_days, :pass_min_days, :pass_warn_age, :sub_gid_min, :sub_gid_max, :sub_gid_count, :sub_uid_min, :sub_uid_max, :sub_uid_count, :sys_gid_max, :sys_gid_min, :sys_uid_max, :sys_uid_min, :uid_max, :uid_min, :umask, :useradd_cmd, :userdel_postcmd, :userdel_precmd, :usergroups_enab ].freeze
- DEFAULT_PATH =
"/etc/login.defs".freeze
Instance Attribute Summary collapse
-
#file_path ⇒ String
readonly
File path.
Class Method Summary collapse
-
.known_attributes ⇒ Array<Symbol>
Returns the list of known attributes.
-
.load(file_path: DEFAULT_PATH, file_handler: Yast::TargetFile) ⇒ LoginDefs
Instantiates and loads a file.
Instance Method Summary collapse
-
#conflicts(other) ⇒ Array<Symbol>
Determines the list of conflicting attributes for two files.
-
#initialize(file_path: DEFAULT_PATH, file_handler: Yast::TargetFile) ⇒ LoginDefs
constructor
Constructor.
-
#load ⇒ Object
Loads the file content.
-
#present?(attr) ⇒ Boolean
Determines whether an attribute has a value.
-
#present_attributes ⇒ Array<Symbol>
Returns the list of attributes with a value.
-
#save ⇒ Object
Saves the file content.
Constructor Details
#initialize(file_path: DEFAULT_PATH, file_handler: Yast::TargetFile) ⇒ LoginDefs
Constructor
113 114 115 |
# File 'library/general/src/lib/cfa/login_defs.rb', line 113 def initialize(file_path: DEFAULT_PATH, file_handler: Yast::TargetFile) super(AugeasParser.new("login_defs.lns"), file_path, file_handler: file_handler) end |
Instance Attribute Details
#file_path ⇒ String (readonly)
Returns File path.
105 106 107 |
# File 'library/general/src/lib/cfa/login_defs.rb', line 105 def file_path @file_path end |
Class Method Details
.known_attributes ⇒ Array<Symbol>
Returns the list of known attributes
84 85 86 |
# File 'library/general/src/lib/cfa/login_defs.rb', line 84 def known_attributes KNOWN_ATTRIBUTES end |
.load(file_path: DEFAULT_PATH, file_handler: Yast::TargetFile) ⇒ LoginDefs
Instantiates and loads a file
This method is basically a shortcut to instantiate and load the content in just one call.
95 96 97 |
# File 'library/general/src/lib/cfa/login_defs.rb', line 95 def load(file_path: DEFAULT_PATH, file_handler: Yast::TargetFile) new(file_path: file_path, file_handler: file_handler).tap(&:load) end |
Instance Method Details
#conflicts(other) ⇒ Array<Symbol>
Determines the list of conflicting attributes for two files
Two attributes are conflicting when both of them are defined with different values.
139 140 141 142 |
# File 'library/general/src/lib/cfa/login_defs.rb', line 139 def conflicts(other) conflicting_attrs = present_attributes & other.present_attributes conflicting_attrs.reject { |a| public_send(a) == other.public_send(a) } end |
#load ⇒ Object
Loads the file content
If the file does not exist, consider the file as empty.
149 150 151 152 153 154 |
# File 'library/general/src/lib/cfa/login_defs.rb', line 149 def load super rescue Errno::ENOENT # PATH does not exist yet self.data = @parser.empty @loaded = true end |
#present?(attr) ⇒ Boolean
Determines whether an attribute has a value
120 121 122 |
# File 'library/general/src/lib/cfa/login_defs.rb', line 120 def present?(attr) !public_send(attr).nil? end |
#present_attributes ⇒ Array<Symbol>
Returns the list of attributes with a value
128 129 130 |
# File 'library/general/src/lib/cfa/login_defs.rb', line 128 def present_attributes self.class.known_attributes.select { |a| present?(a) } end |
#save ⇒ Object
Saves the file content
It creates the directory if it does not exist.
161 162 163 164 165 |
# File 'library/general/src/lib/cfa/login_defs.rb', line 161 def save directory = File.dirname(file_path) Yast::Execute.on_target("/usr/bin/mkdir", "--parents", directory) if !Yast::FileUtils.IsDirectory(directory) super end |