Update Key Vault packages to use Shared-code (#2905)

* Use key vault shared code strategy for code-reuse between packages

* use a class instead of function only

* unwanted change

* unwanted change

* remove the install interface

* typo
This commit is contained in:
Victor Vazquez 2021-10-11 14:17:55 -07:00 committed by GitHub
parent eb2fab16a0
commit 4eb33a0015
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 85 additions and 461 deletions

View File

@ -54,6 +54,14 @@ target_include_directories(
$<INSTALL_INTERFACE:include>
)
# Include shared source code
# NOTE: Use shared-code only within .cpp files. DO NEVER consume the shared-code from header files.
target_include_directories(
azure-security-keyvault-certificates
PRIVATE
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/sdk/keyvault/azure-security-keyvault-shared/inc>
)
target_link_libraries(azure-security-keyvault-certificates PUBLIC Azure::azure-core)
# coverage. Has no effect if BUILD_CODE_COVERAGE is OFF

View File

@ -8,6 +8,8 @@
#include "private/keyvault_certificates_common_request.hpp"
#include "private/package_version.hpp"
#include <azure/keyvault/shared/keyvault_shared.hpp>
#include <azure/core/credentials/credentials.hpp>
#include <azure/core/http/http.hpp>
#include <azure/core/http/policies/policy.hpp>
@ -28,25 +30,6 @@ using namespace Azure::Core::Http::_internal;
using namespace Azure::Security::KeyVault::_detail;
namespace {
// This is a Key-Vault only patch to calculate token scope/audience
std::string GetScopeFromUrl(Azure::Core::Url const& url)
{
std::string calculatedScope(url.GetScheme() + "://");
auto const& hostWithAccount = url.GetHost();
auto hostNoAccountStart = std::find(hostWithAccount.begin(), hostWithAccount.end(), '.');
// Insert the calculated scope only when then host in the url contains at least a `.`
// Otherwise, only the default scope will be there.
// We don't want to throw/validate input but just leave the values go to azure to decide what to
// do.
if (hostNoAccountStart != hostWithAccount.end())
{
calculatedScope.append(hostNoAccountStart + 1, hostWithAccount.end());
calculatedScope.append("/.default");
}
return calculatedScope;
}
} // namespace
std::unique_ptr<RawResponse> CertificateClient::SendRequest(
@ -76,7 +59,7 @@ CertificateClient::CertificateClient(
std::vector<std::unique_ptr<HttpPolicy>> perRetrypolicies;
{
Azure::Core::Credentials::TokenRequestContext const tokenContext
= {{::GetScopeFromUrl(m_vaultUrl)}};
= {{_internal::UrlScope::GetScopeFromUrl(m_vaultUrl)}};
perRetrypolicies.emplace_back(
std::make_unique<BearerTokenAuthenticationPolicy>(credential, std::move(tokenContext)));

View File

@ -1,26 +0,0 @@
# Release History
## 4.0.0-beta.4 (Unreleased)
### Breaking Changes
- Removed `SHA256`, `SHA384`, and `SHA512` hashing classes by making them internal since the end user doesn't need them.
- Removed header `single_page.hpp`.
## 4.0.0-beta.3 (2021-06-08)
No breaking changes or new features added. Includes only implementation enhancements.
## 4.0.0-beta.2 (2021-05-18)
### Breaking Changes
- Added `final` specifier to classes and structures that are are not expected to be inheritable at the moment.
- Removed `KeyVaultException`.
- Removed `ClientOptions`.
## 4.0.0-beta.1 (2021-04-07)
### New Features
- KeyVaultException.

View File

@ -1,81 +0,0 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# SPDX-License-Identifier: MIT
cmake_minimum_required (VERSION 3.13)
project(azure-security-keyvault-common LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake-modules")
include(AzureVcpkg)
include(AzureVersion)
include(AzureCodeCoverage)
include(AzureTransportAdapters)
include(AzureDoxygen)
include(AzureGlobalCompileOptions)
az_vcpkg_integrate()
if(NOT AZ_ALL_LIBRARIES)
find_package(azure-core-cpp "1.2.0" CONFIG QUIET)
if(NOT azure-core-cpp_FOUND)
find_package(azure-core-cpp "1.2.0" REQUIRED)
endif()
endif()
set(
AZURE_KEYVAULT_COMMON_SOURCE
src/private/package_version.hpp
)
add_library(
azure-security-keyvault-common
${AZURE_KEYVAULT_COMMON_SOURCE}
)
add_library(Azure::azure-security-keyvault-common ALIAS azure-security-keyvault-common)
target_include_directories(
azure-security-keyvault-common
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(azure-security-keyvault-common PUBLIC Azure::azure-core)
if(WIN32)
target_link_libraries(azure-security-keyvault-common PRIVATE bcrypt crypt32)
else()
find_package(OpenSSL REQUIRED)
target_link_libraries(azure-security-keyvault-common PRIVATE OpenSSL::SSL)
endif()
if(MSVC)
# C28020 and C28204 are introduced by nlohmann/json
target_compile_options(azure-security-keyvault-common PUBLIC /wd28204 /wd28020)
endif()
# coverage. Has no effect if BUILD_CODE_COVERAGE is OFF
create_code_coverage(keyvault azure-security-keyvault-common azure-security-keyvault-common-test)
get_az_version("${CMAKE_CURRENT_SOURCE_DIR}/src/private/package_version.hpp")
#generate_documentation(azure-security-keyvault-common ${AZ_LIBRARY_VERSION})
if(BUILD_TESTING)
# tests
if (NOT AZ_ALL_LIBRARIES)
include(AddGoogleTest)
enable_testing ()
endif()
add_subdirectory(test/ut)
endif()
az_vcpkg_export(
azure-security-keyvault-common
SECURITY_KEYVAULT_COMMON
"azure/keyvault/common/dll_import_export.hpp"
)

View File

@ -1,32 +0,0 @@
azure-sdk-for-cpp
NOTICES AND INFORMATION
Do Not Translate or Localize
This software incorporates material from third parties. Microsoft makes certain
open source code available at https://3rdpartysource.microsoft.com, or you may
send a check or money order for US $5.00, including the product name, the open
source component name, and version number, to:
Source Code Compliance Team
Microsoft Corporation
One Microsoft Way
Redmond, WA 98052
USA
Notwithstanding any other terms, you may reverse engineer this software to the
extent required to debug changes to any libraries licensed under the GNU Lesser
General Public License.
------------------------------------------------------------------------------
Azure SDK for C++ uses third-party libraries or other resources that may be
distributed under licenses different than the Azure SDK for C++ software.
In the event that we accidentally failed to list a required notice, please
bring it to our attention. Post an issue or email us:
azcppsdkhelp@microsoft.com
The attached notices are provided for information only.

View File

@ -1,36 +0,0 @@
{
"Registrations": [
{
"Component": {
"Type": "git",
"git": {
"RepositoryUrl": "https://github.com/google/googletest",
"CommitHash": "703bd9caab50b139428cea1aaff9974ebee5742e"
}
},
"DevelopmentDependency": true
},
{
"Component": {
"Type": "other",
"Other": {
"Name": "clang-format",
"Version": "9.0.0-2",
"DownloadUrl": "https://ubuntu.pkgs.org/18.04/ubuntu-updates-universe-amd64/clang-format-9_9-2~ubuntu18.04.2_amd64.deb.html"
}
},
"DevelopmentDependency": true
},
{
"Component": {
"Type": "other",
"Other": {
"Name": "doxygen",
"Version": "1.8.20",
"DownloadUrl": "http://doxygen.nl/files/doxygen-1.8.20-setup.exe"
}
},
"DevelopmentDependency": true
}
]
}

View File

@ -1,40 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
/**
* @file
* @brief DLL export macro.
*/
// For explanation, see the comment in azure/core/dll_import_export.hpp
#pragma once
/**
* @def AZ_SECURITY_KEYVAULT_COMMON_DLLEXPORT
* @brief Applies DLL export attribute, when applicable.
* @note See https://docs.microsoft.com/cpp/cpp/dllexport-dllimport?view=msvc-160.
*/
#if defined(AZ_SECURITY_KEYVAULT_COMMON_DLL) \
|| (0 /*@AZ_SECURITY_KEYVAULT_COMMON_DLL_INSTALLED_AS_PACKAGE@*/)
#define AZ_SECURITY_KEYVAULT_COMMON_BUILT_AS_DLL 1
#else
#define AZ_SECURITY_KEYVAULT_COMMON_BUILT_AS_DLL 0
#endif
#if AZ_SECURITY_KEYVAULT_COMMON_BUILT_AS_DLL
#if defined(_MSC_VER)
#if defined(AZ_SECURITY_KEYVAULT_COMMON_BEING_BUILT)
#define AZ_SECURITY_KEYVAULT_COMMON_DLLEXPORT __declspec(dllexport)
#else // !defined(AZ_SECURITY_KEYVAULT_COMMON_BEING_BUILT)
#define AZ_SECURITY_KEYVAULT_COMMON_DLLEXPORT __declspec(dllimport)
#endif // AZ_SECURITY_KEYVAULT_COMMON_BEING_BUILT
#else // !defined(_MSC_VER)
#define AZ_SECURITY_KEYVAULT_COMMON_DLLEXPORT
#endif // _MSC_VER
#else // !AZ_SECURITY_KEYVAULT_COMMON_BUILT_AS_DLL
#define AZ_SECURITY_KEYVAULT_COMMON_DLLEXPORT
#endif // AZ_SECURITY_KEYVAULT_COMMON_BUILT_AS_DLL
#undef AZ_SECURITY_KEYVAULT_COMMON_BUILT_AS_DLL

View File

@ -1,63 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
/**
* @file
* @brief Provides version information.
*/
#pragma once
#include <cstdint>
#define AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MAJOR 4
#define AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MINOR 0
#define AZURE_SECURITY_KEYVAULT_COMMON_VERSION_PATCH 0
#define AZURE_SECURITY_KEYVAULT_COMMON_VERSION_PRERELEASE "beta.4"
#define AZURE_SECURITY_KEYVAULT_COMMON_VERSION_ITOA_HELPER(i) #i
#define AZURE_SECURITY_KEYVAULT_COMMON_VERSION_ITOA(i) \
AZURE_SECURITY_KEYVAULT_COMMON_VERSION_ITOA_HELPER(i)
namespace Azure { namespace Security { namespace KeyVault { namespace Common { namespace _detail {
/**
* @brief Provides version information.
*
*/
class PackageVersion final {
public:
/// Major numeric identifier.
static constexpr int32_t Major = AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MAJOR;
/// Minor numeric identifier.
static constexpr int32_t Minor = AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MINOR;
/// Patch numeric identifier.
static constexpr int32_t Patch = AZURE_SECURITY_KEYVAULT_COMMON_VERSION_PATCH;
/// Indicates whether the SDK is in a pre-release state.
static constexpr bool IsPreRelease
= sizeof(AZURE_SECURITY_KEYVAULT_COMMON_VERSION_PRERELEASE) != sizeof("");
/**
* @brief The version in string format used for telemetry following the `semver.org` standard
* (https://semver.org).
*/
static constexpr const char* ToString()
{
return IsPreRelease
? AZURE_SECURITY_KEYVAULT_COMMON_VERSION_ITOA(AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MAJOR) "." AZURE_SECURITY_KEYVAULT_COMMON_VERSION_ITOA(
AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MINOR) "." AZURE_SECURITY_KEYVAULT_COMMON_VERSION_ITOA(AZURE_SECURITY_KEYVAULT_COMMON_VERSION_PATCH) "-" AZURE_SECURITY_KEYVAULT_COMMON_VERSION_PRERELEASE
: AZURE_SECURITY_KEYVAULT_COMMON_VERSION_ITOA(AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MAJOR) "." AZURE_SECURITY_KEYVAULT_COMMON_VERSION_ITOA(
AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MINOR) "." AZURE_SECURITY_KEYVAULT_COMMON_VERSION_ITOA(AZURE_SECURITY_KEYVAULT_COMMON_VERSION_PATCH);
}
};
}}}}} // namespace Azure::Security::KeyVault::Common::_detail
#undef AZURE_SECURITY_KEYVAULT_COMMON_VERSION_ITOA_HELPER
#undef AZURE_SECURITY_KEYVAULT_COMMON_VERSION_ITOA
#undef AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MAJOR
#undef AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MINOR
#undef AZURE_SECURITY_KEYVAULT_COMMON_VERSION_PATCH
#undef AZURE_SECURITY_KEYVAULT_COMMON_VERSION_PRERELEASE

View File

@ -1,29 +0,0 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# SPDX-License-Identifier: MIT
cmake_minimum_required (VERSION 3.13)
project (azure-security-keyvault-common-test LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)
include(GoogleTest)
add_executable (
azure-security-keyvault-common-test
azure_security_keyvault_common_test.cpp
)
if (MSVC)
target_compile_options(azure-security-keyvault-common-test PUBLIC /wd6326 /wd26495 /wd26812)
endif()
target_link_libraries(azure-security-keyvault-common-test PUBLIC gtest gmock)
# gtest_discover_tests will scan the test from azure-core-test and call add_test
# for each test to ctest. This enables `ctest -r` to run specific tests directly.
gtest_discover_tests(azure-security-keyvault-common-test
TEST_PREFIX azure-security-keyvault-common-unittest.
NO_PRETTY_TYPES
NO_PRETTY_VALUES
)

View File

@ -1,11 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include "gtest/gtest.h"
int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
auto r = RUN_ALL_TESTS();
return r;
}

View File

@ -1,11 +0,0 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# SPDX-License-Identifier: MIT
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
find_dependency(azure-core-cpp "1.2.0")
include("${CMAKE_CURRENT_LIST_DIR}/azure-security-keyvault-common-cppTargets.cmake")
check_required_components("azure-security-keyvault-common-cpp")

View File

@ -1,21 +0,0 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# SPDX-License-Identifier: MIT
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO Azure/azure-sdk-for-cpp
REF azure-security-keyvault-common_@AZ_LIBRARY_VERSION@
SHA512 0
)
vcpkg_cmake_configure(
SOURCE_PATH ${SOURCE_PATH}/sdk/keyvault/azure-security-keyvault-common/
OPTIONS
-DWARNINGS_AS_ERRORS=OFF
)
vcpkg_cmake_install()
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
vcpkg_cmake_config_fixup()
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")
vcpkg_copy_pdbs()

View File

@ -1,28 +0,0 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# SPDX-License-Identifier: MIT
{
"name": "azure-security-keyvault-common-cpp",
"version-semver": "@AZ_LIBRARY_VERSION@",
"description": [
"Microsoft Azure Common Key Vault SDK for C++",
"This library provides common Azure Key Vault related abstractions for Azure SDK."
],
"homepage": "https://github.com/Azure/azure-sdk-for-cpp/tree/main/sdk/keyvault/azure-security-keyvault-common",
"license": "MIT",
"dependencies": [
{
"name": "azure-core-cpp",
"default-features": false,
"version>=": "1.2.0"
},
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
}
]
}

View File

@ -95,6 +95,14 @@ target_include_directories(
$<INSTALL_INTERFACE:include>
)
# Include shared source code
# NOTE: Use shared-code only within .cpp files. DO NEVER consume the shared-code from header files.
target_include_directories(
azure-security-keyvault-keys
PRIVATE
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/sdk/keyvault/azure-security-keyvault-shared/inc>
)
target_link_libraries(azure-security-keyvault-keys PUBLIC Azure::azure-core)
# coverage. Has no effect if BUILD_CODE_COVERAGE is OFF

View File

@ -6,6 +6,8 @@
#include <azure/core/http/http.hpp>
#include <azure/core/http/policies/policy.hpp>
#include <azure/keyvault/shared/keyvault_shared.hpp>
#include "azure/keyvault/keys/cryptography/cryptography_client.hpp"
#include "azure/keyvault/keys/key_client_models.hpp"
@ -59,26 +61,6 @@ inline std::vector<uint8_t> CreateDigest(
return hashAlgorithm->Final(data.data(), data.size());
}
// This is a Key-Vault only patch to calculate token scope/audience
std::string GetScopeFromUrl(Azure::Core::Url const& url)
{
std::string calculatedScope(url.GetScheme() + "://");
auto const& hostWithAccount = url.GetHost();
auto hostNoAccountStart = std::find(hostWithAccount.begin(), hostWithAccount.end(), '.');
// Insert the calculated scope only when then host in the url contains at least a `.`
// Otherwise, only the default scope will be there.
// We don't want to throw/validate input but just leave the values go to azure to decide what to
// do.
if (hostNoAccountStart != hostWithAccount.end())
{
calculatedScope.append(hostNoAccountStart + 1, hostWithAccount.end());
calculatedScope.append("/.default");
}
return calculatedScope;
}
} // namespace
Request CryptographyClient::CreateRequest(
@ -120,7 +102,7 @@ CryptographyClient::CryptographyClient(
std::vector<std::unique_ptr<HttpPolicy>> perRetrypolicies;
{
Azure::Core::Credentials::TokenRequestContext const tokenContext
= {{::GetScopeFromUrl(m_keyId)}};
= {{_internal::UrlScope::GetScopeFromUrl(m_keyId)}};
perRetrypolicies.emplace_back(
std::make_unique<BearerTokenAuthenticationPolicy>(credential, tokenContext));

View File

@ -6,6 +6,8 @@
#include <azure/core/http/policies/policy.hpp>
#include <azure/core/internal/http/pipeline.hpp>
#include <azure/keyvault/shared/keyvault_shared.hpp>
#include "azure/keyvault/keys/key_client.hpp"
#include "private/cryptography_internal_access.hpp"
#include "private/key_backup.hpp"
@ -30,27 +32,6 @@ using namespace Azure::Core::Http::_internal;
namespace {
constexpr static const char KeyVaultServicePackageName[] = "keyvault-keys";
constexpr static const char CreateValue[] = "create";
// This is a Key-Vault only patch to calculate token scope/audience
std::string GetScopeFromUrl(Azure::Core::Url const& url)
{
std::string calculatedScope(url.GetScheme() + "://");
auto const& hostWithAccount = url.GetHost();
auto hostNoAccountStart = std::find(hostWithAccount.begin(), hostWithAccount.end(), '.');
// Insert the calculated scope only when then host in the url contains at least a `.`
// Otherwise, only the default scope will be there.
// We don't want to throw/validate input but just leave the values go to azure to decide what to
// do.
if (hostNoAccountStart != hostWithAccount.end())
{
calculatedScope.append(hostNoAccountStart + 1, hostWithAccount.end());
calculatedScope.append("/.default");
}
return calculatedScope;
}
} // namespace
std::unique_ptr<RawResponse> KeyClient::SendRequest(
@ -93,7 +74,7 @@ KeyClient::KeyClient(
std::vector<std::unique_ptr<HttpPolicy>> perRetrypolicies;
{
Azure::Core::Credentials::TokenRequestContext const tokenContext
= {{::GetScopeFromUrl(m_vaultUrl)}};
= {{_internal::UrlScope::GetScopeFromUrl(m_vaultUrl)}};
perRetrypolicies.emplace_back(
std::make_unique<BearerTokenAuthenticationPolicy>(credential, std::move(tokenContext)));

View File

@ -64,6 +64,14 @@ target_include_directories(
$<INSTALL_INTERFACE:include>
)
# Include shared source code
# NOTE: Use shared-code only within .cpp files. DO NEVER consume the shared-code from header files.
target_include_directories(
azure-security-keyvault-secrets
PRIVATE
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/sdk/keyvault/azure-security-keyvault-shared/inc>
)
target_link_libraries(azure-security-keyvault-secrets PUBLIC Azure::azure-core)
# coverage. Has no effect if BUILD_CODE_COVERAGE is OFF

View File

@ -12,6 +12,9 @@
#include "private/package_version.hpp"
#include "private/secret_constants.hpp"
#include "private/secret_serializers.hpp"
#include <azure/keyvault/shared/keyvault_shared.hpp>
#include <azure/core/credentials/credentials.hpp>
#include <azure/core/http/http.hpp>
#include <azure/core/http/policies/policy.hpp>
@ -53,25 +56,6 @@ static inline RequestWithContinuationToken BuildRequestFromContinuationToken(
return request;
}
// This is a Key-Vault only patch to calculate token scope/audience
std::string GetScopeFromUrl(Azure::Core::Url const& url)
{
std::string calculatedScope(url.GetScheme() + "://");
auto const& hostWithAccount = url.GetHost();
auto hostNoAccountStart = std::find(hostWithAccount.begin(), hostWithAccount.end(), '.');
// Insert the calculated scope only when then host in the url contains at least a `.`
// Otherwise, only the default scope will be there.
// We don't want to throw/validate input but just leave the values go to azure to decide what to
// do.
if (hostNoAccountStart != hostWithAccount.end())
{
calculatedScope.append(hostNoAccountStart + 1, hostWithAccount.end());
calculatedScope.append("/.default");
}
return calculatedScope;
}
} // namespace
const ServiceVersion ServiceVersion::V7_2("7.2");
@ -86,7 +70,8 @@ SecretClient::SecretClient(
std::vector<std::unique_ptr<HttpPolicy>> perRetrypolicies;
{
Azure::Core::Credentials::TokenRequestContext const tokenContext = {{::GetScopeFromUrl(url)}};
Azure::Core::Credentials::TokenRequestContext const tokenContext
= {{_internal::UrlScope::GetScopeFromUrl(url)}};
perRetrypolicies.emplace_back(
std::make_unique<BearerTokenAuthenticationPolicy>(credential, tokenContext));

View File

@ -0,0 +1,47 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
/**
* @file
* @brief Shared code between Key Vault services.
*
*/
#pragma once
#include <azure/core/url.hpp>
#include <string>
namespace Azure { namespace Security { namespace KeyVault { namespace _internal {
/**
* @brief Provides functionality to get scope information from a URL.
*
*/
class UrlScope {
UrlScope() = delete;
public:
// This is a Key-Vault only patch to calculate token scope/audience
static std::string GetScopeFromUrl(Azure::Core::Url const& url)
{
std::string calculatedScope(url.GetScheme() + "://");
auto const& hostWithAccount = url.GetHost();
auto hostNoAccountStart = std::find(hostWithAccount.begin(), hostWithAccount.end(), '.');
// Insert the calculated scope only when the host in the url contains at least a `.`
// Otherwise, only the default scope will be there.
// We don't want to throw/validate input but just leave the values go to azure to decide what
// to do.
if (hostNoAccountStart != hostWithAccount.end())
{
calculatedScope.append(hostNoAccountStart + 1, hostWithAccount.end());
calculatedScope.append("/.default");
}
return calculatedScope;
}
};
}}}} // namespace Azure::Security::KeyVault::_internal