Skip to content

Commit 8e78b28

Browse files
committed
azure impl and fix aws
1 parent 7266d92 commit 8e78b28

6 files changed

Lines changed: 36 additions & 14 deletions

File tree

src/Backups/registerBackupEngineAzureBlobStorage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void registerBackupEngineAzureBlobStorage(BackupFactory & factory)
9696
auto account_name = args[3].safeGet<String>();
9797
auto account_key = args[4].safeGet<String>();
9898

99-
connection_params.auth_method = std::make_shared<Azure::Storage::StorageSharedKeyCredential>(account_name, account_key);
99+
connection_params.auth_method = std::make_shared<AzureBlobStorage::StorageSharedKeyCredentialWithAccessToSecret>(account_name, account_key);
100100
connection_params.client_options = AzureBlobStorage::getClientOptions(*request_settings, /*for_disk=*/ true);
101101
}
102102
else

src/Disks/ObjectStorages/AzureBlobStorage/AzureBlobStorageCommon.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ std::unique_ptr<ServiceClient> ConnectionParams::createForService() const
146146
{
147147
if constexpr (std::is_same_v<T, ConnectionString>)
148148
return std::make_unique<ServiceClient>(ServiceClient::CreateFromConnectionString(auth.toUnderType(), client_options));
149+
else if constexpr (std::is_same_v<T, std::shared_ptr<StorageSharedKeyCredentialWithAccessToSecret>>)
150+
return std::make_unique<ServiceClient>(endpoint.getServiceEndpoint(), auth->impl, client_options);
149151
else
150152
return std::make_unique<ServiceClient>(endpoint.getServiceEndpoint(), auth, client_options);
151153
}, auth_method);
@@ -166,6 +168,11 @@ std::unique_ptr<ContainerClient> ConnectionParams::createForContainer() const
166168
auto raw_client = RawContainerClient::CreateFromConnectionString(auth.toUnderType(), endpoint.container_name, client_options);
167169
return std::make_unique<ContainerClient>(std::move(raw_client), endpoint.prefix);
168170
}
171+
else if constexpr (std::is_same_v<T, std::shared_ptr<StorageSharedKeyCredentialWithAccessToSecret>>)
172+
{
173+
RawContainerClient raw_client{endpoint.getContainerEndpoint(), auth->impl, client_options};
174+
return std::make_unique<ContainerClient>(std::move(raw_client), endpoint.prefix);
175+
}
169176
else
170177
{
171178
RawContainerClient raw_client{endpoint.getContainerEndpoint(), auth, client_options};
@@ -369,7 +376,7 @@ AuthMethod getAuthMethod(const Poco::Util::AbstractConfiguration & config, const
369376
{
370377
if (config.has(config_prefix + ".account_key") && config.has(config_prefix + ".account_name"))
371378
{
372-
return std::make_shared<Azure::Storage::StorageSharedKeyCredential>(
379+
return std::make_shared<StorageSharedKeyCredentialWithAccessToSecret>(
373380
config.getString(config_prefix + ".account_name"),
374381
config.getString(config_prefix + ".account_key")
375382
);

src/Disks/ObjectStorages/AzureBlobStorage/AzureBlobStorageCommon.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,25 @@ using ServiceClient = Azure::Storage::Blobs::BlobServiceClient;
126126
using BlobClientOptions = Azure::Storage::Blobs::BlobClientOptions;
127127
using ConnectionString = StrongTypedef<String, struct ConnectionStringTag>;
128128

129+
/*
130+
* In order to implement `AzureObjectStorage::getIdentityFingerprint()` for `StorageSharedKeyCredential`, we need to
131+
* access `account_key`. The problem is that `Azure::Storage::StorageSharedKeyCredential::AccessKey` is private and the
132+
* class is final inside `Azure SDK`.
133+
*/
134+
struct StorageSharedKeyCredentialWithAccessToSecret
135+
{
136+
StorageSharedKeyCredentialWithAccessToSecret(const String & account_name_, const String & account_key_)
137+
: account_name(account_name_), account_key(account_key_), impl(std::make_shared<Azure::Storage::StorageSharedKeyCredential>(account_name, account_key))
138+
{}
139+
140+
const std::string account_name;
141+
const std::string account_key;
142+
std::shared_ptr<Azure::Storage::StorageSharedKeyCredential> impl;
143+
};
144+
129145
using AuthMethod = std::variant<
130146
ConnectionString,
131-
std::shared_ptr<Azure::Storage::StorageSharedKeyCredential>,
147+
std::shared_ptr<StorageSharedKeyCredentialWithAccessToSecret>,
132148
std::shared_ptr<Azure::Identity::WorkloadIdentityCredential>,
133149
std::shared_ptr<Azure::Identity::ManagedIdentityCredential>>;
134150

src/Disks/ObjectStorages/AzureBlobStorage/AzureObjectStorage.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,30 +156,29 @@ ObjectStorageIteratorPtr AzureObjectStorage::iterate(const std::string & path_pr
156156
return std::make_shared<AzureIteratorAsync>(path_prefix, client_ptr, max_keys ? max_keys : settings_ptr->list_object_keys_size);
157157
}
158158

159+
/*
160+
* Only `ConnectionString` and `StorageSharedKeyCredential` auth methods are supported for now.
161+
*/
159162
std::optional<std::string> AzureObjectStorage::getIdentityFingerprint() const
160163
{
161164
std::optional<std::string> fingerprint;
162165

163-
std::visit([&fingerprint](const auto & auth) {
166+
std::visit([&fingerprint](const auto & auth)
167+
{
164168
using T = std::decay_t<decltype(auth)>;
165169

166170
if constexpr (std::is_same_v<T, AzureBlobStorage::ConnectionString>)
167171
{
168172
auto connection_string_parts = Azure::Storage::_internal::ParseConnectionString(auth);
169-
fingerprint = std::to_string(std::hash<std::string>()(connection_string_parts.AccountName));
173+
fingerprint = connection_string_parts.AccountName + connection_string_parts.AccountKey;
170174
}
171-
else if constexpr (std::is_same_v<T, std::shared_ptr<Azure::Storage::StorageSharedKeyCredential>>)
175+
else if constexpr (std::is_same_v<T, std::shared_ptr<AzureBlobStorage::StorageSharedKeyCredentialWithAccessToSecret>>)
172176
{
173177
if (auth)
174178
{
175-
fingerprint = std::to_string(std::hash<std::string>()(auth->AccountName));
179+
fingerprint = auth->account_name + auth->account_key;
176180
}
177181
}
178-
/// I am not sure what to do with the other auth methods, needs further investigation
179-
// else if constexpr (std::is_same_v<T, std::shared_ptr<Azure::Identity::WorkloadIdentityCredential>>) {
180-
// }
181-
// else if constexpr (std::is_same_v<T, std::shared_ptr<Azure::Identity::ManagedIdentityCredential>>) {
182-
// }
183182
}, auth_method);
184183

185184
if (!fingerprint)

src/Disks/ObjectStorages/S3/S3ObjectStorage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ std::optional<std::string> S3ObjectStorage::getIdentityFingerprint() const
168168
{
169169
const auto credentials = client.get()->getCredentials();
170170

171-
return getName() + credentials.GetAWSAccessKeyId();
171+
return getName() + credentials.GetAWSAccessKeyId() + credentials.GetAWSSecretKey();
172172
}
173173

174174
std::unique_ptr<ReadBufferFromFileBase> S3ObjectStorage::readObject( /// NOLINT

src/Storages/ObjectStorage/Azure/Configuration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static AzureBlobStorage::ConnectionParams getConnectionParams(
117117
{
118118
connection_params.endpoint.storage_account_url = connection_url;
119119
connection_params.endpoint.container_name = container_name;
120-
connection_params.auth_method = std::make_shared<Azure::Storage::StorageSharedKeyCredential>(*account_name, *account_key);
120+
connection_params.auth_method = std::make_shared<AzureBlobStorage::StorageSharedKeyCredentialWithAccessToSecret>(*account_name, *account_key);
121121
connection_params.client_options = AzureBlobStorage::getClientOptions(*request_settings, /*for_disk=*/ false);
122122
}
123123
else

0 commit comments

Comments
 (0)