-
-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathfunctions.rs
More file actions
83 lines (76 loc) · 2.13 KB
/
Copy pathfunctions.rs
File metadata and controls
83 lines (76 loc) · 2.13 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
82
83
//! Built-in `SQLPage` SQL functions.
//!
//! Every function is a plain `async fn` in its own module under [`functions/`](self). To add one,
//! create `functions/<name>.rs` with an `async fn <name>` and add it to the
//! [`sqlpage_functions!`](super::function_traits::sqlpage_functions) call below. The macro declares
//! the module and adds it to the dispatch enum. Argument conversion and
//! dispatch are handled generically in [`super::function_traits`].
use std::fmt::Write;
use super::function_traits::sqlpage_functions;
sqlpage_functions! {
basic_auth_password,
basic_auth_username,
client_ip,
configuration_directory,
cookie,
current_working_directory,
environment_variable,
exec,
fetch,
fetch_with_meta,
hash_password,
header,
headers,
hmac,
link,
oidc_logout_url,
path,
persist_uploaded_file,
protocol,
random_string,
read_file_as_data_url,
read_file_as_text,
regex_match,
request_body,
request_body_base64,
request_method,
run_sql,
set_variable,
uploaded_file_mime_type,
uploaded_file_name,
uploaded_file_path,
url_encode,
user_info,
user_info_token,
variables,
version,
web_root,
}
impl ::std::str::FromStr for SqlPageFunctionName {
type Err = anyhow::Error;
fn from_str(name: &str) -> anyhow::Result<Self> {
SqlPageFunctionName::ALL
.iter()
.copied()
.find(|function| function.name() == name)
.ok_or_else(|| {
anyhow::anyhow!(
"Unknown function {name:?}. Supported functions:\n{}",
supported_function_list()
)
})
}
}
impl ::std::fmt::Display for SqlPageFunctionName {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
f.write_str("sqlpage.")?;
f.write_str(self.name())
}
}
fn supported_function_list() -> String {
let mut supported = String::new();
for function in SqlPageFunctionName::ALL {
writeln!(supported, " - {function}").expect("writing to a String cannot fail");
}
supported
}