Browse Source
Adding initial cloudflare client interaction
Adding initial cloudflare client interaction
* address lookup for defined zonedevelop
Drew Short
6 years ago
6 changed files with 123 additions and 47 deletions
-
13src/main.rs
-
48src/server/api.rs
-
48src/server/middleware/api_auth.rs
-
1src/server/mod.rs
-
8src/server/router.rs
-
52src/server/util.rs
@ -0,0 +1,52 @@ |
|||
use actix_web::HttpRequest;
|
|||
|
|||
use crate::config::model::Config;
|
|||
use crate::config::model::UserConfig;
|
|||
use crate::server::router::AppState;
|
|||
|
|||
pub fn get_match_value<S>(req: &HttpRequest<S>, key: &str) -> Option<String> {
|
|||
let match_info = req.resource().match_info();
|
|||
match match_info.get(key) {
|
|||
Some(value) => Some(String::from(value)),
|
|||
None => None
|
|||
}
|
|||
}
|
|||
|
|||
pub fn get_header_value<S>(req: &HttpRequest<S>, key: &str) -> Option<String> {
|
|||
match req.headers().get(key) {
|
|||
Some(header) => match header.to_str() {
|
|||
Ok(header_value) => Some(String::from(header_value)),
|
|||
Err(_e) => None
|
|||
},
|
|||
None => None
|
|||
}
|
|||
}
|
|||
|
|||
pub fn get_user_from_request(req: &HttpRequest<AppState>) -> Option<&UserConfig> {
|
|||
let config: &Config = &req.state().config;
|
|||
let username = get_username_from_request(req);
|
|||
match username {
|
|||
Some(username) => config.get_user(&username),
|
|||
None => None
|
|||
}
|
|||
}
|
|||
|
|||
pub fn get_username_from_request<S>(req: &HttpRequest<S>) -> Option<String> {
|
|||
get_header_value(req, "X-AUTH-USERNAME")
|
|||
}
|
|||
|
|||
pub fn get_token_from_request<S>(req: &HttpRequest<S>) -> Option<String> {
|
|||
get_header_value(req, "X-AUTH-TOKEN")
|
|||
}
|
|||
|
|||
pub fn get_domain_from_root(root: &str) -> Option<String> {
|
|||
let mut parts: Vec<&str> = root.split('.').collect();
|
|||
let length = parts.len();
|
|||
if length <= 1 {
|
|||
None
|
|||
} else if length == 2 {
|
|||
Some(String::from(root))
|
|||
} else {
|
|||
Some(String::from(parts.split_off(length - 2).join(".")))
|
|||
}
|
|||
}
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue