-
Notifications
You must be signed in to change notification settings - Fork 826
Suppress user and password info output via Config structure. #947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fd9c4f6
6c49576
dad5daf
e5a35a5
01a0b98
6e45a51
da1dc07
98d5295
a583eb9
d64ffaa
ecfa8fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
// | ||
// SPDX-License-Identifier: Apache-2.0. | ||
|
||
use std::fmt; | ||
use std::str::FromStr; | ||
|
||
use common_exception::ErrorCode; | ||
use common_exception::Result; | ||
use lazy_static::lazy_static; | ||
|
@@ -137,15 +140,81 @@ pub struct Config { | |
pub store_api_address: String, | ||
|
||
#[structopt(long, env = STORE_API_USERNAME, default_value = "root")] | ||
pub store_api_username: String, | ||
pub store_api_username: User, | ||
|
||
#[structopt(long, env = STORE_API_PASSWORD, default_value = "root")] | ||
pub store_api_password: String, | ||
pub store_api_password: Password, | ||
|
||
#[structopt(long, short = "c", env = CONFIG_FILE, default_value = "")] | ||
pub config_file: String, | ||
} | ||
|
||
#[derive(Clone, serde::Deserialize, PartialEq, StructOpt, StructOptToml)] | ||
#[serde(default)] | ||
zhang2014 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub struct Password { | ||
pub store_api_password: String, | ||
} | ||
|
||
impl AsRef<String> for Password { | ||
fn as_ref(&self) -> &String { | ||
&self.store_api_password | ||
} | ||
} | ||
|
||
impl FromStr for Password { | ||
type Err = ErrorCode; | ||
fn from_str(s: &str) -> common_exception::Result<Self> { | ||
Ok(Self { | ||
store_api_password: s.to_string(), | ||
}) | ||
} | ||
} | ||
|
||
impl ToString for Password { | ||
fn to_string(&self) -> String { | ||
self.store_api_password.clone() | ||
} | ||
} | ||
|
||
impl fmt::Debug for Password { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "******") | ||
} | ||
} | ||
|
||
#[derive(Clone, serde::Deserialize, PartialEq, StructOpt, StructOptToml)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need new line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use rust-fmt to format the code. You can use |
||
#[serde(default)] | ||
pub struct User { | ||
pub store_api_username: String, | ||
} | ||
|
||
impl ToString for User { | ||
fn to_string(&self) -> String { | ||
self.store_api_username.clone() | ||
} | ||
} | ||
|
||
impl fmt::Debug for User { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "******") | ||
} | ||
} | ||
|
||
impl AsRef<String> for User { | ||
fn as_ref(&self) -> &String { | ||
&self.store_api_username | ||
} | ||
} | ||
|
||
impl FromStr for User { | ||
type Err = ErrorCode; | ||
fn from_str(s: &str) -> common_exception::Result<Self> { | ||
Ok(Self { | ||
store_api_username: s.to_string(), | ||
}) | ||
} | ||
} | ||
|
||
impl Config { | ||
/// Default configs. | ||
pub fn default() -> Self { | ||
|
@@ -163,8 +232,12 @@ impl Config { | |
http_api_address: "127.0.0.1:8080".to_string(), | ||
metric_api_address: "127.0.0.1:7070".to_string(), | ||
store_api_address: "127.0.0.1:9191".to_string(), | ||
store_api_username: "root".to_string(), | ||
store_api_password: "root".to_string(), | ||
store_api_username: User { | ||
store_api_username: "root".to_string(), | ||
}, | ||
store_api_password: Password { | ||
store_api_password: "root".to_string(), | ||
}, | ||
config_file: "".to_string(), | ||
} | ||
} | ||
|
@@ -231,8 +304,8 @@ impl Config { | |
env_helper!(mut_config, http_api_address, String, HTTP_API_ADDRESS); | ||
env_helper!(mut_config, metric_api_address, String, METRICS_API_ADDRESS); | ||
env_helper!(mut_config, store_api_address, String, STORE_API_ADDRESS); | ||
env_helper!(mut_config, store_api_username, String, STORE_API_USERNAME); | ||
env_helper!(mut_config, store_api_password, String, STORE_API_PASSWORD); | ||
env_helper!(mut_config, store_api_username, User, STORE_API_USERNAME); | ||
env_helper!(mut_config, store_api_password, Password, STORE_API_PASSWORD); | ||
|
||
Ok(mut_config) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need new line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok