1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 11:36:03 +01:00

libstore: Make AwsAuthError more legible

Instead of the cryptic:

> error: Failed to resolve AWS credentials: error code 6153`

We now get more legible:

> error: AWS authentication error: 'Valid credentials could not be sourced by the IMDS provider' (6153)
This commit is contained in:
Sergei Zimmerman 2025-10-16 21:48:13 +03:00
parent dc03c6a812
commit 33e94fe19f
No known key found for this signature in database
3 changed files with 22 additions and 6 deletions

View file

@ -22,6 +22,12 @@
namespace nix { namespace nix {
AwsAuthError::AwsAuthError(int errorCode)
: Error("AWS authentication error: '%s' (%d)", aws_error_str(errorCode), errorCode)
, errorCode(errorCode)
{
}
namespace { namespace {
static AwsCredentials getCredentialsFromProvider(std::shared_ptr<Aws::Crt::Auth::ICredentialsProvider> provider) static AwsCredentials getCredentialsFromProvider(std::shared_ptr<Aws::Crt::Auth::ICredentialsProvider> provider)
@ -35,8 +41,7 @@ static AwsCredentials getCredentialsFromProvider(std::shared_ptr<Aws::Crt::Auth:
provider->GetCredentials([prom](std::shared_ptr<Aws::Crt::Auth::Credentials> credentials, int errorCode) { provider->GetCredentials([prom](std::shared_ptr<Aws::Crt::Auth::Credentials> credentials, int errorCode) {
if (errorCode != 0 || !credentials) { if (errorCode != 0 || !credentials) {
prom->set_exception( prom->set_exception(std::make_exception_ptr(AwsAuthError(errorCode)));
std::make_exception_ptr(AwsAuthError("Failed to resolve AWS credentials: error code %d", errorCode)));
} else { } else {
auto accessKeyId = Aws::Crt::ByteCursorToStringView(credentials->GetAccessKeyId()); auto accessKeyId = Aws::Crt::ByteCursorToStringView(credentials->GetAccessKeyId());
auto secretAccessKey = Aws::Crt::ByteCursorToStringView(credentials->GetSecretAccessKey()); auto secretAccessKey = Aws::Crt::ByteCursorToStringView(credentials->GetSecretAccessKey());

View file

@ -34,10 +34,19 @@ struct AwsCredentials
} }
}; };
/** class AwsAuthError : public Error
* Exception thrown when AWS authentication fails {
*/ std::optional<int> errorCode;
MakeError(AwsAuthError, Error);
public:
using Error::Error;
AwsAuthError(int errorCode);
std::optional<int> getErrorCode() const
{
return errorCode;
}
};
class AwsCredentialProvider class AwsCredentialProvider
{ {

View file

@ -158,6 +158,8 @@ curl_s3_store_opt = get_option('curl-s3-store').require(
if curl_s3_store_opt.enabled() if curl_s3_store_opt.enabled()
deps_other += aws_crt_cpp deps_other += aws_crt_cpp
aws_c_common = cxx.find_library('aws-c-common', required : true)
deps_other += aws_c_common
endif endif
configdata_pub.set('NIX_WITH_AWS_AUTH', curl_s3_store_opt.enabled().to_int()) configdata_pub.set('NIX_WITH_AWS_AUTH', curl_s3_store_opt.enabled().to_int())