URL and credentials from env for stalwart-cli (closes #88)

This commit is contained in:
mdecimus 2024-01-09 18:23:12 +01:00
parent 5c1a0f7d2f
commit b7c03445e4
3 changed files with 29 additions and 17 deletions

View file

@ -44,9 +44,18 @@ pub mod modules;
#[tokio::main]
async fn main() -> std::io::Result<()> {
let args = Cli::parse();
let url = args
.url
.or_else(|| std::env::var("URL").ok())
.unwrap_or_else(|| {
eprintln!("No URL specified. Use --url or set the URL environment variable.");
std::process::exit(1);
});
let client = Client {
credentials: if let Some(credentials) = args.credentials {
parse_credentials(&credentials)
} else if let Ok(credentials) = std::env::var("CREDENTIALS") {
parse_credentials(&credentials)
} else {
let credentials = rpassword::prompt_password(
"\nEnter administrator credentials or press [ENTER] to use OAuth: ",
@ -55,11 +64,11 @@ async fn main() -> std::io::Result<()> {
if !credentials.is_empty() {
parse_credentials(&credentials)
} else {
oauth(&args.url).await
oauth(&url).await
}
},
timeout: args.timeout,
url: args.url,
url,
};
match args.command {

View file

@ -34,7 +34,7 @@ pub struct Cli {
pub command: Commands,
/// Server base URL
#[clap(short, long)]
pub url: String,
pub url: Option<String>,
/// Authentication credentials
#[clap(short, long)]
pub credentials: Option<String>,

View file

@ -1,16 +1,19 @@
#!/bin/bash
cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret domain create example.org
cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret account create john 12345 -d "John Doe" -a john@example.org -a john.doe@example.org
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret account create jane abcde -d "Jane Doe" -a jane@example.org
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret account create bill xyz12 -d "Bill Foobar" -a bill@example.org
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret group create sales -d "Sales Department"
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret group create support -d "Technical Support"
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret account add-to-group john sales support
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret account remove-from-group john support
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret account add-email jane jane.doe@example.org
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret list create everyone everyone@example.org
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret list add-members everyone jane john bill
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret account list
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret import messages --format mbox john _ignore/dovecot-crlf
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret import messages --format maildir john /var/mail/john
URL="https://127.0.0.1:443"
CREDENTIALS="admin:secret"
cargo run -p stalwart-cli -- domain create example.org
cargo run -p stalwart-cli -- account create john 12345 -d "John Doe" -a john@example.org -a john.doe@example.org
#cargo run -p stalwart-cli -- account create jane abcde -d "Jane Doe" -a jane@example.org
#cargo run -p stalwart-cli -- account create bill xyz12 -d "Bill Foobar" -a bill@example.org
#cargo run -p stalwart-cli -- group create sales -d "Sales Department"
#cargo run -p stalwart-cli -- group create support -d "Technical Support"
#cargo run -p stalwart-cli -- account add-to-group john sales support
#cargo run -p stalwart-cli -- account remove-from-group john support
#cargo run -p stalwart-cli -- account add-email jane jane.doe@example.org
#cargo run -p stalwart-cli -- list create everyone everyone@example.org
#cargo run -p stalwart-cli -- list add-members everyone jane john bill
#cargo run -p stalwart-cli -- account list
#cargo run -p stalwart-cli -- import messages --format mbox john _ignore/dovecot-crlf
#cargo run -p stalwart-cli -- import messages --format maildir john /var/mail/john