From 9fcf84c0e0ebb0f48cd1b2afefdef3e78c73d837 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Mon, 15 Aug 2022 19:28:15 +0000 Subject: [PATCH] better defaults on create_user --- .../src/bin/web3_proxy_cli/create_user.rs | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/web3_proxy/src/bin/web3_proxy_cli/create_user.rs b/web3_proxy/src/bin/web3_proxy_cli/create_user.rs index 09e90132..554548dd 100644 --- a/web3_proxy/src/bin/web3_proxy_cli/create_user.rs +++ b/web3_proxy/src/bin/web3_proxy_cli/create_user.rs @@ -7,6 +7,10 @@ use tracing::info; use uuid::Uuid; use web3_proxy::users::new_api_key; +fn default_rpm() -> usize { + 6_000_000 +} + #[derive(FromArgs, PartialEq, Debug, Eq)] /// Create a new user and api key #[argh(subcommand, name = "create_user")] @@ -19,10 +23,14 @@ pub struct CreateUserSubCommand { /// the user's optional email email: Option, - #[argh(option)] + #[argh(option, default = "new_api_key()")] /// the user's first api key. - /// If none given, one will be generated randomly - api_key: Option, + /// If none given, one will be generated randomly. + api_key: Uuid, + + #[argh(option, default = "default_rpm()")] + /// maximum requests per minute + rpm: usize, } impl CreateUserSubCommand { @@ -45,16 +53,16 @@ impl CreateUserSubCommand { info!("user #{}: {:?}", u.id, Address::from_slice(&u.address)); - let api_key = self.api_key.unwrap_or_else(new_api_key); - // create a key for the new user + // TODO: requests_per_minute should be configurable let uk = user_keys::ActiveModel { user_id: sea_orm::Set(u.id), - api_key: sea_orm::Set(api_key), + api_key: sea_orm::Set(self.api_key), requests_per_minute: sea_orm::Set(6_000_000), ..Default::default() }; + // TODO: if this fails, rever adding the user, too let uk = uk.insert(db).await.context("Failed saving new user key")?; info!("user key: {}", uk.api_key);