Skip to content

Commit 665e97e

Browse files
authored
fix: Restrict profile command to idc users only (#3306)
* only allow idc user call profile * delete imports * change fun type
1 parent 2bda8e4 commit 665e97e

File tree

4 files changed

+10
-17
lines changed

4 files changed

+10
-17
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ use aws_smithy_runtime_api::client::identity::{
4141
};
4242
use aws_smithy_types::error::display::DisplayErrorContext;
4343
use aws_types::region::Region;
44-
use eyre::{
45-
Result,
46-
eyre,
47-
};
44+
use eyre::Result;
4845
use time::OffsetDateTime;
4946
use tracing::{
5047
debug,
@@ -614,14 +611,14 @@ impl ResolveIdentity for BearerResolver {
614611
}
615612
}
616613

617-
pub async fn is_idc_user(database: &Database) -> Result<bool> {
614+
pub async fn is_idc_user(database: &Database) -> bool {
618615
if cfg!(test) {
619-
return Ok(false);
616+
return false;
620617
}
621618
if let Ok(Some(token)) = BuilderIdToken::load(database).await {
622-
Ok(token.token_type() == TokenType::IamIdentityCenter)
619+
token.token_type() == TokenType::IamIdentityCenter
623620
} else {
624-
Err(eyre!("No auth token found - is the user signed in?"))
621+
false
625622
}
626623
}
627624

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ pub struct SubscribeArgs {
3737

3838
impl SubscribeArgs {
3939
pub async fn execute(self, os: &mut Os, session: &mut ChatSession) -> Result<ChatState, ChatError> {
40-
if is_idc_user(&os.database)
41-
.await
42-
.map_err(|e| ChatError::Custom(e.to_string().into()))?
43-
{
40+
if is_idc_user(&os.database).await {
4441
execute!(
4542
session.stderr,
4643
StyledText::warning_fg(),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3737,7 +3737,7 @@ enum ActualSubscriptionStatus {
37373737
//
37383738
// Also, it is currently not possible to subscribe or re-subscribe via console, only IDE/CLI.
37393739
async fn get_subscription_status(os: &mut Os) -> Result<ActualSubscriptionStatus> {
3740-
if is_idc_user(&os.database).await? {
3740+
if is_idc_user(&os.database).await {
37413741
return Ok(ActualSubscriptionStatus::Active);
37423742
}
37433743

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use crate::auth::builder_id::{
3232
BuilderIdToken,
3333
PollCreateToken,
3434
TokenType,
35+
is_idc_user,
3536
poll_create_token,
3637
start_device_authorization,
3738
};
@@ -338,10 +339,8 @@ pub enum LicenseType {
338339
}
339340

340341
pub async fn profile(os: &mut Os) -> Result<ExitCode> {
341-
if let Ok(Some(token)) = BuilderIdToken::load(&os.database).await {
342-
if matches!(token.token_type(), TokenType::BuilderId) {
343-
bail!("This command is only available for Pro users");
344-
}
342+
if !is_idc_user(&os.database).await {
343+
bail!("This command is only available for IAM Identity Center users");
345344
}
346345

347346
select_profile_interactive(os, false).await?;

0 commit comments

Comments
 (0)