Skip to content

Commit c87e267

Browse files
committed
used from/into instead of a new function
1 parent 7792907 commit c87e267

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

crates/chat-cli/src/auth/builder_id.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,16 @@ pub enum TokenType {
273273
IamIdentityCenter,
274274
}
275275

276+
impl From<Option<&str>> for TokenType {
277+
fn from(start_url: Option<&str>) -> Self {
278+
match start_url {
279+
Some(url) if url == START_URL => TokenType::BuilderId,
280+
None => TokenType::BuilderId,
281+
Some(_) => TokenType::IamIdentityCenter,
282+
}
283+
}
284+
}
285+
276286
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
277287
pub struct BuilderIdToken {
278288
pub access_token: Secret,
@@ -494,7 +504,7 @@ impl BuilderIdToken {
494504
}
495505

496506
pub fn token_type(&self) -> TokenType {
497-
token_type_from_start_url(self.start_url.as_deref())
507+
TokenType::from(self.start_url.as_deref())
498508
}
499509

500510
/// Check if the token is for the internal amzn start URL (`https://amzn.awsapps.com/start`),
@@ -505,14 +515,6 @@ impl BuilderIdToken {
505515
}
506516
}
507517

508-
pub fn token_type_from_start_url(start_url: Option<&str>) -> TokenType {
509-
match start_url {
510-
Some(url) if url == START_URL => TokenType::BuilderId,
511-
None => TokenType::BuilderId,
512-
Some(_) => TokenType::IamIdentityCenter,
513-
}
514-
}
515-
516518
pub enum PollCreateToken {
517519
Pending,
518520
Complete,
@@ -568,7 +570,7 @@ pub async fn poll_create_token(
568570
error!(?err, "Failed to poll for builder id token");
569571

570572
// Send telemetry for device code failure
571-
let auth_method = match token_type_from_start_url(start_url.as_deref()) {
573+
let auth_method = match TokenType::from(start_url.as_deref()) {
572574
TokenType::BuilderId => "BuilderId",
573575
TokenType::IamIdentityCenter => "IdentityCenter",
574576
};

crates/chat-cli/src/cli/user.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl LoginArgs {
145145
tokio::select! {
146146
res = registration.finish(&client, Some(&mut os.database)) => {
147147
if let Err(err) = res {
148-
let auth_method = match crate::auth::builder_id::token_type_from_start_url(start_url.as_deref()) {
148+
let auth_method = match crate::auth::builder_id::TokenType::from(start_url.as_deref()) {
149149
crate::auth::builder_id::TokenType::BuilderId => "BuilderId",
150150
crate::auth::builder_id::TokenType::IamIdentityCenter => "IdentityCenter",
151151
};

0 commit comments

Comments
 (0)