diff --git a/sdk/attestation/azure-security-attestation/vcpkg/vcpkg.json b/sdk/attestation/azure-security-attestation/vcpkg/vcpkg.json index a92569c2d..191d5fbc5 100644 --- a/sdk/attestation/azure-security-attestation/vcpkg/vcpkg.json +++ b/sdk/attestation/azure-security-attestation/vcpkg/vcpkg.json @@ -16,6 +16,7 @@ "default-features": false, "version>=": "1.7.0" }, + "openssl", { "name": "vcpkg-cmake", "host": true @@ -23,9 +24,6 @@ { "name": "vcpkg-cmake-config", "host": true - }, - { - "name": "openssl" } ] } diff --git a/sdk/core/azure-core/vcpkg/Config.cmake.in b/sdk/core/azure-core/vcpkg/Config.cmake.in index 8b22867ca..412cce6d4 100644 --- a/sdk/core/azure-core/vcpkg/Config.cmake.in +++ b/sdk/core/azure-core/vcpkg/Config.cmake.in @@ -10,9 +10,11 @@ if(@BUILD_TRANSPORT_CURL@) find_dependency(CURL @CURL_MIN_REQUIRED_VERSION@) endif() -if(WIN32) +if(@BUILD_TRANSPORT_WINHTTP@) find_dependency(wil) -else() +endif() + +if (NOT WIN32) find_dependency(OpenSSL) endif() diff --git a/sdk/core/azure-core/vcpkg/vcpkg.json b/sdk/core/azure-core/vcpkg/vcpkg.json index bc300bd5c..d0f2bac77 100644 --- a/sdk/core/azure-core/vcpkg/vcpkg.json +++ b/sdk/core/azure-core/vcpkg/vcpkg.json @@ -22,10 +22,6 @@ { "name": "vcpkg-cmake-config", "host": true - }, - { - "name": "wil", - "platform": "windows" } ], "default-features": [ @@ -71,11 +67,13 @@ }, "winhttp": { "description": "WinHTTP HTTP transport implementation", + "supports": "windows", "dependencies": [ { "name": "azure-core-cpp", "default-features": false - } + }, + "wil" ] } } diff --git a/sdk/identity/azure-identity/src/azure_cli_credential.cpp b/sdk/identity/azure-identity/src/azure_cli_credential.cpp index 279d273d1..fc1f1329f 100644 --- a/sdk/identity/azure-identity/src/azure_cli_credential.cpp +++ b/sdk/identity/azure-identity/src/azure_cli_credential.cpp @@ -154,6 +154,7 @@ AccessToken AzureCliCredential::GetToken( namespace { #if defined(AZ_PLATFORM_WINDOWS) +#if !defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP // not UWP template struct UniqueHandleHelper; template <> struct UniqueHandleHelper { @@ -163,6 +164,7 @@ template <> struct UniqueHandleHelper template using UniqueHandle = Azure::Core::_internal::UniqueHandle; +#endif // not UWP #endif class ShellProcess; @@ -171,10 +173,12 @@ class OutputPipe final { private: #if defined(AZ_PLATFORM_WINDOWS) +#if !defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP // not UWP UniqueHandle m_writeHandle; UniqueHandle m_readHandle; OVERLAPPED m_overlapped = {}; -#else +#endif // not UWP +#else // not Windows std::vector m_fd; #endif @@ -195,8 +199,10 @@ public: class ShellProcess final { private: #if defined(AZ_PLATFORM_WINDOWS) +#if !defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP // not UWP UniqueHandle m_processHandle; -#else +#endif // not UWP +#else // not Windows std::vector m_argv; std::vector m_argvValues; @@ -271,6 +277,7 @@ std::string RunShellCommand( } #if defined(AZ_PLATFORM_WINDOWS) +#if !defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP // not UWP void ThrowIfApiCallFails(BOOL apiResult, std::string const& errMsg) { // LCOV_EXCL_START @@ -283,7 +290,8 @@ void ThrowIfApiCallFails(BOOL apiResult, std::string const& errMsg) } // LCOV_EXCL_STOP } -#else +#endif // not UWP +#else // not Windows void ThrowIfApiCallFails(int apiResult, std::string const& errMsg) { // LCOV_EXCL_START @@ -299,6 +307,7 @@ void ThrowIfApiCallFails(int apiResult, std::string const& errMsg) OutputPipe::OutputPipe() { #if defined(AZ_PLATFORM_WINDOWS) +#if !defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP // not UWP SECURITY_ATTRIBUTES pipeSecurity = {}; pipeSecurity.nLength = sizeof(decltype(pipeSecurity)); pipeSecurity.bInheritHandle = TRUE; @@ -318,7 +327,10 @@ OutputPipe::OutputPipe() ThrowIfApiCallFails( SetHandleInformation(m_readHandle.get(), HANDLE_FLAG_INHERIT, 0), "Cannot ensure the read handle for the output pipe is not inherited"); -#else +#else // UWP + throw std::runtime_error("The credential is not supported on UWP."); +#endif +#else // not Windows m_fd.push_back(-1); m_fd.push_back(-1); @@ -342,6 +354,7 @@ OutputPipe::~OutputPipe() } #if defined(AZ_PLATFORM_WINDOWS) +#if !defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP // not UWP void AppendToEnvironmentValuesIfNotEmpty( std::vector& environmentValues, std::string const& envVarName, @@ -365,7 +378,8 @@ void AppendToEnvironmentValuesIfDefined( AppendToEnvironmentValuesIfNotEmpty( environmentValues, envVarName, Environment::GetVariable(envVarName.c_str())); } -#else +#endif // not UWP +#else // not Windows void AppendToArgvValues( std::vector& argvValues, std::vector::type::size_type>& argvValuePositions, @@ -394,6 +408,7 @@ void EnsureShellExists(std::string const& pathToShell) ShellProcess::ShellProcess(std::string const& command, OutputPipe& outputPipe) { #if defined(AZ_PLATFORM_WINDOWS) +#if !defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP // not UWP // Start the process. PROCESS_INFORMATION procInfo = {}; @@ -484,7 +499,11 @@ ShellProcess::ShellProcess(std::string const& command, OutputPipe& outputPipe) // We will only be reading the pipe. // So, now that the process is started, we can close write handle on our end. outputPipe.m_writeHandle.reset(); -#else +#else // UWP + static_cast(command); + static_cast(outputPipe); +#endif // UWP +#else // not Windows // Form the 'argv' array: // * An array of pointers to non-const C strings (0-terminated). // * Last element is nullptr. @@ -587,8 +606,10 @@ void ShellProcess::Finalize() void ShellProcess::Terminate() { #if defined(AZ_PLATFORM_WINDOWS) +#if !defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP // not UWP static_cast(TerminateProcess(m_processHandle.get(), 0)); -#else +#endif // not UWP +#else // not Windows if (m_pid > 0) { static_cast(kill(m_pid, SIGKILL)); @@ -602,6 +623,7 @@ bool OutputPipe::NonBlockingRead( bool& willHaveMoreData) { #if defined(AZ_PLATFORM_WINDOWS) +#if !defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP // not UWP static_assert( sizeof(std::remove_reference::type::value_type) == sizeof(CHAR), "buffer elements and CHARs should be of the same size"); @@ -627,7 +649,13 @@ bool OutputPipe::NonBlockingRead( willHaveMoreData = (GetLastError() != ERROR_BROKEN_PIPE); return hadData && bytesRead > 0; -#else +#else // UWP + static_cast(buffer); + static_cast(bytesRead); + static_cast(willHaveMoreData); + throw std::runtime_error("The credential is not supported on UWP."); +#endif // UWP +#else // not Windows static_assert( sizeof(std::remove_reference::type::value_type) == sizeof(char), "buffer elements and chars should be of the same size"); diff --git a/sdk/identity/azure-identity/test/ut/azure_cli_credential_test.cpp b/sdk/identity/azure-identity/test/ut/azure_cli_credential_test.cpp index 4fb9125e0..44f5ad4cc 100644 --- a/sdk/identity/azure-identity/test/ut/azure_cli_credential_test.cpp +++ b/sdk/identity/azure-identity/test/ut/azure_cli_credential_test.cpp @@ -82,7 +82,12 @@ public: }; } // namespace +#if !defined(AZ_PLATFORM_WINDOWS) \ + || (!defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP) // not UWP TEST(AzureCliCredential, Success) +#else +TEST(AzureCliCredential, NotAvailable) +#endif { constexpr auto Token = "{\"accessToken\":\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"," "\"expiresOn\":\"2022-08-24 00:43:08.000000\"," @@ -93,6 +98,8 @@ TEST(AzureCliCredential, Success) TokenRequestContext trc; trc.Scopes.push_back("https://storage.azure.com/.default"); +#if !defined(AZ_PLATFORM_WINDOWS) \ + || (!defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP) // not UWP auto const token = azCliCred.GetToken(trc, {}); EXPECT_EQ(token.Token, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); @@ -100,8 +107,19 @@ TEST(AzureCliCredential, Success) EXPECT_EQ( token.ExpiresOn, DateTime::Parse("2022-08-24T00:43:08.000000Z", DateTime::DateFormat::Rfc3339)); +#else // UWP + // The credential should throw during GetToken() and not during construction, because it allows + // customers to put it into ChainedTokenCredential and successfully use it there without writing + // ifdefs for UWP. It is not too late to throw - for example, if Azure CLI is not installed, then + // the credential will also find out during GetToken() and not during construction (if we had to + // find out during the construction, we'd have to fire up some 'az' command in constructor; again, + // that would also make it hard to put the credential into ChainedTokenCredential). + EXPECT_THROW(static_cast(azCliCred.GetToken(trc, {})), AuthenticationException); +#endif // UWP } +#if !defined(AZ_PLATFORM_WINDOWS) \ + || (!defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP) // not UWP TEST(AzureCliCredential, Error) { AzureCliTestCredential const azCliCred( @@ -308,3 +326,4 @@ TEST(AzureCliCredential, StrictIso8601TimeFormat) token.ExpiresOn, DateTime::Parse("2022-08-24T00:43:08.000000Z", DateTime::DateFormat::Rfc3339)); } +#endif // not UWP diff --git a/sdk/identity/azure-identity/vcpkg/vcpkg.json b/sdk/identity/azure-identity/vcpkg/vcpkg.json index d53c9d7fd..a5ec152de 100644 --- a/sdk/identity/azure-identity/vcpkg/vcpkg.json +++ b/sdk/identity/azure-identity/vcpkg/vcpkg.json @@ -16,9 +16,7 @@ "default-features": false, "version>=": "1.4.0" }, - { - "name": "openssl" - }, + "openssl", { "name": "vcpkg-cmake", "host": true