1
0
Fork 0
mirror of https://github.com/zhaofengli/attic.git synced 2024-12-14 11:57:30 +00:00

remove duplicate rs256 generation, simplify output

This commit is contained in:
vonjackets 2024-11-30 18:02:14 +00:00
parent 6378a5a215
commit 86b375381f
3 changed files with 14 additions and 42 deletions

View file

@ -612,13 +612,12 @@ pub async fn load_config(config_path: Option<&Path>) -> Option<Config> {
else if let Ok(config_path) = get_xdg_config_path(){
match load_config_from_path(&config_path) {
Ok(config) => Some(config),
Err(e) => {
eprintln!("Unable to read configuration from XDG path: {e}");
Err(_) => {
None
}
}
} else {
//couldn't find anything
eprintln!("No configuration found!");
Option::None
}
@ -721,6 +720,8 @@ pub async fn generate_monolithic_config() -> Result<()> {
let storage_path = data_path.join("storage");
fs::create_dir_all(&storage_path).await?;
//no config provided, start fresh and create a config, a token, and a sqllite db
//generate rsa256 key
let rs256_secret_base64 = {
let mut rng = rand::thread_rng();
let private_key = rsa::RsaPrivateKey::new(&mut rng, 4096)?;
@ -736,18 +737,9 @@ pub async fn generate_monolithic_config() -> Result<()> {
let config_path = get_xdg_config_path()?;
eprintln!("writing server.toml to {}",config_path.display());
fs::write(&config_path, config_content.as_bytes()).await?;
//no config provided, start fresh and create a config, a token, and a sqllite db
//generate rsa256 key
let rs256_secret_base64 = {
let mut rng = rand::thread_rng();
let private_key = rsa::RsaPrivateKey::new(&mut rng, 4096)?;
let pkcs1_pem = private_key.to_pkcs1_pem(rsa::pkcs1::LineEnding::LF)?;
BASE64_STANDARD.encode(pkcs1_pem.as_bytes())
};
// Generate a JWT token
let root_token = generate_root_token(rs256_secret_base64);

View file

@ -106,9 +106,6 @@ async fn main() -> Result<()> {
attic_server::run_migrations(config.clone()).await?;
}
attic_server::run_api_server(opts.listen, config).await?;
} else {
//Exit gracefully, no config present
display_no_config_msg();
}
}
ServerMode::GarbageCollector => {
@ -117,9 +114,6 @@ async fn main() -> Result<()> {
config::reinit_from_config(config.clone()).await?;
}
attic_server::gc::run_garbage_collection(config.clone()).await;
} else {
//Exit gracefully, no config present
display_no_config_msg();
}
}
@ -129,9 +123,6 @@ async fn main() -> Result<()> {
config::reinit_from_config(config.clone()).await?;
}
attic_server::run_migrations(config).await?;
} else {
//Exit gracefully, no config present
display_no_config_msg();
}
}
ServerMode::GarbageCollectorOnce => {
@ -140,9 +131,6 @@ async fn main() -> Result<()> {
config::reinit_from_config(config.clone()).await?;
}
attic_server::gc::run_garbage_collection_once(config).await?;
} else {
//Exit gracefully, no config present
display_no_config_msg();
}
}
ServerMode::CheckConfig => {
@ -159,9 +147,6 @@ async fn main() -> Result<()> {
eprintln!("Enjoy!");
eprintln!("-----------------");
eprintln!();
} else {
//Exit gracefully, no config present
display_no_config_msg();
}
}
@ -183,11 +168,6 @@ async fn run_monolithic(opts: Opts, config: Config) -> Result<()> {
}
}
fn display_no_config_msg() {
eprintln!();
eprintln!("No config found, please provide a config.toml file");
}
fn init_logging(tokio_console: bool) {
let env_filter = EnvFilter::from_default_env();
let fmt_layer = tracing_subscriber::fmt::layer().with_filter(env_filter);