cdk_mint_rpc/mint_rpc_cli/subcommands/update_urls.rs
1use anyhow::Result;
2use clap::Args;
3use tonic::Request;
4
5use crate::{InterceptedCdkMintClient, UpdateUrlRequest};
6
7/// Command to add a URL to the mint's list of endpoints
8///
9/// This command adds a new URL to the mint's list of available endpoints.
10/// Multiple URLs allow clients to access the mint through different endpoints,
11/// providing redundancy and flexibility.
12#[derive(Args, Debug)]
13pub struct AddUrlCommand {
14 /// The URL to add to the mint's endpoints
15 url: String,
16}
17
18/// Executes the add_url command against the mint server
19///
20/// This function sends an RPC request to add a new URL to the mint's list of endpoints.
21///
22/// # Arguments
23/// * `client` - The RPC client used to communicate with the mint
24/// * `sub_command_args` - The URL to add to the mint
25pub async fn add_url(
26 client: &mut InterceptedCdkMintClient,
27 sub_command_args: &AddUrlCommand,
28) -> Result<()> {
29 let _response = client
30 .add_url(Request::new(UpdateUrlRequest {
31 url: sub_command_args.url.clone(),
32 }))
33 .await?;
34
35 Ok(())
36}
37
38/// Command to remove a URL from the mint's list of endpoints
39///
40/// This command removes an existing URL from the mint's list of available endpoints.
41/// This can be used to retire endpoints that are no longer in use or available.
42#[derive(Args, Debug)]
43pub struct RemoveUrlCommand {
44 /// The URL to remove from the mint's endpoints
45 url: String,
46}
47
48/// Executes the remove_url command against the mint server
49///
50/// This function sends an RPC request to remove an existing URL from the mint's list of endpoints.
51///
52/// # Arguments
53/// * `client` - The RPC client used to communicate with the mint
54/// * `sub_command_args` - The URL to remove from the mint
55pub async fn remove_url(
56 client: &mut InterceptedCdkMintClient,
57 sub_command_args: &RemoveUrlCommand,
58) -> Result<()> {
59 let _response = client
60 .remove_url(Request::new(UpdateUrlRequest {
61 url: sub_command_args.url.clone(),
62 }))
63 .await?;
64
65 Ok(())
66}