Merge branch 'RustImplementation' of https://git.racooncity.org/brotoskyj/Airlocktools into RustImplementation

This commit is contained in:
2025-11-14 17:08:05 -05:00
7 changed files with 1222 additions and 280 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ jobs:
- name: Install Prerequisites - name: Install Prerequisites
run: | run: |
apt update apt update
apt install curl git python3 pip pkg-config openssl libssl-dev patchelf binutils-mingw-w64-x86-64 mingw-w64 -y apt install curl git python3 pip pkg-config openssl libssl-dev patchelf binutils-mingw-w64-x86-64 mingw-w64 protobuf-compiler -y
curl https://sh.rustup.rs -sSf | sh -s -- -y curl https://sh.rustup.rs -sSf | sh -s -- -y
pip install maturin twine --break-system-packages pip install maturin twine --break-system-packages
+1056 -191
View File
File diff suppressed because it is too large Load Diff
+9 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "airlock_libs" name = "airlock_libs"
version = "2.0.0" version = "3.0.0"
edition = "2024" edition = "2024"
[lib] [lib]
@@ -10,12 +10,20 @@ crate-type = ["cdylib"]
chrono = "0.4.42" chrono = "0.4.42"
indicatif = "0.18.2" indicatif = "0.18.2"
mongodb = "3.3.0" mongodb = "3.3.0"
opentelemetry = { version = "0.18.0", features = ["rt-tokio", "metrics", "trace"] }
opentelemetry-otlp = { version = "0.11.0", features = ["trace", "metrics"] }
opentelemetry-semantic-conventions = { version = "0.10.0" }
opentelemetry-proto = { version = "0.1.0"}
pyo3 = { version = "0.27.0", features = ["extension-module", "generate-import-lib"] } pyo3 = { version = "0.27.0", features = ["extension-module", "generate-import-lib"] }
reqwest = { version = "0.12.24", features = ["json", "native-tls"] } reqwest = { version = "0.12.24", features = ["json", "native-tls"] }
serde = "1.0.228" serde = "1.0.228"
serde-pyobject = "0.8.0" serde-pyobject = "0.8.0"
serde_json = "1.0.145" serde_json = "1.0.145"
tokio = { version = "1.48.0", features = ["full"] } tokio = { version = "1.48.0", features = ["full"] }
tonic = { version = "0.8.2", features = ["tls-roots"] }
tracing = "0.1.41"
tracing-subscriber = "0.3.20"
tracing-opentelemetry = "0.32.0"
[package.metadata.maturin] [package.metadata.maturin]
generate-abi-stubs = true generate-abi-stubs = true
+1 -1
View File
@@ -4,7 +4,7 @@ build-backend = "maturin"
[project] [project]
name = "airlock_libs" name = "airlock_libs"
version = "2.0.0" version = "3.0.0"
description = "Airlock Digital API Wrapper" description = "Airlock Digital API Wrapper"
readme = "README.md" readme = "README.md"
license = { text = "AGPL-3.0-only" } license = { text = "AGPL-3.0-only" }
+74 -5
View File
@@ -1,6 +1,12 @@
use chrono::{Duration, Local, NaiveDate}; use chrono::{Duration, Local, NaiveDate};
use indicatif::{MultiProgress, ProgressBar, ProgressDrawTarget, ProgressStyle}; use indicatif::{MultiProgress, ProgressBar, ProgressDrawTarget, ProgressStyle};
use mongodb::bson::oid::ObjectId; use mongodb::bson::oid::ObjectId;
use opentelemetry::global::shutdown_tracer_provider;
use opentelemetry::sdk::Resource;
use opentelemetry::trace::{Status, TraceContextExt, TraceError};
use opentelemetry::{Context, KeyValue, sdk::trace as sdktrace, trace::Tracer};
use opentelemetry::{Key, global};
use opentelemetry_otlp::WithExportConfig;
use pyo3::{prelude::*, types::PyString}; use pyo3::{prelude::*, types::PyString};
use reqwest::{ use reqwest::{
Client, Client,
@@ -17,6 +23,7 @@ use std::{
path::PathBuf, path::PathBuf,
str::FromStr, str::FromStr,
}; };
use tracing_subscriber::prelude::*;
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
struct ApiResponse { struct ApiResponse {
@@ -61,6 +68,12 @@ pub fn pull_policy_exec_histories(
exec_types: String, exec_types: String,
days: i64, days: i64,
) -> Py<PyString> { ) -> Py<PyString> {
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
let _ = init_tracer();
});
let tracer = global::tracer("global_tracer");
let _cx = Context::new();
let file_path: PathBuf = format!( let file_path: PathBuf = format!(
"{}\\cache\\chunkinator.json", "{}\\cache\\chunkinator.json",
get_base_directory().display() get_base_directory().display()
@@ -93,13 +106,44 @@ pub fn pull_policy_exec_histories(
.unwrap(), .unwrap(),
); );
progress_bar.enable_steady_tick(std::time::Duration::from_millis(100)); progress_bar.enable_steady_tick(std::time::Duration::from_millis(100));
let client = build_client(py, &py_self); let client = tracer.in_span("Building HTTP Client", |cx| {
let client_result = build_client(py, &py_self);
match client_result {
Ok(client_result) => {
cx.span().add_event(
"info",
vec![KeyValue::new(
"Client Built Successfully",
format!("{:?}", client_result),
)],
);
client_result
}
Err(client_result) => {
cx.span().add_event(
"warn",
vec![KeyValue::new(
"Client Failed to Build",
format!("{:?}", &client_result),
)],
);
cx.span()
.set_status(Status::error("Client Failed to Build"));
panic!("Failed to Build Client: {:?}", client_result);
}
}
});
let api: Py<PyAny> = py_self; let api: Py<PyAny> = py_self;
let cutoff = Local::now().naive_local() - Duration::days(days); let cutoff = Local::now().naive_local() - Duration::days(days);
let mut f = File::open(&writeable_filepath).unwrap(); let mut f = File::open(&writeable_filepath).unwrap();
tracer.in_span("Airlock Data Retreival", |cx| {
let span = cx.span();
span.set_attribute(Key::new("Days").string(days.to_string().to_string()));
loop { loop {
tracing::info!("Starting Airlock Data Retrieval");
f.seek(SeekFrom::Start(0)).unwrap(); f.seek(SeekFrom::Start(0)).unwrap();
let execution_histories = history_logging( let execution_histories = tracer.in_span(checkpoint_number.to_string(), |cx| {
let results: ApiResponse = history_logging(
py, py,
&api, &api,
&exec_types, &exec_types,
@@ -107,11 +151,18 @@ pub fn pull_policy_exec_histories(
&policy_names, &policy_names,
&client, &client,
); );
cx.span().set_attribute(KeyValue::new(
"Items in Response",
results.response.exechistories.len().to_string(),
));
results
});
let parsed_responses = execution_histories.response.exechistories; let parsed_responses = execution_histories.response.exechistories;
if parsed_responses.is_empty() { if parsed_responses.is_empty() {
break; break;
} }
let mut seen: HashMap<(String, String, String), Group> = if writeable_filepath.exists() { let mut seen: HashMap<(String, String, String), Group> = if writeable_filepath.exists()
{
let mut contents = String::new(); let mut contents = String::new();
f.read_to_string(&mut contents).unwrap(); f.read_to_string(&mut contents).unwrap();
let existing_data: ApiResponse = let existing_data: ApiResponse =
@@ -183,12 +234,14 @@ pub fn pull_policy_exec_histories(
progress_bar.set_message("Total Percent Complete"); progress_bar.set_message("Total Percent Complete");
} }
} }
});
progress_bar.finish_with_message("All Checkpoints Complete"); progress_bar.finish_with_message("All Checkpoints Complete");
let return_data = fs::read_to_string(&writeable_filepath).unwrap(); let return_data = fs::read_to_string(&writeable_filepath).unwrap();
shutdown_tracer_provider();
PyString::new(py, &return_data).into() PyString::new(py, &return_data).into()
} }
fn build_client(py: Python<'_>, py_self: &Py<PyAny>) -> Client { fn build_client(py: Python<'_>, py_self: &Py<PyAny>) -> Result<reqwest::Client, reqwest::Error> {
let headers = py_self.getattr(py, "headers").unwrap().to_string(); let headers = py_self.getattr(py, "headers").unwrap().to_string();
let headers_replace = headers.replace('\'', "\""); let headers_replace = headers.replace('\'', "\"");
let parsed: Value = serde_json::from_str(headers_replace.as_str()).unwrap(); let parsed: Value = serde_json::from_str(headers_replace.as_str()).unwrap();
@@ -207,7 +260,6 @@ fn build_client(py: Python<'_>, py_self: &Py<PyAny>) -> Client {
.default_headers(header_map) .default_headers(header_map)
.timeout(std::time::Duration::from_secs(300)) .timeout(std::time::Duration::from_secs(300))
.build() .build()
.unwrap()
} }
#[tokio::main] #[tokio::main]
@@ -276,3 +328,20 @@ fn skipback(days: i64) -> ObjectId {
let objectid_hex = format!("{}0000000000000000", hex_timestamp); let objectid_hex = format!("{}0000000000000000", hex_timestamp);
ObjectId::parse_str(&objectid_hex).expect("Invalid ObjectId hex") ObjectId::parse_str(&objectid_hex).expect("Invalid ObjectId hex")
} }
fn init_tracer() -> Result<sdktrace::Tracer, TraceError> {
opentelemetry_otlp::new_pipeline()
.tracing()
.with_exporter(
opentelemetry_otlp::new_exporter()
.tonic()
.with_endpoint("https://signoz.racooncity.org"),
)
.with_trace_config(
sdktrace::config().with_resource(Resource::new(vec![KeyValue::new(
"service.name",
"LoxideLibs",
)])),
)
.install_simple()
}
+1 -1
View File
@@ -11,4 +11,4 @@ urllib3==2.5.0
pyperclip==1.11.0 pyperclip==1.11.0
--extra-index-url https://git.racooncity.org/api/packages/brotoskyj/pypi/simple/ --extra-index-url https://git.racooncity.org/api/packages/brotoskyj/pypi/simple/
airlock_libs==2.0.0 airlock_libs==3.0.0