2019-01-26 14:08:02 +00:00
|
|
|
use std::collections::HashMap;
|
|
|
|
use serde_json::Value;
|
|
|
|
|
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,
|
2019-01-26 14:08:02 +00:00
|
|
|
result_attributes: HashMap<String, 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 {
|
|
|
|
result_attributes: HashMap::new(),
|
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 {
|
|
|
|
|
|
|
|
fn set_result_attrib(&mut self, name: &str, value: Value) {
|
|
|
|
self.result_attributes.insert(name.into(), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_result_attrib(&self, name: &str) -> Option<&Value> {
|
|
|
|
self.result_attributes.get(name)
|
|
|
|
}
|
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
|
|
|
}
|