-
Notifications
You must be signed in to change notification settings - Fork 608
Add AuthCtx to ReducerContext for rust #3288
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
base: master
Are you sure you want to change the base?
Conversation
crates/core/src/host/wasm_common.rs
Outdated
"spacetime_10.0"::get_jwt, | ||
"spacetime_10.0"::jwt_len, |
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.
These should be in a new ABI version and module, spacetime_11.0
. See comment in bindings_sys/src/lib.rs
around line 20.
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.
Ah, looks like this should be spacetime_10.1
, actually.
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.
See #3294 for an example of adding a new host function with a new minor version. These can all go in 10.1
so long as we don't cut a release in between the two PRs.
/// Find the jwt payload for the given connection id, and write the | ||
/// BytesSourceId to the given pointer. | ||
/// If this is not found, BytesSourceId::INVALID (aka 0) will be written. | ||
pub fn get_jwt(connection_id_ptr: *const u8, bytes_source_id: *mut BytesSource); |
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.
This should follow the above documentation style in terms of ABI and traps and errors.
}) | ||
} | ||
|
||
pub fn get_jwt( |
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.
This needs corresponding docs in the style of e.g., table_id_from_name
including traps and errors (e.g., NOT_IN_TRANSACTION
applies here).
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.
I updated it to clarify that it traps for errors. Returning an integer error code doesn't seem very useful.
target_ptr: WasmPtr<u32>, | ||
) -> RtResult<()> { | ||
log::info!("Calling get_jwt"); | ||
Self::with_span(caller, AbiCall::GetJwt, |caller| { |
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.
Looks like this could use cvt_ret
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.
It probably could, but it using that function just seemed to make the error handling more difficult to reason about.
Description of Changes
This exposes client credentials in reducer calls for rust.
API and ABI breaking changes
API Changes:
The main API change is the addition of
AuthCtx
and thesender_auth
inReducerContext
.ABI Changes:
This adds two new functions
jwt_len
andget_jwt
. These usest_connection_credentials
to look up the credentials associated with a connection id.jwt_len
can be used to figure out the size of the payload, so thatget_jwt
can provide a large enough buffer.TODO: I assume I need to bump the ABI version in this PR.
Expected complexity level and risk
Testing
I've done some manual testing with modified versions of the quickstart. We should add some examples that use the new API.