Skip to content

Commit 245ba46

Browse files
committed
Add change-password command
1 parent 6c0fb4c commit 245ba46

4 files changed

Lines changed: 21 additions & 15 deletions

File tree

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ colored_json = { version = "5.0.0", default-features = false }
1616
rusqlite = { version = "0.32.1", default-features = false, features = ["bundled"] }
1717
dirs = { version = "6.0.0", default-features = false }
1818
serde_json = { version = "1.0.140", default-features = false, features = ["preserve_order"] }
19-
clap = { version = "4.5.36", default-features = false, features = ["std", "derive"] }
19+
clap = { version = "4.5.38", default-features = false, features = ["std", "derive", "help"] }
2020
serde = { version = "1.0.219", default-features = false, features = ["derive"] }

src/command/admin.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ pub fn add_admin(args: &AddAdminArgs) -> Result<()> {
3535
}
3636

3737
#[derive(Args)]
38-
pub struct SetPasswordArgs {
38+
pub struct ChangePasswordArgs {
39+
pub username: String,
3940
pub old_password: String,
4041
pub new_password: String,
4142
}
4243

43-
pub fn set_password(args: &SetPasswordArgs) -> Result<()> {
44+
pub fn change_password(args: &ChangePasswordArgs) -> Result<()> {
4445
rpc::call(
45-
"set_password",
46-
json!({"old_password": args.old_password, "new_password": args.new_password}),
46+
"change_password",
47+
json!({"username": args.username, "old_password": args.old_password, "new_password": args.new_password}),
4748
)?
4849
.print()
4950
}

src/main.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ use command::{
1111
mod command;
1212

1313
#[derive(Parser)]
14-
#[command(version, about)]
14+
#[command(version, about, long_about = None)]
1515
struct Cli {
16-
#[command(subcommand)]
17-
command: Option<Commands>,
1816
#[arg(short, long, action = clap::ArgAction::Count)]
1917
verbose: u8,
18+
#[command(subcommand)]
19+
command: Option<Commands>,
2020
}
2121

2222
#[derive(Subcommand)]
@@ -55,12 +55,13 @@ enum Commands {
5555
/// Generate category tags for a specific element id range
5656
GenerateElementCategories(GenerateElementCategoriesArgs),
5757

58+
// Auth - https://github.com/teambtcmap/btcmap-api/blob/master/docs/rpc-api/auth.md
59+
/// Change admin password. Knowledge of an old password is required
60+
ChangePassword(command::admin::ChangePasswordArgs),
5861
/// Login with your username and password and get an auth token
5962
Login(command::admin::LoginArgs),
6063
/// Create a new admin user. New admins have no permissions by default, use add-admin-action to allow certain acitons
6164
AddAdmin(command::admin::AddAdminArgs),
62-
/// Change admin password. Knowledge of an old password is required
63-
SetPassword(command::admin::SetPasswordArgs),
6465
/// Allow other admin to perform a certain action. You must be super admin to use this command
6566
AddAdminAction(command::admin::AddAdminActionArgs),
6667
/// Block other admin from using a certain action. You must be super admin to use this command
@@ -109,6 +110,10 @@ fn main() -> Result<()> {
109110
return command::setup::set_server(args);
110111
}
111112

113+
if let Some(Commands::ChangePassword(args)) = &cli.command {
114+
return command::admin::change_password(args);
115+
}
116+
112117
if let Some(Commands::Login(args)) = &cli.command {
113118
return command::admin::login(args);
114119
}
@@ -131,6 +136,7 @@ fn main() -> Result<()> {
131136
Commands::SetServer(_) => Err("supposed to be unreachable".into()),
132137
Commands::Login(_) => Err("supposed to be unreachable".into()),
133138
Commands::State(_) => Err("supposed to be unreachable".into()),
139+
Commands::ChangePassword(_) => Err("supposed to be unreachable".into()),
134140
// Element
135141
Commands::GetElement(args) => element::get_element(args),
136142
Commands::SetElementTag(args) => element::set_element_tag(args),
@@ -154,7 +160,6 @@ fn main() -> Result<()> {
154160
Commands::GenerateElementCategories(args) => element::generate_element_categories(args),
155161
// Admin
156162
Commands::AddAdmin(args) => command::admin::add_admin(args),
157-
Commands::SetPassword(args) => command::admin::set_password(args),
158163
Commands::AddAdminAction(args) => command::admin::add_admin_action(args),
159164
Commands::RemoveAdminAction(args) => command::admin::remove_admin_action(args),
160165
Commands::GenerateInvoice(args) => command::admin::generate_invoice(args),

0 commit comments

Comments
 (0)