-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathapi.rs
More file actions
81 lines (72 loc) · 2.17 KB
/
Copy pathapi.rs
File metadata and controls
81 lines (72 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use ak_meta::user_agent;
use ak_platform::generated::{
agent::RequestHeader,
agent_auth::{CurrentTokenRequest, current_token_request::Type},
};
use authentik_client::apis::configuration::Configuration;
use eyre::{Result, WrapErr};
include!(concat!(env!("OUT_DIR"), "/api_commands.rs"));
pub async fn exec_api_command(mut app: super::App, cmd: &ApiCommand) -> Result<()> {
let profile = app.profile().await;
let res = app
.user()
.await?
.clone()
.auth()
.get_current_token(CurrentTokenRequest {
header: Some(RequestHeader { profile }),
r#type: Type::Verified as i32,
})
.await
.wrap_err("failed to get API access token")?
.into_inner();
let config = Configuration {
base_path: format!("{}/api/v3", res.url),
bearer_access_token: Some(res.raw),
user_agent: Some(user_agent()),
..Default::default()
};
cmd.execute(&config).await.wrap_err("API command failed")
}
#[cfg(test)]
mod tests {
// Smoke tests for the generated CLI commands.
// The primary test is that the crate compiles — if the generator emits invalid Rust,
// the build step fails before these tests run. These tests add runtime assertions.
#[test]
fn api_modules_non_empty() {
assert!(
!super::API_MODULES.is_empty(),
"expected at least one API module"
);
}
#[test]
fn core_module_present() {
assert!(
super::API_MODULES.contains(&"core"),
"core module missing from API_MODULES"
);
}
#[test]
fn admin_module_present() {
assert!(
super::API_MODULES.contains(&"admin"),
"admin module missing from API_MODULES"
);
}
#[test]
fn flows_module_present() {
assert!(
super::API_MODULES.contains(&"flows"),
"flows module missing from API_MODULES"
);
}
#[test]
fn function_count_reasonable() {
assert!(
super::API_FUNCTION_COUNT > 100,
"expected more than 100 API functions, found {}",
super::API_FUNCTION_COUNT
);
}
}