Skip to content

Commit

Permalink
CLI: simplify authentication logout client usage
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
svix-onelson committed Dec 20, 2024
1 parent 118fa0c commit d02b78b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
12 changes: 3 additions & 9 deletions svix-cli/src/cmds/api/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion svix-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?)?;
Expand Down

0 comments on commit d02b78b

Please sign in to comment.