From d02b78be80be87dc27d68c041c950b3e56408857 Mon Sep 17 00:00:00 2001 From: Owen Nelson Date: Thu, 19 Dec 2024 18:16:12 -0800 Subject: [PATCH] CLI: simplify authentication logout client usage While looking at the SDK source, I noticed there's a `with_token` method on the Svix client. This means we no longer have to pass the CLI's config value down into the authentication command's `exec()` method. Instead, use the already constructed client and build a new one from it using the supplied token argument. --- svix-cli/src/cmds/api/authentication.rs | 12 +++--------- svix-cli/src/main.rs | 2 +- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/svix-cli/src/cmds/api/authentication.rs b/svix-cli/src/cmds/api/authentication.rs index e1a431883..474c970f3 100644 --- a/svix-cli/src/cmds/api/authentication.rs +++ b/svix-cli/src/cmds/api/authentication.rs @@ -2,7 +2,7 @@ use clap::{Args, Subcommand}; use colored_json::ColorMode; use svix::api::AppPortalAccessIn; -use crate::{cli_types::PostOptions, config::Config, get_client_options, json::JsonOf}; +use crate::{cli_types::PostOptions, json::JsonOf}; #[derive(Args)] #[command(args_conflicts_with_subcommands = true)] @@ -32,12 +32,7 @@ pub enum AuthenticationCommands { } impl AuthenticationCommands { - pub async fn exec( - self, - client: &svix::api::Svix, - color_mode: ColorMode, - cfg: &Config, - ) -> anyhow::Result<()> { + pub async fn exec(self, client: &svix::api::Svix, color_mode: ColorMode) -> anyhow::Result<()> { match self { Self::AppPortalAccess { app_id, @@ -60,8 +55,7 @@ impl AuthenticationCommands { } => { // We're not using the client received by `exec()` here since the token is an // arg, not whatever is configured for the cli otherwise. - let client = - svix::api::Svix::new(dashboard_auth_token, Some(get_client_options(cfg)?)); + let client = client.with_token(dashboard_auth_token); client .authentication() diff --git a/svix-cli/src/main.rs b/svix-cli/src/main.rs index 3079b0edb..f13313ca5 100644 --- a/svix-cli/src/main.rs +++ b/svix-cli/src/main.rs @@ -103,7 +103,7 @@ async fn main() -> Result<()> { RootCommands::Authentication(args) => { let cfg = cfg?; let client = get_client(&cfg)?; - args.command.exec(&client, color_mode, &cfg).await?; + args.command.exec(&client, color_mode).await?; } RootCommands::EventType(args) => { let client = get_client(&cfg?)?;