-
Notifications
You must be signed in to change notification settings - Fork 364
Add native AAD credential callback #5082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ananth7592
wants to merge
4
commits into
main
Choose a base branch
from
ananth7592-cosmos-native-aad-callback
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
480063e
Add native AAD credential callback
ananth7592 5ae72a4
Use RwLock for CallbackTokenCredential cache
ananth7592 5f58093
Align CallbackTokenCredential skew and post-fetch semantics with azur…
ananth7592 f6049fb
Merge branch 'main' into ananth7592-cosmos-native-aad-callback
ananth7592 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -961,6 +961,60 @@ typedef struct cosmos_error_t { | |
| const char *backtrace; | ||
| } cosmos_error_t; | ||
|
|
||
| /** | ||
| * Completes an asynchronous host token request. | ||
| * | ||
| * The host must invoke this callback exactly once after its token-provider | ||
| * callback returns success. Token and error buffers are borrowed only for the | ||
| * duration of this call; Rust copies them before returning. | ||
| */ | ||
| typedef void (*cosmos_token_completion_t)(void *completion_context, | ||
| int32_t status, | ||
| const uint8_t *token, | ||
| uintptr_t token_len, | ||
| int64_t expires_on_unix_seconds, | ||
| const uint8_t *error_message, | ||
| uintptr_t error_message_len); | ||
|
|
||
| /** | ||
| * One asynchronous access-token request passed to the host. | ||
| * | ||
| * `scope` is borrowed and valid only until the token-provider callback | ||
| * returns. The host must copy it before starting asynchronous work. | ||
| */ | ||
| typedef struct cosmos_token_request_t { | ||
| /** | ||
| * UTF-8 token scope bytes. | ||
| */ | ||
| const uint8_t *scope; | ||
| /** | ||
| * Number of bytes addressable from `scope`. | ||
| */ | ||
| uintptr_t scope_len; | ||
| /** | ||
| * Rust completion callback the host invokes exactly once. | ||
| */ | ||
| cosmos_token_completion_t completion; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this need to be a callback? Couldn't it be just a normal function, and rust maintains a map of context -> outstanding operations? |
||
| /** | ||
| * Opaque Rust-owned context passed unchanged to `completion`. | ||
| */ | ||
| void *completion_context; | ||
| } cosmos_token_request_t; | ||
|
|
||
| /** | ||
| * Host callbacks used to acquire tokens and release host state. | ||
| */ | ||
| typedef struct cosmos_token_provider_t { | ||
| /** | ||
| * Starts token acquisition. Must be non-NULL. | ||
| */ | ||
| int32_t (*get_token)(intptr_t user_data, const struct cosmos_token_request_t *request); | ||
| /** | ||
| * Releases `user_data` after the last Rust credential reference is gone. | ||
| */ | ||
| void (*user_data_free)(intptr_t user_data); | ||
| } cosmos_token_provider_t; | ||
|
|
||
| /** | ||
| * A library-owned byte buffer returned by value across the C ABI. | ||
| * | ||
|
|
@@ -1644,6 +1698,29 @@ cosmos_status_code_t cosmos_account_ref_with_master_key(const char *endpoint, | |
| struct cosmos_account_ref_t **out_account, | ||
| struct cosmos_error_t **out_error); | ||
|
|
||
| /** | ||
| * Creates an account reference authenticated by a host token credential. | ||
| * | ||
| * The callback provider is adapted into the driver's async | ||
| * [`azure_core::credentials::TokenCredential`] interface. Ownership of | ||
| * `user_data` transfers to Rust only on success. The optional | ||
| * `user_data_free` callback runs after the final account/driver credential | ||
| * reference is released. | ||
| * | ||
| * # Returns | ||
| * | ||
| * - `SUCCESS` (0) with `*out_account` populated. | ||
| * - `INVALID_ARGUMENT` (1) when `endpoint`, `out_account`, or the provider's | ||
| * `get_token` callback is NULL. | ||
| * - `INVALID_UTF8` (2) when `endpoint` is not valid UTF-8. | ||
| * - `INVALID_ACCOUNT_REFERENCE` (4003) when `endpoint` is not a parsable URL. | ||
| */ | ||
| cosmos_status_code_t cosmos_account_ref_with_credential(const char *endpoint, | ||
| struct cosmos_token_provider_t provider, | ||
| intptr_t user_data, | ||
| struct cosmos_account_ref_t **out_account, | ||
| struct cosmos_error_t **out_error); | ||
|
|
||
| /** | ||
| * Frees an account-reference handle. NULL is a no-op. | ||
| */ | ||
|
|
||
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two minutes seems very short. I thought for .NET we had a custom policy that tries to refresh at 50% of the token lifetime, so that there is time for retries if the token server is down. Would should probably do the same here.