use std::sync::Arc; use std::collections::HashMap; use serde_json::Value; use crate::api_schema::router::{RpcEnvironment, RpcEnvironmentType}; use crate::server::WorkerTask; use crate::backup::*; /// `RpcEnvironmet` implementation for backup service #[derive(Clone)] pub struct BackupEnvironment { env_type: RpcEnvironmentType, result_attributes: HashMap, user: String, pub worker: Arc, pub datastore: Arc, } impl BackupEnvironment { pub fn new(env_type: RpcEnvironmentType, user: String, worker: Arc, datastore: Arc) -> Self { Self { result_attributes: HashMap::new(), env_type, user, worker, datastore, } } pub fn log>(&self, msg: S) { self.worker.log(msg); } } impl RpcEnvironment for BackupEnvironment { 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) } fn env_type(&self) -> RpcEnvironmentType { self.env_type } fn set_user(&mut self, _user: Option) { panic!("unable to change user"); } fn get_user(&self) -> Option { Some(self.user.clone()) } } impl AsRef for RpcEnvironment { fn as_ref(&self) -> &BackupEnvironment { self.as_any().downcast_ref::().unwrap() } }