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
82
83
84
85
use crate::cli::cliopts::CliOpts;
use crate::cli_stderr_printline;
use crate::cli_stdout_printline;
use crate::utils::otoroshi::Otoroshi;
pub struct ToolboxCommands {}
impl ToolboxCommands {
pub async fn mtls(cli_opts: CliOpts, mode: Option<String>) {
match mode {
None => {
let config = Otoroshi::get_global_config(cli_opts.clone()).await;
match config {
None => {
cli_stderr_printline!("error while fetching global otoroshi config");
std::process::exit(-1)
}
Some(config) => {
let mode = config
.body
.get("tlsSettings")
.unwrap()
.get("clientAuth")
.unwrap()
.as_str()
.unwrap()
.to_string();
let doc = serde_json::json!({"mode": mode});
match cli_opts.ouput {
Some(str) => match str.as_str() {
"json" => cli_stdout_printline!(
"{}",
serde_json::to_string(&doc).unwrap()
),
"json_pretty" => cli_stdout_printline!(
"{}",
serde_json::to_string_pretty(&doc).unwrap()
),
"yaml" => cli_stdout_printline!(
"{}",
serde_yaml::to_string(&doc).unwrap()
),
_ => cli_stdout_printline!("mTLS mode: {}", mode),
},
_ => cli_stdout_printline!("mTLS mode: {}", mode),
}
}
}
}
Some(mode) => {
let config = Otoroshi::get_global_config(cli_opts.clone()).await;
match config {
None => {
cli_stderr_printline!("error while fetching global otoroshi config");
std::process::exit(-1)
}
Some(config) => {
let mut doc = config.body;
match mode.to_lowercase().as_str() {
"none" => {
doc["tlsSettings"]["clientAuth"] = "None".into();
let body_str = serde_json::to_string(&doc).unwrap();
Otoroshi::update_global_config(cli_opts.clone(), body_str).await;
}
"want" => {
doc["tlsSettings"]["clientAuth"] = "Want".into();
let body_str = serde_json::to_string(&doc).unwrap();
Otoroshi::update_global_config(cli_opts.clone(), body_str).await;
}
"need" => {
doc["tlsSettings"]["clientAuth"] = "Need".into();
let body_str = serde_json::to_string(&doc).unwrap();
Otoroshi::update_global_config(cli_opts.clone(), body_str).await;
}
other => {
cli_stderr_printline!("unknown mTLS mode: {}", other);
std::process::exit(-1)
}
}
}
}
}
}
}
}