Skip to content

Commit 87f19da

Browse files
authored
Merge branch 'main' into ci
2 parents be67b27 + b5d7bb3 commit 87f19da

File tree

19 files changed

+152
-77
lines changed

19 files changed

+152
-77
lines changed

.github/workflows/rust.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ jobs:
3535
run: ulimit -n 65535
3636
- name: Run tests
3737
run: cargo test --verbose
38+
- name: Run tests with sync_handler features
39+
run: cargo test --features sync_handler --verbose
3840
- name: Run Clippy
3941
run: cargo clippy -- -D warnings
4042
- name: Install tarpaulin
@@ -74,6 +76,10 @@ jobs:
7476
run : |
7577
export LD_LIBRARY_PATH=${RUNNER_TEMP}/tongsuo/lib
7678
OPENSSL_DIR=${RUNNER_TEMP}/tongsuo RUSTFLAGS="-C link-args=-Wl,-rpath,${RUNNER_TEMP}/tongsuo/lib" cargo test --verbose --features crypto_adaptor_tongsuo --no-default-features
79+
- name: Run tests with sync_handler features
80+
run : |
81+
export LD_LIBRARY_PATH=${RUNNER_TEMP}/tongsuo/lib
82+
OPENSSL_DIR=${RUNNER_TEMP}/tongsuo RUSTFLAGS="-C link-args=-Wl,-rpath,${RUNNER_TEMP}/tongsuo/lib" cargo test --verbose --features crypto_adaptor_tongsuo --features sync_handler --no-default-features
7783
7884
unix-mysql-test:
7985
strategy:
@@ -126,6 +132,8 @@ jobs:
126132
run: cargo build --verbose
127133
- name: Run tests
128134
run: cargo test --verbose
135+
- name: Run tests with sync_handler features
136+
run: cargo test --features sync_handler --verbose
129137

130138
windows-mysql-test:
131139
strategy:

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ prettytable = "0.10"
7575
rpassword = "7.3"
7676
async-trait = "0.1"
7777
stretto = "0.8"
78-
itertools = "0.14"
7978
priority-queue = "2.1"
8079
crossbeam-channel = "0.5"
80+
maybe-async = { version = "0.2", optional = false }
8181

8282
# optional dependencies
8383
openssl = { version = "*", optional = true }
@@ -96,6 +96,7 @@ default = ["crypto_adaptor_openssl"]
9696
storage_mysql = ["diesel", "r2d2", "r2d2-diesel"]
9797
crypto_adaptor_openssl = ["dep:openssl", "dep:openssl-sys"]
9898
crypto_adaptor_tongsuo = ["dep:openssl", "dep:openssl-sys"]
99+
sync_handler = ["maybe-async/is_sync"]
99100

100101
[target.'cfg(unix)'.dependencies]
101102
daemonize = "0.5"

netlify.toml

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/cli/command/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl Server {
5959
Ok(_) => EXIT_CODE_OK,
6060
Err(e) => {
6161
println!("server error: {:?}", e);
62-
EXIT_CODE_LOAD_CONFIG_FAILURE
62+
std::process::exit(EXIT_CODE_LOAD_CONFIG_FAILURE as i32);
6363
}
6464
};
6565
}

src/core.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ impl Default for Core {
107107
}
108108
}
109109

