2022-08-15 20:23:13 +03:00
|
|
|
mod check_config;
|
2022-08-06 03:07:12 +03:00
|
|
|
mod create_user;
|
|
|
|
|
|
|
|
use argh::FromArgs;
|
|
|
|
use web3_proxy::app::get_migrated_db;
|
|
|
|
|
|
|
|
#[derive(Debug, FromArgs)]
|
2022-08-06 08:46:33 +03:00
|
|
|
/// Command line interface for admins to interact with web3_proxy
|
2022-08-06 03:07:12 +03:00
|
|
|
pub struct TopConfig {
|
2022-08-06 04:17:25 +03:00
|
|
|
/// what database the client should connect to
|
2022-08-06 03:07:12 +03:00
|
|
|
#[argh(
|
|
|
|
option,
|
2022-08-06 08:49:52 +03:00
|
|
|
default = "\"mysql://root:dev_web3_proxy@127.0.0.1:13306/dev_web3_proxy\".to_string()"
|
2022-08-06 03:07:12 +03:00
|
|
|
)]
|
|
|
|
pub db_url: String,
|
|
|
|
|
|
|
|
/// this one cli can do multiple things
|
|
|
|
#[argh(subcommand)]
|
|
|
|
sub_command: SubCommand,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(FromArgs, PartialEq, Debug)]
|
|
|
|
#[argh(subcommand)]
|
|
|
|
enum SubCommand {
|
|
|
|
CreateUser(create_user::CreateUserSubCommand),
|
2022-08-15 20:23:13 +03:00
|
|
|
CheckConfig(check_config::CheckConfigSubCommand),
|
2022-08-06 03:07:12 +03:00
|
|
|
// TODO: sub command to downgrade migrations?
|
|
|
|
// TODO: sub command to add new api keys to an existing user?
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> anyhow::Result<()> {
|
|
|
|
// if RUST_LOG isn't set, configure a default
|
|
|
|
// TODO: is there a better way to do this?
|
|
|
|
if std::env::var("RUST_LOG").is_err() {
|
|
|
|
// std::env::set_var("RUST_LOG", "info,web3_proxy=debug,web3_proxy_cli=debug");
|
|
|
|
std::env::set_var("RUST_LOG", "info,web3_proxy=debug,web3_proxy_cli=debug");
|
|
|
|
}
|
|
|
|
|
|
|
|
// install global collector configured based on RUST_LOG env var.
|
|
|
|
tracing_subscriber::fmt()
|
|
|
|
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
|
|
|
|
.compact()
|
|
|
|
.init();
|
|
|
|
|
|
|
|
// this probably won't matter for us in docker, but better safe than sorry
|
|
|
|
fdlimit::raise_fd_limit();
|
|
|
|
|
|
|
|
let cli_config: TopConfig = argh::from_env();
|
|
|
|
|
|
|
|
match cli_config.sub_command {
|
|
|
|
SubCommand::CreateUser(x) => {
|
2022-09-02 23:16:20 +03:00
|
|
|
let db = get_migrated_db(cli_config.db_url, 1, 1).await?;
|
2022-08-06 03:07:12 +03:00
|
|
|
|
|
|
|
x.main(&db).await
|
|
|
|
}
|
2022-08-15 20:50:14 +03:00
|
|
|
SubCommand::CheckConfig(x) => x.main().await,
|
2022-08-06 03:07:12 +03:00
|
|
|
}
|
|
|
|
}
|