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, :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, :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
109 110 111 |
# File 'library/general/src/lib/cfa/login_defs.rb', line 109 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.
101 102 103 |
# File 'library/general/src/lib/cfa/login_defs.rb', line 101 def file_path @file_path end |
Class Method Details
.known_attributes ⇒ Array<Symbol>
Returns the list of known attributes
80 81 82 |
# File 'library/general/src/lib/cfa/login_defs.rb', line 80 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.
91 92 93 |
# File 'library/general/src/lib/cfa/login_defs.rb', line 91 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.
135 136 137 138 |
# File 'library/general/src/lib/cfa/login_defs.rb', line 135 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.
145 146 147 148 149 150 |
# File 'library/general/src/lib/cfa/login_defs.rb', line 145 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
116 117 118 |
# File 'library/general/src/lib/cfa/login_defs.rb', line 116 def present?(attr) !public_send(attr).nil? end |
#present_attributes ⇒ Array<Symbol>
Returns the list of attributes with a value
124 125 126 |
# File 'library/general/src/lib/cfa/login_defs.rb', line 124 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.
157 158 159 160 161 |
# File 'library/general/src/lib/cfa/login_defs.rb', line 157 def save directory = File.dirname(file_path) Yast::Execute.on_target("/usr/bin/mkdir", "--parents", directory) if !Yast::FileUtils.IsDirectory(directory) super end |