110+
#[maybe_async::maybe_async]
110111
impl Core {
111112
pub fn config(&mut self, core: Arc<RwLock<Core>>, config: Option<&Config>) -> Result<(), RvError> {
112113
if let Some(conf) = config {
@@ -411,6 +412,7 @@ impl Core {
411412
Ok(())
412413
}
413414

415+
#[maybe_async::maybe_async]
414416
pub async fn handle_request(&self, req: &mut Request) -> Result<Option<Response>, RvError> {
415417
let mut resp = None;
416418
let mut err: Option<RvError> = None;

src/handler.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//! The `Handler` trait should be implemented in other module, such as the `rusty_vault::router`
77
//! for instance.
88
9-
use async_trait::async_trait;
109
use derive_more::Display;
1110

1211
use crate::{
@@ -16,7 +15,7 @@ use crate::{
1615
logical::{request::Request, response::Response, Auth},
1716
};
1817

19-
#[async_trait]
18+
#[maybe_async::maybe_async]
2019
pub trait Handler: Send + Sync {
2120
fn name(&self) -> String;
2221

@@ -41,7 +40,7 @@ pub trait Handler: Send + Sync {
4140
}
4241
}
4342

44-
#[async_trait]
43+
#[maybe_async::maybe_async]
4544
pub trait AuthHandler: Send + Sync {
4645
fn name(&self) -> String;
4746

src/http/logical.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,12 @@ async fn logical_request_handler(
8181
r.operation = Operation::List;
8282
}
8383
}
84+
#[cfg(feature = "sync_handler")]
85+
let ret = core.read()?.handle_request(&mut r)?;
86+
#[cfg(not(feature = "sync_handler"))]
87+
let ret = core.read()?.handle_request(&mut r).await?;
8488

85-
match core.read()?.handle_request(&mut r).await? {
89+
match ret {
8690
Some(resp) => response_logical(&resp, &r.path),
8791
None => {
8892
if matches!(r.operation, Operation::Read | Operation::List) {

src/http/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ pub fn response_json_ok<T: Serialize>(cookie: Option<Cookie>, body: T) -> HttpRe
199199

200200
pub async fn handle_request(core: web::Data<Arc<RwLock<Core>>>, req: &mut Request) -> Result<HttpResponse, RvError> {
201201
let core = core.read()?;
202+
#[cfg(feature = "sync_handler")]
203+
let resp = core.handle_request(req)?;
204+
#[cfg(not(feature = "sync_handler"))]
202205
let resp = core.handle_request(req).await?;
203206
if resp.is_none() {
204207
Ok(response_ok(None, None))

src/modules/auth/token_store.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::{
99
time::{Duration, SystemTime, UNIX_EPOCH},
1010
};
1111

12-
use async_trait::async_trait;
1312
use better_default::Default;
1413
use humantime::parse_duration;
1514
use lazy_static::lazy_static;
@@ -727,7 +726,7 @@ impl TokenStore {
727726
}
728727
}
729728

730-
#[async_trait]
729+
#[maybe_async::maybe_async]
731730
impl Handler for TokenStore {
732731
fn name(&self) -> String {
733732
"auth_token".to_string()

src/modules/credential/approle/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ mod test {
216216
test_utils::{test_delete_api, test_mount_auth_api, test_read_api, test_rusty_vault_init, test_write_api},
217217
};
218218

219+
#[maybe_async::maybe_async]
219220
pub async fn test_read_role(
220221
core: &Core,
221222
token: &str,
@@ -227,6 +228,7 @@ mod test {
227228
resp
228229
}
229230

231+
#[maybe_async::maybe_async]
230232
pub async fn test_write_role(
231233
core: &Core,
232234
token: &str,
@@ -257,12 +259,13 @@ mod test {
257259
.await;
258260
}
259261

262+
#[maybe_async::maybe_async]
260263
pub async fn test_delete_role(core: &Core, token: &str, path: &str, role_name: &str) {
261-
assert!(test_delete_api(core, token, format!("auth/{}/role/{}", path, role_name).as_str(), true, None)
262-
.await
263-
.is_ok());
264+
let resp = test_delete_api(core, token, format!("auth/{}/role/{}", path, role_name).as_str(), true, None).await;
265+
assert!(resp.is_ok());
264266
}
265267

268+
#[maybe_async::maybe_async]
266269
pub async fn generate_secret_id(core: &Core, token: &str, path: &str, role_name: &str) -> (String, String) {
267270
let resp =
268271
test_write_api(core, token, format!("auth/{}/role/{}/secret-id", path, role_name).as_str(), true, None)
@@ -275,6 +278,7 @@ mod test {
275278
(secret_id.to_string(), secret_id_accessor.to_string())
276279
}
277280

281+
#[maybe_async::maybe_async]
278282
pub async fn test_login(
279283
core: &Core,
280284
path: &str,
@@ -308,6 +312,7 @@ mod test {
308312
resp
309313
}
310314

315+
#[maybe_async::maybe_async]
311316
async fn test_approle(core: &Core, token: &str, path: &str, role_name: &str) {
312317
// Create a role
313318
let resp = test_write_api(core, token, format!("auth/{}/role/{}", path, role_name).as_str(), true, None).await;
@@ -460,6 +465,7 @@ mod test {
460465
let _ = test_login(core, path, role_id, &secret_id, false).await;
461466
}
462467

468+
#[maybe_async::maybe_async]
463469
async fn test_approle_role_service(core: &Core, token: &str, path: &str, role_name: &str) {
464470
// Create a role
465471
let mut data = json!({
@@ -549,7 +555,7 @@ mod test {
549555
println!("resp_data: {:?}", resp_data);
550556
}
551557

552-
#[tokio::test]
558+
#[maybe_async::test(feature = "sync_handler", async(all(not(feature = "sync_handler")), tokio::test))]
553559
async fn test_credential_approle_module() {
554560
let (root_token, core) = test_rusty_vault_init("test_approle_module");
555561
let core = core.read().unwrap();

0 commit comments

Comments
 (0)