Remove unused SharedKeyLitePolicy and connection string helpers in Tables. (#6268)
* Remove SharedKeyLitePolicy and connection string helpers in Tables. * Remove files and tests that are no longer necessary.
This commit is contained in:
parent
11ee6a6005
commit
4efb0fcb2d
@ -57,16 +57,13 @@ set(
|
||||
set(
|
||||
AZURE_DATA_TABLES_SOURCE
|
||||
src/account_sas_builder.cpp
|
||||
src/credentials/named_key_credential.cpp
|
||||
src/cryptography/hmacsha256.cpp
|
||||
src/models.cpp
|
||||
src/policies/shared_key_lite_policy.cpp
|
||||
src/policies/tenant_bearer_token_policy.cpp
|
||||
src/policies/timeout_policy.cpp
|
||||
src/private/hmacsha256.hpp
|
||||
src/private/package_version.hpp
|
||||
src/private/policies/service_version_policy.hpp
|
||||
src/private/policies/shared_key_lite_policy.hpp
|
||||
src/private/policies/tenant_bearer_token_policy.hpp
|
||||
src/private/policies/timeout_policy.hpp
|
||||
src/private/serializers.hpp
|
||||
|
||||
@ -8,9 +8,6 @@
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
namespace Azure { namespace Data { namespace Tables { namespace _detail { namespace Policies {
|
||||
class SharedKeyLitePolicy;
|
||||
}}}}} // namespace Azure::Data::Tables::_detail::Policies
|
||||
|
||||
namespace Azure { namespace Data { namespace Tables { namespace Sas {
|
||||
class AccountSasBuilder;
|
||||
@ -28,7 +25,7 @@ namespace Azure { namespace Data { namespace Tables { namespace Credentials {
|
||||
/**
|
||||
* @brief Initializes a new instance of the NamedKeyCredential.
|
||||
*
|
||||
* @param accountName Name of the account.
|
||||
* @param accountName Name of the account.
|
||||
* @param accountKey Access key of the
|
||||
* account.
|
||||
*/
|
||||
@ -38,10 +35,10 @@ namespace Azure { namespace Data { namespace Tables { namespace Credentials {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update the account's access key. This intended to be used when you've
|
||||
* @brief Update the account's access key. This intended to be used when you've
|
||||
* regenerated your account's access keys and want to update long lived clients.
|
||||
*
|
||||
* @param accountKey An account access key.
|
||||
* @param accountKey An account access key.
|
||||
*/
|
||||
void Update(std::string accountKey)
|
||||
{
|
||||
@ -55,7 +52,6 @@ namespace Azure { namespace Data { namespace Tables { namespace Credentials {
|
||||
const std::string AccountName;
|
||||
|
||||
private:
|
||||
friend class Azure::Data::Tables::_detail::Policies::SharedKeyLitePolicy;
|
||||
friend class Azure::Data::Tables::Sas::AccountSasBuilder;
|
||||
friend class Azure::Data::Tables::Sas::TablesSasBuilder;
|
||||
|
||||
@ -69,17 +65,4 @@ namespace Azure { namespace Data { namespace Tables { namespace Credentials {
|
||||
std::string m_accountKey;
|
||||
};
|
||||
|
||||
namespace _detail {
|
||||
struct ConnectionStringParts
|
||||
{
|
||||
std::string AccountName;
|
||||
std::string AccountKey;
|
||||
Azure::Core::Url TableServiceUrl;
|
||||
std::shared_ptr<NamedKeyCredential> KeyCredential;
|
||||
};
|
||||
|
||||
ConnectionStringParts ParseConnectionString(const std::string& connectionString);
|
||||
std::string GetDefaultScopeForAudience(const std::string& audience);
|
||||
} // namespace _detail
|
||||
|
||||
}}}} // namespace Azure::Data::Tables::Credentials
|
||||
|
||||
@ -1,100 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "azure/data/tables/credentials/named_key_credential.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace Azure { namespace Data { namespace Tables { namespace Credentials { namespace _detail {
|
||||
|
||||
ConnectionStringParts ParseConnectionString(const std::string& connectionString)
|
||||
{
|
||||
std::map<std::string, std::string> connectionStringMap;
|
||||
|
||||
std::string::const_iterator cur = connectionString.begin();
|
||||
|
||||
while (cur != connectionString.end())
|
||||
{
|
||||
auto key_begin = cur;
|
||||
auto key_end = std::find(cur, connectionString.end(), '=');
|
||||
std::string key = std::string(key_begin, key_end);
|
||||
cur = key_end;
|
||||
if (cur != connectionString.end())
|
||||
{
|
||||
++cur;
|
||||
}
|
||||
|
||||
auto value_begin = cur;
|
||||
auto value_end = std::find(cur, connectionString.end(), ';');
|
||||
std::string value = std::string(value_begin, value_end);
|
||||
cur = value_end;
|
||||
if (cur != connectionString.end())
|
||||
{
|
||||
++cur;
|
||||
}
|
||||
|
||||
if (!key.empty() || !value.empty())
|
||||
{
|
||||
connectionStringMap[std::move(key)] = std::move(value);
|
||||
}
|
||||
}
|
||||
|
||||
auto getWithDefault = [](const std::map<std::string, std::string>& m,
|
||||
const std::string& key,
|
||||
const std::string& defaultValue = std::string()) {
|
||||
auto ite = m.find(key);
|
||||
return ite == m.end() ? defaultValue : ite->second;
|
||||
};
|
||||
|
||||
ConnectionStringParts connectionStringParts;
|
||||
|
||||
std::string defaultEndpointsProtocol
|
||||
= getWithDefault(connectionStringMap, "DefaultEndpointsProtocol", "https");
|
||||
std::string EndpointSuffix
|
||||
= getWithDefault(connectionStringMap, "EndpointSuffix", "core.windows.net");
|
||||
std::string accountName = getWithDefault(connectionStringMap, "AccountName");
|
||||
connectionStringParts.AccountName = accountName;
|
||||
|
||||
std::string endpoint = getWithDefault(connectionStringMap, "TableEndpoint");
|
||||
if (endpoint.empty() && !accountName.empty())
|
||||
{
|
||||
endpoint = defaultEndpointsProtocol + "://" + accountName + ".table." + EndpointSuffix;
|
||||
}
|
||||
connectionStringParts.TableServiceUrl = Azure::Core::Url(std::move(endpoint));
|
||||
|
||||
std::string accountKey = getWithDefault(connectionStringMap, "AccountKey");
|
||||
connectionStringParts.AccountKey = accountKey;
|
||||
if (!accountKey.empty())
|
||||
{
|
||||
if (accountName.empty())
|
||||
{
|
||||
throw std::runtime_error("Cannot find account name in connection string.");
|
||||
}
|
||||
connectionStringParts.KeyCredential
|
||||
= std::make_shared<NamedKeyCredential>(accountName, accountKey);
|
||||
}
|
||||
|
||||
std::string sas = getWithDefault(connectionStringMap, "SharedAccessSignature");
|
||||
if (!sas.empty())
|
||||
{
|
||||
if (sas[0] != '?')
|
||||
{
|
||||
sas = '?' + sas;
|
||||
}
|
||||
|
||||
connectionStringParts.TableServiceUrl
|
||||
= Azure::Core::Url(connectionStringParts.TableServiceUrl.GetAbsoluteUrl() + sas);
|
||||
}
|
||||
|
||||
return connectionStringParts;
|
||||
}
|
||||
|
||||
std::string GetDefaultScopeForAudience(const std::string& audience)
|
||||
{
|
||||
if (!audience.empty() && audience.back() == '/')
|
||||
{
|
||||
return audience + ".default";
|
||||
}
|
||||
return audience + "/.default";
|
||||
}
|
||||
}}}}} // namespace Azure::Data::Tables::Credentials::_detail
|
||||
@ -1,46 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "../private/policies/shared_key_lite_policy.hpp"
|
||||
|
||||
#include "../private/hmacsha256.hpp"
|
||||
|
||||
#include <azure/core/base64.hpp>
|
||||
#include <azure/core/cryptography/hash.hpp>
|
||||
#include <azure/core/http/http.hpp>
|
||||
#include <azure/core/internal/strings.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace Azure { namespace Data { namespace Tables { namespace _detail { namespace Policies {
|
||||
|
||||
std::string SharedKeyLitePolicy::GetSignature(const Core::Http::Request& request) const
|
||||
{
|
||||
std::string string_to_sign;
|
||||
|
||||
const auto& headers = request.GetHeaders();
|
||||
|
||||
// canonical date header headers
|
||||
const std::string dateHeader = headers.at("x-ms-date");
|
||||
string_to_sign += dateHeader + "\n";
|
||||
|
||||
// If the request URI addresses a component of the resource, append the appropriate query
|
||||
// string. The query string should include the question mark and the comp parameter (for
|
||||
// example, ?comp=metadata). No other parameters should be included on the query string.
|
||||
// https://docs.microsoft.com/en-us/rest/api/storageservices/authorize-with-shared-key#shared-key-lite-and-table-service-format-for-2009-09-19-and-later
|
||||
// canonicalized resource
|
||||
string_to_sign += "/" + m_credential->AccountName + "/" + request.GetUrl().GetPath();
|
||||
auto queryParameters = request.GetUrl().GetQueryParameters();
|
||||
if (queryParameters.count("comp") > 0)
|
||||
{
|
||||
const std::string keyValue = Azure::Core::Url::Encode("comp");
|
||||
auto compValue = queryParameters.at(keyValue);
|
||||
string_to_sign += "?comp=" + Azure::Core::Url::Decode(compValue);
|
||||
}
|
||||
|
||||
return Azure::Core::Convert::Base64Encode(
|
||||
Azure::Data::Tables::_detail::Cryptography::HmacSha256::Compute(
|
||||
std::vector<uint8_t>(string_to_sign.begin(), string_to_sign.end()),
|
||||
Azure::Core::Convert::Base64Decode(m_credential->GetAccountKey())));
|
||||
}
|
||||
}}}}} // namespace Azure::Data::Tables::_detail::Policies
|
||||
@ -1,43 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "azure/data/tables/credentials/named_key_credential.hpp"
|
||||
|
||||
#include <azure/core/http/policies/policy.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace Azure { namespace Data { namespace Tables { namespace _detail { namespace Policies {
|
||||
class SharedKeyLitePolicy final : public Core::Http::Policies::HttpPolicy {
|
||||
public:
|
||||
explicit SharedKeyLitePolicy(std::shared_ptr<Credentials::NamedKeyCredential> credential)
|
||||
: m_credential{std::move(credential)}
|
||||
{
|
||||
}
|
||||
|
||||
~SharedKeyLitePolicy() override {}
|
||||
|
||||
std::unique_ptr<HttpPolicy> Clone() const override
|
||||
{
|
||||
return std::make_unique<SharedKeyLitePolicy>(m_credential);
|
||||
}
|
||||
|
||||
std::unique_ptr<Core::Http::RawResponse> Send(
|
||||
Core::Http::Request& request,
|
||||
Core::Http::Policies::NextHttpPolicy nextPolicy,
|
||||
Core::Context const& context) const override
|
||||
{
|
||||
request.SetHeader(
|
||||
"Authorization",
|
||||
"SharedKeyLite " + m_credential->AccountName + ":" + GetSignature(request));
|
||||
return nextPolicy.Send(request, context);
|
||||
}
|
||||
|
||||
std::string GetSignature(const Core::Http::Request& request) const;
|
||||
std::shared_ptr<Credentials::NamedKeyCredential> m_credential;
|
||||
};
|
||||
|
||||
}}}}} // namespace Azure::Data::Tables::_detail::Policies
|
||||
@ -5,7 +5,6 @@
|
||||
#include "azure/data/tables/table_service_client.hpp"
|
||||
#include "private/package_version.hpp"
|
||||
#include "private/policies/service_version_policy.hpp"
|
||||
#include "private/policies/shared_key_lite_policy.hpp"
|
||||
#include "private/policies/tenant_bearer_token_policy.hpp"
|
||||
#include "private/policies/timeout_policy.hpp"
|
||||
#include "private/serializers.hpp"
|
||||
@ -17,7 +16,6 @@
|
||||
using namespace Azure::Data::Tables;
|
||||
using namespace Azure::Data::Tables::_detail::Policies;
|
||||
using namespace Azure::Data::Tables::_detail::Xml;
|
||||
using namespace Azure::Data::Tables::Credentials::_detail;
|
||||
using namespace Azure::Data::Tables::_detail;
|
||||
|
||||
TableServiceClient::TableServiceClient(
|
||||
|
||||
@ -22,7 +22,6 @@ add_executable (
|
||||
sas_test.cpp
|
||||
serializers_test.hpp
|
||||
serializers_test.cpp
|
||||
shared_key_lite_policy_test.cpp
|
||||
table_client_test.cpp
|
||||
table_client_test.hpp
|
||||
transactions_test.hpp
|
||||
|
||||
@ -1,93 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "../src/private/hmacsha256.hpp"
|
||||
#include "../src/private/policies/shared_key_lite_policy.hpp"
|
||||
#include "azure/data/tables/credentials/named_key_credential.hpp"
|
||||
|
||||
#include <azure/core/base64.hpp>
|
||||
#include <azure/core/cryptography/hash.hpp>
|
||||
#include <azure/core/http/policies/policy.hpp>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using namespace Azure::Core::Http::Policies;
|
||||
using namespace Azure::Data::Tables::_detail::Policies;
|
||||
using namespace Azure::Data::Tables::Credentials;
|
||||
using namespace Azure::Data::Tables::Credentials::_detail;
|
||||
namespace Azure { namespace Data { namespace Tables { namespace _internal { namespace Policies {
|
||||
namespace Test {
|
||||
|
||||
TEST(SharedKeyCredentialLiteTest, SharedKeyCredentialLite)
|
||||
{
|
||||
const std::string accountKey = "account-key";
|
||||
std::string connectionString = "DefaultEndpointsProtocol=https;AccountName=account-name;"
|
||||
"AccountKey="
|
||||
+ Azure::Core::Convert::Base64Encode(
|
||||
std::vector<uint8_t>(accountKey.begin(), accountKey.end()))
|
||||
+ ";EndpointSuffix = core.windows.net ";
|
||||
|
||||
std::shared_ptr<NamedKeyCredential> credential;
|
||||
auto parsedConnectionString = ParseConnectionString(connectionString);
|
||||
SharedKeyLitePolicy policy(parsedConnectionString.KeyCredential);
|
||||
|
||||
Azure::Core::Url url("https://goqu.table.core.windows.net");
|
||||
url.SetQueryParameters({{"restype", "service"}, {"comp", "properties"}});
|
||||
Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url);
|
||||
request.SetHeader("x-ms-date", "Thu, 23 Apr 2020 09:43:37 GMT");
|
||||
auto result = policy.GetSignature(request);
|
||||
const std::string stringTest
|
||||
= "Thu, 23 Apr 2020 09:43:37 GMT\n/account-name/?comp=properties";
|
||||
const std::string expectedSignature = Azure::Core::Convert::Base64Encode(
|
||||
Azure::Data::Tables::_detail::Cryptography::HmacSha256::Compute(
|
||||
std::vector<uint8_t>(stringTest.begin(), stringTest.end()),
|
||||
std::vector<uint8_t>(accountKey.begin(), accountKey.end())));
|
||||
EXPECT_EQ(result, expectedSignature);
|
||||
}
|
||||
|
||||
TEST(SharedKeyCredentialLiteTest, SharedKeyCredentialLiteNoDate)
|
||||
{
|
||||
const std::string accountKey = "account-key";
|
||||
std::string connectionString = "DefaultEndpointsProtocol=https;AccountName=account-name;"
|
||||
"AccountKey="
|
||||
+ Azure::Core::Convert::Base64Encode(
|
||||
std::vector<uint8_t>(accountKey.begin(), accountKey.end()))
|
||||
+ ";EndpointSuffix = core.windows.net ";
|
||||
|
||||
std::shared_ptr<NamedKeyCredential> credential;
|
||||
auto parsedConnectionString = ParseConnectionString(connectionString);
|
||||
SharedKeyLitePolicy policy(parsedConnectionString.KeyCredential);
|
||||
|
||||
Azure::Core::Url url("https://goqu.table.core.windows.net");
|
||||
url.SetQueryParameters({{"restype", "service"}, {"comp", "properties"}});
|
||||
Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url);
|
||||
EXPECT_THROW(policy.GetSignature(request), std::exception);
|
||||
}
|
||||
|
||||
TEST(SharedKeyCredentialLiteTest, SharedKeyCredentialLiteNoQuery)
|
||||
{
|
||||
const std::string accountKey = "account-key";
|
||||
std::string connectionString = "DefaultEndpointsProtocol=https;AccountName=account-name;"
|
||||
"AccountKey="
|
||||
+ Azure::Core::Convert::Base64Encode(
|
||||
std::vector<uint8_t>(accountKey.begin(), accountKey.end()))
|
||||
+ ";EndpointSuffix = core.windows.net ";
|
||||
|
||||
std::shared_ptr<NamedKeyCredential> credential;
|
||||
auto parsedConnectionString = ParseConnectionString(connectionString);
|
||||
SharedKeyLitePolicy policy(parsedConnectionString.KeyCredential);
|
||||
|
||||
Azure::Core::Url url("https://goqu.table.core.windows.net");
|
||||
Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url);
|
||||
request.SetHeader("x-ms-date", "Thu, 23 Apr 2020 09:43:37 GMT");
|
||||
auto result = policy.GetSignature(request);
|
||||
const std::string stringTest = "Thu, 23 Apr 2020 09:43:37 GMT\n/account-name/";
|
||||
const std::string expectedSignature = Azure::Core::Convert::Base64Encode(
|
||||
Azure::Data::Tables::_detail::Cryptography::HmacSha256::Compute(
|
||||
std::vector<uint8_t>(stringTest.begin(), stringTest.end()),
|
||||
std::vector<uint8_t>(accountKey.begin(), accountKey.end())));
|
||||
|
||||
EXPECT_EQ(result, expectedSignature);
|
||||
}
|
||||
|
||||
}}}}}} // namespace Azure::Data::Tables::_internal::Policies::Test
|
||||
Loading…
Reference in New Issue
Block a user