65 lines
2.1 KiB
Rust
65 lines
2.1 KiB
Rust
use std::str::FromStr;
|
|
|
|
use pyo3::prelude::*;
|
|
use reqwest::{Client, header::{HeaderMap, HeaderName, HeaderValue}};
|
|
use serde::{Deserialize, Serialize};
|
|
use serde_json::{Value, json};
|
|
|
|
#[pyfunction]
|
|
pub fn pull_policy_exec_histories() {
|
|
println!("Hello World from Rust!");
|
|
}
|
|
|
|
#[pyfunction]
|
|
pub fn api(py: Python<'_>, x: Py<PyAny>) {
|
|
let base_url: String = x.getattr(py, "base_url").unwrap().to_string();
|
|
println!("{}", base_url);
|
|
}
|
|
|
|
#[tokio::main]
|
|
#[pyfunction]
|
|
pub async fn history_logging(py: Python<'_>, py_self: Py<PyAny>, exec_types: String, checkpoint_number: String, policy_names: String ) -> String {
|
|
#[derive(Serialize, Debug)]
|
|
struct Payload {
|
|
checkpoint: String,
|
|
}
|
|
let base_url = py_self.getattr(py, "base_url").unwrap().to_string();
|
|
let headers = py_self.getattr(py, "headers").unwrap().to_string();
|
|
let headers_replace = headers.replace('\'', "\"");
|
|
let parsed: Value = serde_json::from_str(&headers_replace.as_str()).unwrap();
|
|
let mut header_map = HeaderMap::new();
|
|
if let Some(obj) = parsed.as_object() {
|
|
for (key, value) in obj {
|
|
if let Some(v) = value.as_str() {
|
|
let val = HeaderValue::from_str(v).unwrap();
|
|
header_map.insert(HeaderName::from_str("X-APIKey").unwrap(), val);
|
|
}
|
|
}
|
|
}
|
|
let exec_types = exec_types.replace(" ", "");
|
|
let payload_dict: Payload = Payload {
|
|
checkpoint:exec_types.to_string(),
|
|
};
|
|
println!("{:?}", payload_dict);
|
|
let client = Client::builder()
|
|
.danger_accept_invalid_certs(true)
|
|
.default_headers(header_map)
|
|
.timeout(std::time::Duration::from_secs(30))
|
|
.build()
|
|
.unwrap();
|
|
let res = client
|
|
.post(format!("{}/v1/logging/exechistories", base_url))
|
|
.json(&payload_dict)
|
|
.send()
|
|
.await;
|
|
match res {
|
|
Ok(res) => {
|
|
println!("{:?}", res.text().await.unwrap());
|
|
}
|
|
Err(e) => {
|
|
eprintln!("{}", e);
|
|
}
|
|
}
|
|
let testingstring: String = "Testing".to_string();
|
|
return testingstring
|
|
} |