Skip to content

Commit

Permalink
clippy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wandapeter committed Dec 22, 2023
1 parent c764566 commit 1922150
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 34 deletions.
56 changes: 26 additions & 30 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ use users::User;
const DEFAULT_TALLY_DIR: &str = "/var/run/rampdelay";
const DEFAULT_CONFIG_FILE_PATH: &str = "/etc/security/rampdelay.conf";


// Settings struct represents the configuration loaded from default values, configuration file and parameters
#[derive(Debug)]
pub struct Settings {
Expand All @@ -58,7 +57,7 @@ pub struct Settings {
}

impl Default for Settings {
/// Creates a default 'Settings' struct. Default configruation values are set here.
/// Creates a default 'Settings' struct. Default configruation values are set here.
fn default() -> Self {
Settings {
tally_dir: PathBuf::from(DEFAULT_TALLY_DIR),
Expand All @@ -72,7 +71,7 @@ impl Default for Settings {
}

impl Settings {
/// Loads configuration settings from an INI file, returning a `Settings` instance.
/// Loads configuration settings from an INI file, returning a `Settings` instance.
///
/// # Arguments
///
Expand All @@ -84,33 +83,31 @@ impl Settings {
/// A `Settings` instance populated with values from the configuration file, or the
/// default values if the file is not present or cannot be loaded.
fn load_conf_file(config_file: Option<PathBuf>) -> Settings {
Ini::load_from_file(
config_file.unwrap_or(PathBuf::from(DEFAULT_CONFIG_FILE_PATH)),
)
.ok()
.and_then(|ini| ini.section(Some("Settings")).cloned())
.map(|settings| Settings {
tally_dir: settings
.get("tally_dir")
.map(PathBuf::from)
.unwrap_or_default(),
free_tries: settings
.get("free_tries")
.and_then(|val| val.parse().ok())
.unwrap_or_default(),
base_delay_seconds: settings
.get("base_delay")
.and_then(|val| val.parse().ok())
.unwrap_or_default(),
ramp_multiplier: settings
.get("ramp_multiplier")
.and_then(|val| val.parse().ok())
.unwrap_or_default(),
..Settings::default()
})
.unwrap_or_default()
Ini::load_from_file(config_file.unwrap_or(PathBuf::from(DEFAULT_CONFIG_FILE_PATH)))
.ok()
.and_then(|ini| ini.section(Some("Settings")).cloned())
.map(|settings| Settings {
tally_dir: settings
.get("tally_dir")
.map(PathBuf::from)
.unwrap_or_default(),
free_tries: settings
.get("free_tries")
.and_then(|val| val.parse().ok())
.unwrap_or_default(),
base_delay_seconds: settings
.get("base_delay")
.and_then(|val| val.parse().ok())
.unwrap_or_default(),
ramp_multiplier: settings
.get("ramp_multiplier")
.and_then(|val| val.parse().ok())
.unwrap_or_default(),
..Settings::default()
})
.unwrap_or_default()
}

/// Constructs a `Settings` instance based on input parameters, including user
/// information, PAM flags, and an optional configuration file path.
///
Expand All @@ -133,7 +130,6 @@ impl Settings {
_flags: PamFlag,
config_file: Option<PathBuf>,
) -> Result<Settings, PamResultCode> {

// Load INI file.
let mut settings = Self::load_conf_file(config_file);

Expand Down
8 changes: 4 additions & 4 deletions tests/test-pam-auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
//! The `test-pam-auth` module contains integration tests for the rampdelay PAM module. These tests
//! simulate authentication scenarios and validate the behavior of the module, including tally file
//! creation, tally count updates, and successful authentication clearing the tally.
//!
//!
//! ## Issues
//!
//!
//! Because this module uses the systems pam these tests need to be run with evelated privileges.
//! Also the library needs to be built and copied to the correct location.
//! Also the library needs to be built and copied to the correct location.
//! These tests will thus only run correctly via the `cargo xtask test` or `cargo xtask pam-test` commands.
//!
//! ## Test Scenarios
Expand All @@ -29,7 +29,7 @@
//!
//! The `init_and_clear_test` function is utilized to initialize the testing environment, perform
//! the tests, and clear the environment afterward.
//!
//!
//! ## License
//!
//! pam-authramp
Expand Down

0 comments on commit 1922150

Please # to comment.