diff --git a/api/src/config.rs b/api/src/config.rs index 8038573..99fadcd 100644 --- a/api/src/config.rs +++ b/api/src/config.rs @@ -37,7 +37,9 @@ impl std::ops::DerefMut for SharedAppConfig { pub struct PaymentConfig { payu_client_id: Option, payu_client_secret: Option, + /// Create payu account and copy here merchant id payu_client_merchant_id: Option, + /// Allow customers to pay on site optional_payment: bool, } @@ -50,8 +52,9 @@ impl Example for PaymentConfig { payu_client_secret: Some(pay_u::ClientSecret::new( "Create payu account and copy here client_secret", )), - /// "Create payu account and copy here merchant id" + /// Create payu account and copy here merchant id payu_client_merchant_id: Some(pay_u::MerchantPosId::from(0)), + /// Allow customers to pay on site optional_payment: true, } } @@ -348,7 +351,10 @@ fn load(config_path: &str, opts: &impl UpdateConfig) -> SharedAppConfig { Err(e) if e.kind() == std::io::ErrorKind::NotFound => { let config = AppConfig::example(); std::fs::write(config_path, toml::to_string_pretty(&config).unwrap()).unwrap(); - SharedAppConfig::new(config) + eprintln!("Config was automatically generated"); + eprintln!("Please review ./bazzar.toml, fill all fields or provide all environment variables in .env"); + eprintln!("And restart service."); + std::process::exit(1); } Err(e) => { log::error!("{e:?}"); @@ -357,6 +363,28 @@ fn load(config_path: &str, opts: &impl UpdateConfig) -> SharedAppConfig { } } +pub async fn config_info() -> crate::Result<()> { + println!( + r#"Environment variables: +PAYU_CLIENT_ID - PayU client id, you can obtain it by creating account (account requires one-time payment) +PAYU_CLIENT_SECRET - PayU client secret +PAYU_CLIENT_MERCHANT_ID - PayU client merchant id, you can obtain it by creating account (account requires one-time payment) +WEB_HOST - your domain name, it's required for PayU notifications, service emails and redirections +PASS_SALT - password encryption secret string, you can generate it with this CLI +SESSION_SECRET - 100 characters admin session encryption +JWT_SECRET - 100 characters user session encryption +BAZZAR_BIND - address to which server should be bind, typically 0.0.0.0 +BAZZAR_PORT - port which server should use, typically 80 +SENDGRID_SECRET - e-mail sending service secret +SENDGRID_API_KEY - e-mail sending service api key +SMTP_FROM - e-mail sending service authorized e-mail address used as sender e-mail address +DATABASE_URL - postgresql address (ex. postgres://postgres@localhost/bazzar) + "# + ); + + Ok(()) +} + pub fn save(config_path: &str, config: &mut AppConfig) { config.config_path = String::from(config_path); std::fs::write(config_path, toml::to_string_pretty(&config).unwrap()).unwrap(); diff --git a/api/src/main.rs b/api/src/main.rs index 416121e..a450aaa 100644 --- a/api/src/main.rs +++ b/api/src/main.rs @@ -204,5 +204,6 @@ async fn main() -> Result<()> { Command::GenerateHash(opts) => generate_hash(opts).await, Command::CreateAccount(opts) => create_account(opts).await, Command::TestMailer(opts) => test_mailer(opts).await, + Command::ConfigInfo(_) => config::config_info().await, } } diff --git a/api/src/opts.rs b/api/src/opts.rs index 6f52b8e..89efdcc 100644 --- a/api/src/opts.rs +++ b/api/src/opts.rs @@ -47,6 +47,8 @@ pub enum Command { CreateAccount(CreateAccountOpts), #[options(help = "Check mailer config")] TestMailer(TestMailerOpts), + #[options(help = "Print config information")] + ConfigInfo(ConfigInfo), } impl UpdateConfig for Command { @@ -67,6 +69,7 @@ impl UpdateConfig for Command { Command::TestMailer(opts) => { opts.update_config(config); } + Command::ConfigInfo(_) => {} } } } @@ -77,6 +80,8 @@ impl Default for Command { } } +pub struct ConfigInfo {} + #[derive(Options, Debug)] pub struct GenerateHashOpts { pub help: bool,