diff --git a/src/cli/api_client.rs b/src/cli/api_client.rs index 14bfef52..e8f593f8 100644 --- a/src/cli/api_client.rs +++ b/src/cli/api_client.rs @@ -78,6 +78,42 @@ impl ApiClient { output_json(response) } + pub async fn update_profile( + &self, + id: String, + addresses: Option>, + max_payout: Option, + ) -> anyhow::Result<()> { + let spending_policy = match (addresses, max_payout) { + (Some(allowed_payout_addresses), Some(max_payout_sats)) => { + Some(proto::SpendingPolicy { + allowed_payout_addresses, + max_payout_sats: Some(max_payout_sats), + }) + } + (Some(allowed_payout_addresses), None) => Some(proto::SpendingPolicy { + allowed_payout_addresses, + max_payout_sats: None, + }), + (None, Some(max_payout_sats)) => Some(proto::SpendingPolicy { + allowed_payout_addresses: Vec::new(), + max_payout_sats: Some(max_payout_sats), + }), + (None, None) => None, + }; + + let request = tonic::Request::new(proto::UpdateProfileRequest { + id, + spending_policy, + }); + let response = self + .connect() + .await? + .update_profile(self.inject_auth_token(request)?) + .await?; + output_json(response) + } + pub async fn list_profiles(&self) -> anyhow::Result<()> { let request = tonic::Request::new(proto::ListProfilesRequest {}); let response = self diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 6c8504f4..4eb7f973 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -85,6 +85,28 @@ enum Command { #[clap(short, long)] name: String, }, + /// Update a profile + UpdateProfile { + #[clap( + short, + long, + value_parser, + default_value = "http://localhost:2742", + env = "BRIA_API_URL" + )] + url: Option, + #[clap(env = "BRIA_API_KEY", default_value = "")] + api_key: String, + /// The id to update + #[clap(short, long)] + id: String, + /// Allowed payout addresses for the spending policy + #[clap(short, long)] + addresses: Option>, + /// The max payout amount in Satoshi + #[clap(short, long)] + max_payout: Option, + }, /// List all profiles ListProfiles { #[clap( @@ -733,6 +755,16 @@ pub async fn run() -> anyhow::Result<()> { let client = api_client(cli.bria_home, url, api_key); client.create_profile(name).await?; } + Command::UpdateProfile { + url, + api_key, + id, + addresses, + max_payout, + } => { + let client = api_client(cli.bria_home, url, api_key); + client.update_profile(id, addresses, max_payout).await?; + } Command::ListProfiles { url, api_key } => { let client = api_client(cli.bria_home, url, api_key); client.list_profiles().await?;