2020-05-18 07:57:35 +00:00
|
|
|
use serde_json::{json, Value};
|
2019-01-26 14:08:02 +00:00
|
|
|
|
2019-11-21 13:36:28 +00:00
|
|
|
use proxmox::api::{RpcEnvironment, RpcEnvironmentType};
|
|
|
|
|
2019-04-06 07:17:25 +00:00
|
|
|
/// Encapsulates information about the runtime environment
|
2019-01-26 14:08:02 +00:00
|
|
|
pub struct RestEnvironment {
|
2019-01-27 09:33:42 +00:00
|
|
|
env_type: RpcEnvironmentType,
|
2020-05-18 07:57:35 +00:00
|
|
|
result_attributes: Value,
|
2020-10-23 11:33:21 +00:00
|
|
|
auth_id: Option<String>,
|
2020-10-15 15:43:42 +00:00
|
|
|
client_ip: Option<std::net::SocketAddr>,
|
2019-01-26 14:08:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl RestEnvironment {
|
2019-01-27 09:33:42 +00:00
|
|
|
pub fn new(env_type: RpcEnvironmentType) -> Self {
|
|
|
|
Self {
|
2020-05-18 07:57:35 +00:00
|
|
|
result_attributes: json!({}),
|
2020-10-23 11:33:21 +00:00
|
|
|
auth_id: None,
|
2020-10-15 15:43:42 +00:00
|
|
|
client_ip: None,
|
2019-01-27 09:33:42 +00:00
|
|
|
env_type,
|
|
|
|
}
|
2019-01-26 14:08:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RpcEnvironment for RestEnvironment {
|
|
|
|
|
2020-05-18 07:57:35 +00:00
|
|
|
fn result_attrib_mut (&mut self) -> &mut Value {
|
|
|
|
&mut self.result_attributes
|
2019-01-26 14:08:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-18 07:57:35 +00:00
|
|
|
fn result_attrib(&self) -> &Value {
|
|
|
|
&self.result_attributes
|
2019-01-26 14:08:02 +00:00
|
|
|
}
|
2019-01-27 09:33:42 +00:00
|
|
|
|
|
|
|
fn env_type(&self) -> RpcEnvironmentType {
|
|
|
|
self.env_type
|
|
|
|
}
|
2019-01-27 09:42:45 +00:00
|
|
|
|
2020-10-23 11:33:21 +00:00
|
|
|
fn set_auth_id(&mut self, auth_id: Option<String>) {
|
|
|
|
self.auth_id = auth_id;
|
2019-01-27 09:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-10-23 11:33:21 +00:00
|
|
|
fn get_auth_id(&self) -> Option<String> {
|
|
|
|
self.auth_id.clone()
|
2019-01-27 09:42:45 +00:00
|
|
|
}
|
2020-10-15 15:43:42 +00:00
|
|
|
|
|
|
|
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> {
|
2021-01-15 13:38:27 +00:00
|
|
|
self.client_ip
|
2020-10-15 15:43:42 +00:00
|
|
|
}
|
2019-01-26 14:08:02 +00:00
|
|
|
}
|