(os: &mut Os, whoami: bool)
| 343 | } |
| 344 | |
| 345 | async fn select_profile_interactive(os: &mut Os, whoami: bool) -> Result<()> { |
| 346 | let mut spinner = Spinner::new(vec![ |
| 347 | SpinnerComponent::Spinner, |
| 348 | SpinnerComponent::Text(" Fetching profiles...".into()), |
| 349 | ]); |
| 350 | let profiles = list_available_profiles(&os.env, &os.fs, &mut os.database).await?; |
| 351 | if profiles.is_empty() { |
| 352 | info!("Available profiles was empty"); |
| 353 | return Ok(()); |
| 354 | } |
| 355 | |
| 356 | let sso_region = os.database.get_idc_region()?; |
| 357 | let total_profiles = profiles.len() as i64; |
| 358 | |
| 359 | if whoami && profiles.len() == 1 { |
| 360 | if let Some(profile_region) = profiles[0].arn.split(':').nth(3) { |
| 361 | os.telemetry |
| 362 | .send_profile_state( |
| 363 | QProfileSwitchIntent::Update, |
| 364 | profile_region.to_string(), |
| 365 | TelemetryResult::Succeeded, |
| 366 | sso_region, |
| 367 | ) |
| 368 | .ok(); |
| 369 | } |
| 370 | |
| 371 | spinner.stop_with_message(String::new()); |
| 372 | os.database.set_auth_profile(&profiles[0])?; |
| 373 | return Ok(()); |
| 374 | } |
| 375 | |
| 376 | let mut items: Vec<String> = profiles |
| 377 | .iter() |
| 378 | .map(|p| format!("{} (arn: {})", p.profile_name, p.arn)) |
| 379 | .collect(); |
| 380 | let active_profile = os.database.get_auth_profile()?; |
| 381 | |
| 382 | if let Some(default_idx) = active_profile |
| 383 | .as_ref() |
| 384 | .and_then(|active| profiles.iter().position(|p| p.arn == active.arn)) |
| 385 | { |
| 386 | items[default_idx] = format!("{} (active)", items[default_idx].as_str()); |
| 387 | } |
| 388 | |
| 389 | spinner.stop_with_message(String::new()); |
| 390 | let selected = Select::with_theme(&crate::util::dialoguer_theme()) |
| 391 | .with_prompt("Select an IAM Identity Center profile") |
| 392 | .items(&items) |
| 393 | .default(0) |
| 394 | .interact_opt()?; |
| 395 | |
| 396 | match selected { |
| 397 | Some(i) => { |
| 398 | let chosen = &profiles[i]; |
| 399 | eprintln!("Profile set"); |
| 400 | os.database.set_auth_profile(chosen)?; |
| 401 | |
| 402 | if let Some(profile_region) = chosen.arn.split(':').nth(3) { |
no test coverage detected