optional config in web3_proxy_cli

This commit is contained in:
Bryan Stitt 2022-11-14 19:35:33 +00:00
parent ee35c15ff4
commit 0460d74c2f
2 changed files with 29 additions and 6 deletions

@ -237,6 +237,8 @@ These are roughly in order of completition
- [x] flamegraphs show 52% of the time to be in tracing. replace with simpler logging
- [x] add optional display name to rpc configs
- [x] add locking around running migrations
- [x] cli tool for checking config
- [x] web3_proxy_cli command should read database settings from config
- [-] add configurable size limits to all the Caches
- instead of configuring each cache with MB sizes, have one value for total memory footprint and then percentages for each cache
- [ ] add block timestamp to the /status page
@ -407,7 +409,6 @@ in another repo: event subscriber
- after looking at my request logs, i think its worth doing this. no point hitting the backends with requests for blocks multiple times. will also help with cache hit rates since we can keep recent blocks in a separate cache
- [ ] Public bsc server got “0” for block data limit (ninicoin)
- [ ] cli tool for resetting api keys
- [ ] cli tool for checking config
- [ ] benchmarks of the different Cache implementations (futures vs dash)
- [ ] Advanced load testing scripts so we can find optimal cost servers
- [ ] benchmarks from https://github.com/llamafolio/llamafolio-api/
@ -499,7 +500,6 @@ in another repo: event subscriber
- [ ] web3 on rpc1 exited without errors. maybe promote some shutdown messages from debug to info?
- [ ] better handling for offline http servers
- if we get a connection refused, we should remove the server's block info so it is taken out of rotation
- [ ] web3_proxy_cli command should read database settings from config
- [ ] how should we handle reverting transactions? they won't confirm for a while after we send them
- [ ] allow configuration of the expiration time of bearer tokens. currently defaults to 4 weeks
- [ ] emit stat when an IP/key goes over rate limits

@ -2,13 +2,22 @@ mod check_config;
mod clear_migration_lock;
mod create_user;
use std::fs;
use argh::FromArgs;
use web3_proxy::app::{get_db, get_migrated_db};
use web3_proxy::{
app::{get_db, get_migrated_db},
config::TopConfig,
};
#[derive(Debug, FromArgs)]
/// Command line interface for admins to interact with web3_proxy
pub struct TopConfig {
/// what database the client should connect to
pub struct CliConfig {
/// path to the application config (optional).
#[argh(option)]
pub config: Option<String>,
/// if no config, what database the client should connect to. Defaults to dev db.
#[argh(
option,
default = "\"mysql://root:dev_web3_proxy@127.0.0.1:13306/dev_web3_proxy\".to_string()"
@ -28,6 +37,7 @@ enum SubCommand {
DropMigrationLock(clear_migration_lock::DropMigrationLockSubCommand),
// TODO: sub command to downgrade migrations?
// TODO: sub command to add new api keys to an existing user?
// TODO: sub command to change a user's tier
}
#[tokio::main]
@ -44,7 +54,20 @@ async fn main() -> anyhow::Result<()> {
// 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();
let mut cli_config: CliConfig = argh::from_env();
let _top_config = if let Some(top_config_path) = cli_config.config.clone() {
let top_config: String = fs::read_to_string(top_config_path)?;
let top_config: TopConfig = toml::from_str(&top_config)?;
if let Some(top_config_db_url) = top_config.app.db_url.clone() {
cli_config.db_url = top_config_db_url;
}
Some(top_config)
} else {
None
};
match cli_config.sub_command {
SubCommand::CreateUser(x) => {