1. Added compatibility check, LoxideLibs will now abort the entire program if OS is not linux or windows. 2. Changed the python data extraction compatibility layer, LoxideLibs was calling the extract data function twice, causing very slight overhead. I have now changed this so that the function returns a Struct that is now easily extractable via dot method notation.
This commit is contained in:
Generated
+1
-1
@@ -26,7 +26,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "airlock_libs"
|
||||
version = "5.2.0"
|
||||
version = "5.2.1"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"crossbeam",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "airlock_libs"
|
||||
version = "5.2.0"
|
||||
version = "5.2.1"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
|
||||
@@ -4,7 +4,7 @@ build-backend = "maturin"
|
||||
|
||||
[project]
|
||||
name = "airlock_libs"
|
||||
version = "5.2.0"
|
||||
version = "5.2.1"
|
||||
description = "Airlock Digital API Wrapper"
|
||||
readme = "README.md"
|
||||
license = { text = "AGPL-3.0-only" }
|
||||
|
||||
@@ -64,36 +64,30 @@ pub struct Group {
|
||||
pub(crate) localip: String,
|
||||
}
|
||||
|
||||
pub enum ExtractedValues {
|
||||
Headers(reqwest::header::HeaderMap),
|
||||
BaseUrl(String),
|
||||
pub struct PyData {
|
||||
pub headers: reqwest::header::HeaderMap,
|
||||
pub base_url: String,
|
||||
}
|
||||
|
||||
pub trait Converter {
|
||||
fn convert(py: Python<'_>, py_self: &Py<PyAny>, extract_headers: bool) -> ExtractedValues;
|
||||
}
|
||||
|
||||
pub struct PyData;
|
||||
|
||||
impl Converter for PyData {
|
||||
fn convert(py: Python<'_>, py_self: &Py<PyAny>, extract_headers: bool) -> ExtractedValues {
|
||||
if extract_headers {
|
||||
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);
|
||||
}
|
||||
impl PyData {
|
||||
pub fn extract_data(py: Python<'_>, obj: &Py<PyAny>) -> Self {
|
||||
let headers_raw = obj.getattr(py, "headers").unwrap().to_string();
|
||||
let headers_json = headers_raw.replace('\'', "\"");
|
||||
let parsed: Value = serde_json::from_str(&headers_json).unwrap();
|
||||
let mut header_map = HeaderMap::new();
|
||||
if let Some(obj) = parsed.as_object() {
|
||||
for (key, val) in obj {
|
||||
if let Some(v) = val.as_str() {
|
||||
let header_name = HeaderName::from_str(key).unwrap();
|
||||
let header_value: HeaderValue = HeaderValue::from_str(v).unwrap();
|
||||
header_map.insert(header_name, header_value);
|
||||
}
|
||||
}
|
||||
ExtractedValues::Headers(header_map)
|
||||
} else {
|
||||
let base_url = py_self.getattr(py, "base_url").unwrap().to_string();
|
||||
ExtractedValues::BaseUrl(base_url)
|
||||
}
|
||||
let base_url = obj.getattr(py, "base_url").unwrap().to_string();
|
||||
Self {
|
||||
headers: header_map,
|
||||
base_url,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,14 +11,9 @@ pub fn pull_policy_exec_histories(
|
||||
exec_types: String,
|
||||
days: i64,
|
||||
) -> Py<PyString> {
|
||||
let headers: HeaderMap = match PyData::convert(py, &py_self, true) {
|
||||
ExtractedValues::Headers(h) => h,
|
||||
ExtractedValues::BaseUrl(_) => std::process::abort(),
|
||||
};
|
||||
let base_url: String = match PyData::convert(py, &py_self, false) {
|
||||
ExtractedValues::Headers(_) => std::process::abort(),
|
||||
ExtractedValues::BaseUrl(b) => b,
|
||||
};
|
||||
let data = PyData::extract_data(py, &py_self);
|
||||
let headers = data.headers;
|
||||
let base_url = data.base_url;
|
||||
let handle: thread::JoinHandle<String> = std::thread::spawn(move || {
|
||||
let rt: tokio::runtime::Runtime = match tokio::runtime::Runtime::new() {
|
||||
Ok(rt) => rt,
|
||||
@@ -310,7 +305,11 @@ pub fn get_base_directory() -> PathBuf {
|
||||
.unwrap_or_else(|| home.join("AppData").join("Roaming"));
|
||||
appdata.join("Loxide")
|
||||
}
|
||||
_ => home.join(".local").join("share").join("Loxide"),
|
||||
"linux" => home.join(".local").join("share").join("Loxide"),
|
||||
_ => {
|
||||
println!("{} is currently not compatible with LoxideLibs", os);
|
||||
std::process::abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user