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,
|
2019-01-27 09:42:45 +00:00
|
|
|
user: Option<String>,
|
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!({}),
|
2019-01-27 09:42:45 +00:00
|
|
|
user: 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
|
|
|
|
|
|
|
fn set_user(&mut self, user: Option<String>) {
|
|
|
|
self.user = user;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_user(&self) -> Option<String> {
|
|
|
|
self.user.clone()
|
|
|
|
}
|
2019-01-26 14:08:02 +00:00
|
|
|
}
|