diff --git a/crates/utils/src/config/auth.rs b/crates/utils/src/config/auth.rs index b8bbc1989..6cdf6e649 100644 --- a/crates/utils/src/config/auth.rs +++ b/crates/utils/src/config/auth.rs @@ -17,13 +17,42 @@ pub struct AuthConfig { } impl AuthConfig { - /// Generate a new `AuthConfig` object - #[must_use] - #[inline] - pub fn new(auth_public_key: Option, auth_private_key: Option) -> 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, + /// The private key file + auth_private_key: Option, +} + +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(), } } } diff --git a/crates/xline/src/utils/args.rs b/crates/xline/src/utils/args.rs index c7ea409b3..bf6e03807 100644 --- a/crates/xline/src/utils/args.rs +++ b/crates/xline/src/utils/args.rs @@ -317,7 +317,10 @@ impl From 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" => {