Extract part of credentials to Identity module (#748)

This commit is contained in:
Anton Kolesnyk 2020-10-13 07:33:18 -07:00 committed by GitHub
parent e9f37a5760
commit a38de03e7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
58 changed files with 616 additions and 359 deletions

3
.github/CODEOWNERS vendored
View File

@ -16,6 +16,9 @@
# Azure::Core
/sdk/core/ @ahsonkhan @antkmsft @rickwinter @vhvb1989
# Azure::Identity
/sdk/identity/ @antkmsft
# Service teams
/sdk/storage/ @vinjiang @katmsft @JinmingHu-MSFT @antkmsft @rickwinter @vhvb1989

View File

@ -66,5 +66,7 @@ if(BUILD_TESTING)
add_subdirectory(sdk/core/azure-core/test/e2e)
endif()
add_subdirectory(sdk/identity/azure-identity)
add_subdirectory(sdk/storage)
add_subdirectory(sdk/template/azure-template)

View File

@ -24,8 +24,7 @@ endif()
add_library (
${TARGET_NAME}
src/context.cpp
src/credentials/credentials.cpp
src/credentials/policy/policies.cpp
src/credentials.cpp
src/datetime.cpp
src/http/body_stream.cpp
${CURL_TRANSPORT_ADAPTER_SRC}

View File

@ -3,19 +3,77 @@
/**
* @file
* @brief Authentication policies.
* @brief Credentials used for authentication with many (not all) Azure SDK client libraries.
*/
#pragma once
#include "azure/core/credentials/credentials.hpp"
#include "azure/core/http/policy.hpp"
#include <azure/core/context.hpp>
#include <azure/core/http/policy.hpp>
#include <chrono>
#include <memory>
#include <mutex>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
namespace Azure { namespace Core { namespace Credentials { namespace Policy {
namespace Azure { namespace Core {
/**
* @brief Represents an access token.
*/
struct AccessToken
{
/**
* @brief Token string.
*/
std::string Token;
/**
* @brief Token expiration.
*/
std::chrono::system_clock::time_point ExpiresOn;
};
/**
* @brief Token credential.
*/
class TokenCredential {
public:
/**
* @brief Get an authentication token.
*
* @param context #Context so that operation can be canceled.
* @param scopes Authentication scopes.
*/
virtual AccessToken GetToken(Context const& context, std::vector<std::string> const& scopes)
const = 0;
/// Destructor.
virtual ~TokenCredential() = default;
protected:
TokenCredential() {}
private:
TokenCredential(TokenCredential const&) = delete;
void operator=(TokenCredential const&) = delete;
};
/**
* @brief An exception that gets thrown when authentication error occurs.
*/
class AuthenticationException : public std::runtime_error {
public:
/**
* @brief Construct with message string.
*
* @param msg Message string.
*/
explicit AuthenticationException(std::string const& msg) : std::runtime_error(msg) {}
};
/**
* @brief Bearer Token authentication policy.
@ -89,4 +147,4 @@ namespace Azure { namespace Core { namespace Credentials { namespace Policy {
Http::NextHttpPolicy policy) const override;
};
}}}} // namespace Azure::Core::Credentials::Policy
}} // namespace Azure::Core

View File

@ -1,128 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
/**
* @file
* @brief Credentials used for authentication with many (not all) Azure SDK client libraries.
*/
#pragma once
#include "azure/core/context.hpp"
#include <chrono>
#include <memory>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
namespace Azure { namespace Core { namespace Credentials {
/**
* @brief Represents an access token.
*/
struct AccessToken
{
/**
* @brief Token string.
*/
std::string Token;
/**
* @brief Token expiration.
*/
std::chrono::system_clock::time_point ExpiresOn;
};
/**
* @brief Token credential.
*/
class TokenCredential {
public:
/**
* @brief Get an authentication token.
*
* @param context #Context so that operation can be canceled.
* @param scopes Authentication scopes.
*/
virtual AccessToken GetToken(Context const& context, std::vector<std::string> const& scopes)
const = 0;
/// Destructor.
virtual ~TokenCredential() = default;
protected:
TokenCredential() {}
private:
TokenCredential(TokenCredential const&) = delete;
void operator=(TokenCredential const&) = delete;
};
/**
* @brief This class is used by Azure SDK clients to authenticate with the Azure service using a
* tenant ID, client ID and client secret.
*/
class ClientSecretCredential : public TokenCredential {
private:
static std::string const g_aadGlobalAuthority;
std::string m_tenantId;
std::string m_clientId;
std::string m_clientSecret;
std::string m_authority;
public:
/**
* @brief Construct a Client Secret credential.
*
* @param tenantId Tenant ID.
* @param clientId Client ID.
* @param clientSecret Client Secret.
* @param authority Authentication authority URL to set. If omitted, initializes credential with
* default authority (Azure AD global authority - "https://login.microsoftonline.com/").
*
* @note Example of a \p authority string: "https://login.microsoftonline.us/". See national
* clouds' Azure AD authentication endpoints:
* https://docs.microsoft.com/en-us/azure/active-directory/develop/authentication-national-cloud.
*/
explicit ClientSecretCredential(
std::string tenantId,
std::string clientId,
std::string clientSecret,
std::string authority = g_aadGlobalAuthority)
: m_tenantId(std::move(tenantId)), m_clientId(std::move(clientId)),
m_clientSecret(std::move(clientSecret)), m_authority(std::move(authority))
{
}
AccessToken GetToken(Context const& context, std::vector<std::string> const& scopes)
const override;
};
/**
* @brief An exception that gets thrown when authentication error occurs.
*/
class AuthenticationException : public std::runtime_error {
public:
explicit AuthenticationException(std::string const& msg) : std::runtime_error(msg) {}
};
/**
* @brief An environment credential.
*/
class EnvironmentCredential : public TokenCredential {
std::unique_ptr<TokenCredential> m_credentialImpl;
public:
/**
* Constructs an environment credential.
*/
explicit EnvironmentCredential();
AccessToken GetToken(Context const& context, std::vector<std::string> const& scopes)
const override;
};
}}} // namespace Azure::Core::Credentials

View File

@ -38,7 +38,7 @@ namespace Azure { namespace Core {
* @brief The version in string format used for telemetry following the `semver.org` standard
* (https://semver.org).
*/
static std::string const VersionString();
static std::string VersionString();
private:
// To avoid leaking out the #define values we smuggle out the value
@ -52,5 +52,3 @@ namespace Azure { namespace Core {
#undef AZURE_CORE_VERSION_MINOR
#undef AZURE_CORE_VERSION_PATCH
#undef AZURE_CORE_VERSION_PRERELEASE

View File

@ -1,11 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include "azure/core/credentials/policy/policies.hpp"
#include <azure/core/credentials.hpp>
using namespace Azure::Core::Credentials::Policy;
using namespace Azure::Core;
std::unique_ptr<Azure::Core::Http::RawResponse> BearerTokenAuthenticationPolicy::Send(
std::unique_ptr<Http::RawResponse> BearerTokenAuthenticationPolicy::Send(
Context const& context,
Http::Request& request,
Http::NextHttpPolicy policy) const

View File

@ -3,28 +3,27 @@
#include "azure/core/version.hpp"
#include <string>
#include <sstream>
#include <string>
using namespace Azure::Core;
const std::string Version::PreRelease = secret;
std::string const Version::VersionString()
std::string Version::VersionString()
{
static const std::string versionString = [] {
std::string version;
std::stringstream ss;
std::string dot = ".";
std::string version;
std::stringstream ss;
std::string dot = ".";
ss << Version::Major << dot << Version::Minor << dot << Version::Patch;
ss << Version::Major << dot << Version::Minor << dot << Version::Patch;
if (!Version::PreRelease.empty())
ss << "-" << Version::PreRelease;
if (!Version::PreRelease.empty())
ss << "-" << Version::PreRelease;
return ss.str();
return ss.str();
}();
return versionString;
}

View File

@ -0,0 +1,6 @@
# Release History
## 1.0.0-beta.1 (Unreleased)
* Support for Client Secret Credential
* Support for Environment Credential

View File

@ -0,0 +1,11 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# SPDX-License-Identifier: MIT
cmake_minimum_required (VERSION 3.12)
project (azure-identity LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
add_subdirectory(azure-identity)

View File

@ -0,0 +1,25 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# SPDX-License-Identifier: MIT
cmake_minimum_required (VERSION 3.12)
set (AZURE_IDENTITY_HEADER
inc/azure/identity/client_secret_credential.hpp
inc/azure/identity/environment_credential.hpp
inc/azure/identity/version.hpp
)
set (AZURE_IDENTITY_SOURCE
src/client_secret_credential.cpp
src/environment_credential.cpp
src/version.cpp
)
add_library(azure-identity ${AZURE_IDENTITY_HEADER} ${AZURE_IDENTITY_SOURCE})
target_include_directories(azure-identity PUBLIC inc)
target_link_libraries(azure-identity azure-core)
add_library(azure::identity ALIAS azure-identity)
get_az_version("${CMAKE_CURRENT_SOURCE_DIR}/inc/azure/identity/version.hpp")
generate_documentation(azure-identity ${AZ_LIBRARY_VERSION})

View File

@ -0,0 +1,73 @@
# Azure SDK Identity Library for C++
Azure::Identity (`azure-identity`) provides shared primitives, abstractions, and helpers for modern Azure SDK client libraries written in the C++. These libraries follow the [Azure SDK Design Guidelines for C++][azure_sdk_cpp_development_guidelines].
The library contains commonly (but not universally) used credential types.
## Getting started
Typically, you will not need to download `azure-identity`; it will be downloaded for you as a dependency of the client libraries. In case you want to download it explicitly (to implement your own client library, for example), you can find the source
in here.
## Key concepts
Azure::Identity credentials:
- Client Secret Credential (`ClientSecretCredential`)
- Environment Credential (`EnvironmentCredential`)
## Troubleshooting
Three main ways of troubleshooting failures are:
- Inspecting exceptions
- Enabling logging (`Available in future release`)
- Distributed tracing (`Available in future release`)
## Next steps
Explore and install available Azure SDK libraries.
## Contributing
For details on contributing to this repository, see the [contributing guide][azure_sdk_for_cpp_contributing].
This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
### Additional Helpful Links for Contributors
Many people all over the world have helped make this project better. You'll want to check out:
* [What are some good first issues for new contributors to the repo?](https://github.com/azure/azure-sdk-for-cpp/issues?q=is%3Aopen+is%3Aissue+label%3A%22up+for+grabs%22)
* [How to build and test your change][azure_sdk_for_cpp_contributing_developer_guide]
* [How you can make a change happen!][azure_sdk_for_cpp_contributing_pull_requests]
* Frequently Asked Questions (FAQ) and Conceptual Topics in the detailed [Azure SDK for C++ wiki](https://github.com/azure/azure-sdk-for-cpp/wiki).
<!-- ### Community-->
### Reporting security issues and security bugs
Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC) <secure@microsoft.com>. You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Further information, including the MSRC PGP key, can be found in the [Security TechCenter](https://www.microsoft.com/msrc/faqs-report-an-issue).
### License
Azure SDK for C++ is licensed under the [MIT](https://github.com/Azure/azure-sdk-for-cpp/blob/master/sdk/core/azure-core/LICENSE) license.
<!-- LINKS -->
[azure_sdk_for_cpp_contributing]: https://github.com/Azure/azure-sdk-for-cpp/blob/master/CONTRIBUTING.md
[azure_sdk_for_cpp_contributing_developer_guide]: https://github.com/Azure/azure-sdk-for-cpp/blob/master/CONTRIBUTING.md#developer-guide
[azure_sdk_for_cpp_contributing_pull_requests]: https://github.com/Azure/azure-sdk-for-cpp/blob/master/CONTRIBUTING.md#pull-requests
[azure_sdk_cpp_development_guidelines]: https://azure.github.io/azure-sdk/cpp_introduction.html
[azure_cli]: https://docs.microsoft.com/cli/azure
[azure_pattern_circuit_breaker]: https://docs.microsoft.com/azure/architecture/patterns/circuit-breaker
[azure_pattern_retry]: https://docs.microsoft.com/azure/architecture/patterns/retry
[azure_portal]: https://portal.azure.com
[azure_sub]: https://azure.microsoft.com/free/
[c_compiler]: https://visualstudio.microsoft.com/vs/features/cplusplus/
[cloud_shell]: https://docs.microsoft.com/azure/cloud-shell/overview
[cloud_shell_bash]: https://shell.azure.com/bash

View File

@ -0,0 +1,59 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
/**
* @file
* @brief Client Secret Credential.
*/
#pragma once
#include <azure/core/credentials.hpp>
#include <string>
#include <utility>
namespace Azure { namespace Identity {
/**
* @brief This class is used by Azure SDK clients to authenticate with the Azure service using a
* tenant ID, client ID and client secret.
*/
class ClientSecretCredential : public Core::TokenCredential {
private:
static std::string const g_aadGlobalAuthority;
std::string m_tenantId;
std::string m_clientId;
std::string m_clientSecret;
std::string m_authority;
public:
/**
* @brief Construct a Client Secret credential.
*
* @param tenantId Tenant ID.
* @param clientId Client ID.
* @param clientSecret Client Secret.
* @param authority Authentication authority URL to set. If omitted, initializes credential with
* default authority (Azure AD global authority - "https://login.microsoftonline.com/").
*
* @note Example of a \p authority string: "https://login.microsoftonline.us/". See national
* clouds' Azure AD authentication endpoints:
* https://docs.microsoft.com/en-us/azure/active-directory/develop/authentication-national-cloud.
*/
explicit ClientSecretCredential(
std::string tenantId,
std::string clientId,
std::string clientSecret,
std::string authority = g_aadGlobalAuthority)
: m_tenantId(std::move(tenantId)), m_clientId(std::move(clientId)),
m_clientSecret(std::move(clientSecret)), m_authority(std::move(authority))
{
}
Core::AccessToken GetToken(Core::Context const& context, std::vector<std::string> const& scopes)
const override;
};
}} // namespace Azure::Identity

View File

@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
/**
* @file
* @brief Environment Credential.
*/
#pragma once
#include <azure/core/credentials.hpp>
#include <memory>
namespace Azure { namespace Identity {
/**
* @brief An environment credential.
*/
class EnvironmentCredential : public Core::TokenCredential {
std::unique_ptr<TokenCredential> m_credentialImpl;
public:
/**
* Constructs an environment credential.
*/
explicit EnvironmentCredential();
Core::AccessToken GetToken(Core::Context const& context, std::vector<std::string> const& scopes)
const override;
};
}} // namespace Azure::Identity

View File

@ -0,0 +1,54 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
/**
* @file
* @brief Provides version information.
*/
#pragma once
#include <string>
#define AZURE_IDENTITY_VERSION_MAJOR 1
#define AZURE_IDENTITY_VERSION_MINOR 0
#define AZURE_IDENTITY_VERSION_PATCH 0
#define AZURE_IDENTITY_VERSION_PRERELEASE "beta.1"
namespace Azure { namespace Identity {
/**
* @brief Provides version information.
*/
class Version {
public:
/// Major numeric identifier.
static constexpr int Major = AZURE_IDENTITY_VERSION_MAJOR;
/// Minor numeric identifier.
static constexpr int Minor = AZURE_IDENTITY_VERSION_MINOR;
/// Patch numeric identifier.
static constexpr int Patch = AZURE_IDENTITY_VERSION_PATCH;
/// Optional pre-release identifier. SDK is in a pre-release state when not empty.
static std::string const PreRelease;
/**
* @brief The version in string format used for telemetry following the `semver.org` standard
* (https://semver.org).
*/
static std::string VersionString();
private:
// To avoid leaking out the #define values we smuggle out the value
// which will later be used to initialize the PreRelease std::string
static constexpr char const* secret = AZURE_IDENTITY_VERSION_PRERELEASE;
};
}} // namespace Azure::Identity
#undef AZURE_IDENTITY_VERSION_MAJOR
#undef AZURE_IDENTITY_VERSION_MINOR
#undef AZURE_IDENTITY_VERSION_PATCH
#undef AZURE_IDENTITY_VERSION_PRERELEASE

View File

@ -1,18 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include "azure/core/credentials/credentials.hpp"
#include "azure/core/http/body_stream.hpp"
#include "azure/core/http/curl/curl.hpp"
#include "azure/core/http/http.hpp"
#include "azure/core/http/pipeline.hpp"
#include <azure/identity/client_secret_credential.hpp>
#include <azure/core/http/curl/curl.hpp>
#include <azure/core/http/pipeline.hpp>
#include <cstdlib>
#include <iomanip>
#include <sstream>
#include <stdexcept>
using namespace Azure::Core::Credentials;
using namespace Azure::Identity;
namespace {
std::string UrlEncode(std::string const& s)
@ -39,17 +36,20 @@ std::string UrlEncode(std::string const& s)
}
} // namespace
std::string const Azure::Core::Credentials::ClientSecretCredential::g_aadGlobalAuthority
std::string const ClientSecretCredential::g_aadGlobalAuthority
= "https://login.microsoftonline.com/";
AccessToken Azure::Core::Credentials::ClientSecretCredential::GetToken(
Context const& context,
Azure::Core::AccessToken ClientSecretCredential::GetToken(
Azure::Core::Context const& context,
std::vector<std::string> const& scopes) const
{
using namespace Azure::Core;
using namespace Azure::Core::Http;
static std::string const errorMsgPrefix("ClientSecretCredential::GetToken: ");
try
{
Http::Url url(m_authority);
Url url(m_authority);
url.AppendPath(m_tenantId);
url.AppendPath("oauth2/v2.0/token");
@ -72,27 +72,27 @@ AccessToken Azure::Core::Credentials::ClientSecretCredential::GetToken(
auto const bodyString = body.str();
auto bodyStream
= std::make_unique<Http::MemoryBodyStream>((uint8_t*)bodyString.data(), bodyString.size());
= std::make_unique<MemoryBodyStream>((uint8_t*)bodyString.data(), bodyString.size());
Http::Request request(Http::HttpMethod::Post, url, bodyStream.get());
Request request(HttpMethod::Post, url, bodyStream.get());
bodyStream.release();
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddHeader("Content-Length", std::to_string(bodyString.size()));
std::shared_ptr<Http::HttpTransport> transport = std::make_unique<Http::CurlTransport>();
std::shared_ptr<HttpTransport> transport = std::make_unique<CurlTransport>();
std::vector<std::unique_ptr<Http::HttpPolicy>> policies;
policies.push_back(std::make_unique<Http::RequestIdPolicy>());
std::vector<std::unique_ptr<HttpPolicy>> policies;
policies.push_back(std::make_unique<RequestIdPolicy>());
Http::RetryOptions retryOptions;
policies.push_back(std::make_unique<Http::RetryPolicy>(retryOptions));
RetryOptions retryOptions;
policies.push_back(std::make_unique<RetryPolicy>(retryOptions));
policies.push_back(std::make_unique<Http::TransportPolicy>(std::move(transport)));
policies.push_back(std::make_unique<TransportPolicy>(std::move(transport)));
Http::HttpPipeline httpPipeline(policies);
HttpPipeline httpPipeline(policies);
std::shared_ptr<Http::RawResponse> response = httpPipeline.Send(context, request);
std::shared_ptr<RawResponse> response = httpPipeline.Send(context, request);
if (!response)
{
@ -100,11 +100,11 @@ AccessToken Azure::Core::Credentials::ClientSecretCredential::GetToken(
}
auto const statusCode = response->GetStatusCode();
if (statusCode != Http::HttpStatusCode::Ok)
if (statusCode != HttpStatusCode::Ok)
{
std::ostringstream errorMsg;
errorMsg << errorMsgPrefix << "error response: "
<< static_cast<std::underlying_type<Http::HttpStatusCode>::type>(statusCode) << " "
<< static_cast<std::underlying_type<HttpStatusCode>::type>(statusCode) << " "
<< response->GetReasonPhrase();
throw AuthenticationException(errorMsg.str());
@ -200,68 +200,3 @@ AccessToken Azure::Core::Credentials::ClientSecretCredential::GetToken(
throw AuthenticationException("unknown error");
}
}
Azure::Core::Credentials::EnvironmentCredential::EnvironmentCredential()
{
#ifdef _MSC_VER
#pragma warning(push)
// warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s
// instead.
#pragma warning(disable : 4996)
#endif
auto tenantId = std::getenv("AZURE_TENANT_ID");
auto clientId = std::getenv("AZURE_CLIENT_ID");
auto clientSecret = std::getenv("AZURE_CLIENT_SECRET");
auto authority = std::getenv("AZURE_AUTHORITY_HOST");
// auto username = std::getenv("AZURE_USERNAME");
// auto password = std::getenv("AZURE_PASSWORD");
//
// auto clientCertificatePath = std::getenv("AZURE_CLIENT_CERTIFICATE_PATH");
#ifdef _MSC_VER
#pragma warning(pop)
#endif
if (tenantId != nullptr && clientId != nullptr)
{
if (clientSecret != nullptr)
{
if (authority != nullptr)
{
m_credentialImpl.reset(
new ClientSecretCredential(tenantId, clientId, clientSecret, authority));
}
else
{
m_credentialImpl.reset(new ClientSecretCredential(tenantId, clientId, clientSecret));
}
}
// TODO: These credential types are not implemented. Uncomment when implemented.
// else if (username != nullptr && password != nullptr)
//{
// m_credentialImpl.reset(
// new UsernamePasswordCredential(username, password, tenantId, clientId));
//}
// else if (clientCertificatePath != nullptr)
//{
// m_credentialImpl.reset(
// new ClientCertificateCredential(tenantId, clientId, clientCertificatePath));
//}
}
}
AccessToken Azure::Core::Credentials::EnvironmentCredential::GetToken(
Context const& context,
std::vector<std::string> const& scopes) const
{
if (!m_credentialImpl)
{
throw AuthenticationException("EnvironmentCredential authentication unavailable. "
"Environment variables are not fully configured.");
}
return m_credentialImpl->GetToken(context, scopes);
}

View File

@ -0,0 +1,77 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include <azure/identity/environment_credential.hpp>
#include <azure/identity/client_secret_credential.hpp>
#include <cstdlib>
using namespace Azure::Identity;
EnvironmentCredential::EnvironmentCredential()
{
#ifdef _MSC_VER
#pragma warning(push)
// warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s
// instead.
#pragma warning(disable : 4996)
#endif
auto tenantId = std::getenv("AZURE_TENANT_ID");
auto clientId = std::getenv("AZURE_CLIENT_ID");
auto clientSecret = std::getenv("AZURE_CLIENT_SECRET");
auto authority = std::getenv("AZURE_AUTHORITY_HOST");
// auto username = std::getenv("AZURE_USERNAME");
// auto password = std::getenv("AZURE_PASSWORD");
//
// auto clientCertificatePath = std::getenv("AZURE_CLIENT_CERTIFICATE_PATH");
#ifdef _MSC_VER
#pragma warning(pop)
#endif
if (tenantId != nullptr && clientId != nullptr)
{
if (clientSecret != nullptr)
{
if (authority != nullptr)
{
m_credentialImpl.reset(
new ClientSecretCredential(tenantId, clientId, clientSecret, authority));
}
else
{
m_credentialImpl.reset(new ClientSecretCredential(tenantId, clientId, clientSecret));
}
}
// TODO: These credential types are not implemented. Uncomment when implemented.
// else if (username != nullptr && password != nullptr)
//{
// m_credentialImpl.reset(
// new UsernamePasswordCredential(username, password, tenantId, clientId));
//}
// else if (clientCertificatePath != nullptr)
//{
// m_credentialImpl.reset(
// new ClientCertificateCredential(tenantId, clientId, clientCertificatePath));
//}
}
}
Azure::Core::AccessToken EnvironmentCredential::GetToken(
Azure::Core::Context const& context,
std::vector<std::string> const& scopes) const
{
using namespace Azure::Core;
if (!m_credentialImpl)
{
throw AuthenticationException("EnvironmentCredential authentication unavailable. "
"Environment variables are not fully configured.");
}
return m_credentialImpl->GetToken(context, scopes);
}

View File

@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include "azure/identity/version.hpp"
#include <sstream>
#include <string>
using namespace Azure::Identity;
std::string const Version::PreRelease = secret;
std::string Version::VersionString()
{
static const std::string versionString = [] {
std::string version;
std::stringstream ss;
std::string dot = ".";
ss << Version::Major << dot << Version::Minor << dot << Version::Patch;
if (!Version::PreRelease.empty())
ss << "-" << Version::PreRelease;
return ss.str();
}();
return versionString;
}

37
sdk/identity/ci.yml Normal file
View File

@ -0,0 +1,37 @@
# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file.
trigger:
branches:
include:
- master
- feature/*
- release/*
- hotfix/*
paths:
include:
- eng/
- CMakeLists.txt
- sdk/core
- sdk/identity
pr:
branches:
include:
- master
- feature/*
- release/*
- hotfix/*
paths:
include:
- eng/
- CMakeLists.txt
- sdk/core
- sdk/identity
stages:
- template: ../../eng/pipelines/templates/stages/archetype-sdk-client.yml
parameters:
ServiceDirectory: identity
CtestRegex: azure-identity
Artifacts:
- Name: azure-identity
Path: azure-identity

View File

@ -3,7 +3,7 @@
#pragma once
#include "azure/core/credentials/credentials.hpp"
#include "azure/identity/client_secret_credential.hpp"
#include "azure/storage/blobs/blob_client.hpp"
#include "azure/storage/blobs/blob_options.hpp"
#include "azure/storage/blobs/protocol/blob_rest_client.hpp"
@ -68,7 +68,7 @@ namespace Azure { namespace Storage { namespace Blobs {
*/
explicit AppendBlobClient(
const std::string& blobUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const AppendBlobClientOptions& options = AppendBlobClientOptions());
/**

View File

@ -121,7 +121,7 @@ namespace Azure { namespace Storage { namespace Blobs {
*/
explicit BlobBatchClient(
const std::string& serviceUri,
std::shared_ptr<Core::Credentials::TokenCredential> credential,
std::shared_ptr<Core::TokenCredential> credential,
const BlobBatchClientOptions& options = BlobBatchClientOptions());
/**

View File

@ -3,7 +3,7 @@
#pragma once
#include "azure/core/credentials/credentials.hpp"
#include "azure/identity/client_secret_credential.hpp"
#include "azure/storage/blobs/blob_options.hpp"
#include "azure/storage/blobs/blob_responses.hpp"
#include "azure/storage/blobs/protocol/blob_rest_client.hpp"
@ -71,7 +71,7 @@ namespace Azure { namespace Storage { namespace Blobs {
*/
explicit BlobClient(
const std::string& blobUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const BlobClientOptions& options = BlobClientOptions());
/**

View File

@ -3,7 +3,7 @@
#pragma once
#include "azure/core/credentials/credentials.hpp"
#include "azure/identity/client_secret_credential.hpp"
#include "azure/storage/blobs/blob_client.hpp"
#include "azure/storage/blobs/blob_options.hpp"
#include "azure/storage/blobs/protocol/blob_rest_client.hpp"
@ -64,7 +64,7 @@ namespace Azure { namespace Storage { namespace Blobs {
*/
explicit BlobContainerClient(
const std::string& containerUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const BlobContainerClientOptions& options = BlobContainerClientOptions());
/**

View File

@ -3,7 +3,7 @@
#pragma once
#include "azure/core/credentials/credentials.hpp"
#include "azure/identity/client_secret_credential.hpp"
#include "azure/storage/blobs/blob_container_client.hpp"
#include "azure/storage/blobs/blob_options.hpp"
#include "azure/storage/blobs/protocol/blob_rest_client.hpp"
@ -56,7 +56,7 @@ namespace Azure { namespace Storage { namespace Blobs {
*/
explicit BlobServiceClient(
const std::string& serviceUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const BlobServiceClientOptions& options = BlobServiceClientOptions());
/**

View File

@ -3,7 +3,7 @@
#pragma once
#include "azure/core/credentials/credentials.hpp"
#include "azure/identity/client_secret_credential.hpp"
#include "azure/storage/blobs/blob_client.hpp"
#include "azure/storage/blobs/blob_options.hpp"
#include "azure/storage/blobs/protocol/blob_rest_client.hpp"
@ -78,7 +78,7 @@ namespace Azure { namespace Storage { namespace Blobs {
*/
explicit BlockBlobClient(
const std::string& blobUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const BlockBlobClientOptions& options = BlockBlobClientOptions());
/**

View File

@ -3,7 +3,7 @@
#pragma once
#include "azure/core/credentials/credentials.hpp"
#include "azure/identity/client_secret_credential.hpp"
#include "azure/storage/blobs/blob_client.hpp"
#include "azure/storage/blobs/blob_options.hpp"
#include "azure/storage/blobs/blob_responses.hpp"
@ -70,7 +70,7 @@ namespace Azure { namespace Storage { namespace Blobs {
*/
explicit PageBlobClient(
const std::string& blobUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const PageBlobClientOptions& options = PageBlobClientOptions());
/**

View File

@ -29,7 +29,7 @@ namespace Azure { namespace Storage { namespace Blobs {
AppendBlobClient::AppendBlobClient(
const std::string& blobUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const AppendBlobClientOptions& options)
: BlobClient(blobUri, std::move(credential), options)
{

View File

@ -7,7 +7,7 @@
#include <cstring>
#include <memory>
#include "azure/core/credentials/policy/policies.hpp"
#include "azure/core/credentials.hpp"
#include "azure/core/http/curl/curl.hpp"
#include "azure/storage/common/constants.hpp"
#include "azure/storage/common/shared_key_policy.hpp"
@ -126,7 +126,7 @@ namespace Azure { namespace Storage { namespace Blobs {
BlobBatchClient::BlobBatchClient(
const std::string& serviceUri,
std::shared_ptr<Core::Credentials::TokenCredential> credential,
std::shared_ptr<Core::TokenCredential> credential,
const BlobBatchClientOptions& options)
: m_serviceUrl(serviceUri)
{
@ -145,9 +145,8 @@ namespace Azure { namespace Storage { namespace Blobs {
policies.emplace_back(p->Clone());
}
policies.emplace_back(std::make_unique<StoragePerRetryPolicy>());
policies.emplace_back(
std::make_unique<Core::Credentials::Policy::BearerTokenAuthenticationPolicy>(
credential, Details::c_StorageScope));
policies.emplace_back(std::make_unique<Core::BearerTokenAuthenticationPolicy>(
credential, Details::c_StorageScope));
policies.emplace_back(std::make_unique<Azure::Core::Http::TransportPolicy>(
std::make_shared<Azure::Core::Http::CurlTransport>()));
m_pipeline = std::make_shared<Azure::Core::Http::HttpPipeline>(policies);
@ -162,9 +161,8 @@ namespace Azure { namespace Storage { namespace Blobs {
policies.emplace_back(p->Clone());
}
policies.emplace_back(std::make_unique<StoragePerRetryPolicy>());
policies.emplace_back(
std::make_unique<Core::Credentials::Policy::BearerTokenAuthenticationPolicy>(
credential, Details::c_StorageScope));
policies.emplace_back(std::make_unique<Core::BearerTokenAuthenticationPolicy>(
credential, Details::c_StorageScope));
policies.emplace_back(std::make_unique<NoopTransportPolicy>());
m_subRequestPipeline = std::make_shared<Azure::Core::Http::HttpPipeline>(policies);
}

View File

@ -3,7 +3,7 @@
#include "azure/storage/blobs/blob_client.hpp"
#include "azure/core/credentials/policy/policies.hpp"
#include "azure/core/credentials.hpp"
#include "azure/core/http/curl/curl.hpp"
#include "azure/storage/blobs/append_blob_client.hpp"
#include "azure/storage/blobs/block_blob_client.hpp"
@ -68,7 +68,7 @@ namespace Azure { namespace Storage { namespace Blobs {
BlobClient::BlobClient(
const std::string& blobUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const BlobClientOptions& options)
: BlobClient(blobUri, options)
{
@ -86,9 +86,8 @@ namespace Azure { namespace Storage { namespace Blobs {
policies.emplace_back(p->Clone());
}
policies.emplace_back(std::make_unique<StoragePerRetryPolicy>());
policies.emplace_back(
std::make_unique<Core::Credentials::Policy::BearerTokenAuthenticationPolicy>(
credential, Details::c_StorageScope));
policies.emplace_back(std::make_unique<Core::BearerTokenAuthenticationPolicy>(
credential, Details::c_StorageScope));
policies.emplace_back(std::make_unique<Azure::Core::Http::TransportPolicy>(
std::make_shared<Azure::Core::Http::CurlTransport>()));
m_pipeline = std::make_shared<Azure::Core::Http::HttpPipeline>(policies);

View File

@ -3,7 +3,7 @@
#include "azure/storage/blobs/blob_container_client.hpp"
#include "azure/core/credentials/policy/policies.hpp"
#include "azure/core/credentials.hpp"
#include "azure/core/http/curl/curl.hpp"
#include "azure/storage/blobs/append_blob_client.hpp"
#include "azure/storage/blobs/block_blob_client.hpp"
@ -64,7 +64,7 @@ namespace Azure { namespace Storage { namespace Blobs {
BlobContainerClient::BlobContainerClient(
const std::string& containerUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const BlobContainerClientOptions& options)
: BlobContainerClient(containerUri, options)
{
@ -82,9 +82,8 @@ namespace Azure { namespace Storage { namespace Blobs {
policies.emplace_back(p->Clone());
}
policies.emplace_back(std::make_unique<StoragePerRetryPolicy>());
policies.emplace_back(
std::make_unique<Core::Credentials::Policy::BearerTokenAuthenticationPolicy>(
credential, Details::c_StorageScope));
policies.emplace_back(std::make_unique<Core::BearerTokenAuthenticationPolicy>(
credential, Details::c_StorageScope));
policies.emplace_back(std::make_unique<Azure::Core::Http::TransportPolicy>(
std::make_shared<Azure::Core::Http::CurlTransport>()));
m_pipeline = std::make_shared<Azure::Core::Http::HttpPipeline>(policies);

View File

@ -3,7 +3,7 @@
#include "azure/storage/blobs/blob_service_client.hpp"
#include "azure/core/credentials/policy/policies.hpp"
#include "azure/core/credentials.hpp"
#include "azure/core/http/curl/curl.hpp"
#include "azure/storage/common/constants.hpp"
#include "azure/storage/common/shared_key_policy.hpp"
@ -59,7 +59,7 @@ namespace Azure { namespace Storage { namespace Blobs {
BlobServiceClient::BlobServiceClient(
const std::string& serviceUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const BlobServiceClientOptions& options)
: m_serviceUrl(serviceUri)
{
@ -77,9 +77,8 @@ namespace Azure { namespace Storage { namespace Blobs {
policies.emplace_back(p->Clone());
}
policies.emplace_back(std::make_unique<StoragePerRetryPolicy>());
policies.emplace_back(
std::make_unique<Core::Credentials::Policy::BearerTokenAuthenticationPolicy>(
credential, Details::c_StorageScope));
policies.emplace_back(std::make_unique<Core::BearerTokenAuthenticationPolicy>(
credential, Details::c_StorageScope));
policies.emplace_back(std::make_unique<Azure::Core::Http::TransportPolicy>(
std::make_shared<Azure::Core::Http::CurlTransport>()));
m_pipeline = std::make_shared<Azure::Core::Http::HttpPipeline>(policies);

View File

@ -32,7 +32,7 @@ namespace Azure { namespace Storage { namespace Blobs {
BlockBlobClient::BlockBlobClient(
const std::string& blobUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const BlockBlobClientOptions& options)
: BlobClient(blobUri, std::move(credential), options)
{

View File

@ -31,7 +31,7 @@ namespace Azure { namespace Storage { namespace Blobs {
PageBlobClient::PageBlobClient(
const std::string& blobUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const PageBlobClientOptions& options)
: BlobClient(blobUri, std::move(credential), options)
{

View File

@ -45,7 +45,7 @@ namespace Azure { namespace Storage { namespace Test {
auto blobServiceClient1 = Blobs::BlobServiceClient(
serviceUri,
std::make_shared<Azure::Core::Credentials::ClientSecretCredential>(
std::make_shared<Azure::Identity::ClientSecretCredential>(
AadTenantId(), AadClientId(), AadClientSecret()));
auto userDelegationKey = *blobServiceClient1.GetUserDelegationKey(
ToIso8601(std::chrono::system_clock::now() - std::chrono::minutes(5)),

View File

@ -45,7 +45,7 @@ find_package(Threads REQUIRED)
find_package(LibXml2 REQUIRED)
target_include_directories(azure-storage-common PUBLIC inc ${LIBXML2_INCLUDE_DIR})
target_link_libraries(azure-storage-common Threads::Threads azure-core ${LIBXML2_LIBRARIES})
target_link_libraries(azure-storage-common Threads::Threads azure-core azure-identity ${LIBXML2_LIBRARIES})
if(MSVC)
target_link_libraries(azure-storage-common bcrypt)
# C28020 and C28204 are introduced by nlohmann/json

View File

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include "azure/core/credentials/credentials.hpp"
#include "azure/identity/client_secret_credential.hpp"
#include "azure/storage/blobs/blob.hpp"
#include "test_base.hpp"
@ -13,7 +13,7 @@ namespace Azure { namespace Storage { namespace Test {
EXPECT_FALSE(AadClientId().empty() || AadClientSecret().empty() || AadTenantId().empty());
auto credential = std::make_shared<Azure::Core::Credentials::ClientSecretCredential>(
auto credential = std::make_shared<Azure::Identity::ClientSecretCredential>(
AadTenantId(), AadClientId(), AadClientSecret());
auto containerClient = Azure::Storage::Blobs::BlobContainerClient(

View File

@ -3,9 +3,9 @@
#pragma once
#include "azure/core/credentials/credentials.hpp"
#include "azure/core/http/pipeline.hpp"
#include "azure/core/response.hpp"
#include "azure/identity/client_secret_credential.hpp"
#include "azure/storage/common/storage_credential.hpp"
#include "azure/storage/files/datalake/datalake_options.hpp"
#include "azure/storage/files/datalake/datalake_path_client.hpp"
@ -52,7 +52,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
*/
explicit DirectoryClient(
const std::string& directoryUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const DirectoryClientOptions& options = DirectoryClientOptions());
/**

View File

@ -3,9 +3,9 @@
#pragma once
#include "azure/core/credentials/credentials.hpp"
#include "azure/core/http/pipeline.hpp"
#include "azure/core/response.hpp"
#include "azure/identity/client_secret_credential.hpp"
#include "azure/storage/blobs/block_blob_client.hpp"
#include "azure/storage/common/storage_credential.hpp"
#include "azure/storage/files/datalake/datalake_options.hpp"
@ -53,7 +53,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
*/
explicit FileClient(
const std::string& fileUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const FileClientOptions& options = FileClientOptions());
/**

View File

@ -3,9 +3,9 @@
#pragma once
#include "azure/core/credentials/credentials.hpp"
#include "azure/core/http/pipeline.hpp"
#include "azure/core/response.hpp"
#include "azure/identity/client_secret_credential.hpp"
#include "azure/storage/blobs/blob_container_client.hpp"
#include "azure/storage/common/storage_credential.hpp"
#include "azure/storage/files/datalake/datalake_options.hpp"
@ -55,7 +55,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
*/
explicit FileSystemClient(
const std::string& fileSystemUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const FileSystemClientOptions& options = FileSystemClientOptions());
/**

View File

@ -3,9 +3,9 @@
#pragma once
#include "azure/core/credentials/credentials.hpp"
#include "azure/core/http/pipeline.hpp"
#include "azure/core/response.hpp"
#include "azure/identity/client_secret_credential.hpp"
#include "azure/storage/blobs/blob_client.hpp"
#include "azure/storage/common/storage_credential.hpp"
#include "azure/storage/files/datalake/datalake_file_system_client.hpp"
@ -53,7 +53,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
*/
explicit PathClient(
const std::string& pathUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const PathClientOptions& options = PathClientOptions());
/**

View File

@ -3,9 +3,9 @@
#pragma once
#include "azure/core/credentials/credentials.hpp"
#include "azure/core/http/pipeline.hpp"
#include "azure/core/response.hpp"
#include "azure/identity/client_secret_credential.hpp"
#include "azure/storage/blobs/blob_service_client.hpp"
#include "azure/storage/common/storage_credential.hpp"
#include "azure/storage/files/datalake/datalake_options.hpp"
@ -50,7 +50,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
*/
explicit ServiceClient(
const std::string& serviceUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const ServiceClientOptions& options = ServiceClientOptions());
/**

View File

@ -3,7 +3,7 @@
#include "azure/storage/files/datalake/datalake_directory_client.hpp"
#include "azure/core/credentials/policy/policies.hpp"
#include "azure/core/credentials.hpp"
#include "azure/core/http/curl/curl.hpp"
#include "azure/storage/common/constants.hpp"
#include "azure/storage/common/crypt.hpp"
@ -74,7 +74,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
DirectoryClient::DirectoryClient(
const std::string& directoryUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const DirectoryClientOptions& options)
: PathClient(directoryUri, credential, options)
{
@ -95,9 +95,8 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
policies.emplace_back(p->Clone());
}
policies.emplace_back(std::make_unique<StoragePerRetryPolicy>());
policies.emplace_back(
std::make_unique<Core::Credentials::Policy::BearerTokenAuthenticationPolicy>(
credential, Azure::Storage::Details::c_StorageScope));
policies.emplace_back(std::make_unique<Core::BearerTokenAuthenticationPolicy>(
credential, Azure::Storage::Details::c_StorageScope));
policies.emplace_back(std::make_unique<Azure::Core::Http::TransportPolicy>(
std::make_shared<Azure::Core::Http::CurlTransport>()));
m_pipeline = std::make_shared<Azure::Core::Http::HttpPipeline>(policies);

View File

@ -3,7 +3,7 @@
#include "azure/storage/files/datalake/datalake_file_client.hpp"
#include "azure/core/credentials/policy/policies.hpp"
#include "azure/core/credentials.hpp"
#include "azure/core/http/curl/curl.hpp"
#include "azure/storage/common/constants.hpp"
#include "azure/storage/common/crypt.hpp"
@ -152,7 +152,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
FileClient::FileClient(
const std::string& fileUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const FileClientOptions& options)
: PathClient(fileUri, credential, options),
m_blockBlobClient(m_blobClient.GetBlockBlobClient())
@ -175,9 +175,8 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
}
policies.emplace_back(std::make_unique<StoragePerRetryPolicy>());
policies.emplace_back(
std::make_unique<Core::Credentials::Policy::BearerTokenAuthenticationPolicy>(
credential, Azure::Storage::Details::c_StorageScope));
policies.emplace_back(std::make_unique<Core::BearerTokenAuthenticationPolicy>(
credential, Azure::Storage::Details::c_StorageScope));
policies.emplace_back(std::make_unique<Azure::Core::Http::TransportPolicy>(
std::make_shared<Azure::Core::Http::CurlTransport>()));
m_pipeline = std::make_shared<Azure::Core::Http::HttpPipeline>(policies);

View File

@ -3,7 +3,7 @@
#include "azure/storage/files/datalake/datalake_file_system_client.hpp"
#include "azure/core/credentials/policy/policies.hpp"
#include "azure/core/credentials.hpp"
#include "azure/core/http/curl/curl.hpp"
#include "azure/storage/blobs/protocol/blob_rest_client.hpp"
#include "azure/storage/common/constants.hpp"
@ -96,7 +96,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
FileSystemClient::FileSystemClient(
const std::string& fileSystemUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const FileSystemClientOptions& options)
: m_dfsUri(Details::GetDfsUriFromUri(fileSystemUri)),
m_blobContainerClient(
@ -122,9 +122,8 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
}
policies.emplace_back(std::make_unique<StoragePerRetryPolicy>());
policies.emplace_back(
std::make_unique<Core::Credentials::Policy::BearerTokenAuthenticationPolicy>(
credential, Azure::Storage::Details::c_StorageScope));
policies.emplace_back(std::make_unique<Core::BearerTokenAuthenticationPolicy>(
credential, Azure::Storage::Details::c_StorageScope));
policies.emplace_back(std::make_unique<Azure::Core::Http::TransportPolicy>(
std::make_shared<Azure::Core::Http::CurlTransport>()));
m_pipeline = std::make_shared<Azure::Core::Http::HttpPipeline>(policies);

View File

@ -3,7 +3,7 @@
#include "azure/storage/files/datalake/datalake_path_client.hpp"
#include "azure/core/credentials/policy/policies.hpp"
#include "azure/core/credentials.hpp"
#include "azure/core/http/curl/curl.hpp"
#include "azure/storage/common/constants.hpp"
#include "azure/storage/common/crypt.hpp"
@ -136,7 +136,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
PathClient::PathClient(
const std::string& pathUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const PathClientOptions& options)
: m_dfsUri(Details::GetDfsUriFromUri(pathUri)),
m_blobClient(Details::GetBlobUriFromUri(pathUri), credential, GetBlobClientOptions(options))
@ -159,9 +159,8 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
}
policies.emplace_back(std::make_unique<StoragePerRetryPolicy>());
policies.emplace_back(
std::make_unique<Core::Credentials::Policy::BearerTokenAuthenticationPolicy>(
credential, Azure::Storage::Details::c_StorageScope));
policies.emplace_back(std::make_unique<Core::BearerTokenAuthenticationPolicy>(
credential, Azure::Storage::Details::c_StorageScope));
policies.emplace_back(std::make_unique<Azure::Core::Http::TransportPolicy>(
std::make_shared<Azure::Core::Http::CurlTransport>()));
m_pipeline = std::make_shared<Azure::Core::Http::HttpPipeline>(policies);

View File

@ -3,7 +3,7 @@
#include "azure/storage/files/datalake/datalake_service_client.hpp"
#include "azure/core/credentials/policy/policies.hpp"
#include "azure/core/credentials.hpp"
#include "azure/core/http/curl/curl.hpp"
#include "azure/storage/blobs/protocol/blob_rest_client.hpp"
#include "azure/storage/common/constants.hpp"
@ -103,7 +103,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
ServiceClient::ServiceClient(
const std::string& serviceUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const ServiceClientOptions& options)
: m_dfsUri(Details::GetDfsUriFromUri(serviceUri)), m_blobServiceClient(
Details::GetBlobUriFromUri(serviceUri),
@ -127,9 +127,8 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
policies.emplace_back(p->Clone());
}
policies.emplace_back(std::make_unique<StoragePerRetryPolicy>());
policies.emplace_back(
std::make_unique<Core::Credentials::Policy::BearerTokenAuthenticationPolicy>(
credential, Azure::Storage::Details::c_StorageScope));
policies.emplace_back(std::make_unique<Core::BearerTokenAuthenticationPolicy>(
credential, Azure::Storage::Details::c_StorageScope));
policies.emplace_back(std::make_unique<Azure::Core::Http::TransportPolicy>(
std::make_shared<Azure::Core::Http::CurlTransport>()));
m_pipeline = std::make_shared<Azure::Core::Http::HttpPipeline>(policies);

View File

@ -52,7 +52,7 @@ namespace Azure { namespace Storage { namespace Test {
auto serviceClient1 = Files::DataLake::ServiceClient(
serviceUri,
std::make_shared<Azure::Core::Credentials::ClientSecretCredential>(
std::make_shared<Azure::Identity::ClientSecretCredential>(
AadTenantId(), AadClientId(), AadClientSecret()));
auto userDelegationKey = *serviceClient1.GetUserDelegationKey(
ToIso8601(std::chrono::system_clock::now() - std::chrono::minutes(5)),

View File

@ -3,9 +3,9 @@
#pragma once
#include "azure/core/credentials/credentials.hpp"
#include "azure/core/http/pipeline.hpp"
#include "azure/core/response.hpp"
#include "azure/identity/client_secret_credential.hpp"
#include "azure/storage/common/storage_credential.hpp"
#include "azure/storage/files/shares/protocol/share_rest_client.hpp"
#include "azure/storage/files/shares/share_options.hpp"
@ -53,7 +53,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
*/
explicit ShareClient(
const std::string& shareUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const ShareClientOptions& options = ShareClientOptions());
/**

View File

@ -3,9 +3,9 @@
#pragma once
#include "azure/core/credentials/credentials.hpp"
#include "azure/core/http/pipeline.hpp"
#include "azure/core/response.hpp"
#include "azure/identity/client_secret_credential.hpp"
#include "azure/storage/common/storage_credential.hpp"
#include "azure/storage/files/shares/protocol/share_rest_client.hpp"
#include "azure/storage/files/shares/share_client.hpp"
@ -55,7 +55,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
*/
explicit DirectoryClient(
const std::string& shareDirectoryUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const DirectoryClientOptions& options = DirectoryClientOptions());
/**

View File

@ -3,9 +3,9 @@
#pragma once
#include "azure/core/credentials/credentials.hpp"
#include "azure/core/http/pipeline.hpp"
#include "azure/core/response.hpp"
#include "azure/identity/client_secret_credential.hpp"
#include "azure/storage/common/storage_credential.hpp"
#include "azure/storage/files/shares/protocol/share_rest_client.hpp"
#include "azure/storage/files/shares/share_client.hpp"
@ -54,7 +54,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
*/
explicit FileClient(
const std::string& shareFileUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const FileClientOptions& options = FileClientOptions());
/**

View File

@ -3,9 +3,9 @@
#pragma once
#include "azure/core/credentials/credentials.hpp"
#include "azure/core/http/pipeline.hpp"
#include "azure/core/response.hpp"
#include "azure/identity/client_secret_credential.hpp"
#include "azure/storage/common/storage_credential.hpp"
#include "azure/storage/files/shares/protocol/share_rest_client.hpp"
#include "azure/storage/files/shares/share_options.hpp"
@ -50,7 +50,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
*/
explicit ServiceClient(
const std::string& serviceUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const ServiceClientOptions& options = ServiceClientOptions());
/**

View File

@ -3,7 +3,7 @@
#include "azure/storage/files/shares/share_client.hpp"
#include "azure/core/credentials/policy/policies.hpp"
#include "azure/core/credentials.hpp"
#include "azure/core/http/curl/curl.hpp"
#include "azure/storage/common/constants.hpp"
#include "azure/storage/common/crypt.hpp"
@ -65,7 +65,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
ShareClient::ShareClient(
const std::string& shareUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const ShareClientOptions& options)
: m_shareUri(shareUri)
{
@ -83,9 +83,8 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
policies.emplace_back(p->Clone());
}
policies.emplace_back(std::make_unique<StoragePerRetryPolicy>());
policies.emplace_back(
std::make_unique<Core::Credentials::Policy::BearerTokenAuthenticationPolicy>(
credential, Azure::Storage::Details::c_StorageScope));
policies.emplace_back(std::make_unique<Core::BearerTokenAuthenticationPolicy>(
credential, Azure::Storage::Details::c_StorageScope));
policies.emplace_back(std::make_unique<Azure::Core::Http::TransportPolicy>(
std::make_shared<Azure::Core::Http::CurlTransport>()));
m_pipeline = std::make_shared<Azure::Core::Http::HttpPipeline>(policies);

View File

@ -3,7 +3,7 @@
#include "azure/storage/files/shares/share_directory_client.hpp"
#include "azure/core/credentials/policy/policies.hpp"
#include "azure/core/credentials.hpp"
#include "azure/core/http/curl/curl.hpp"
#include "azure/storage/common/constants.hpp"
#include "azure/storage/common/crypt.hpp"
@ -66,7 +66,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
DirectoryClient::DirectoryClient(
const std::string& shareDirectoryUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const DirectoryClientOptions& options)
: m_shareDirectoryUri(shareDirectoryUri)
{
@ -84,9 +84,8 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
policies.emplace_back(p->Clone());
}
policies.emplace_back(std::make_unique<StoragePerRetryPolicy>());
policies.emplace_back(
std::make_unique<Core::Credentials::Policy::BearerTokenAuthenticationPolicy>(
credential, Azure::Storage::Details::c_StorageScope));
policies.emplace_back(std::make_unique<Core::BearerTokenAuthenticationPolicy>(
credential, Azure::Storage::Details::c_StorageScope));
policies.emplace_back(std::make_unique<Azure::Core::Http::TransportPolicy>(
std::make_shared<Azure::Core::Http::CurlTransport>()));
m_pipeline = std::make_shared<Azure::Core::Http::HttpPipeline>(policies);

View File

@ -3,7 +3,7 @@
#include "azure/storage/files/shares/share_file_client.hpp"
#include "azure/core/credentials/policy/policies.hpp"
#include "azure/core/credentials.hpp"
#include "azure/core/http/curl/curl.hpp"
#include "azure/storage/common/concurrent_transfer.hpp"
#include "azure/storage/common/constants.hpp"
@ -69,7 +69,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
FileClient::FileClient(
const std::string& shareFileUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const FileClientOptions& options)
: m_shareFileUri(shareFileUri)
{
@ -87,9 +87,8 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
policies.emplace_back(p->Clone());
}
policies.emplace_back(std::make_unique<StoragePerRetryPolicy>());
policies.emplace_back(
std::make_unique<Core::Credentials::Policy::BearerTokenAuthenticationPolicy>(
credential, Azure::Storage::Details::c_StorageScope));
policies.emplace_back(std::make_unique<Core::BearerTokenAuthenticationPolicy>(
credential, Azure::Storage::Details::c_StorageScope));
policies.emplace_back(std::make_unique<Azure::Core::Http::TransportPolicy>(
std::make_shared<Azure::Core::Http::CurlTransport>()));
m_pipeline = std::make_shared<Azure::Core::Http::HttpPipeline>(policies);

View File

@ -3,7 +3,7 @@
#include "azure/storage/files/shares/share_service_client.hpp"
#include "azure/core/credentials/policy/policies.hpp"
#include "azure/core/credentials.hpp"
#include "azure/core/http/curl/curl.hpp"
#include "azure/storage/common/constants.hpp"
#include "azure/storage/common/shared_key_policy.hpp"
@ -61,7 +61,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
ServiceClient::ServiceClient(
const std::string& serviceUri,
std::shared_ptr<Core::Credentials::ClientSecretCredential> credential,
std::shared_ptr<Identity::ClientSecretCredential> credential,
const ServiceClientOptions& options)
: m_serviceUri(serviceUri)
{
@ -79,9 +79,8 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
policies.emplace_back(p->Clone());
}
policies.emplace_back(std::make_unique<StoragePerRetryPolicy>());
policies.emplace_back(
std::make_unique<Core::Credentials::Policy::BearerTokenAuthenticationPolicy>(
credential, Azure::Storage::Details::c_StorageScope));
policies.emplace_back(std::make_unique<Core::BearerTokenAuthenticationPolicy>(
credential, Azure::Storage::Details::c_StorageScope));
policies.emplace_back(std::make_unique<Azure::Core::Http::TransportPolicy>(
std::make_shared<Azure::Core::Http::CurlTransport>()));
m_pipeline = std::make_shared<Azure::Core::Http::HttpPipeline>(policies);

View File

@ -12,6 +12,7 @@ trigger:
- eng/
- CMakeLists.txt
- sdk/core
- sdk/identity
- sdk/storage
pr:
@ -27,6 +28,7 @@ pr:
- eng/
- CMakeLists.txt
- sdk/core/
- sdk/identity/
- sdk/storage
stages:

View File

@ -18,10 +18,10 @@ namespace Azure { namespace Template {
static constexpr int Minor = AZURE_TEMPLATE_VERSION_MINOR;
static constexpr int Patch = AZURE_TEMPLATE_VERSION_PATCH;
static std::string const PreRelease;
static std::string const VersionString();
static std::string VersionString();
private:
//To avoid leaking out the #define values we smuggle out the value
// To avoid leaking out the #define values we smuggle out the value
// which will later be used to initialize the PreRelease std::string
static constexpr const char* secret = AZURE_TEMPLATE_VERSION_PRERELEASE;
};

View File

@ -2,28 +2,27 @@
// SPDX-License-Identifier: MIT
#include <azure/template/version.hpp>
#include <string>
#include <sstream>
#include <string>
using namespace Azure::Template;
const std::string Version::PreRelease = secret;
std::string const Azure::Template::Version::VersionString()
std::string Azure::Template::Version::VersionString()
{
static const std::string versionString = [] {
std::string version;
std::stringstream ss;
std::string dot = ".";
std::string version;
std::stringstream ss;
std::string dot = ".";
ss << Version::Major << dot << Version::Minor << dot << Version::Patch;
ss << Version::Major << dot << Version::Minor << dot << Version::Patch;
if (!Version::PreRelease.empty())
ss << "-" << Version::PreRelease;
if (!Version::PreRelease.empty())
ss << "-" << Version::PreRelease;
return ss.str();
return ss.str();
}();
return versionString;
}