lints and copypasta

This commit is contained in:
Bryan Stitt 2022-08-15 17:50:14 +00:00
parent 0cfe5bbb8a
commit 19626a8190
7 changed files with 17 additions and 9 deletions

@ -3,7 +3,7 @@
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "role")]
pub enum Role {
#[sea_orm(string_value = "owner")]

@ -4,7 +4,7 @@ use super::sea_orm_active_enums::Role;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "secondary_user")]
pub struct Model {
#[sea_orm(primary_key)]

@ -3,7 +3,7 @@
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "user")]
pub struct Model {
#[sea_orm(primary_key)]

@ -4,7 +4,7 @@ use sea_orm::entity::prelude::*;
use sea_orm::prelude::Uuid;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "user_keys")]
pub struct Model {
#[sea_orm(primary_key)]

@ -1,6 +1,6 @@
use argh::FromArgs;
#[derive(FromArgs, PartialEq, Debug)]
#[derive(FromArgs, PartialEq, Eq, Debug)]
/// Second subcommand.
#[argh(subcommand, name = "check_config")]
pub struct CheckConfigSubCommand {

@ -1,12 +1,13 @@
use anyhow::Context;
use argh::FromArgs;
use entities::{user, user_keys};
use ethers::types::Address;
use ethers::prelude::Address;
use sea_orm::ActiveModelTrait;
use tracing::info;
use uuid::Uuid;
use web3_proxy::users::new_api_key;
#[derive(FromArgs, PartialEq, Debug)]
#[derive(FromArgs, PartialEq, Debug, Eq)]
/// Create a new user and api key
#[argh(subcommand, name = "create_user")]
pub struct CreateUserSubCommand {
@ -17,6 +18,11 @@ pub struct CreateUserSubCommand {
#[argh(option)]
/// the user's optional email
email: Option<String>,
#[argh(option)]
/// the user's first api key.
/// If none given, one will be generated randomly
api_key: Option<Uuid>,
}
impl CreateUserSubCommand {
@ -39,10 +45,12 @@ 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
let uk = user_keys::ActiveModel {
user_id: sea_orm::Set(u.id),
api_key: sea_orm::Set(new_api_key()),
api_key: sea_orm::Set(api_key),
requests_per_minute: sea_orm::Set(6_000_000),
..Default::default()
};

@ -54,6 +54,6 @@ async fn main() -> anyhow::Result<()> {
x.main(&db).await
}
SubCommand::Two(x) => x.main().await,
SubCommand::CheckConfig(x) => x.main().await,
}
}