From 01e5348c1c0ca9fbf2826e4e35d71a743ba28741 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 24 Aug 2020 23:08:03 -0700 Subject: more progress on parsing/validating --- src/main.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 017b8c8..632c159 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,21 +1,21 @@ use hyper::service::{make_service_fn, service_fn}; -use hyper::{Body, Client, Request, Response, Server, Uri, StatusCode}; +use hyper::{Body, Client, Request, Response, Server, StatusCode}; use std::net::SocketAddr; use std::env; use toml; -use es_public_proxy::{ProxyConfig, ParsedRequest, parse_request}; +use es_public_proxy::{ProxyConfig, ProxyError, parse_request}; async fn upstream_req(req: Request, config: ProxyConfig) -> Result, hyper::Error> { println!("hit: {}", req.uri()); - let parsed = parse_request(req, &config); + let parsed = parse_request(req, &config).await; let resp = match parsed { - ParsedRequest::Allowed(upstream_req) => { + Ok(upstream_req) => { println!("sending request..."); Client::new().request(upstream_req).await? } - other => { + Err(other) => { Response::builder() .status(StatusCode::NOT_FOUND) .body(format!("oh noooo! {:?}", other).into()) @@ -68,6 +68,7 @@ fn load_config() -> ProxyConfig { let args: Vec = env::args().collect(); let args: Vec<&str> = args.iter().map(|x| x.as_str()).collect(); let mut config_path: Option = None; + let mut allow_all_indices = false; // first parse CLI arg match args.as_slice() { @@ -77,6 +78,7 @@ fn load_config() -> ProxyConfig { std::process::exit(0); }, [_, "--config", p] => { config_path = Some(p.to_string()) }, + [_, "--allow-all-indices"] => { allow_all_indices = true }, _ => { eprintln!("{}", usage()); eprintln!("couldn't parse arguments"); @@ -90,13 +92,17 @@ fn load_config() -> ProxyConfig { } // then either load config file (TOML), or use default config - if let Some(config_path) = config_path { + let mut config = if let Some(config_path) = config_path { let config_toml = std::fs::read_to_string(config_path).unwrap(); let config: ProxyConfig = toml::from_str(&config_toml).unwrap(); config } else { ProxyConfig::default() + }; + if allow_all_indices { + config.allow_all_indices = Some(true); } + config } #[tokio::main] -- cgit v1.2.3