-
Notifications
You must be signed in to change notification settings - Fork 75
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
refactor(jans-cedarling): improve WASM compatibility #10331
base: main
Are you sure you want to change the base?
Conversation
DryRun Security SummaryThe provided GitHub pull request contains changes across multiple files in the Expand for full summarySummary: The provided GitHub pull request contains a series of changes across multiple files in the From an application security perspective, the changes do not introduce any obvious security vulnerabilities. The updates appear to be focused on improving the reliability, performance, and maintainability of the code, with a particular emphasis on ensuring that time-related operations are handled correctly and securely. Some key security-related aspects of the changes include:
Overall, the changes in this pull request appear to be focused on improving the functionality and reliability of the Files Changed:
Code AnalysisWe ran |
- replace std::time using with the chrono crate to improve WASM compalibility - use reqwest::Client instead of reqwest::blocking::Client Signed-off-by: rmarinn <[email protected]>
3df6e1d
to
6f9eb61
Compare
Signed-off-by: rmarinn <[email protected]>
Signed-off-by: rmarinn <[email protected]>
Signed-off-by: rmarinn <[email protected]>
Signed-off-by: rmarinn <[email protected]>
- make SparKV use chrono::Duration instead of std::time::Duration to allow compilation to WASM. Signed-off-by: rmarinn <[email protected]>
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.
Locally, there are build failures with cargo test --target wasm32-wasip1
and cargo test --target wasm32-unknown-unknown
. Is that expected right now?
Looks to me the cause is jsonwebkey
, which pulls in an older version of jsonwebtoken
which then pulls in an older version of ring
.
Yeah... turns out we need to change more things (other than the
we're only really using |
let resp_text = self | ||
.rt | ||
.block_on(async { self.resp.text().await }) | ||
.map_err(HttpClientError::DeserializeJson)?; |
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.
maybe it should be better to use DeserializeText
instead of DeserializeJson
here
let rt = RtBuilder::new_current_thread() | ||
.enable_all() | ||
.build() | ||
.expect("Failed to create Tokio runtime"); | ||
let client = Client::builder() | ||
.build() |
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's a good practice to add a timeout in during an http request like:
let client = Client::builder()
.timeout(Duration::from_sec(20))
.build()
.map_err(HttpClientError::Initialization)?;
{ | ||
let resp_json = self | ||
.rt | ||
.block_on(async { self.resp.json::<T>().await }) |
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.
In general it's better to use async then block_on. Here you can do something like :
let resp_json = self
.resp
.json::<T>()
.await
.map_err(HttpClientError::DeserializeJson)?;
Ok(resp_json)
Moreover, you can remove the lifetime parameter <'rt> from Response.
Prepare
Description
This PR improves WASM compatibility by:
chrono
crate which has WASM support instead ofstd::time
for getting the time.reqwest::blocking::Client
withreqwest::Client
.Target issue
target issue: refactor(jans-cedarling): improve WASM compatibility #10330
closes #10330
Implementation Details
HttpClient
create will store a reference to atokio
runtime which it will use to make async requests so compiling to WASM would be possible.Test and Document the changes
Please check the below before submitting your PR. The PR will not be merged if there are no commits that start with
docs:
to indicate documentation changes or if the below checklist is not selected.