Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@
"default-features": false,
"version>=": "1.7.0"
},
"openssl",
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
},
{
"name": "openssl"
}
]
}
6 changes: 4 additions & 2 deletions sdk/core/azure-core/vcpkg/Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
8 changes: 3 additions & 5 deletions sdk/core/azure-core/vcpkg/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
{
"name": "vcpkg-cmake-config",
"host": true
},
{
"name": "wil",
"platform": "windows"
}
],
"default-features": [
Expand Down Expand Up @@ -71,11 +67,13 @@
},
"winhttp": {
"description": "WinHTTP HTTP transport implementation",
"supports": "windows",
"dependencies": [
{
"name": "azure-core-cpp",
"default-features": false
}
},
"wil"
]
}
}
Expand Down
44 changes: 36 additions & 8 deletions sdk/identity/azure-identity/src/azure_cli_credential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ AccessToken AzureCliCredential::GetToken(

namespace {
#if defined(AZ_PLATFORM_WINDOWS)
#if !defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP // not UWP
Comment thread
antkmsft marked this conversation as resolved.
template <typename> struct UniqueHandleHelper;
template <> struct UniqueHandleHelper<HANDLE>
{
Expand All @@ -163,6 +164,7 @@ template <> struct UniqueHandleHelper<HANDLE>

template <typename T>
using UniqueHandle = Azure::Core::_internal::UniqueHandle<T, UniqueHandleHelper>;
#endif // not UWP
#endif

class ShellProcess;
Expand All @@ -171,10 +173,12 @@ class OutputPipe final {

private:
#if defined(AZ_PLATFORM_WINDOWS)
#if !defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP // not UWP
Comment thread
antkmsft marked this conversation as resolved.
UniqueHandle<HANDLE> m_writeHandle;
UniqueHandle<HANDLE> m_readHandle;
OVERLAPPED m_overlapped = {};
#else
#endif // not UWP
#else // not Windows
std::vector<int> m_fd;
#endif

Expand All @@ -195,8 +199,10 @@ class OutputPipe final {
class ShellProcess final {
private:
#if defined(AZ_PLATFORM_WINDOWS)
#if !defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP // not UWP
UniqueHandle<HANDLE> m_processHandle;
#else
#endif // not UWP
#else // not Windows
std::vector<char*> m_argv;
std::vector<char> m_argvValues;

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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);

Expand All @@ -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<CHAR>& environmentValues,
std::string const& envVarName,
Expand All @@ -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<char>& argvValues,
std::vector<std::remove_reference<decltype(argvValues)>::type::size_type>& argvValuePositions,
Expand Down Expand Up @@ -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 = {};

Expand Down Expand Up @@ -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<void>(command);
static_cast<void>(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.
Expand Down Expand Up @@ -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<void>(TerminateProcess(m_processHandle.get(), 0));
#else
#endif // not UWP
#else // not Windows
if (m_pid > 0)
{
static_cast<void>(kill(m_pid, SIGKILL));
Expand All @@ -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<decltype(buffer)>::type::value_type) == sizeof(CHAR),
"buffer elements and CHARs should be of the same size");
Expand All @@ -627,7 +649,13 @@ bool OutputPipe::NonBlockingRead(
willHaveMoreData = (GetLastError() != ERROR_BROKEN_PIPE);

return hadData && bytesRead > 0;
#else
#else // UWP
static_cast<void>(buffer);
static_cast<void>(bytesRead);
static_cast<void>(willHaveMoreData);
throw std::runtime_error("The credential is not supported on UWP.");
#endif // UWP
#else // not Windows
static_assert(
sizeof(std::remove_reference<decltype(buffer)>::type::value_type) == sizeof(char),
"buffer elements and chars should be of the same size");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ class AzureCliTestCredential : public AzureCliCredential {
};
} // 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\","
Expand All @@ -93,15 +98,28 @@ 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");

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<void>(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(
Expand Down Expand Up @@ -308,3 +326,4 @@ TEST(AzureCliCredential, StrictIso8601TimeFormat)
token.ExpiresOn,
DateTime::Parse("2022-08-24T00:43:08.000000Z", DateTime::DateFormat::Rfc3339));
}
#endif // not UWP
4 changes: 1 addition & 3 deletions sdk/identity/azure-identity/vcpkg/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
"default-features": false,
"version>=": "1.4.0"
},
{
"name": "openssl"
},
"openssl",
{
"name": "vcpkg-cmake",
"host": true
Expand Down