refactor(aws): one definition of the keychain id rule
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
60dad7b6b6
commit
e42261bac8
2 files changed
+5
-9
No files matched your search
@@ -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())
|
||||
|
||||
@@ -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<String, String> {
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user