# HG changeset patch # User Alain Mazy # Date 1621580573 -7200 # Node ID 1c3e34f5c5c65abb964b305f3355eb71b93bfef8 # Parent 8a1dfd2d790d25c0876de590f968a301190f66c4 AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager diff -r 8a1dfd2d790d -r 1c3e34f5c5c6 Aws/AwsS3StoragePlugin.cpp --- a/Aws/AwsS3StoragePlugin.cpp Mon Apr 26 09:42:30 2021 +0200 +++ b/Aws/AwsS3StoragePlugin.cpp Fri May 21 09:02:53 2021 +0200 @@ -234,18 +234,6 @@ return nullptr; } - if (!pluginSection.LookupStringValue(accessKey, "AccessKey")) - { - OrthancPlugins::LogError("AwsS3Storage/AccessKey configuration missing. Unable to initialize plugin"); - return nullptr; - } - - if (!pluginSection.LookupStringValue(secretKey, "SecretKey")) - { - OrthancPlugins::LogError("AwsS3Storage/SecretKey configuration missing. Unable to initialize plugin"); - return nullptr; - } - std::string endpoint = pluginSection.GetStringValue("Endpoint", ""); unsigned int connectTimeout = pluginSection.GetUnsignedIntegerValue("ConnectTimeout", 30); unsigned int requestTimeout = pluginSection.GetUnsignedIntegerValue("RequestTimeout", 1200); @@ -256,7 +244,6 @@ Aws::SDKOptions options; Aws::InitAPI(options); - Aws::Auth::AWSCredentials credentials(accessKey.c_str(), secretKey.c_str()); Aws::Client::ClientConfiguration configuration; configuration.region = region.c_str(); configuration.scheme = Aws::Http::Scheme::HTTPS; @@ -269,15 +256,31 @@ configuration.endpointOverride = endpoint.c_str(); } - Aws::S3::S3Client client(credentials, configuration, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never, virtualAddressing); + if (pluginSection.LookupStringValue(accessKey, "AccessKey") && pluginSection.LookupStringValue(secretKey, "SecretKey")) + { + OrthancPlugins::LogInfo("AWS S3 Storage: using credentials from the configuration file"); + Aws::Auth::AWSCredentials credentials(accessKey.c_str(), secretKey.c_str()); + + Aws::S3::S3Client client(credentials, configuration, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never, virtualAddressing); + + OrthancPlugins::LogInfo("AWS S3 storage initialized"); - OrthancPlugins::LogInfo("AWS S3 storage initialized"); + return new AwsS3StoragePlugin(client, bucketName, enableLegacyStorageStructure); + } + else + { + // when using default credentials, credentials are not checked at startup but only the first time you try to access the bucket ! + OrthancPlugins::LogInfo("AWS S3 Storage: using default credentials provider"); + Aws::S3::S3Client client(configuration, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never, virtualAddressing); - return new AwsS3StoragePlugin(client, bucketName, enableLegacyStorageStructure); + OrthancPlugins::LogInfo("AWS S3 storage initialized"); + + return new AwsS3StoragePlugin(client, bucketName, enableLegacyStorageStructure); + } } catch (const std::exception& e) { - OrthancPlugins::LogError(std::string("AzureBlobStorage plugin: failed to initialize plugin: ") + e.what()); + OrthancPlugins::LogError(std::string("AWS S3 Storage plugin: failed to initialize plugin: ") + e.what()); return nullptr; } diff -r 8a1dfd2d790d -r 1c3e34f5c5c6 NEWS --- a/NEWS Mon Apr 26 09:42:30 2021 +0200 +++ b/NEWS Fri May 21 09:02:53 2021 +0200 @@ -1,6 +1,7 @@ Pending changes in the mainline =============================== +* AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager 2021-04-26 - v 1.2.0 ====================