From 8345f1753cfe59b5f51e62395fe60c49f77b14b2 Mon Sep 17 00:00:00 2001 From: tison Date: Fri, 22 Mar 2024 19:16:36 +0800 Subject: [PATCH] chore: avoid confusing TryFrom (#3565) Signed-off-by: tison --- src/auth/src/common.rs | 2 +- .../src/user_provider/static_user_provider.rs | 22 +++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/auth/src/common.rs b/src/auth/src/common.rs index 16e1ecec2b..109a98175d 100644 --- a/src/auth/src/common.rs +++ b/src/auth/src/common.rs @@ -40,7 +40,7 @@ pub fn user_provider_from_option(opt: &String) -> Result { match name { STATIC_USER_PROVIDER => { let provider = - StaticUserProvider::try_from(content).map(|p| Arc::new(p) as UserProviderRef)?; + StaticUserProvider::new(content).map(|p| Arc::new(p) as UserProviderRef)?; Ok(provider) } _ => InvalidConfigSnafu { diff --git a/src/auth/src/user_provider/static_user_provider.rs b/src/auth/src/user_provider/static_user_provider.rs index 591a116b92..e6d4743894 100644 --- a/src/auth/src/user_provider/static_user_provider.rs +++ b/src/auth/src/user_provider/static_user_provider.rs @@ -23,7 +23,7 @@ use secrecy::ExposeSecret; use snafu::{ensure, OptionExt, ResultExt}; use crate::error::{ - Error, IllegalParamSnafu, InvalidConfigSnafu, IoSnafu, Result, UnsupportedPasswordTypeSnafu, + IllegalParamSnafu, InvalidConfigSnafu, IoSnafu, Result, UnsupportedPasswordTypeSnafu, UserNotFoundSnafu, UserPasswordMismatchSnafu, }; use crate::user_info::DefaultUserInfo; @@ -31,10 +31,12 @@ use crate::{auth_mysql, Identity, Password, UserInfoRef, UserProvider}; pub(crate) const STATIC_USER_PROVIDER: &str = "static_user_provider"; -impl TryFrom<&str> for StaticUserProvider { - type Error = Error; +pub(crate) struct StaticUserProvider { + users: HashMap>, +} - fn try_from(value: &str) -> Result { +impl StaticUserProvider { + pub(crate) fn new(value: &str) -> Result { let (mode, content) = value.split_once(':').context(InvalidConfigSnafu { value: value.to_string(), msg: "StaticUserProviderOption must be in format `