From e42261bac87e8cc93735a9c50704233b6dca94ac Mon Sep 17 00:00:00 2001 From: Josh Knapp Date: Sat, 14 Nov 2026 15:42:28 -0800 Subject: [PATCH] refactor(aws): one definition of the keychain id rule Co-Authored-By: Claude Opus 5.5 --- app/src-tauri/src/commands/marketplace_commands.rs | 5 +---- app/src-tauri/src/storage/secure.rs | 9 ++++----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/app/src-tauri/src/commands/marketplace_commands.rs b/app/src-tauri/src/commands/marketplace_commands.rs index c59a127..b7dfca4 100644 --- a/app/src-tauri/src/commands/marketplace_commands.rs +++ b/app/src-tauri/src/commands/marketplace_commands.rs @@ -173,10 +173,7 @@ pub(crate) mod ops { /// directories, so an id from outside (an import) must be the shape the /// commands mint: a UUID-like `[A-Za-z0-9-]{1,64}`. pub fn validate_id(id: &str) -> Result<(), String> { - let ok = !id.is_empty() - && id.len() <= 64 - && id.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'-'); - if ok { + if crate::storage::secure::is_valid_connection_id(id) { Ok(()) } else { Err("An account or marketplace id is malformed.".to_string()) diff --git a/app/src-tauri/src/storage/secure.rs b/app/src-tauri/src/storage/secure.rs index 4b29dad..7c63c4c 100644 --- a/app/src-tauri/src/storage/secure.rs +++ b/app/src-tauri/src/storage/secure.rs @@ -384,10 +384,7 @@ const MARKETPLACE_TOKEN_SERVICE_PREFIX: &str = "triple-c-marketplace-account-"; /// The service name for one account. Ids are uuids; anything else is refused /// before a keychain entry is constructed. fn marketplace_token_service(account_id: &str) -> Result { - let ok = !account_id.is_empty() - && account_id.len() <= 64 - && account_id.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'-'); - if !ok { + if !is_valid_connection_id(account_id) { return Err(format!("Invalid marketplace account id {:?}", account_id)); } Ok(format!("{}{}", MARKETPLACE_TOKEN_SERVICE_PREFIX, account_id)) @@ -440,7 +437,9 @@ impl std::fmt::Debug for AwsKeys { } /// Whether `id` may be used as a connection id / keyring reference: 1..=64 of -/// `[A-Za-z0-9-]`. The same rule as marketplace account ids. +/// `[A-Za-z0-9-]`. The single definition of the keychain-id rule: marketplace +/// account ids, AWS connection ids and `commands::marketplace_commands`'s +/// `validate_id` all go through it. pub fn is_valid_connection_id(id: &str) -> bool { !id.is_empty() && id.len() <= 64