Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions bottlecap/src/secrets/decrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ use tracing::debug;
use tracing::error;

pub async fn resolve_secrets(config: Arc<Config>, aws_config: &AwsConfig) -> Option<String> {
if !config.api_key.is_empty() {
debug!("DD_API_KEY found, not trying to resolve secrets");
Some(config.api_key.clone())
} else if !config.api_key_secret_arn.is_empty() || !config.kms_api_key.is_empty() {
if !config.api_key_secret_arn.is_empty() || !config.kms_api_key.is_empty() {
let before_decrypt = Instant::now();

let client = match Client::builder().use_rustls_tls().build() {
Expand All @@ -27,10 +24,10 @@ pub async fn resolve_secrets(config: Arc<Config>, aws_config: &AwsConfig) -> Opt
}
};

let decrypted_key = if config.api_key_secret_arn.is_empty() {
decrypt_aws_kms(&client, config.kms_api_key.clone(), aws_config).await
let decrypted_key = if config.kms_api_key.is_empty() {
decrypt_aws_kms(&client, config.api_key_secret_arn.clone(), aws_config).await
} else {
decrypt_aws_sm(&client, config.api_key_secret_arn.clone(), aws_config).await
decrypt_aws_sm(&client, config.kms_api_key.clone(), aws_config).await
};

debug!("Decrypt took {}ms", before_decrypt.elapsed().as_millis());
Expand All @@ -43,7 +40,7 @@ pub async fn resolve_secrets(config: Arc<Config>, aws_config: &AwsConfig) -> Opt
}
}
} else {
return None;
Some(config.api_key.clone())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this resolve to None since the API key wouldn't be set either?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean.
Why shouldn't it be set? And how would it resolve to None?
I moved the cleanup code inside, so maybe it's less confusing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's empty, we should send None

}
}

Expand Down
Loading