forked from proxmox-mirrors/proxmox
		
	RpcEnvironment: implement set_user() and get_user()
This commit is contained in:
		
							parent
							
								
									23db39488f
								
							
						
					
					
						commit
						42e06fc5ca
					
				@ -6,12 +6,14 @@ use serde_json::Value;
 | 
			
		||||
pub struct RestEnvironment {
 | 
			
		||||
    env_type: RpcEnvironmentType,
 | 
			
		||||
    result_attributes: HashMap<String, Value>,
 | 
			
		||||
    user: Option<String>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl RestEnvironment {
 | 
			
		||||
    pub fn new(env_type: RpcEnvironmentType) -> Self {
 | 
			
		||||
        Self {
 | 
			
		||||
            result_attributes: HashMap::new(),
 | 
			
		||||
            user: None,
 | 
			
		||||
            env_type,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@ -30,4 +32,12 @@ impl RpcEnvironment for RestEnvironment {
 | 
			
		||||
    fn env_type(&self) -> RpcEnvironmentType {
 | 
			
		||||
        self.env_type
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn set_user(&mut self, user: Option<String>) {
 | 
			
		||||
        self.user = user;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn get_user(&self) -> Option<String> {
 | 
			
		||||
        self.user.clone()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -397,7 +397,7 @@ pub fn handle_request(api: Arc<ApiConfig>, req: Request<Body>) -> BoxFut {
 | 
			
		||||
    println!("REQUEST {} {}", method, path);
 | 
			
		||||
    println!("COMPO {:?}", components);
 | 
			
		||||
 | 
			
		||||
    let rpcenv = RestEnvironment::new(RpcEnvironmentType::PRIVILEDGED);
 | 
			
		||||
    let mut rpcenv = RestEnvironment::new(RpcEnvironmentType::PRIVILEDGED);
 | 
			
		||||
 | 
			
		||||
    if comp_len >= 1 && components[0] == "api2" {
 | 
			
		||||
        println!("GOT API REQUEST");
 | 
			
		||||
@ -414,6 +414,8 @@ pub fn handle_request(api: Arc<ApiConfig>, req: Request<Body>) -> BoxFut {
 | 
			
		||||
            let mut uri_param = HashMap::new();
 | 
			
		||||
 | 
			
		||||
            // fixme: handle auth
 | 
			
		||||
            rpcenv.set_user(Some(String::from("root@pam")));
 | 
			
		||||
 | 
			
		||||
            match api.find_method(&components[2..], method, &mut uri_param) {
 | 
			
		||||
                MethodDefinition::None => {}
 | 
			
		||||
                MethodDefinition::Simple(api_method) => {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user