-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update rlclientlib and rl.net to support azure credential hooks (#609)
* added azure_credentials_provider.h to the public headers update rl_sim to use azure_credentials_provider with DefaultAzureCredential added support for the azure_credentials_provider in rl.net.native and rl.net added cmake checks for dotnet-t4 * added memory and azure include to the azure_credentials_provider * added trace logger to the azure credential providers added 2 new error code for failing to authenticate updated items as per PR comments * removed trace from lock scope * added set(CMAKE_DEBUG_POSTFIX "") to ensure VS builds have the same lib debug suffixes as the Ninja builds. update the rlnetnative import constant (removing the d suffix) * updated formatting (according to tidy) * moved find dotnet-t4 to FindDotnet.cmake and check it for windows only. the build explicitly installs dotnet-t4 for windows. * the x64 macos image was changed to macos-latest-large. see (https://github.com/actions/runner-images?tab=readme-ov-file#available-images) * for now, moving to build runner macos-13 supporting x64 * updates to provide default azure credential implementations via the factory resolver cmake changes to link with azure identity when RL_LINK_AZURE_LIBS is defined * fixed formatting added missing include * added missing call to azure_cred_provider_factory_t dtor in factory_initializer * update the job name for macos so that we don't need to change the status check names (start with asan) * fix using ternary operator expression * updated the vcpkg build to align the macos package names with the status checks * the job name should 'macos-latest' * updated another macos-13 os tag to macos-latest * changed macos-13 exact match to startsWith added missing macos-13 transforms * corrected startsWith 'macos-13' to 'macos' added job names to test-nuget and build-nuget-dotnet to match the status checks
- Loading branch information
1 parent
cd6eabe
commit e1b77f6
Showing
55 changed files
with
1,025 additions
and
355 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "rl.net.azure_factories.h" | ||
|
||
namespace rl_net_native | ||
{ | ||
rl_net_native::azure_factory_oauth_callback_t g_oauth_callback = nullptr; | ||
rl_net_native::azure_factory_oauth_callback_complete_t g_oauth_callback_complete = nullptr; | ||
|
||
static int azure_factory_oauth_callback(const std::vector<std::string>& scopes, std::string& oauth_token, | ||
std::chrono::system_clock::time_point& token_expiry, reinforcement_learning::i_trace* trace) | ||
{ | ||
if (g_oauth_callback == nullptr) { return reinforcement_learning::error_code::invalid_argument; } | ||
// create a null terminated array of scope string pointers. | ||
// these are pointers are readonly and owned by the caller. | ||
// since we create the vector of n elements, we can guarantee | ||
// the last element is null. | ||
std::vector<const char*> native_scopes(scopes.size() + 1); | ||
for (int i = 0; i < scopes.size(); ++i) { native_scopes[i] = scopes[i].c_str(); } | ||
// we expect to get a pointer to a null terminated string. | ||
// it's allocated on the managed heap, so we can't free it here | ||
// instead, we will pass it back to the managed code after we copy it. | ||
char* oauth_token_ptr = nullptr; | ||
std::int64_t expiryUnixTime = 0; | ||
auto ret = g_oauth_callback(native_scopes.data(), &oauth_token_ptr, &expiryUnixTime); | ||
if (ret == reinforcement_learning::error_code::success) | ||
{ | ||
TRACE_DEBUG(trace, "rl_net_native::azure_factory_oauth_callback: successfully retrieved token"); | ||
oauth_token = oauth_token_ptr; | ||
token_expiry = std::chrono::system_clock::from_time_t(expiryUnixTime); | ||
} | ||
else { TRACE_ERROR(trace, "rl_net_native::azure_factory_oauth_callback: failed to retrieve token"); } | ||
g_oauth_callback_complete(oauth_token_ptr, reinforcement_learning::error_code::success); | ||
return ret; | ||
} | ||
} // namespace rl_net_native | ||
|
||
API void RegisterDefaultFactoriesCallback(rl_net_native::azure_factory_oauth_callback_t callback, | ||
rl_net_native::azure_factory_oauth_callback_complete_t completion) | ||
{ | ||
if (rl_net_native::g_oauth_callback == nullptr) | ||
{ | ||
rl_net_native::g_oauth_callback = callback; | ||
reinforcement_learning::register_default_factories_callback( | ||
reinforcement_learning::oauth_callback_t{rl_net_native::azure_factory_oauth_callback}); | ||
rl_net_native::g_oauth_callback_complete = completion; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
|
||
#include "factory_resolver.h" | ||
#include "rl.net.native.h" | ||
|
||
#include <cstddef> | ||
|
||
namespace rl_net_native | ||
{ | ||
// Callback function to be called by the C# code to get the OAuth token | ||
// The callback function should return 0 on success and non-zero on failure (see reinforcement_learning::error_code) | ||
// prototype - azure_factory_oauth_callback(const char** scopes, char** token, std::int64_t* expiryUnixTime) | ||
// scopes - null terminated array of scope strings | ||
// token - out pointer to a null terminated string allocated on the managed heap | ||
// expiryUnixTime - pointer to the expiry time of the token in Unix time | ||
typedef int (*azure_factory_oauth_callback_t)(const char**, char**, std::int64_t*); | ||
|
||
// Callback function to be called by the C# code to signal the completion of the OAuth token request | ||
// this provides the C# code with the opportunity to free the memory allocated for the token | ||
// tokenStringToFree - pointer to the token string than needs to be freed | ||
// errorCode - for future use | ||
typedef void (*azure_factory_oauth_callback_complete_t)(char*, int); | ||
} // namespace rl_net_native | ||
|
||
extern "C" | ||
{ | ||
// Register the callback function to be called by the C++ code to get the OAuth token | ||
// both the callback and completion functions must be registered before any calls to the Azure factories are made | ||
// typically, this function should be called once during the initialization of the application | ||
// callback - the callback function to be called by the C++ code to get the OAuth token | ||
// completion - the callback function to be called by the C++ code to signal the completion of the OAuth token | ||
// request | ||
API void RegisterDefaultFactoriesCallback(rl_net_native::azure_factory_oauth_callback_t callback, | ||
rl_net_native::azure_factory_oauth_callback_complete_t completion); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.