Skip to content

Commit 4a4892b

Browse files
Merge pull request #253 from ptournaris-ai/feat/site-flag-on-auth-status
feat(auth): add --site flag to auth status command
2 parents 919fd10 + 79a14ef commit 4a4892b

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

src/main.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5610,7 +5610,12 @@ enum AuthActions {
56105610
/// Logout and clear tokens
56115611
Logout,
56125612
/// Check authentication status
5613-
Status,
5613+
Status {
5614+
/// Datadog site to check status for (e.g. datadoghq.eu, us3.datadoghq.com).
5615+
/// Overrides DD_SITE env var and config file. Defaults to datadoghq.com.
5616+
#[arg(long, value_name = "SITE")]
5617+
site: Option<String>,
5618+
},
56145619
/// Print access token (debug builds only)
56155620
#[cfg(debug_assertions)]
56165621
Token,
@@ -8194,7 +8199,12 @@ async fn main_inner() -> anyhow::Result<()> {
81948199
commands::auth::login(&cfg, resolved).await?
81958200
}
81968201
AuthActions::Logout => commands::auth::logout(&cfg).await?,
8197-
AuthActions::Status => commands::auth::status(&cfg)?,
8202+
AuthActions::Status { site } => {
8203+
if let Some(s) = site {
8204+
cfg.site = s;
8205+
}
8206+
commands::auth::status(&cfg)?
8207+
}
81988208
#[cfg(debug_assertions)]
81998209
AuthActions::Token => commands::auth::token(&cfg)?,
82008210
AuthActions::Refresh => commands::auth::refresh(&cfg).await?,

src/test_commands.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3170,3 +3170,43 @@ async fn test_llm_obs_spans_search_no_auth() {
31703170
assert!(result.is_err(), "should fail without auth");
31713171
cleanup_env();
31723172
}
3173+
3174+
// -------------------------------------------------------------------------
3175+
// Auth status --site flag
3176+
// -------------------------------------------------------------------------
3177+
3178+
#[test]
3179+
fn test_auth_status_accepts_site_flag() {
3180+
use clap::Parser;
3181+
3182+
let cli = crate::Cli::try_parse_from(["pup", "auth", "status", "--site", "datadoghq.eu"])
3183+
.expect("auth status --site should parse");
3184+
3185+
match cli.command {
3186+
crate::Commands::Auth { action } => match action {
3187+
crate::AuthActions::Status { site } => {
3188+
assert_eq!(site, Some("datadoghq.eu".to_string()));
3189+
}
3190+
_ => panic!("expected AuthActions::Status"),
3191+
},
3192+
_ => panic!("expected Commands::Auth"),
3193+
}
3194+
}
3195+
3196+
#[test]
3197+
fn test_auth_status_site_flag_is_optional() {
3198+
use clap::Parser;
3199+
3200+
let cli = crate::Cli::try_parse_from(["pup", "auth", "status"])
3201+
.expect("auth status without --site should parse");
3202+
3203+
match cli.command {
3204+
crate::Commands::Auth { action } => match action {
3205+
crate::AuthActions::Status { site } => {
3206+
assert_eq!(site, None);
3207+
}
3208+
_ => panic!("expected AuthActions::Status"),
3209+
},
3210+
_ => panic!("expected Commands::Auth"),
3211+
}
3212+
}

0 commit comments

Comments
 (0)