]> git.proxmox.com Git - proxmox-backup.git/blame - src/server/environment.rs
clippy: remove unnecessary clones
[proxmox-backup.git] / src / server / environment.rs
CommitLineData
e8d1da6a 1use serde_json::{json, Value};
0f253593 2
a2479cfa
WB
3use proxmox::api::{RpcEnvironment, RpcEnvironmentType};
4
882594c5 5/// Encapsulates information about the runtime environment
0f253593 6pub struct RestEnvironment {
162b9793 7 env_type: RpcEnvironmentType,
e8d1da6a 8 result_attributes: Value,
e6dc35ac 9 auth_id: Option<String>,
29633e2f 10 client_ip: Option<std::net::SocketAddr>,
0f253593
DM
11}
12
13impl RestEnvironment {
162b9793
DM
14 pub fn new(env_type: RpcEnvironmentType) -> Self {
15 Self {
e8d1da6a 16 result_attributes: json!({}),
e6dc35ac 17 auth_id: None,
29633e2f 18 client_ip: None,
162b9793
DM
19 env_type,
20 }
0f253593
DM
21 }
22}
23
24impl RpcEnvironment for RestEnvironment {
25
e8d1da6a
DM
26 fn result_attrib_mut (&mut self) -> &mut Value {
27 &mut self.result_attributes
0f253593
DM
28 }
29
e8d1da6a
DM
30 fn result_attrib(&self) -> &Value {
31 &self.result_attributes
0f253593 32 }
162b9793
DM
33
34 fn env_type(&self) -> RpcEnvironmentType {
35 self.env_type
36 }
d7d23785 37
e6dc35ac
FG
38 fn set_auth_id(&mut self, auth_id: Option<String>) {
39 self.auth_id = auth_id;
d7d23785
DM
40 }
41
e6dc35ac
FG
42 fn get_auth_id(&self) -> Option<String> {
43 self.auth_id.clone()
d7d23785 44 }
29633e2f
TL
45
46 fn set_client_ip(&mut self, client_ip: Option<std::net::SocketAddr>) {
47 self.client_ip = client_ip;
48 }
49
50 fn get_client_ip(&self) -> Option<std::net::SocketAddr> {
44288184 51 self.client_ip
29633e2f 52 }
0f253593 53}