Files
proxmox-backup/src/server/environment.rs
Thomas Lamprecht 29633e2fe9 server/rest: forward real client IP on proxied request
needs new proxmox dependency to get the RpcEnvironment changes,
adding client_ip getter and setter.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-16 10:36:54 +02:00

54 lines
1.2 KiB
Rust

use serde_json::{json, Value};
use proxmox::api::{RpcEnvironment, RpcEnvironmentType};
/// Encapsulates information about the runtime environment
pub struct RestEnvironment {
env_type: RpcEnvironmentType,
result_attributes: Value,
user: Option<String>,
client_ip: Option<std::net::SocketAddr>,
}
impl RestEnvironment {
pub fn new(env_type: RpcEnvironmentType) -> Self {
Self {
result_attributes: json!({}),
user: None,
client_ip: None,
env_type,
}
}
}
impl RpcEnvironment for RestEnvironment {
fn result_attrib_mut (&mut self) -> &mut Value {
&mut self.result_attributes
}
fn result_attrib(&self) -> &Value {
&self.result_attributes
}
fn env_type(&self) -> RpcEnvironmentType {
self.env_type
}
fn set_user(&mut self, user: Option<String>) {
self.user = user;
}
fn get_user(&self) -> Option<String> {
self.user.clone()
}
fn set_client_ip(&mut self, client_ip: Option<std::net::SocketAddr>) {
self.client_ip = client_ip;
}
fn get_client_ip(&self) -> Option<std::net::SocketAddr> {
self.client_ip.clone()
}
}