since we systemd-encode parts of the upid string, and those can contain characters that are invalid in urls (e.g. '\'), we have to percent encode those add a 'percent_encode_component' helper, so that we can maybe change the AsciiSet for all uses at the same time Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
		
			
				
	
	
		
			54 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
| use anyhow::{bail, Error};
 | |
| use serde_json::json;
 | |
| 
 | |
| use super::HttpClient;
 | |
| use crate::tools;
 | |
| 
 | |
| pub async fn display_task_log(
 | |
|     client: HttpClient,
 | |
|     upid_str: &str,
 | |
|     strip_date: bool,
 | |
| ) -> Result<(), Error> {
 | |
| 
 | |
|     let path = format!("api2/json/nodes/localhost/tasks/{}/log", tools::percent_encode_component(upid_str));
 | |
| 
 | |
|     let mut start = 1;
 | |
|     let limit = 500;
 | |
| 
 | |
|     loop {
 | |
|         let param = json!({ "start": start, "limit": limit, "test-status": true });
 | |
|         let result = client.get(&path, Some(param)).await?;
 | |
| 
 | |
|         let active = result["active"].as_bool().unwrap();
 | |
|         let total = result["total"].as_u64().unwrap();
 | |
|         let data = result["data"].as_array().unwrap();
 | |
| 
 | |
|         let lines = data.len();
 | |
| 
 | |
|         for item in data {
 | |
|             let n = item["n"].as_u64().unwrap();
 | |
|             let t = item["t"].as_str().unwrap();
 | |
|             if n != start { bail!("got wrong line number in response data ({} != {}", n, start); }
 | |
|              if strip_date && t.len() > 27 && &t[25..27] == ": " {
 | |
|                 let line = &t[27..];
 | |
|                 println!("{}", line);
 | |
|             } else {
 | |
|                 println!("{}", t);
 | |
|             }
 | |
|             start += 1;
 | |
|        }
 | |
| 
 | |
|         if start > total {
 | |
|             if active {
 | |
|                 std::thread::sleep(std::time::Duration::from_millis(1000));
 | |
|             } else {
 | |
|                 break;
 | |
|             }
 | |
|         } else if lines != limit {
 | |
|             bail!("got wrong number of lines from server ({} != {})", lines, limit);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     Ok(())
 | |
| }
 |