Skip to content

Commit

Permalink
refactor-config: Implements builder pattern for AuthConfig struct
Browse files Browse the repository at this point in the history
Signed-off-by: Harsh1s <[email protected]>
  • Loading branch information
Harsh1s committed May 17, 2024
1 parent 3482952 commit 93f0429
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
43 changes: 36 additions & 7 deletions crates/utils/src/config/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,42 @@ pub struct AuthConfig {
}

impl AuthConfig {
/// Generate a new `AuthConfig` object
#[must_use]
#[inline]
pub fn new(auth_public_key: Option<PathBuf>, auth_private_key: Option<PathBuf>) -> Self {
Self {
auth_public_key,
auth_private_key,
/// Creates a new `AuthConfigBuilder` for building `AuthConfig` objects.
pub fn new() -> AuthConfigBuilder {
AuthConfigBuilder {
auth_public_key: None,
auth_private_key: None,
}
}
}

/// `AuthConfigBuilder` is a builder for `AuthConfig` objects.
#[derive(Debug)]
pub struct AuthConfigBuilder {
/// The public key file
auth_public_key: Option<PathBuf>,
/// The private key file
auth_private_key: Option<PathBuf>,
}

impl AuthConfigBuilder {
/// Sets the public key file path for the `AuthConfig`.
pub fn auth_public_key(&mut self, path: PathBuf) -> &mut Self {
self.auth_public_key = Some(path);
self
}

/// Sets the private key file path for the `AuthConfig`.
pub fn auth_private_key(&mut self, path: PathBuf) -> &mut Self {
self.auth_private_key = Some(path);
self
}

/// Builds the `AuthConfig` object with the provided configurations.
pub fn build(&mut self) -> AuthConfig {
AuthConfig {
auth_public_key: self.auth_public_key.take(),
auth_private_key: self.auth_private_key.take(),
}
}
}
5 changes: 4 additions & 1 deletion crates/xline/src/utils/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,10 @@ impl From<ServerArgs> for XlineServerConfig {
args.jaeger_output_dir,
args.jaeger_level,
);
let auth = AuthConfig::new(args.auth_public_key, args.auth_private_key);
let auth = AuthConfig::new()
.auth_public_key(args.auth_public_key.unwrap())
.auth_private_key(args.auth_private_key.unwrap())
.build();
let auto_compactor_cfg = if let Some(mode) = args.auto_compact_mode {
match mode.as_str() {
"periodic" => {
Expand Down

0 comments on commit 93f0429

Please sign in to comment.