diff --git a/src/api/router.rs b/src/api/router.rs index 82345525..0aaeec8f 100644 --- a/src/api/router.rs +++ b/src/api/router.rs @@ -24,7 +24,7 @@ pub trait RpcEnvironment { fn get_user(&self) -> Option; } -#[derive(Copy, Clone)] +#[derive(PartialEq, Copy, Clone)] pub enum RpcEnvironmentType { /// command started from command line CLI, diff --git a/src/api2/node/dns.rs b/src/api2/node/dns.rs index 0a9184e5..992567b2 100644 --- a/src/api2/node/dns.rs +++ b/src/api2/node/dns.rs @@ -148,7 +148,7 @@ pub fn router() -> Router { .optional("dns2", SECOND_DNS_SERVER_SCHEMA.clone()) .optional("dns3", THIRD_DNS_SERVER_SCHEMA.clone()) .optional("digest", PVE_CONFIG_DIGEST_SCHEMA.clone()) - ) + ).protected(true) ); route diff --git a/src/server/rest.rs b/src/server/rest.rs index d585cd03..97ebd078 100644 --- a/src/server/rest.rs +++ b/src/server/rest.rs @@ -158,6 +158,19 @@ fn get_request_parameters_async( Box::new(resp) } +fn proxy_sync_api_request( + mut rpcenv: RestEnvironment, + info: &'static ApiMethod, + formatter: &'static OutputFormatter, + parts: Parts, + req_body: Body, + uri_param: HashMap, +) -> BoxFut +{ + + return Box::new(future::err(http_err!(BAD_REQUEST, String::from("implement proxy")))); +} + fn handle_sync_api_request( mut rpcenv: RestEnvironment, info: &'static ApiMethod, @@ -397,7 +410,8 @@ pub fn handle_request(api: Arc, req: Request) -> BoxFut { println!("REQUEST {} {}", method, path); println!("COMPO {:?}", components); - let mut rpcenv = RestEnvironment::new(api.env_type()); + let env_type = api.env_type(); + let mut rpcenv = RestEnvironment::new(env_type); if comp_len >= 1 && components[0] == "api2" { println!("GOT API REQUEST"); @@ -419,7 +433,11 @@ pub fn handle_request(api: Arc, req: Request) -> BoxFut { match api.find_method(&components[2..], method, &mut uri_param) { MethodDefinition::None => {} MethodDefinition::Simple(api_method) => { - return handle_sync_api_request(rpcenv, api_method, formatter, parts, body, uri_param); + if api_method.protected && env_type == RpcEnvironmentType::PUBLIC { + return proxy_sync_api_request(rpcenv, api_method, formatter, parts, body, uri_param); + } else { + return handle_sync_api_request(rpcenv, api_method, formatter, parts, body, uri_param); + } } MethodDefinition::Async(async_method) => { return handle_async_api_request(rpcenv, async_method, formatter, parts, body, uri_param);