Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ namespace Azure { namespace Core { namespace Credentials {
*
*/
std::string TenantId;

/**
* @brief Use credentials cache.
*
*/
bool CacheCredentials = true;
};

/**
Expand Down
4 changes: 0 additions & 4 deletions sdk/core/perf/src/arg_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ Azure::Perf::GlobalTestOptions Azure::Perf::Program::ArgParser::Parse(
options.TestProxies.push_back(proxy);
}
}
if (parsedArgs["TestProxy"])
{
options.TestProxies.push_back(parsedArgs["TestProxy"].as<std::string>());
}

return options;
}
2 changes: 0 additions & 2 deletions sdk/core/perf/src/base_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ namespace Azure { namespace Perf {
#if defined(BUILD_CURL_HTTP_TRANSPORT_ADAPTER)
Azure::Core::Http::CurlTransportOptions curlOptions;
curlOptions.SslVerifyPeer = false;
curlOptions.SslOptions.AllowFailedCrlRetrieval = true;
clientOptions.Transport.Transport
= std::make_shared<Azure::Core::Http::CurlTransport>(curlOptions);
#elif defined(BUILD_TRANSPORT_WINHTTP_ADAPTER)
Expand Down Expand Up @@ -195,7 +194,6 @@ namespace Azure { namespace Perf {
Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Post, startPlayback);
request.SetHeader("x-recording-id", m_recordId);
auto response = pipeline.Send(request, ctx);

auto const& headers = response->GetHeaders();
auto findHeader = std::find_if(
headers.begin(),
Expand Down
2 changes: 0 additions & 2 deletions sdk/core/perf/src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ std::vector<Azure::Perf::TestOption> Azure::Perf::GlobalTestOptions::GetOptionMe
[Option("sync", HelpText = "Runs sync version of test")] -- Not supported
[Option('w', "warmup", Default = 5, HelpText = "Duration of warmup in seconds")]
[Option('x', "proxy", Default = "", HelpText = "Proxy server")]
[Option("test-proxy", HelpText = "URI of TestProxy Server")]
*/
return {
{"Duration",
Expand Down Expand Up @@ -88,7 +87,6 @@ std::vector<Azure::Perf::TestOption> Azure::Perf::GlobalTestOptions::GetOptionMe

{"Sync", {"-y", "--sync"}, "Runs sync version of test, not implemented", 0},
{"TestProxies", {"-x", "--test-proxies"}, "URIs of TestProxy Servers (separated by ';')", 1},
{"TestProxy", {"--test-proxy"}, "URI of TestProxy Server", 1},
{"Warmup", {"-w", "--warmup"}, "Duration of warmup in seconds. Default to 5 seconds.", 1},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ namespace Azure { namespace Identity { namespace _detail {
// Gets item from cache, or creates it, puts into cache, and returns.
std::shared_ptr<CacheValue> GetOrCreateValue(
CacheKey const& key,
DateTime::duration minimumExpiration,
bool useCaching) const;
DateTime::duration minimumExpiration) const;

public:
TokenCache() = default;
Expand All @@ -92,15 +91,14 @@ namespace Azure { namespace Identity { namespace _detail {
* @param minimumExpiration Minimum token lifetime for the cached value to be returned.
* @param getNewToken Function to get the new token for the given \p scopeString, in case when
* cache does not have it, or if its remaining lifetime is less than \p minimumExpiration.
* @param useCaching If set to false, the token will not be cached.
*
* @return Authentication token.
*
*/
Core::Credentials::AccessToken GetToken(
std::string const& scopeString,
std::string const& tenantId,
DateTime::duration minimumExpiration,
std::function<Core::Credentials::AccessToken()> const& getNewToken,
bool useCaching = true) const;
std::function<Core::Credentials::AccessToken()> const& getNewToken) const;
};
}}} // namespace Azure::Identity::_detail
43 changes: 19 additions & 24 deletions sdk/identity/azure-identity/src/client_secret_credential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,23 @@ AccessToken ClientSecretCredential::GetToken(
// when they are being executed. They are not supposed to keep a reference to lambda argument to
// call it later. Therefore, any capture made here will outlive the possible time frame when the
// lambda might get called.
return m_tokenCache.GetToken(
scopesStr,
tenantId,
tokenRequestContext.MinimumExpiration,
[&]() {
return m_tokenCredentialImpl->GetToken(context, [&]() {
auto body = m_requestBody;

if (!scopesStr.empty())
{
body += "&scope=" + scopesStr;
}

auto const requestUrl = m_clientCredentialCore.GetRequestUrl(tenantId);

auto request = std::make_unique<TokenCredentialImpl::TokenRequest>(
HttpMethod::Post, requestUrl, body);

request->HttpRequest.SetHeader("Host", requestUrl.GetHost());

return request;
});
},
tokenRequestContext.CacheCredentials);
return m_tokenCache.GetToken(scopesStr, tenantId, tokenRequestContext.MinimumExpiration, [&]() {
return m_tokenCredentialImpl->GetToken(context, [&]() {
auto body = m_requestBody;

if (!scopesStr.empty())
{
body += "&scope=" + scopesStr;
}

auto const requestUrl = m_clientCredentialCore.GetRequestUrl(tenantId);

auto request
= std::make_unique<TokenCredentialImpl::TokenRequest>(HttpMethod::Post, requestUrl, body);

request->HttpRequest.SetHeader("Host", requestUrl.GetHost());

return request;
});
});
}
14 changes: 3 additions & 11 deletions sdk/identity/azure-identity/src/token_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,8 @@ template <typename T> bool ShouldCleanUpCacheFromExpiredItems(T cacheSize);

std::shared_ptr<TokenCache::CacheValue> TokenCache::GetOrCreateValue(
CacheKey const& key,
DateTime::duration minimumExpiration,
bool useCaching) const
DateTime::duration minimumExpiration) const
{
// not using caching, return new value;
if (!useCaching)
{
return std::make_shared<CacheValue>();
}

{
std::shared_lock<std::shared_timed_mutex> cacheReadLock(m_cacheMutex);

Expand Down Expand Up @@ -95,10 +88,9 @@ AccessToken TokenCache::GetToken(
std::string const& scopeString,
std::string const& tenantId,
DateTime::duration minimumExpiration,
std::function<AccessToken()> const& getNewToken,
bool useCaching) const
std::function<AccessToken()> const& getNewToken) const
{
auto const item = GetOrCreateValue({scopeString, tenantId}, minimumExpiration, useCaching);
auto const item = GetOrCreateValue({scopeString, tenantId}, minimumExpiration);

{
std::shared_lock<std::shared_timed_mutex> itemReadLock(item->ElementMutex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ namespace Azure { namespace Identity { namespace Test {
m_clientId = m_options.GetMandatoryOption<std::string>("ClientId");
m_secret = m_options.GetMandatoryOption<std::string>("Secret");
m_tokenRequestContext.Scopes.push_back(m_options.GetMandatoryOption<std::string>("Scope"));
m_tokenRequestContext.CacheCredentials = m_options.GetOptionOrDefault<bool>("Cache", false);
if (m_options.GetOptionOrDefault<bool>("Cache", false) == false)
{
m_tokenRequestContext.MinimumExpiration = std::chrono::hours(1000000);
}
m_credential = std::make_unique<Azure::Identity::ClientSecretCredential>(
m_tenantId,
m_clientId,
Expand Down