From 99db07b01b1c698a899f79fa5eb3d6c744b2daeb Mon Sep 17 00:00:00 2001 From: George Arama <50641385+gearama@users.noreply.github.com> Date: Thu, 7 Apr 2022 10:54:31 -0700 Subject: [PATCH 01/10] one commit to rule them all --- cmake-modules/FolderList.cmake | 10 +++++----- eng/common/testproxy/test-proxy-tool.yml | 17 ++++++++++++++++- .../azure-security-attestation/CHANGELOG.md | 10 ++++++++++ .../src/private/package_version.hpp | 2 +- sdk/core/azure-core/CHANGELOG.md | 10 ++++++++++ .../azure-core/src/private/package_version.hpp | 4 ++-- sdk/storage/azure-storage-blobs/CHANGELOG.md | 8 +++++++- sdk/storage/azure-storage-blobs/CMakeLists.txt | 4 ++-- .../src/private/package_version.hpp | 4 ++-- sdk/storage/azure-storage-blobs/vcpkg.json | 4 ++-- .../azure-storage-blobs/vcpkg/Config.cmake.in | 2 +- .../azure-storage-blobs/vcpkg/vcpkg.json | 2 +- sdk/storage/azure-storage-common/CHANGELOG.md | 8 ++++++-- sdk/storage/azure-storage-common/CMakeLists.txt | 4 ++-- sdk/storage/azure-storage-common/vcpkg.json | 4 ++-- .../azure-storage-common/vcpkg/Config.cmake.in | 2 +- .../azure-storage-common/vcpkg/vcpkg.json | 2 +- sdk/storage/azure-storage-queues/CHANGELOG.md | 8 +++++++- sdk/storage/azure-storage-queues/CMakeLists.txt | 4 ++-- .../src/private/package_version.hpp | 4 ++-- sdk/storage/azure-storage-queues/vcpkg.json | 4 ++-- .../azure-storage-queues/vcpkg/Config.cmake.in | 2 +- .../azure-storage-queues/vcpkg/vcpkg.json | 2 +- 23 files changed, 86 insertions(+), 35 deletions(-) diff --git a/cmake-modules/FolderList.cmake b/cmake-modules/FolderList.cmake index f2a555f2da..52de3985cd 100644 --- a/cmake-modules/FolderList.cmake +++ b/cmake-modules/FolderList.cmake @@ -13,10 +13,10 @@ macro(GetFolderList project) DownloadDepVersion(sdk/core azure-core 1.2.0) DownloadDepVersion(sdk/identity azure-identity 1.1.0) elseif(${project} STREQUAL STORAGE_COMMON) - DownloadDepVersion(sdk/core azure-core 1.3.1) + DownloadDepVersion(sdk/core azure-core 1.5.0) elseif(${project} STREQUAL STORAGE_BLOBS) - DownloadDepVersion(sdk/core azure-core 1.3.1) - DownloadDepVersion(sdk/storage/azure-storage-common azure-storage-common 12.2.2) + DownloadDepVersion(sdk/core azure-core 1.5.0) + DownloadDepVersion(sdk/storage/azure-storage-common azure-storage-common 12.2.3) elseif(${project} STREQUAL STORAGE_DATALAKE) DownloadDepVersion(sdk/core azure-core 1.3.1) DownloadDepVersion(sdk/storage/azure-storage-common azure-storage-common 12.2.2) @@ -25,8 +25,8 @@ macro(GetFolderList project) DownloadDepVersion(sdk/core azure-core 1.3.1) DownloadDepVersion(sdk/storage/azure-storage-common azure-storage-common 12.2.2) elseif(${project} STREQUAL STORAGE_QUEUES) - DownloadDepVersion(sdk/core azure-core 1.3.1) - DownloadDepVersion(sdk/storage/azure-storage-common azure-storage-common 12.2.2) + DownloadDepVersion(sdk/core azure-core 1.5.0) + DownloadDepVersion(sdk/storage/azure-storage-common azure-storage-common 12.2.3) endif() list(REMOVE_DUPLICATES BUILD_FOLDERS) endmacro() diff --git a/eng/common/testproxy/test-proxy-tool.yml b/eng/common/testproxy/test-proxy-tool.yml index 9006c0d7af..7b5fedaaeb 100644 --- a/eng/common/testproxy/test-proxy-tool.yml +++ b/eng/common/testproxy/test-proxy-tool.yml @@ -11,7 +11,7 @@ steps: - pwsh: | $version = $(Get-Content "$(Build.SourcesDirectory)/eng/common/testproxy/target_version.txt" -Raw).Trim() $overrideVersion = "${{ parameters.targetVersion }}" - + if($overrideVersion) { Write-Host "Overriding default target proxy version of '$version' with override $overrideVersion." $version = $overrideVersion @@ -47,3 +47,18 @@ steps: displayName: "Run the testproxy - linux/mac" condition: and(succeeded(), ne(variables['Agent.OS'],'Windows_NT')) workingDirectory: "${{ parameters.rootFolder }}" + + - pwsh: | + for ($i = 0; $i -lt 10; $i++) { + try { + Invoke-WebRequest -Uri "http://localhost:5000/Admin/IsAlive" | Out-Null + exit 0 + } catch { + Write-Warning "Failed to successfully connect to test proxy. Retrying..." + Start-Sleep 6 + } + } + Write-Error "Could not connect to test proxy." + exit 1 + displayName: Test Proxy IsAlive + diff --git a/sdk/attestation/azure-security-attestation/CHANGELOG.md b/sdk/attestation/azure-security-attestation/CHANGELOG.md index c18b84f051..ebe12c9519 100644 --- a/sdk/attestation/azure-security-attestation/CHANGELOG.md +++ b/sdk/attestation/azure-security-attestation/CHANGELOG.md @@ -1,5 +1,15 @@ # Release History +## 1.0.0-beta.2 (Unreleased) + +### Features Added + +### Breaking Changes + +### Bugs Fixed + +### Other Changes + ## 1.0.0-beta.1 (2022-04-05) ### Features Added diff --git a/sdk/attestation/azure-security-attestation/src/private/package_version.hpp b/sdk/attestation/azure-security-attestation/src/private/package_version.hpp index 9765dad46f..f762853cea 100644 --- a/sdk/attestation/azure-security-attestation/src/private/package_version.hpp +++ b/sdk/attestation/azure-security-attestation/src/private/package_version.hpp @@ -11,7 +11,7 @@ #define AZURE_ATTESTATION_VERSION_MAJOR 1 #define AZURE_ATTESTATION_VERSION_MINOR 0 #define AZURE_ATTESTATION_VERSION_PATCH 0 -#define AZURE_ATTESTATION_VERSION_PRERELEASE "beta.1" +#define AZURE_ATTESTATION_VERSION_PRERELEASE "beta.2" #define AZURE_ATTESTATION_VERSION_ITOA_HELPER(i) #i #define AZURE_ATTESTATION_VERSION_ITOA(i) AZURE_ATTESTATION_VERSION_ITOA_HELPER(i) diff --git a/sdk/core/azure-core/CHANGELOG.md b/sdk/core/azure-core/CHANGELOG.md index 6b46b7079d..7d96da393c 100644 --- a/sdk/core/azure-core/CHANGELOG.md +++ b/sdk/core/azure-core/CHANGELOG.md @@ -1,5 +1,15 @@ # Release History +## 1.6.0-beta.1 (Unreleased) + +### Features Added + +### Breaking Changes + +### Bugs Fixed + +### Other Changes + ## 1.5.0 (2022-03-31) ### Features Added diff --git a/sdk/core/azure-core/src/private/package_version.hpp b/sdk/core/azure-core/src/private/package_version.hpp index 59ba877a3d..b0f9e28ebe 100644 --- a/sdk/core/azure-core/src/private/package_version.hpp +++ b/sdk/core/azure-core/src/private/package_version.hpp @@ -11,9 +11,9 @@ #include #define AZURE_CORE_VERSION_MAJOR 1 -#define AZURE_CORE_VERSION_MINOR 5 +#define AZURE_CORE_VERSION_MINOR 6 #define AZURE_CORE_VERSION_PATCH 0 -#define AZURE_CORE_VERSION_PRERELEASE "" +#define AZURE_CORE_VERSION_PRERELEASE "beta.1" #define AZURE_CORE_VERSION_ITOA_HELPER(i) #i #define AZURE_CORE_VERSION_ITOA(i) AZURE_CORE_VERSION_ITOA_HELPER(i) diff --git a/sdk/storage/azure-storage-blobs/CHANGELOG.md b/sdk/storage/azure-storage-blobs/CHANGELOG.md index 6ff5f13bac..3ca4d85de9 100644 --- a/sdk/storage/azure-storage-blobs/CHANGELOG.md +++ b/sdk/storage/azure-storage-blobs/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 12.4.0-beta.2 (Unreleased) +## 12.5.0-beta.1 (Unreleased) ### Features Added @@ -10,6 +10,12 @@ ### Other Changes +## 12.4.0 (2022-04-06) + +### Other changes + +- No public changes in this release. + ## 12.4.0-beta.1 (2022-03-09) ### Features Added diff --git a/sdk/storage/azure-storage-blobs/CMakeLists.txt b/sdk/storage/azure-storage-blobs/CMakeLists.txt index 63348e5314..122ad8b768 100644 --- a/sdk/storage/azure-storage-blobs/CMakeLists.txt +++ b/sdk/storage/azure-storage-blobs/CMakeLists.txt @@ -32,9 +32,9 @@ if(FETCH_SOURCE_DEPS) add_subdirectory(${oneFolder} EXCLUDE_FROM_ALL) endforeach() elseif(NOT AZ_ALL_LIBRARIES) - find_package(azure-storage-common-cpp "12.2.2" CONFIG QUIET) + find_package(azure-storage-common-cpp "12.2.3" CONFIG QUIET) if(NOT azure-storage-common-cpp_FOUND) - find_package(azure-storage-common-cpp "12.2.2" REQUIRED) + find_package(azure-storage-common-cpp "12.2.3" REQUIRED) endif() endif() diff --git a/sdk/storage/azure-storage-blobs/src/private/package_version.hpp b/sdk/storage/azure-storage-blobs/src/private/package_version.hpp index 76fa57e75f..b2361f3b40 100644 --- a/sdk/storage/azure-storage-blobs/src/private/package_version.hpp +++ b/sdk/storage/azure-storage-blobs/src/private/package_version.hpp @@ -9,9 +9,9 @@ #pragma once #define AZURE_STORAGE_BLOBS_VERSION_MAJOR 12 -#define AZURE_STORAGE_BLOBS_VERSION_MINOR 4 +#define AZURE_STORAGE_BLOBS_VERSION_MINOR 5 #define AZURE_STORAGE_BLOBS_VERSION_PATCH 0 -#define AZURE_STORAGE_BLOBS_VERSION_PRERELEASE "beta.2" +#define AZURE_STORAGE_BLOBS_VERSION_PRERELEASE "beta.1" #define AZURE_STORAGE_BLOBS_VERSION_ITOA_HELPER(i) #i #define AZURE_STORAGE_BLOBS_VERSION_ITOA(i) AZURE_STORAGE_BLOBS_VERSION_ITOA_HELPER(i) diff --git a/sdk/storage/azure-storage-blobs/vcpkg.json b/sdk/storage/azure-storage-blobs/vcpkg.json index c06b902a0d..2847c101f2 100644 --- a/sdk/storage/azure-storage-blobs/vcpkg.json +++ b/sdk/storage/azure-storage-blobs/vcpkg.json @@ -1,6 +1,6 @@ { "name": "azure-storage-blobs-cpp", - "version-semver": "12.4.0-beta.1", + "version-semver": "12.4.0", "description": [ "Microsoft Azure Storage Blobs SDK for C++", "This library provides Azure Storage Blobs SDK." @@ -11,7 +11,7 @@ { "name": "azure-storage-common-cpp", "default-features": false, - "version>=": "12.2.2" + "version>=": "12.2.3" }, { "name": "vcpkg-cmake", diff --git a/sdk/storage/azure-storage-blobs/vcpkg/Config.cmake.in b/sdk/storage/azure-storage-blobs/vcpkg/Config.cmake.in index 479be48447..e2692f288a 100644 --- a/sdk/storage/azure-storage-blobs/vcpkg/Config.cmake.in +++ b/sdk/storage/azure-storage-blobs/vcpkg/Config.cmake.in @@ -4,7 +4,7 @@ @PACKAGE_INIT@ include(CMakeFindDependencyMacro) -find_dependency(azure-storage-common-cpp "12.2.2") +find_dependency(azure-storage-common-cpp "12.2.3") include("${CMAKE_CURRENT_LIST_DIR}/azure-storage-blobs-cppTargets.cmake") diff --git a/sdk/storage/azure-storage-blobs/vcpkg/vcpkg.json b/sdk/storage/azure-storage-blobs/vcpkg/vcpkg.json index ec303d341d..648b9f5082 100644 --- a/sdk/storage/azure-storage-blobs/vcpkg/vcpkg.json +++ b/sdk/storage/azure-storage-blobs/vcpkg/vcpkg.json @@ -14,7 +14,7 @@ { "name": "azure-storage-common-cpp", "default-features": false, - "version>=": "12.2.2" + "version>=": "12.2.3" }, { "name": "vcpkg-cmake", diff --git a/sdk/storage/azure-storage-common/CHANGELOG.md b/sdk/storage/azure-storage-common/CHANGELOG.md index 80956642fb..85fac2ba62 100644 --- a/sdk/storage/azure-storage-common/CHANGELOG.md +++ b/sdk/storage/azure-storage-common/CHANGELOG.md @@ -8,10 +8,14 @@ ### Bugs Fixed -- Fixed a bug where we got error when XML request body is too big. - ### Other Changes +## 12.2.3 (2022-04-06) + +### Bugs Fixed + +- Fixed a bug where we got error when XML request body is too big. + ## 12.2.2 (2022-03-09) ### Features Added diff --git a/sdk/storage/azure-storage-common/CMakeLists.txt b/sdk/storage/azure-storage-common/CMakeLists.txt index 04674fc200..2e1f73e873 100644 --- a/sdk/storage/azure-storage-common/CMakeLists.txt +++ b/sdk/storage/azure-storage-common/CMakeLists.txt @@ -32,9 +32,9 @@ if(FETCH_SOURCE_DEPS) add_subdirectory(${oneFolder} EXCLUDE_FROM_ALL) endforeach() elseif(NOT AZ_ALL_LIBRARIES) - find_package(azure-core-cpp "1.3.1" CONFIG QUIET) + find_package(azure-core-cpp "1.5.0" CONFIG QUIET) if(NOT azure-core-cpp_FOUND) - find_package(azure-core-cpp "1.3.1" REQUIRED) + find_package(azure-core-cpp "1.5.0" REQUIRED) endif() endif() diff --git a/sdk/storage/azure-storage-common/vcpkg.json b/sdk/storage/azure-storage-common/vcpkg.json index 916203dfe0..ff818f2a25 100644 --- a/sdk/storage/azure-storage-common/vcpkg.json +++ b/sdk/storage/azure-storage-common/vcpkg.json @@ -1,6 +1,6 @@ { "name": "azure-storage-common-cpp", - "version-semver": "12.2.2", + "version-semver": "12.2.3", "description": [ "Microsoft Azure Common Storage SDK for C++", "This library provides common Azure Storage-related abstractions for Azure SDK." @@ -11,7 +11,7 @@ { "name": "azure-core-cpp", "default-features": false, - "version>=": "1.3.1" + "version>=": "1.5.0" }, { "name": "libxml2", diff --git a/sdk/storage/azure-storage-common/vcpkg/Config.cmake.in b/sdk/storage/azure-storage-common/vcpkg/Config.cmake.in index 08fc765c37..f92c6f19be 100644 --- a/sdk/storage/azure-storage-common/vcpkg/Config.cmake.in +++ b/sdk/storage/azure-storage-common/vcpkg/Config.cmake.in @@ -5,7 +5,7 @@ include(CMakeFindDependencyMacro) find_dependency(Threads) -find_dependency(azure-core-cpp "1.3.1") +find_dependency(azure-core-cpp "1.5.0") if(NOT WIN32) find_dependency(LibXml2) diff --git a/sdk/storage/azure-storage-common/vcpkg/vcpkg.json b/sdk/storage/azure-storage-common/vcpkg/vcpkg.json index 6691770594..5c91fef890 100644 --- a/sdk/storage/azure-storage-common/vcpkg/vcpkg.json +++ b/sdk/storage/azure-storage-common/vcpkg/vcpkg.json @@ -14,7 +14,7 @@ { "name": "azure-core-cpp", "default-features": false, - "version>=": "1.3.1" + "version>=": "1.5.0" }, { "name": "libxml2", diff --git a/sdk/storage/azure-storage-queues/CHANGELOG.md b/sdk/storage/azure-storage-queues/CHANGELOG.md index 35cdb10471..44d6e6f37e 100644 --- a/sdk/storage/azure-storage-queues/CHANGELOG.md +++ b/sdk/storage/azure-storage-queues/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 12.0.0-beta.5 (Unreleased) +## 12.1.0-beta.1 (Unreleased) ### Features Added @@ -10,6 +10,12 @@ ### Other Changes +## 12.0.0 (2022-04-06) + +### New Features + +- This release includes all features from beta.1 to beta.4. This is the first stable release of a ground-up rewrite of our client libraries to ensure consistency, idiomatic design, productivity and an excellent developer experience. It was created following the [Azure SDK Design Guideline for C++](https://azure.github.io/azure-sdk/cpp_introduction.html). + ## 12.0.0-beta.4 (2022-03-09) ### Other Changes diff --git a/sdk/storage/azure-storage-queues/CMakeLists.txt b/sdk/storage/azure-storage-queues/CMakeLists.txt index e1d729eba3..1392c4748d 100644 --- a/sdk/storage/azure-storage-queues/CMakeLists.txt +++ b/sdk/storage/azure-storage-queues/CMakeLists.txt @@ -32,9 +32,9 @@ if(FETCH_SOURCE_DEPS) add_subdirectory(${oneFolder} EXCLUDE_FROM_ALL) endforeach() elseif(NOT AZ_ALL_LIBRARIES) - find_package(azure-storage-common-cpp "12.2.2" CONFIG QUIET) + find_package(azure-storage-common-cpp "12.2.3" CONFIG QUIET) if(NOT azure-storage-common-cpp_FOUND) - find_package(azure-storage-common-cpp "12.2.2" REQUIRED) + find_package(azure-storage-common-cpp "12.2.3" REQUIRED) endif() endif() diff --git a/sdk/storage/azure-storage-queues/src/private/package_version.hpp b/sdk/storage/azure-storage-queues/src/private/package_version.hpp index 2f000c1bcc..817761f962 100644 --- a/sdk/storage/azure-storage-queues/src/private/package_version.hpp +++ b/sdk/storage/azure-storage-queues/src/private/package_version.hpp @@ -9,9 +9,9 @@ #pragma once #define AZURE_STORAGE_QUEUES_VERSION_MAJOR 12 -#define AZURE_STORAGE_QUEUES_VERSION_MINOR 0 +#define AZURE_STORAGE_QUEUES_VERSION_MINOR 1 #define AZURE_STORAGE_QUEUES_VERSION_PATCH 0 -#define AZURE_STORAGE_QUEUES_VERSION_PRERELEASE "beta.5" +#define AZURE_STORAGE_QUEUES_VERSION_PRERELEASE "beta.1" #define AZURE_STORAGE_QUEUES_VERSION_ITOA_HELPER(i) #i #define AZURE_STORAGE_QUEUES_VERSION_ITOA(i) AZURE_STORAGE_QUEUES_VERSION_ITOA_HELPER(i) diff --git a/sdk/storage/azure-storage-queues/vcpkg.json b/sdk/storage/azure-storage-queues/vcpkg.json index b48d71ab27..e81924b0de 100644 --- a/sdk/storage/azure-storage-queues/vcpkg.json +++ b/sdk/storage/azure-storage-queues/vcpkg.json @@ -1,6 +1,6 @@ { "name": "azure-storage-queues-cpp", - "version-semver": "12.0.0-beta.4", + "version-semver": "12.0.0", "description": [ "Microsoft Azure Storage Queues SDK for C++", "This library provides Azure Storage Queues SDK." @@ -11,7 +11,7 @@ { "name": "azure-storage-common-cpp", "default-features": false, - "version>=": "12.2.2" + "version>=": "12.2.3" }, { "name": "vcpkg-cmake", diff --git a/sdk/storage/azure-storage-queues/vcpkg/Config.cmake.in b/sdk/storage/azure-storage-queues/vcpkg/Config.cmake.in index 5e6faa1590..f8463bda82 100644 --- a/sdk/storage/azure-storage-queues/vcpkg/Config.cmake.in +++ b/sdk/storage/azure-storage-queues/vcpkg/Config.cmake.in @@ -4,7 +4,7 @@ @PACKAGE_INIT@ include(CMakeFindDependencyMacro) -find_dependency(azure-storage-common-cpp "12.2.2") +find_dependency(azure-storage-common-cpp "12.2.3") include("${CMAKE_CURRENT_LIST_DIR}/azure-storage-queues-cppTargets.cmake") diff --git a/sdk/storage/azure-storage-queues/vcpkg/vcpkg.json b/sdk/storage/azure-storage-queues/vcpkg/vcpkg.json index 00abee17f5..33a002e51f 100644 --- a/sdk/storage/azure-storage-queues/vcpkg/vcpkg.json +++ b/sdk/storage/azure-storage-queues/vcpkg/vcpkg.json @@ -14,7 +14,7 @@ { "name": "azure-storage-common-cpp", "default-features": false, - "version>=": "12.2.2" + "version>=": "12.2.3" }, { "name": "vcpkg-cmake", From 03bf4c8c1d1af1d372a6f77ee4ebd0730ad6245f Mon Sep 17 00:00:00 2001 From: George Arama <50641385+gearama@users.noreply.github.com> Date: Thu, 14 Apr 2022 13:31:04 -0700 Subject: [PATCH 02/10] work in progress --- .../CMakeLists.txt | 2 + .../inc/azure/keyvault/keys/key_client.hpp | 49 +++++++ .../azure/keyvault/keys/key_client_models.hpp | 137 ++++++++++++++++-- .../keyvault/keys/key_client_options.hpp | 13 ++ .../src/key_client.cpp | 54 +++++++ .../src/key_get_random_bytes.cpp | 32 ++++ .../src/key_rotation_policy.cpp | 128 ++++++++++++++++ .../src/private/key_constants.hpp | 15 ++ .../src/private/key_serializers.hpp | 18 +++ .../test/ut/CMakeLists.txt | 4 +- .../test/ut/key_client_base_test.hpp | 5 +- .../test/ut/key_rotation_policy_test_live.cpp | 107 ++++++++++++++ 12 files changed, 546 insertions(+), 18 deletions(-) create mode 100644 sdk/keyvault/azure-security-keyvault-keys/src/key_get_random_bytes.cpp create mode 100644 sdk/keyvault/azure-security-keyvault-keys/src/key_rotation_policy.cpp create mode 100644 sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp diff --git a/sdk/keyvault/azure-security-keyvault-keys/CMakeLists.txt b/sdk/keyvault/azure-security-keyvault-keys/CMakeLists.txt index 684ab3c60a..0420ba2921 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/CMakeLists.txt +++ b/sdk/keyvault/azure-security-keyvault-keys/CMakeLists.txt @@ -100,6 +100,8 @@ set( src/keyvault_key.cpp src/keyvault_protocol.cpp src/recover_deleted_key_operation.cpp + src/key_rotation_policy.cpp + src/key_get_random_bytes.cpp ) add_library(azure-security-keyvault-keys diff --git a/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client.hpp b/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client.hpp index beeed624b7..65e98451e8 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client.hpp +++ b/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client.hpp @@ -190,6 +190,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { * @param options The #GetPropertiesOfKeysOptions object to for setting the operation * up. * @param context A #Azure::Core::Context controlling the request lifetime. + * @return KeyPropertiesPagedResponse */ KeyPropertiesPagedResponse GetPropertiesOfKeys( GetPropertiesOfKeysOptions const& options = GetPropertiesOfKeysOptions(), @@ -212,6 +213,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { * @param options The #GetPropertiesOfKeyVersionsOptions object to for setting the * operation up. * @param context A #Azure::Core::Context controlling the request lifetime. + * @return KeyPropertiesPagedResponse */ KeyPropertiesPagedResponse GetPropertiesOfKeyVersions( std::string const& name, @@ -283,6 +285,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { * * @param name The name of the key. * @param context A #Azure::Core::Context controlling the request lifetime. + * @return Azure::Response */ Azure::Response PurgeDeletedKey( std::string const& name, @@ -342,6 +345,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { * * @param name The name of the key. * @param context A #Azure::Core::Context controlling the request lifetime. + * @return Azure::Response */ Azure::Response BackupKey( std::string const& name, @@ -364,6 +368,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { * * @param backup The backup blob associated with a key. * @param context A #Azure::Core::Context controlling the request lifetime. + * @return Azure::Response */ Azure::Response RestoreKeyBackup( std::vector const& backup, @@ -398,11 +403,55 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { * @param importKeyOptions The key import configuration object containing information about * the #JsonWebKey being imported. * @param context A #Azure::Core::Context controlling the request lifetime. + * @return Azure::Response */ Azure::Response ImportKey( ImportKeyOptions const& importKeyOptions, Azure::Core::Context const& context = Azure::Core::Context()) const; + /** + * @brief Lists the policy for a key. + * + * @remark The GetKeyRotationPolicy operation returns the specified key policy resources in the + * specified key vault. This operation requires the keys/get permission. + * + * @param name The name of the key in a given key vault. + * @param context A #Azure::Core::Context controlling the request lifetime. + * @return Azure::Response + */ + Azure::Response GetKeyRotationPolicy( + std::string const& name, + Azure::Core::Context const& context = Azure::Core::Context()) const; + + /** + * @brief Updates the rotation policy for a key. + * + * @remark Set specified members in the key policy. Leave others as undefined. This operation + * requires the keys/update permission. + * + * @param name The name of the key in a given key vault. + * @param rotationPolicy The policy for the key. + * @param context A #Azure::Core::Context controlling the request lifetime. + * @return Azure::Response + */ + Azure::Response PutKeyRotationPolicy( + std::string const& name, + KeyRotationPolicy const& rotationPolicy, + Azure::Core::Context const& context = Azure::Core::Context()) const; + + /** + * @brief Get the requested number of bytes containing random values. + * + * @remark Get the requested number of bytes containing random values from a managed HSM. + * + * @param options The request object to get random bytes. + * @param context A #Azure::Core::Context controlling the request lifetime. + * @return Azure::Response> + */ + Azure::Response> GetRandomBytes( + GetRandomBytesOptions const& options, + Azure::Core::Context const& context = Azure::Core::Context()) const; + /** * @brief Gets the key client's primary URL endpoint. * diff --git a/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_models.hpp b/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_models.hpp index 825346f8a9..d6f1cf12a5 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_models.hpp +++ b/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_models.hpp @@ -120,8 +120,8 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyOperation WrapKey; /** - * @brief The key can be used to unwrap another key with the UnwrapKey(KeyWrapAlgorithm, Byte[], - * CancellationToken) method. + * @brief The key can be used to unwrap another key with the UnwrapKey(KeyWrapAlgorithm, + * Byte[], CancellationToken) method. */ AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyOperation UnwrapKey; @@ -420,8 +420,8 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { std::string Version; /** - * @brief Indicate whether the key's lifetime is managed by Key Vault. If this key is backing a - * Key Vault certificate, the value will be true. + * @brief Indicate whether the key's lifetime is managed by Key Vault. If this key is backing + * a Key Vault certificate, the value will be true. * */ bool Managed = false; @@ -505,7 +505,8 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { virtual ~KeyVaultKey() = default; /** - * @brief The cryptographic key, the key type, and the operations you can perform using the key. + * @brief The cryptographic key, the key type, and the operations you can perform using the + * key. * */ JsonWebKey Key; @@ -670,7 +671,8 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { * * @param deletedKeyProperties A previously created #DeletedKeyPagedResponse that is used to * init this new instance. - * @param rawResponse The HTTP raw response from where the #DeletedKeyPagedResponse was parsed. + * @param rawResponse The HTTP raw response from where the #DeletedKeyPagedResponse was + * parsed. * @param keyClient A key client required for getting the next pages. */ DeletedKeyPagedResponse( @@ -713,8 +715,8 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { std::string m_continuationToken; /* This is the implementation for checking the status of a deleted key. The key is considered - * deleted if querying /deletedkeys/keyName returns 200 from server. Or whenever soft-delete is - * disabled.*/ + * deleted if querying /deletedkeys/keyName returns 200 from server. Or whenever soft-delete + * is disabled.*/ std::unique_ptr PollInternal( Azure::Core::Context const& context) override; @@ -776,7 +778,8 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { Azure::Security::KeyVault::Keys::DeletedKey Value() const override { return m_value; } /** - * @brief Get an Url as string which can be used to get the status of the delete key operation. + * @brief Get an Url as string which can be used to get the status of the delete key + * operation. * * @return std::string */ @@ -789,7 +792,8 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { * @remark After the operation is initialized, it is used to poll the last update from the * server using the \p context. * - * @param resumeToken A previously generated token used to resume the polling of the operation. + * @param resumeToken A previously generated token used to resume the polling of the + * operation. * @param client A #KeyClient that is used for getting status updates. * @param context A #Azure::Core::Context controlling the request lifetime. * @return DeleteKeyOperation @@ -837,8 +841,8 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { } /* - * Only friend classes are permitted to construct a RecoverDeletedKeyOperation. This is because - * a KeyVaultPipelne is required and it is not exposed to customers. + * Only friend classes are permitted to construct a RecoverDeletedKeyOperation. This is + * because a KeyVaultPipelne is required and it is not exposed to customers. * * Since C++ doesn't offer `internal` access, we use friends-only instead. */ @@ -875,7 +879,8 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { Azure::Security::KeyVault::Keys::KeyVaultKey Value() const override { return m_value; } /** - * @brief Get an Url as string which can be used to get the status of the delete key operation. + * @brief Get an Url as string which can be used to get the status of the delete key + * operation. * * @return std::string */ @@ -888,7 +893,8 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { * @remark After the operation is initialized, it is used to poll the last update from the * server using the \p context. * - * @param resumeToken A previously generated token used to resume the polling of the operation. + * @param resumeToken A previously generated token used to resume the polling of the + * operation. * @param client A #KeyClient that is used for getting status updates. * @param context A #Azure::Core::Context controlling the request lifetime. * @return DeleteKeyOperation @@ -899,4 +905,107 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { Azure::Core::Context const& context = Azure::Core::Context()); }; + enum LifetimeActionType + { + /** + * @brief Rotate the key based on the key policy. + * + */ + Rotate, + + /** + * @brief Trigger event grid events. For preview, the notification time is not configurable + * and it is default to 30 days before expiry. + * + */ + Notify + }; + + /** + * @brief A condition to be satisfied for an action to be executed. + */ + struct LifetimeActionsTrigger final + { + /** + * @brief Time after creation to attempt to rotate. It only applies to rotate. It will be in + * ISO 8601 duration format. Example: 90 days : "P90D" + * + */ + Azure::Nullable TimeAfterCreate; + /** + * @brief Time before expiry to attempt to rotate or notify. It will be in ISO 8601 duration + * format. Example: 90 days : "P90D" + * + */ + Azure::Nullable TimeBeforeExpiry; + }; + + /** + * @brief Action and its trigger that will be performed by Key Vault over the lifetime of a key. + * + */ + struct LifetimeActions final + { + /** + * @brief The condition that will execute the action. + * + */ + LifetimeActionsTrigger Trigger; + + /** + * @brief The action that will be executed. + */ + LifetimeActionType Action; + }; + + /** + * @brief The key rotation policy attributes. + * + */ + struct KeyRotationPolicyAttributes final + { + /** + * @brief The expiryTime will be applied on the new key version. It should be at least 28 + * days. It will be in ISO 8601 Format. Examples: 90 days: P90D, 3 months: P3M, 48 hours: + * PT48H, 1 year and 10 days: P1Y10D + */ + Azure::Nullable ExpiryTime; + + /** + * @brief The key rotation policy created time in UTC. + * + */ + Azure::Nullable Created; + + /** + * @brief The key rotation policy's last updated time in UTC. + * + */ + Azure::Nullable Updated; + }; + + /** + * @brief Rotation policy for a key. + */ + struct KeyRotationPolicy final + { + /** + * @brief The key policy id. + */ + std::string Id; + + /** + * @brief Actions that will be performed by Key Vault over the lifetime of a key. For preview, + * lifetimeActions can only have two items at maximum: one for rotate, one for notify. + * Notification time would be default to 30 days before expiry and it is not configurable. + * + */ + std::vector LifetimeActions; + + /** + * @brief The key rotation policy attributes. + */ + KeyRotationPolicyAttributes Attributes; + }; + }}}} // namespace Azure::Security::KeyVault::Keys diff --git a/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_options.hpp b/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_options.hpp index 63f0bf6fd0..65aa767ec8 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_options.hpp +++ b/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_options.hpp @@ -401,4 +401,17 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { std::string const& Name() const { return Properties.Name; } }; + /** + * @brief Get Random Byutes options + * + */ + struct GetRandomBytesOptions final + { + /** + * @brief The requested number of random bytes. + * + */ + int32_t Count; + }; + }}}} // namespace Azure::Security::KeyVault::Keys diff --git a/sdk/keyvault/azure-security-keyvault-keys/src/key_client.cpp b/sdk/keyvault/azure-security-keyvault-keys/src/key_client.cpp index a1a6df3325..307253dd48 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/src/key_client.cpp +++ b/sdk/keyvault/azure-security-keyvault-keys/src/key_client.cpp @@ -381,6 +381,60 @@ Azure::Response KeyClient::ImportKey( return Azure::Response(std::move(value), std::move(rawResponse)); } +Azure::Response KeyClient::GetKeyRotationPolicy( + std::string const& name, + Azure::Core::Context const& context) const +{ + // Request with no payload + auto request = CreateRequest(HttpMethod::Get, {_detail::KeysPath, name, "rotationpolicy"}); + request.SetHeader(HttpShared::ContentType, HttpShared::ApplicationJson); + // Send and parse respone + auto rawResponse = SendRequest(request, context); + auto value = _detail::KeyRotationPolicySerializer::KeyRotationPolicyDeserialize(*rawResponse); + return Azure::Response(std::move(value), std::move(rawResponse)); +} + +Azure::Response KeyClient::PutKeyRotationPolicy( + std::string const& name, + KeyRotationPolicy const& rotationPolicy, + Azure::Core::Context const& context) const +{ + // Payload for the request + auto payload = _detail::KeyRotationPolicySerializer::KeyRotationPolicySerialize(rotationPolicy); + Azure::Core::IO::MemoryBodyStream payloadStream( + reinterpret_cast(payload.data()), payload.size()); + + // Request and settings + auto request + = CreateRequest(HttpMethod::Put, {_detail::KeysPath, name, "rotationpolicy"}, &payloadStream); + request.SetHeader(HttpShared::ContentType, HttpShared::ApplicationJson); + + // Send and parse respone + auto rawResponse = SendRequest(request, context); + auto value = _detail::KeyRotationPolicySerializer::KeyRotationPolicyDeserialize(*rawResponse); + return Azure::Response(std::move(value), std::move(rawResponse)); +} + +Azure::Response> KeyClient::GetRandomBytes( + GetRandomBytesOptions const& options, + Azure::Core::Context const& context) const +{ + auto payload = _detail::GetRandomBytesSerializer::GetRandomBytesOptionsSerialize(options); + Azure::Core::IO::MemoryBodyStream payloadStream( + reinterpret_cast(payload.data()), payload.size()); + + // Request and settings + auto request + = CreateRequest(HttpMethod::Post, {"/rng"}, &payloadStream); + request.SetHeader(HttpShared::ContentType, HttpShared::ApplicationJson); + + // Send and parse respone + auto rawResponse = SendRequest(request, context); + + auto value = _detail::GetRandomBytesSerializer::GetRandomBytesResponseDeserialize(*rawResponse); + return Azure::Response>(std::move(value), std::move(rawResponse)); +} + Cryptography::CryptographyClient KeyClient::GetCryptographyClient( std::string const& name, std::string const& version) const diff --git a/sdk/keyvault/azure-security-keyvault-keys/src/key_get_random_bytes.cpp b/sdk/keyvault/azure-security-keyvault-keys/src/key_get_random_bytes.cpp new file mode 100644 index 0000000000..ceabeb523f --- /dev/null +++ b/sdk/keyvault/azure-security-keyvault-keys/src/key_get_random_bytes.cpp @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +#include +#include +#include +#include "azure/keyvault/keys/key_client_models.hpp" +#include "private/key_constants.hpp" +#include "private/key_serializers.hpp" + +using namespace Azure::Security::KeyVault::Keys; +using namespace Azure::Core::Json::_internal; + +std::string _detail::GetRandomBytesSerializer::GetRandomBytesOptionsSerialize( + GetRandomBytesOptions const& options) +{ + json payload; + + payload[_detail::CountPropertiesValue] = options.Count; + + return payload.dump(); +} + +std::vector _detail::GetRandomBytesSerializer::GetRandomBytesResponseDeserialize( + Azure::Core::Http::RawResponse const& rawResponse) +{ + auto body = rawResponse.GetBody(); + auto jsonParser = Azure::Core::Json::_internal::json::parse(body); + + auto value = jsonParser[_detail::ValueParameterValue].get(); + return Azure::Core::Convert::Base64Decode(value); +} \ No newline at end of file diff --git a/sdk/keyvault/azure-security-keyvault-keys/src/key_rotation_policy.cpp b/sdk/keyvault/azure-security-keyvault-keys/src/key_rotation_policy.cpp new file mode 100644 index 0000000000..ae795c7b75 --- /dev/null +++ b/sdk/keyvault/azure-security-keyvault-keys/src/key_rotation_policy.cpp @@ -0,0 +1,128 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +#include +#include + +#include "azure/keyvault/keys/key_client_models.hpp" +#include "private/key_constants.hpp" +#include "private/key_serializers.hpp" + +using namespace Azure::Security::KeyVault::Keys; +using namespace Azure::Core::Json::_internal; +using Azure::Core::_internal::PosixTimeConverter; + +KeyRotationPolicy _detail::KeyRotationPolicySerializer::KeyRotationPolicyDeserialize( + Azure::Core::Http::RawResponse const& rawResponse) +{ + auto body = rawResponse.GetBody(); + return KeyRotationPolicyDeserialize(body); +} + +KeyRotationPolicy _detail::KeyRotationPolicySerializer::KeyRotationPolicyDeserialize( + std::vector const& body) +{ + auto jsonParser = Azure::Core::Json::_internal::json::parse(body); + KeyRotationPolicy policy; + + std::string goqu(body.begin(), body.end()); + + policy.Id = jsonParser[_detail::IdValue].get(); + + if (!jsonParser[_detail::AttributesPropertyName].is_null()) + { + auto jsonFragment = jsonParser[_detail::AttributesPropertyName]; + policy.Attributes.ExpiryTime = jsonFragment[_detail::ExpiryTimeValue].get(); + + JsonOptional::SetIfExists( + policy.Attributes.Created, + jsonFragment, + _detail::CreatedPropertyName, + PosixTimeConverter::PosixTimeToDateTime); + + JsonOptional::SetIfExists( + policy.Attributes.Updated, + jsonFragment, + _detail::UpdatedPropertyName, + PosixTimeConverter::PosixTimeToDateTime); + } + + if (!jsonParser[_detail::LifeTimeActionsValue].is_null()) + { + auto lifeTimeActions = jsonParser[_detail::LifeTimeActionsValue]; + + for (auto action : lifeTimeActions) + { + LifetimeActions currentAction; + + JsonOptional::SetIfExists( + currentAction.Trigger.TimeAfterCreate, + action[_detail::TriggerActionsValue], + _detail::TACActionsValue); + + JsonOptional::SetIfExists( + currentAction.Trigger.TimeBeforeExpiry, + action[_detail::TriggerActionsValue], + _detail::TBEActionsValue); + + auto actionType = action[_detail::ActionActionsValue][TypeActionsValue].get(); + std::transform(actionType.begin(), actionType.end(), actionType.begin(), [](unsigned char c) { + return std::tolower(c); + }); + + if (actionType == _detail::RotateActionsValue) + { + currentAction.Action = LifetimeActionType::Rotate; + } + else if (actionType == _detail::NotifyActionsValue) + { + currentAction.Action = LifetimeActionType::Notify; + } + + policy.LifetimeActions.emplace_back(currentAction); + } + } + + return policy; +} + +std::string _detail::KeyRotationPolicySerializer::KeyRotationPolicySerialize( + KeyRotationPolicy const& rotationPolicy) +{ + json payload; + + JsonOptional::SetFromNullable( + rotationPolicy.Attributes.ExpiryTime, + payload[_detail::AttributesPropertyName], + _detail::ExpiryTimeValue); + payload[_detail::LifeTimeActionsValue].array(); + for (auto lifetimeAction : rotationPolicy.LifetimeActions) + { + json oneAction; + + JsonOptional::SetFromNullable( + lifetimeAction.Trigger.TimeAfterCreate, + oneAction[_detail::TriggerActionsValue], + _detail::TACActionsValue); + + JsonOptional::SetFromNullable( + lifetimeAction.Trigger.TimeBeforeExpiry, + oneAction[_detail::TriggerActionsValue], + _detail::TBEActionsValue); + + if (lifetimeAction.Action == LifetimeActionType::Notify) + { + oneAction[_detail::ActionActionsValue][_detail::TypeActionsValue] + = _detail::NotifyActionsValue; + } + else + { + oneAction[_detail::ActionActionsValue][_detail::TypeActionsValue] + = _detail::RotateActionsValue; + } + + payload[_detail::LifeTimeActionsValue].emplace_back(oneAction); + } + + return payload.dump(); +}; \ No newline at end of file diff --git a/sdk/keyvault/azure-security-keyvault-keys/src/private/key_constants.hpp b/sdk/keyvault/azure-security-keyvault-keys/src/private/key_constants.hpp index 1af3249a2e..9572c46601 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/src/private/key_constants.hpp +++ b/sdk/keyvault/azure-security-keyvault-keys/src/private/key_constants.hpp @@ -126,4 +126,19 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { nam /***************** Service *********/ constexpr static const char ApiVersionValue[] = "api-version"; + /***************** Rotation Policy *********/ + constexpr static const char IdValue[] = "id"; + constexpr static const char ExpiryTimeValue[] = "expiryTime"; + constexpr static const char LifeTimeActionsValue[] = "lifetimeActions"; + constexpr static const char RotateActionsValue[] = "rotate"; + constexpr static const char NotifyActionsValue[] = "notify"; + constexpr static const char ActionActionsValue[] = "action"; + constexpr static const char TriggerActionsValue[] = "trigger"; + constexpr static const char TypeActionsValue[] = "type"; + constexpr static const char TBEActionsValue[] = "timeBeforeExpiry"; + constexpr static const char TACActionsValue[] = "timeAfterCreate"; + + /***************** Get Random Bytes *********/ + constexpr static const char CountPropertiesValue[] = "count"; + }}}}} // namespace Azure::Security::KeyVault::Keys::_detail diff --git a/sdk/keyvault/azure-security-keyvault-keys/src/private/key_serializers.hpp b/sdk/keyvault/azure-security-keyvault-keys/src/private/key_serializers.hpp index 5174f752de..30b613e2ea 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/src/private/key_serializers.hpp +++ b/sdk/keyvault/azure-security-keyvault-keys/src/private/key_serializers.hpp @@ -115,4 +115,22 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { nam Azure::Core::Json::_internal::json const& jsonParser); }; + /**************** Key Properties ************/ + class KeyRotationPolicySerializer final { + public: + static KeyRotationPolicy KeyRotationPolicyDeserialize( + Azure::Core::Http::RawResponse const& rawResponse); + static KeyRotationPolicy KeyRotationPolicyDeserialize(std::vector const& body); + + static std::string KeyRotationPolicySerialize(KeyRotationPolicy const& rotationPolicy); + }; + + /**************** GetRandomBytes ************/ + class GetRandomBytesSerializer final { + public: + static std::string GetRandomBytesOptionsSerialize(GetRandomBytesOptions const& options); + static std::vector GetRandomBytesResponseDeserialize( + Azure::Core::Http::RawResponse const& rawResponse); + }; + }}}}} // namespace Azure::Security::KeyVault::Keys::_detail diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/ut/CMakeLists.txt b/sdk/keyvault/azure-security-keyvault-keys/test/ut/CMakeLists.txt index 9e464f7aee..70665627d2 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/test/ut/CMakeLists.txt +++ b/sdk/keyvault/azure-security-keyvault-keys/test/ut/CMakeLists.txt @@ -25,10 +25,10 @@ add_executable ( key_client_test.cpp key_client_update_test_live.cpp key_cryptographic_client_test_live.cpp + key_rotation_policy_test_live.cpp macro_guard.cpp mocked_client_test.cpp - mocked_transport_adapter_test.hpp -) + mocked_transport_adapter_test.hpp) create_per_service_target_build(keyvault azure-security-keyvault-keys-test) create_map_file(azure-security-keyvault-keys-test azure-security-keyvault-keys-test.map) diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_base_test.hpp b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_base_test.hpp index d7553a6f2f..e523041c09 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_base_test.hpp +++ b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_base_test.hpp @@ -54,6 +54,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { nam // Create virtual void SetUp() override { + _putenv_s("AZURE_TEST_MODE", "LIVE"); Azure::Core::Test::TestBase::SetUpTestBase(AZURE_TEST_RECORDING_DIR); m_keyVaultUrl = GetEnv("AZURE_KEYVAULT_URL"); m_keyVaultHsmUrl = GetEnv("AZURE_KEYVAULT_HSM_URL"); @@ -71,13 +72,13 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { nam UpdateWaitingTime(m_testPollingIntervalMs); } - void CreateHsmClient() + void CreateHsmClient(std::string hsmUrl = "") { KeyClientOptions options; m_client = InitTestClient< Azure::Security::KeyVault::Keys::KeyClient, Azure::Security::KeyVault::Keys::KeyClientOptions>( - m_keyVaultHsmUrl, m_credential, options); + hsmUrl.length() == 0 ? m_keyVaultHsmUrl : hsmUrl, m_credential, options); } public: diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp new file mode 100644 index 0000000000..546b4de2ed --- /dev/null +++ b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp @@ -0,0 +1,107 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +#include "gtest/gtest.h" + +#include "../../src/private/key_serializers.hpp" +#include "key_client_base_test.hpp" +#include +#include +#include + +#include + +using namespace Azure::Security::KeyVault::Keys::Test; +using namespace Azure; +using namespace Azure::Security::KeyVault::Keys; +using namespace Azure::Security::KeyVault::Keys::_detail; + +TEST_F(KeyVaultKeyClient, GetKeyRotationPolicy) +{ + auto const keyName = GetTestName(); + auto const& client = GetClientForTest(keyName); + + auto createKeyResponse = client.CreateEcKey(CreateEcKeyOptions(keyName)); + CheckValidResponse(createKeyResponse); + + std::string input + = "{\"id\":\"https://redacted.vault.azure.net/keys/GetKeyRotationPolicy/" + "rotationpolicy\",\"lifetimeActions\":[{\"trigger\":{\"timeAfterCreate\":\"P18M\"}," + "\"action\":{\"type\":\"Rotate\"}},{\"trigger\":{\"timeBeforeExpiry\":\"P30D\"},\"action\":" + "{\"type\":\"Notify\"}}],\"attributes\":{\"expiryTime\":\"P48M\",\"created\":1649797765," + "\"updated\":1649797765}}"; + + auto policy = KeyRotationPolicySerializer::KeyRotationPolicyDeserialize( + std::vector(input.begin(), input.end())); + + auto putPolicy = client.PutKeyRotationPolicy(keyName, policy).Value; + auto rotationPolicy = client.GetKeyRotationPolicy(keyName).Value; + + EXPECT_EQ(rotationPolicy.Attributes.ExpiryTime.Value(), policy.Attributes.ExpiryTime.Value()); + EXPECT_NE(rotationPolicy.Id.size(), size_t(0)); + EXPECT_EQ(rotationPolicy.LifetimeActions.size(), policy.LifetimeActions.size()); + + for (auto result : rotationPolicy.LifetimeActions) + { + bool found = false; + + for (auto original : policy.LifetimeActions) + { + if (result.Action == original.Action) + { + found = true; + break; + } + } + EXPECT_TRUE(found); + } +} + +TEST_F(KeyVaultKeyClient, GetRandomBytes) +{ + auto const keyName = GetTestName(); + CreateHsmClient("https://gearamamhsm.managedhsm.azure.net/"); + auto const& client = GetClientForTest(keyName); + GetRandomBytesOptions options; + options.Count = 4; + auto result = client.GetRandomBytes(options); + EXPECT_EQ(result.Value.size(), options.Count); +} + +TEST(KeyRotationPolicy, SerializeDeserialize1) +{ + std::string input + = "{\"id\":\"https://redacted.vault.azure.net/keys/GetKeyRotationPolicy/" + "rotationpolicy\",\"lifetimeActions\":[{\"trigger\":{\"timeAfterCreate\":\"P18M\"}," + "\"action\":{\"type\":\"Rotate\"}},{\"trigger\":{\"timeBeforeExpiry\":\"P30D\"},\"action\":" + "{\"type\":\"Notify\"}}],\"attributes\":{\"expiryTime\":\"P48M\",\"created\":1649797765," + "\"updated\":1649797765}}"; + + auto policy = KeyRotationPolicySerializer::KeyRotationPolicyDeserialize( + std::vector(input.begin(), input.end())); + + EXPECT_EQ(policy.Id, "https://redacted.vault.azure.net/keys/GetKeyRotationPolicy/rotationpolicy"); + EXPECT_EQ(policy.Attributes.ExpiryTime.Value(), "P48M"); + EXPECT_TRUE(policy.Attributes.Created); + EXPECT_TRUE(policy.Attributes.Updated); + EXPECT_EQ(policy.LifetimeActions.size(), size_t(2)); + + auto action0 = policy.LifetimeActions[0]; + EXPECT_EQ(action0.Action, LifetimeActionType::Rotate); + EXPECT_EQ(action0.Trigger.TimeAfterCreate.Value(), "P18M"); + EXPECT_FALSE(action0.Trigger.TimeBeforeExpiry); + + auto action1 = policy.LifetimeActions[1]; + EXPECT_EQ(action1.Action, LifetimeActionType::Notify); + EXPECT_EQ(action1.Trigger.TimeBeforeExpiry.Value(), "P30D"); + EXPECT_FALSE(action1.Trigger.TimeAfterCreate); + + auto reserialized = KeyRotationPolicySerializer::KeyRotationPolicySerialize(policy); + + std::string reserializedString + = "{\"attributes\":{\"expiryTime\":\"P48M\"},\"lifetimeActions\":[{\"action\":{\"type\":" + "\"rotate\"},\"trigger\":{\"timeAfterCreate\":\"P18M\"}},{\"action\":{\"type\":\"notify\"}," + "\"trigger\":{\"timeBeforeExpiry\":\"P30D\"}}]}"; + + EXPECT_EQ(reserialized, reserializedString); +} \ No newline at end of file From 864f1a9fac86b28959cb36710b918e78c440f9b3 Mon Sep 17 00:00:00 2001 From: George Arama <50641385+gearama@users.noreply.github.com> Date: Thu, 14 Apr 2022 15:54:09 -0700 Subject: [PATCH 03/10] tests for serialize deserialize --- .../test/ut/key_client_base_test.hpp | 2 +- .../test/ut/key_rotation_policy_test_live.cpp | 56 +++++++++++- ...eyVaultKeyClient.GetKeyRotationPolicy.json | 85 +++++++++++++++++++ 3 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 sdk/keyvault/azure-security-keyvault-keys/test/ut/recordings/KeyVaultKeyClient.GetKeyRotationPolicy.json diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_base_test.hpp b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_base_test.hpp index e523041c09..2ec1cbcc99 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_base_test.hpp +++ b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_base_test.hpp @@ -54,7 +54,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { nam // Create virtual void SetUp() override { - _putenv_s("AZURE_TEST_MODE", "LIVE"); + _putenv_s("AZURE_TEST_MODE", "PLAYBACK"); Azure::Core::Test::TestBase::SetUpTestBase(AZURE_TEST_RECORDING_DIR); m_keyVaultUrl = GetEnv("AZURE_KEYVAULT_URL"); m_keyVaultHsmUrl = GetEnv("AZURE_KEYVAULT_HSM_URL"); diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp index 546b4de2ed..0ff6089771 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp +++ b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp @@ -6,6 +6,7 @@ #include "../../src/private/key_serializers.hpp" #include "key_client_base_test.hpp" #include +#include #include #include @@ -57,7 +58,7 @@ TEST_F(KeyVaultKeyClient, GetKeyRotationPolicy) } } -TEST_F(KeyVaultKeyClient, GetRandomBytes) +TEST_F(KeyVaultKeyClient, DISABLED_GetRandomBytes) { auto const keyName = GetTestName(); CreateHsmClient("https://gearamamhsm.managedhsm.azure.net/"); @@ -68,6 +69,59 @@ TEST_F(KeyVaultKeyClient, GetRandomBytes) EXPECT_EQ(result.Value.size(), options.Count); } +TEST(GetRandomBytesOptions, Serialize) +{ GetRandomBytesOptions options; + { + options.Count = 0; + std::string result = GetRandomBytesSerializer::GetRandomBytesOptionsSerialize(options); + EXPECT_EQ(result, "{\"count\":0}"); + } + + { + options.Count = 5; + std::string result = GetRandomBytesSerializer::GetRandomBytesOptionsSerialize(options); + EXPECT_EQ(result, "{\"count\":5}"); + } + + { + options.Count = -1; + std::string result = GetRandomBytesSerializer::GetRandomBytesOptionsSerialize(options); + EXPECT_EQ(result, "{\"count\":-1}"); + } +} + +TEST(GetRandomBytesOptions, Deserialize) +{ + std::string inputString = "1234"; + auto bytes = Azure::Core::Convert::Base64Encode( + std::vector(inputString.begin(), inputString.end())); + std::string responseText = "{\"value\": \"" + std::string(bytes.begin(), bytes.end()) + "\" }"; + + Azure::Core::Http::RawResponse rawResponse(1, 1, Azure::Core::Http::HttpStatusCode::Ok, "OK"); + rawResponse.SetBody(std::vector(responseText.begin(), responseText.end())); + + auto deserialized = GetRandomBytesSerializer::GetRandomBytesResponseDeserialize(rawResponse); + EXPECT_EQ(deserialized.size(), size_t(4)); + EXPECT_EQ(deserialized[0], uint8_t('1')); + EXPECT_EQ(deserialized[1], uint8_t('2')); + EXPECT_EQ(deserialized[2], uint8_t('3')); + EXPECT_EQ(deserialized[3], uint8_t('4')); +} + +TEST(GetRandomBytesOptions, DeserializeEmpty) +{ + std::string inputString = ""; + auto bytes = Azure::Core::Convert::Base64Encode( + std::vector(inputString.begin(), inputString.end())); + std::string responseText = "{\"value\": \"" + std::string(bytes.begin(), bytes.end()) + "\" }"; + + Azure::Core::Http::RawResponse rawResponse(1, 1, Azure::Core::Http::HttpStatusCode::Ok, "OK"); + rawResponse.SetBody(std::vector(responseText.begin(), responseText.end())); + + auto deserialized = GetRandomBytesSerializer::GetRandomBytesResponseDeserialize(rawResponse); + EXPECT_EQ(deserialized.size(), size_t(0)); +} + TEST(KeyRotationPolicy, SerializeDeserialize1) { std::string input diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/ut/recordings/KeyVaultKeyClient.GetKeyRotationPolicy.json b/sdk/keyvault/azure-security-keyvault-keys/test/ut/recordings/KeyVaultKeyClient.GetKeyRotationPolicy.json new file mode 100644 index 0000000000..b03fb8992c --- /dev/null +++ b/sdk/keyvault/azure-security-keyvault-keys/test/ut/recordings/KeyVaultKeyClient.GetKeyRotationPolicy.json @@ -0,0 +1,85 @@ +{ + "networkCallRecords": [ + { + "Headers": { + "content-type": "application/json", + "user-agent": "azsdk-cpp-keyvault-keys/4.3.0-beta.1 (Windows 10 Enterprise 6.3 22000 22000.1.amd64fre.co_release.210604-1628)", + "x-ms-client-request-id": "d887f7a8-65a9-4768-40a4-0c3a78a9e7a0" + }, + "Method": "POST", + "Response": { + "BODY": "{\"key\":{\"kid\":\"https://REDACTED.vault.azure.net/keys/GetKeyRotationPolicy/a8d2d57a9d1b4f2cb1ae0cefc7de5b85\",\"kty\":\"EC\",\"key_ops\":[\"sign\",\"verify\"],\"crv\":\"P-256\",\"x\":\"ZcFpPeslcbXy4DUol7h5yB3N1mHp4ZNGNy33pArvlUM\",\"y\":\"H7sZUKAQ-lOLxZQ1NhKH62CUALyhDDXp8DuDFNYIvuY\"},\"attributes\":{\"enabled\":true,\"exp\":1776202652,\"created\":1649972252,\"updated\":1649972252,\"recoveryLevel\":\"Recoverable+Purgeable\",\"recoverableDays\":90}}", + "REASON_PHRASE": "OK", + "STATUS_CODE": "200", + "cache-control": "no-cache", + "content-length": "414", + "content-type": "application/json; charset=utf-8", + "date": "Thu, 14 Apr 2022 21:37:32 GMT", + "expires": "-1", + "pragma": "no-cache", + "strict-transport-security": "max-age=31536000;includeSubDomains", + "x-content-type-options": "nosniff", + "x-ms-client-request-id": "d887f7a8-65a9-4768-40a4-0c3a78a9e7a0", + "x-ms-keyvault-network-info": "conn_type=Ipv4;addr=24.22.157.72;act_addr_fam=InterNetwork;", + "x-ms-keyvault-region": "westus3", + "x-ms-keyvault-service-version": "1.9.358.1", + "x-ms-request-id": "09612457-a092-49d2-b8a2-9d02cda2ffd5" + }, + "Url": "https://REDACTED.vault.azure.net/keys/GetKeyRotationPolicy/create?api-version=7.3" + }, + { + "Headers": { + "content-type": "application/json", + "user-agent": "azsdk-cpp-keyvault-keys/4.3.0-beta.1 (Windows 10 Enterprise 6.3 22000 22000.1.amd64fre.co_release.210604-1628)", + "x-ms-client-request-id": "95a445c7-f799-448c-57cf-68cd1ecffa81" + }, + "Method": "PUT", + "Response": { + "BODY": "{\"id\":\"https://REDACTED.vault.azure.net/keys/GetKeyRotationPolicy/rotationpolicy\",\"lifetimeActions\":[{\"trigger\":{\"timeAfterCreate\":\"P18M\"},\"action\":{\"type\":\"Rotate\"}},{\"trigger\":{\"timeBeforeExpiry\":\"P30D\"},\"action\":{\"type\":\"Notify\"}}],\"attributes\":{\"expiryTime\":\"P48M\",\"created\":1649797765,\"updated\":1649797765}}", + "REASON_PHRASE": "OK", + "STATUS_CODE": "200", + "cache-control": "no-cache", + "content-length": "314", + "content-type": "application/json; charset=utf-8", + "date": "Thu, 14 Apr 2022 21:37:33 GMT", + "expires": "-1", + "pragma": "no-cache", + "strict-transport-security": "max-age=31536000;includeSubDomains", + "x-content-type-options": "nosniff", + "x-ms-client-request-id": "95a445c7-f799-448c-57cf-68cd1ecffa81", + "x-ms-keyvault-network-info": "conn_type=Ipv4;addr=24.22.157.72;act_addr_fam=InterNetwork;", + "x-ms-keyvault-region": "westus3", + "x-ms-keyvault-service-version": "1.9.358.1", + "x-ms-request-id": "1a30a112-cb80-4fbb-a41d-7760786ba0ae" + }, + "Url": "https://REDACTED.vault.azure.net/keys/GetKeyRotationPolicy/rotationpolicy?api-version=7.3" + }, + { + "Headers": { + "content-type": "application/json", + "user-agent": "azsdk-cpp-keyvault-keys/4.3.0-beta.1 (Windows 10 Enterprise 6.3 22000 22000.1.amd64fre.co_release.210604-1628)", + "x-ms-client-request-id": "117a5643-f64a-42cf-6f0b-89ff18fb2a95" + }, + "Method": "GET", + "Response": { + "BODY": "{\"id\":\"https://REDACTED.vault.azure.net/keys/GetKeyRotationPolicy/rotationpolicy\",\"lifetimeActions\":[{\"trigger\":{\"timeAfterCreate\":\"P18M\"},\"action\":{\"type\":\"Rotate\"}},{\"trigger\":{\"timeBeforeExpiry\":\"P30D\"},\"action\":{\"type\":\"Notify\"}}],\"attributes\":{\"expiryTime\":\"P48M\",\"created\":1649797765,\"updated\":1649797765}}", + "REASON_PHRASE": "OK", + "STATUS_CODE": "200", + "cache-control": "no-cache", + "content-length": "314", + "content-type": "application/json; charset=utf-8", + "date": "Thu, 14 Apr 2022 21:37:33 GMT", + "expires": "-1", + "pragma": "no-cache", + "strict-transport-security": "max-age=31536000;includeSubDomains", + "x-content-type-options": "nosniff", + "x-ms-client-request-id": "117a5643-f64a-42cf-6f0b-89ff18fb2a95", + "x-ms-keyvault-network-info": "conn_type=Ipv4;addr=24.22.157.72;act_addr_fam=InterNetwork;", + "x-ms-keyvault-region": "westus3", + "x-ms-keyvault-service-version": "1.9.358.1", + "x-ms-request-id": "1cd18be3-f7da-430e-bfd2-4634bb37926a" + }, + "Url": "https://REDACTED.vault.azure.net/keys/GetKeyRotationPolicy/rotationpolicy?api-version=7.3" + } + ] +} From 3268a9e94c53c07d7f6be538edf9baa9969fd3a3 Mon Sep 17 00:00:00 2001 From: George Arama <50641385+gearama@users.noreply.github.com> Date: Thu, 14 Apr 2022 16:11:57 -0700 Subject: [PATCH 04/10] typos --- .../inc/azure/keyvault/keys/key_client_options.hpp | 2 +- .../src/key_rotation_policy.cpp | 2 -- .../test/ut/key_client_base_test.hpp | 1 - .../test/ut/key_rotation_policy_test_live.cpp | 6 +++--- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_options.hpp b/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_options.hpp index 65aa767ec8..6ad65e24f3 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_options.hpp +++ b/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_options.hpp @@ -402,7 +402,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { }; /** - * @brief Get Random Byutes options + * @brief Get Random Bytes options * */ struct GetRandomBytesOptions final diff --git a/sdk/keyvault/azure-security-keyvault-keys/src/key_rotation_policy.cpp b/sdk/keyvault/azure-security-keyvault-keys/src/key_rotation_policy.cpp index ae795c7b75..4308d712da 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/src/key_rotation_policy.cpp +++ b/sdk/keyvault/azure-security-keyvault-keys/src/key_rotation_policy.cpp @@ -25,8 +25,6 @@ KeyRotationPolicy _detail::KeyRotationPolicySerializer::KeyRotationPolicyDeseria auto jsonParser = Azure::Core::Json::_internal::json::parse(body); KeyRotationPolicy policy; - std::string goqu(body.begin(), body.end()); - policy.Id = jsonParser[_detail::IdValue].get(); if (!jsonParser[_detail::AttributesPropertyName].is_null()) diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_base_test.hpp b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_base_test.hpp index 2ec1cbcc99..59998d3668 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_base_test.hpp +++ b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_base_test.hpp @@ -54,7 +54,6 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { nam // Create virtual void SetUp() override { - _putenv_s("AZURE_TEST_MODE", "PLAYBACK"); Azure::Core::Test::TestBase::SetUpTestBase(AZURE_TEST_RECORDING_DIR); m_keyVaultUrl = GetEnv("AZURE_KEYVAULT_URL"); m_keyVaultHsmUrl = GetEnv("AZURE_KEYVAULT_HSM_URL"); diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp index 0ff6089771..acca5b994d 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp +++ b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp @@ -150,12 +150,12 @@ TEST(KeyRotationPolicy, SerializeDeserialize1) EXPECT_EQ(action1.Trigger.TimeBeforeExpiry.Value(), "P30D"); EXPECT_FALSE(action1.Trigger.TimeAfterCreate); - auto reserialized = KeyRotationPolicySerializer::KeyRotationPolicySerialize(policy); + auto serialized = KeyRotationPolicySerializer::KeyRotationPolicySerialize(policy); - std::string reserializedString + std::string serializedString = "{\"attributes\":{\"expiryTime\":\"P48M\"},\"lifetimeActions\":[{\"action\":{\"type\":" "\"rotate\"},\"trigger\":{\"timeAfterCreate\":\"P18M\"}},{\"action\":{\"type\":\"notify\"}," "\"trigger\":{\"timeBeforeExpiry\":\"P30D\"}}]}"; - EXPECT_EQ(reserialized, reserializedString); + EXPECT_EQ(serialized, serializedString); } \ No newline at end of file From ea5f328208e2f6c123846d15430531cb2d38036f Mon Sep 17 00:00:00 2001 From: George Arama <50641385+gearama@users.noreply.github.com> Date: Fri, 15 Apr 2022 11:24:53 -0700 Subject: [PATCH 05/10] to lower --- .../src/key_rotation_policy.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/sdk/keyvault/azure-security-keyvault-keys/src/key_rotation_policy.cpp b/sdk/keyvault/azure-security-keyvault-keys/src/key_rotation_policy.cpp index 4308d712da..68b755548b 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/src/key_rotation_policy.cpp +++ b/sdk/keyvault/azure-security-keyvault-keys/src/key_rotation_policy.cpp @@ -64,15 +64,13 @@ KeyRotationPolicy _detail::KeyRotationPolicySerializer::KeyRotationPolicyDeseria _detail::TBEActionsValue); auto actionType = action[_detail::ActionActionsValue][TypeActionsValue].get(); - std::transform(actionType.begin(), actionType.end(), actionType.begin(), [](unsigned char c) { - return std::tolower(c); - }); + actionType = Azure::Core::_internal::StringExtensions::ToLower(actionType); - if (actionType == _detail::RotateActionsValue) + if (actionType == Azure::Core::_internal::StringExtensions::ToLower(_detail::RotateActionsValue)) { currentAction.Action = LifetimeActionType::Rotate; } - else if (actionType == _detail::NotifyActionsValue) + else if (actionType == Azure::Core::_internal::StringExtensions::ToLower(_detail::NotifyActionsValue)) { currentAction.Action = LifetimeActionType::Notify; } From 908115359e766ea69243809198a49dffb8c2d1f0 Mon Sep 17 00:00:00 2001 From: George Arama <50641385+gearama@users.noreply.github.com> Date: Fri, 15 Apr 2022 11:51:02 -0700 Subject: [PATCH 06/10] enable test --- .../src/key_get_random_bytes.cpp | 2 +- .../test/ut/key_client_base_test.hpp | 1 + .../test/ut/key_rotation_policy_test_live.cpp | 6 ++-- .../KeyVaultKeyClient.GetRandomBytes.json | 29 +++++++++++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 sdk/keyvault/azure-security-keyvault-keys/test/ut/recordings/KeyVaultKeyClient.GetRandomBytes.json diff --git a/sdk/keyvault/azure-security-keyvault-keys/src/key_get_random_bytes.cpp b/sdk/keyvault/azure-security-keyvault-keys/src/key_get_random_bytes.cpp index ceabeb523f..cf411b6d45 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/src/key_get_random_bytes.cpp +++ b/sdk/keyvault/azure-security-keyvault-keys/src/key_get_random_bytes.cpp @@ -28,5 +28,5 @@ std::vector _detail::GetRandomBytesSerializer::GetRandomBytesResponseDe auto jsonParser = Azure::Core::Json::_internal::json::parse(body); auto value = jsonParser[_detail::ValueParameterValue].get(); - return Azure::Core::Convert::Base64Decode(value); + return Azure::Core::_internal::Base64Url::Base64UrlDecode(value); } \ No newline at end of file diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_base_test.hpp b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_base_test.hpp index 59998d3668..ff3e63a09f 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_base_test.hpp +++ b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_base_test.hpp @@ -54,6 +54,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { nam // Create virtual void SetUp() override { + _putenv_s("AZURE_TEST_MODE", "RECORD"); Azure::Core::Test::TestBase::SetUpTestBase(AZURE_TEST_RECORDING_DIR); m_keyVaultUrl = GetEnv("AZURE_KEYVAULT_URL"); m_keyVaultHsmUrl = GetEnv("AZURE_KEYVAULT_HSM_URL"); diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp index acca5b994d..b0085a0ff8 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp +++ b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp @@ -58,10 +58,10 @@ TEST_F(KeyVaultKeyClient, GetKeyRotationPolicy) } } -TEST_F(KeyVaultKeyClient, DISABLED_GetRandomBytes) +TEST_F(KeyVaultKeyClient, GetRandomBytes) { auto const keyName = GetTestName(); - CreateHsmClient("https://gearamamhsm.managedhsm.azure.net/"); + CreateHsmClient(); auto const& client = GetClientForTest(keyName); GetRandomBytesOptions options; options.Count = 4; @@ -93,7 +93,7 @@ TEST(GetRandomBytesOptions, Serialize) TEST(GetRandomBytesOptions, Deserialize) { std::string inputString = "1234"; - auto bytes = Azure::Core::Convert::Base64Encode( + auto bytes = Azure::Core::_internal::Base64Url::Base64UrlEncode( std::vector(inputString.begin(), inputString.end())); std::string responseText = "{\"value\": \"" + std::string(bytes.begin(), bytes.end()) + "\" }"; diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/ut/recordings/KeyVaultKeyClient.GetRandomBytes.json b/sdk/keyvault/azure-security-keyvault-keys/test/ut/recordings/KeyVaultKeyClient.GetRandomBytes.json new file mode 100644 index 0000000000..2537ff3de9 --- /dev/null +++ b/sdk/keyvault/azure-security-keyvault-keys/test/ut/recordings/KeyVaultKeyClient.GetRandomBytes.json @@ -0,0 +1,29 @@ +{ + "networkCallRecords": [ + { + "Headers": { + "content-type": "application/json", + "user-agent": "azsdk-cpp-keyvault-keys/4.3.0-beta.1 (Windows 10 Enterprise 6.3 22000 22000.1.amd64fre.co_release.210604-1628)", + "x-ms-client-request-id": "62efb9c3-6fe1-4ac9-58b7-6ceb5877ef46" + }, + "Method": "POST", + "Response": { + "BODY": "{\"value\":\"QkaFtQ\"}", + "REASON_PHRASE": "OK", + "STATUS_CODE": "200", + "cache-control": "no-cache", + "content-length": "18", + "content-security-policy": "default-src 'self'", + "content-type": "application/json; charset=utf-8", + "strict-transport-security": "max-age=31536000; includeSubDomains", + "x-content-type-options": "nosniff", + "x-frame-options": "SAMEORIGIN", + "x-ms-keyvault-network-info": "conn_type=Ipv4;addr=24.22.157.72;act_addr_fam=Ipv4;", + "x-ms-keyvault-region": "westus3", + "x-ms-request-id": "e0ed8ab4-bcec-11ec-b7b1-6045bd86d68a", + "x-ms-server-latency": "559" + }, + "Url": "https://REDACTED.managedhsm.azure.net//rng?api-version=7.3" + } + ] +} From 089007e62098f8f99c512e35954077486aa1096a Mon Sep 17 00:00:00 2001 From: George Arama <50641385+gearama@users.noreply.github.com> Date: Fri, 15 Apr 2022 12:08:21 -0700 Subject: [PATCH 07/10] guard live --- .../test/ut/key_client_base_test.hpp | 1 - .../test/ut/key_rotation_policy_test_live.cpp | 32 +++++++++++-------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_base_test.hpp b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_base_test.hpp index ff3e63a09f..59998d3668 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_base_test.hpp +++ b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_base_test.hpp @@ -54,7 +54,6 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { nam // Create virtual void SetUp() override { - _putenv_s("AZURE_TEST_MODE", "RECORD"); Azure::Core::Test::TestBase::SetUpTestBase(AZURE_TEST_RECORDING_DIR); m_keyVaultUrl = GetEnv("AZURE_KEYVAULT_URL"); m_keyVaultHsmUrl = GetEnv("AZURE_KEYVAULT_HSM_URL"); diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp index b0085a0ff8..608a4e8a7e 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp +++ b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp @@ -5,8 +5,8 @@ #include "../../src/private/key_serializers.hpp" #include "key_client_base_test.hpp" -#include #include +#include #include #include @@ -58,19 +58,25 @@ TEST_F(KeyVaultKeyClient, GetKeyRotationPolicy) } } -TEST_F(KeyVaultKeyClient, GetRandomBytes) -{ - auto const keyName = GetTestName(); - CreateHsmClient(); - auto const& client = GetClientForTest(keyName); - GetRandomBytesOptions options; - options.Count = 4; - auto result = client.GetRandomBytes(options); - EXPECT_EQ(result.Value.size(), options.Count); +TEST_F(KeyVaultKeyClient, GetRandomBytes) +{ // NEED TO GUARD AGAINST LIVE TEST FOR THE MOMENT. + // DUE TO ISSUE WITH CREATE EC HSM TEST WHICH FAILS WITH ACTUAL HSM BEING SET IN THE ENVIRONMENT + // VARIABLE FILED BUG 3563 TO FIX IT + if (m_testContext.IsPlaybackMode()) + { + auto const keyName = GetTestName(); + CreateHsmClient(); + auto const& client = GetClientForTest(keyName); + GetRandomBytesOptions options; + options.Count = 4; + auto result = client.GetRandomBytes(options); + EXPECT_EQ(result.Value.size(), options.Count); + } } -TEST(GetRandomBytesOptions, Serialize) -{ GetRandomBytesOptions options; +TEST(GetRandomBytesOptions, Serialize) +{ + GetRandomBytesOptions options; { options.Count = 0; std::string result = GetRandomBytesSerializer::GetRandomBytesOptionsSerialize(options); @@ -99,7 +105,7 @@ TEST(GetRandomBytesOptions, Deserialize) Azure::Core::Http::RawResponse rawResponse(1, 1, Azure::Core::Http::HttpStatusCode::Ok, "OK"); rawResponse.SetBody(std::vector(responseText.begin(), responseText.end())); - + auto deserialized = GetRandomBytesSerializer::GetRandomBytesResponseDeserialize(rawResponse); EXPECT_EQ(deserialized.size(), size_t(4)); EXPECT_EQ(deserialized[0], uint8_t('1')); From d2760184e004109b7f400997daccfb375e022c7c Mon Sep 17 00:00:00 2001 From: George Arama <50641385+gearama@users.noreply.github.com> Date: Fri, 15 Apr 2022 12:33:54 -0700 Subject: [PATCH 08/10] typos, types, and many more --- .../azure/keyvault/keys/key_client_models.hpp | 4 ++-- .../keyvault/keys/key_client_options.hpp | 12 +++++------ .../src/key_get_random_bytes.cpp | 6 +++--- .../src/key_rotation_policy.cpp | 11 ++++++---- .../src/private/key_constants.hpp | 2 +- .../test/ut/key_rotation_policy_test_live.cpp | 21 ++++++++----------- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_models.hpp b/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_models.hpp index d6f1cf12a5..0e3a29fcb3 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_models.hpp +++ b/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_models.hpp @@ -944,7 +944,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { * @brief Action and its trigger that will be performed by Key Vault over the lifetime of a key. * */ - struct LifetimeActions final + struct LifetimeActionsType final { /** * @brief The condition that will execute the action. @@ -1000,7 +1000,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { * Notification time would be default to 30 days before expiry and it is not configurable. * */ - std::vector LifetimeActions; + std::vector LifetimeActions; /** * @brief The key rotation policy attributes. diff --git a/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_options.hpp b/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_options.hpp index 6ad65e24f3..522f231f2a 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_options.hpp +++ b/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_options.hpp @@ -402,15 +402,15 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { }; /** - * @brief Get Random Bytes options - * - */ + * @brief Get Random Bytes options + * + */ struct GetRandomBytesOptions final { /** - * @brief The requested number of random bytes. - * - */ + * @brief The requested number of random bytes. + * + */ int32_t Count; }; diff --git a/sdk/keyvault/azure-security-keyvault-keys/src/key_get_random_bytes.cpp b/sdk/keyvault/azure-security-keyvault-keys/src/key_get_random_bytes.cpp index cf411b6d45..106d46aa49 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/src/key_get_random_bytes.cpp +++ b/sdk/keyvault/azure-security-keyvault-keys/src/key_get_random_bytes.cpp @@ -1,12 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // SPDX-License-Identifier: MIT -#include -#include -#include #include "azure/keyvault/keys/key_client_models.hpp" #include "private/key_constants.hpp" #include "private/key_serializers.hpp" +#include +#include +#include using namespace Azure::Security::KeyVault::Keys; using namespace Azure::Core::Json::_internal; diff --git a/sdk/keyvault/azure-security-keyvault-keys/src/key_rotation_policy.cpp b/sdk/keyvault/azure-security-keyvault-keys/src/key_rotation_policy.cpp index 68b755548b..75d7af92b6 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/src/key_rotation_policy.cpp +++ b/sdk/keyvault/azure-security-keyvault-keys/src/key_rotation_policy.cpp @@ -51,7 +51,7 @@ KeyRotationPolicy _detail::KeyRotationPolicySerializer::KeyRotationPolicyDeseria for (auto action : lifeTimeActions) { - LifetimeActions currentAction; + LifetimeActionsType currentAction; JsonOptional::SetIfExists( currentAction.Trigger.TimeAfterCreate, @@ -66,11 +66,14 @@ KeyRotationPolicy _detail::KeyRotationPolicySerializer::KeyRotationPolicyDeseria auto actionType = action[_detail::ActionActionsValue][TypeActionsValue].get(); actionType = Azure::Core::_internal::StringExtensions::ToLower(actionType); - if (actionType == Azure::Core::_internal::StringExtensions::ToLower(_detail::RotateActionsValue)) + if (actionType + == Azure::Core::_internal::StringExtensions::ToLower(_detail::RotateActionsValue)) { currentAction.Action = LifetimeActionType::Rotate; } - else if (actionType == Azure::Core::_internal::StringExtensions::ToLower(_detail::NotifyActionsValue)) + else if ( + actionType + == Azure::Core::_internal::StringExtensions::ToLower(_detail::NotifyActionsValue)) { currentAction.Action = LifetimeActionType::Notify; } @@ -91,7 +94,7 @@ std::string _detail::KeyRotationPolicySerializer::KeyRotationPolicySerialize( rotationPolicy.Attributes.ExpiryTime, payload[_detail::AttributesPropertyName], _detail::ExpiryTimeValue); - payload[_detail::LifeTimeActionsValue].array(); + for (auto lifetimeAction : rotationPolicy.LifetimeActions) { json oneAction; diff --git a/sdk/keyvault/azure-security-keyvault-keys/src/private/key_constants.hpp b/sdk/keyvault/azure-security-keyvault-keys/src/private/key_constants.hpp index 9572c46601..8052206ae4 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/src/private/key_constants.hpp +++ b/sdk/keyvault/azure-security-keyvault-keys/src/private/key_constants.hpp @@ -137,7 +137,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { nam constexpr static const char TypeActionsValue[] = "type"; constexpr static const char TBEActionsValue[] = "timeBeforeExpiry"; constexpr static const char TACActionsValue[] = "timeAfterCreate"; - + /***************** Get Random Bytes *********/ constexpr static const char CountPropertiesValue[] = "count"; diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp index 608a4e8a7e..1c6f79fd7f 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp +++ b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp @@ -58,20 +58,17 @@ TEST_F(KeyVaultKeyClient, GetKeyRotationPolicy) } } -TEST_F(KeyVaultKeyClient, GetRandomBytes) -{ // NEED TO GUARD AGAINST LIVE TEST FOR THE MOMENT. +TEST_F(KeyVaultKeyClient, DISABLED_GetRandomBytes) +{ // NEED TO DISABLE TEST FOR THE MOMENT. // DUE TO ISSUE WITH CREATE EC HSM TEST WHICH FAILS WITH ACTUAL HSM BEING SET IN THE ENVIRONMENT // VARIABLE FILED BUG 3563 TO FIX IT - if (m_testContext.IsPlaybackMode()) - { - auto const keyName = GetTestName(); - CreateHsmClient(); - auto const& client = GetClientForTest(keyName); - GetRandomBytesOptions options; - options.Count = 4; - auto result = client.GetRandomBytes(options); - EXPECT_EQ(result.Value.size(), options.Count); - } + auto const keyName = GetTestName(); + CreateHsmClient(); + auto const& client = GetClientForTest(keyName); + GetRandomBytesOptions options; + options.Count = 4; + auto result = client.GetRandomBytes(options); + EXPECT_EQ(result.Value.size(), size_t(options.Count)); } TEST(GetRandomBytesOptions, Serialize) From 9af28cd2a7a6091e8edc9e8a8976286a37af121b Mon Sep 17 00:00:00 2001 From: George Arama <50641385+gearama@users.noreply.github.com> Date: Fri, 15 Apr 2022 12:57:46 -0700 Subject: [PATCH 09/10] maybe now ? please ... --- sdk/keyvault/azure-security-keyvault-keys/src/key_client.cpp | 3 +-- .../azure-security-keyvault-keys/src/key_rotation_policy.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/sdk/keyvault/azure-security-keyvault-keys/src/key_client.cpp b/sdk/keyvault/azure-security-keyvault-keys/src/key_client.cpp index 307253dd48..f489d05ba9 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/src/key_client.cpp +++ b/sdk/keyvault/azure-security-keyvault-keys/src/key_client.cpp @@ -424,8 +424,7 @@ Azure::Response> KeyClient::GetRandomBytes( reinterpret_cast(payload.data()), payload.size()); // Request and settings - auto request - = CreateRequest(HttpMethod::Post, {"/rng"}, &payloadStream); + auto request = CreateRequest(HttpMethod::Post, {"/rng"}, &payloadStream); request.SetHeader(HttpShared::ContentType, HttpShared::ApplicationJson); // Send and parse respone diff --git a/sdk/keyvault/azure-security-keyvault-keys/src/key_rotation_policy.cpp b/sdk/keyvault/azure-security-keyvault-keys/src/key_rotation_policy.cpp index 75d7af92b6..1d35f36caa 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/src/key_rotation_policy.cpp +++ b/sdk/keyvault/azure-security-keyvault-keys/src/key_rotation_policy.cpp @@ -124,4 +124,4 @@ std::string _detail::KeyRotationPolicySerializer::KeyRotationPolicySerialize( } return payload.dump(); -}; \ No newline at end of file +} From 1fc4061c5a88b473451852e675980da8888d2227 Mon Sep 17 00:00:00 2001 From: George Arama <50641385+gearama@users.noreply.github.com> Date: Wed, 20 Apr 2022 18:02:11 -0700 Subject: [PATCH 10/10] PR comments --- .../inc/azure/keyvault/keys/key_client.hpp | 2 +- .../azure/keyvault/keys/key_client_models.hpp | 19 ++++++++++++++++++- .../src/key_client.cpp | 15 ++++++++------- .../src/key_get_random_bytes.cpp | 6 +++--- .../src/key_rotation_policy.cpp | 5 ++--- .../src/private/key_constants.hpp | 1 + .../test/ut/key_rotation_policy_test_live.cpp | 6 +++--- 7 files changed, 36 insertions(+), 18 deletions(-) diff --git a/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client.hpp b/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client.hpp index 65e98451e8..b68c7d3c89 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client.hpp +++ b/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client.hpp @@ -448,7 +448,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { * @param context A #Azure::Core::Context controlling the request lifetime. * @return Azure::Response> */ - Azure::Response> GetRandomBytes( + Azure::Response GetRandomBytes( GetRandomBytesOptions const& options, Azure::Core::Context const& context = Azure::Core::Context()) const; diff --git a/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_models.hpp b/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_models.hpp index 0e3a29fcb3..8542eff623 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_models.hpp +++ b/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_models.hpp @@ -905,7 +905,11 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { Azure::Core::Context const& context = Azure::Core::Context()); }; - enum LifetimeActionType + /** + * @brief LifeTime action type + * + */ + enum class LifetimeActionType { /** * @brief Rotate the key based on the key policy. @@ -1008,4 +1012,17 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { KeyRotationPolicyAttributes Attributes; }; + /** + * @brief The GetRandomBytes result type containing the random bytes bytes. + * + */ + struct GetRandomBytesResult final + { + /** + * @brief The random generated bytes. + * + */ + std::vector RandomBytes; + }; + }}}} // namespace Azure::Security::KeyVault::Keys diff --git a/sdk/keyvault/azure-security-keyvault-keys/src/key_client.cpp b/sdk/keyvault/azure-security-keyvault-keys/src/key_client.cpp index f489d05ba9..ca6621390c 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/src/key_client.cpp +++ b/sdk/keyvault/azure-security-keyvault-keys/src/key_client.cpp @@ -386,7 +386,8 @@ Azure::Response KeyClient::GetKeyRotationPolicy( Azure::Core::Context const& context) const { // Request with no payload - auto request = CreateRequest(HttpMethod::Get, {_detail::KeysPath, name, "rotationpolicy"}); + auto request + = CreateRequest(HttpMethod::Get, {_detail::KeysPath, name, _detail::RotationPolicyPath}); request.SetHeader(HttpShared::ContentType, HttpShared::ApplicationJson); // Send and parse respone auto rawResponse = SendRequest(request, context); @@ -405,8 +406,8 @@ Azure::Response KeyClient::PutKeyRotationPolicy( reinterpret_cast(payload.data()), payload.size()); // Request and settings - auto request - = CreateRequest(HttpMethod::Put, {_detail::KeysPath, name, "rotationpolicy"}, &payloadStream); + auto request = CreateRequest( + HttpMethod::Put, {_detail::KeysPath, name, _detail::RotationPolicyPath}, &payloadStream); request.SetHeader(HttpShared::ContentType, HttpShared::ApplicationJson); // Send and parse respone @@ -415,7 +416,7 @@ Azure::Response KeyClient::PutKeyRotationPolicy( return Azure::Response(std::move(value), std::move(rawResponse)); } -Azure::Response> KeyClient::GetRandomBytes( +Azure::Response KeyClient::GetRandomBytes( GetRandomBytesOptions const& options, Azure::Core::Context const& context) const { @@ -429,9 +430,9 @@ Azure::Response> KeyClient::GetRandomBytes( // Send and parse respone auto rawResponse = SendRequest(request, context); - - auto value = _detail::GetRandomBytesSerializer::GetRandomBytesResponseDeserialize(*rawResponse); - return Azure::Response>(std::move(value), std::move(rawResponse)); + auto response = GetRandomBytesResult{ + _detail::GetRandomBytesSerializer::GetRandomBytesResponseDeserialize(*rawResponse)}; + return Azure::Response(std::move(response), std::move(rawResponse)); } Cryptography::CryptographyClient KeyClient::GetCryptographyClient( diff --git a/sdk/keyvault/azure-security-keyvault-keys/src/key_get_random_bytes.cpp b/sdk/keyvault/azure-security-keyvault-keys/src/key_get_random_bytes.cpp index 106d46aa49..7e5c9746ff 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/src/key_get_random_bytes.cpp +++ b/sdk/keyvault/azure-security-keyvault-keys/src/key_get_random_bytes.cpp @@ -24,9 +24,9 @@ std::string _detail::GetRandomBytesSerializer::GetRandomBytesOptionsSerialize( std::vector _detail::GetRandomBytesSerializer::GetRandomBytesResponseDeserialize( Azure::Core::Http::RawResponse const& rawResponse) { - auto body = rawResponse.GetBody(); - auto jsonParser = Azure::Core::Json::_internal::json::parse(body); + auto const& body = rawResponse.GetBody(); + auto const jsonParser = Azure::Core::Json::_internal::json::parse(body); auto value = jsonParser[_detail::ValueParameterValue].get(); return Azure::Core::_internal::Base64Url::Base64UrlDecode(value); -} \ No newline at end of file +} diff --git a/sdk/keyvault/azure-security-keyvault-keys/src/key_rotation_policy.cpp b/sdk/keyvault/azure-security-keyvault-keys/src/key_rotation_policy.cpp index 1d35f36caa..6b27ce1c72 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/src/key_rotation_policy.cpp +++ b/sdk/keyvault/azure-security-keyvault-keys/src/key_rotation_policy.cpp @@ -15,14 +15,13 @@ using Azure::Core::_internal::PosixTimeConverter; KeyRotationPolicy _detail::KeyRotationPolicySerializer::KeyRotationPolicyDeserialize( Azure::Core::Http::RawResponse const& rawResponse) { - auto body = rawResponse.GetBody(); - return KeyRotationPolicyDeserialize(body); + return KeyRotationPolicyDeserialize(rawResponse.GetBody()); } KeyRotationPolicy _detail::KeyRotationPolicySerializer::KeyRotationPolicyDeserialize( std::vector const& body) { - auto jsonParser = Azure::Core::Json::_internal::json::parse(body); + auto const jsonParser = Azure::Core::Json::_internal::json::parse(body); KeyRotationPolicy policy; policy.Id = jsonParser[_detail::IdValue].get(); diff --git a/sdk/keyvault/azure-security-keyvault-keys/src/private/key_constants.hpp b/sdk/keyvault/azure-security-keyvault-keys/src/private/key_constants.hpp index 8052206ae4..715ccd26d2 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/src/private/key_constants.hpp +++ b/sdk/keyvault/azure-security-keyvault-keys/src/private/key_constants.hpp @@ -137,6 +137,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { nam constexpr static const char TypeActionsValue[] = "type"; constexpr static const char TBEActionsValue[] = "timeBeforeExpiry"; constexpr static const char TACActionsValue[] = "timeAfterCreate"; + constexpr static const char RotationPolicyPath[] = "rotationpolicy"; /***************** Get Random Bytes *********/ constexpr static const char CountPropertiesValue[] = "count"; diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp index 1c6f79fd7f..ef4f053f01 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp +++ b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_rotation_policy_test_live.cpp @@ -3,8 +3,8 @@ #include "gtest/gtest.h" -#include "../../src/private/key_serializers.hpp" #include "key_client_base_test.hpp" +#include "private/key_serializers.hpp" #include #include #include @@ -68,7 +68,7 @@ TEST_F(KeyVaultKeyClient, DISABLED_GetRandomBytes) GetRandomBytesOptions options; options.Count = 4; auto result = client.GetRandomBytes(options); - EXPECT_EQ(result.Value.size(), size_t(options.Count)); + EXPECT_EQ(result.Value.RandomBytes.size(), size_t(options.Count)); } TEST(GetRandomBytesOptions, Serialize) @@ -161,4 +161,4 @@ TEST(KeyRotationPolicy, SerializeDeserialize1) "\"trigger\":{\"timeBeforeExpiry\":\"P30D\"}}]}"; EXPECT_EQ(serialized, serializedString); -} \ No newline at end of file +}