Skip to content

Commit

Permalink
feat: add update profile cli command
Browse files Browse the repository at this point in the history
  • Loading branch information
thevaibhav-dixit committed Mar 28, 2024
1 parent 77def45 commit ad439e2
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/cli/api_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,42 @@ impl ApiClient {
output_json(response)
}

pub async fn update_profile(
&self,
id: String,
addresses: Option<Vec<String>>,
max_payout: Option<u64>,
) -> 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
Expand Down
32 changes: 32 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Url>,
#[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<Vec<String>>,
/// The max payout amount in Satoshi
#[clap(short, long)]
max_payout: Option<u64>,
},
/// List all profiles
ListProfiles {
#[clap(
Expand Down Expand Up @@ -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?;
Expand Down

0 comments on commit ad439e2

Please sign in to comment.