Compare commits

...

3 Commits

Author SHA1 Message Date
brotoskyj dd206eb272 Feature
closes #37
2025-11-24 10:35:38 -05:00
brotoskyj 87ab1e3b28 Telemetry Config Change
Build Library / Build Library (push) Successful in 4m54s
Added implementation instead of separate function to load Telemetry configuration
2025-11-21 14:00:09 -05:00
brotoskyj 303ecd8368 Removed a lot of unwraps
Build Library / Build Library (push) Successful in 5m2s
Removing the unwraps now has better error handling and will cause the program to crash with crash dumps instead of panic!
2025-11-21 12:20:11 -05:00
6 changed files with 62 additions and 35 deletions
+1
View File
@@ -1,3 +1,4 @@
/target /target
build.sh build.sh
pythontest.py pythontest.py
changelog.md
+1 -1
View File
@@ -26,7 +26,7 @@ dependencies = [
[[package]] [[package]]
name = "airlock_libs" name = "airlock_libs"
version = "3.1.2" version = "4.0.1"
dependencies = [ dependencies = [
"chrono", "chrono",
"indicatif", "indicatif",
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "airlock_libs" name = "airlock_libs"
version = "3.1.2" version = "4.0.1"
edition = "2024" edition = "2024"
[lib] [lib]
+1 -1
View File
@@ -4,7 +4,7 @@ build-backend = "maturin"
[project] [project]
name = "airlock_libs" name = "airlock_libs"
version = "3.1.2" version = "4.0.1"
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" }
+56 -30
View File
@@ -25,12 +25,34 @@ use std::{
str::FromStr, str::FromStr,
}; };
#[allow(non_snake_case)]
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
struct TelemetryConfig { struct TelemetryConfig {
TELEMETRY: bool, TELEMETRY: bool,
TELEM_URL: Option<String>, TELEM_URL: Option<String>,
} }
impl TelemetryConfig {
pub fn load() -> Self {
let cfg_path = get_base_directory().join("config\\user_config.json");
if !cfg_path.exists() {
return Self {
TELEMETRY: false,
TELEM_URL: None,
};
}
match fs::read_to_string(&cfg_path) {
Ok(contents) => serde_json::from_str::<Self>(&contents).unwrap_or(Self {
TELEMETRY: false,
TELEM_URL: None,
}),
Err(_) => Self {
TELEMETRY: false,
TELEM_URL: None,
},
}
}
}
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
struct ApiResponse { struct ApiResponse {
error: String, error: String,
@@ -86,13 +108,25 @@ pub fn pull_policy_exec_histories(
) )
.into(); .into();
let writeable_filepath = file_path.clone(); let writeable_filepath = file_path.clone();
if !file_path.exists() { if !&file_path.exists() {
if let Some(parent_dir) = file_path.parent() if let Some(parent_dir) = &file_path.parent()
&& !parent_dir.exists() && !parent_dir.exists()
{ {
fs::create_dir_all(parent_dir).unwrap(); match fs::create_dir_all(parent_dir) {
Ok(_) => {}
Err(e) => {
println!("Failed to Create Directory {:?}: {}", parent_dir, e);
std::process::abort();
}
}
}
match fs::File::create(&file_path) {
Ok(_) => {}
Err(e) => {
println!("Failed to Create Directory {:?}: {}", &file_path, e);
std::process::abort();
}
} }
fs::File::create(file_path).unwrap();
} }
let data = ApiResponse { let data = ApiResponse {
error: "Success".to_string(), error: "Success".to_string(),
@@ -135,18 +169,32 @@ pub fn pull_policy_exec_histories(
); );
cx.span() cx.span()
.set_status(Status::error("Client Failed to Build")); .set_status(Status::error("Client Failed to Build"));
panic!("Failed to Build Client: {:?}", client_result); println!("Failed to Build Client: {:?}", client_result);
std::process::abort();
} }
} }
}); });
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 = match File::open(&writeable_filepath) {
Ok(f) => f,
Err(e) => {
println!("Failed to Access {:?}: {}", &writeable_filepath, e);
std::process::abort();
}
};
tracer.in_span("Airlock Data Retreival", |cx| { tracer.in_span("Airlock Data Retreival", |cx| {
let span = cx.span(); let span = cx.span();
span.set_attribute(Key::new("Days").string(days.to_string().to_string())); span.set_attribute(Key::new("Days").string(days.to_string().to_string()));
span.set_attribute(KeyValue::new("Policy Name", policy_names.clone()));
loop { loop {
f.seek(SeekFrom::Start(0)).unwrap(); match f.seek(SeekFrom::Start(0)) {
Ok(_) => {}
Err(e) => {
println!("Failed to seek start of {:?}: {}", f, e);
std::process::abort();
}
}
let execution_histories = tracer.in_span(checkpoint_number.to_string(), |cx| { let execution_histories = tracer.in_span(checkpoint_number.to_string(), |cx| {
let results: ApiResponse = history_logging( let results: ApiResponse = history_logging(
py, py,
@@ -334,30 +382,8 @@ fn skipback(days: i64) -> ObjectId {
ObjectId::parse_str(&objectid_hex).expect("Invalid ObjectId hex") ObjectId::parse_str(&objectid_hex).expect("Invalid ObjectId hex")
} }
fn load_telemetry_config() -> TelemetryConfig {
let cfg_path = get_base_directory().join("config\\user_config.json");
if !cfg_path.exists() {
return TelemetryConfig {
TELEMETRY: false,
TELEM_URL: None,
};
}
match fs::read_to_string(&cfg_path) {
Ok(contents) => {
serde_json::from_str::<TelemetryConfig>(&contents).unwrap_or(TelemetryConfig {
TELEMETRY: false,
TELEM_URL: None,
})
}
Err(_) => TelemetryConfig {
TELEMETRY: false,
TELEM_URL: None,
},
}
}
fn init_tracer() -> Result<Option<sdktrace::Tracer>, TraceError> { fn init_tracer() -> Result<Option<sdktrace::Tracer>, TraceError> {
let cfg = load_telemetry_config(); let cfg = TelemetryConfig::load();
if !cfg.TELEMETRY { if !cfg.TELEMETRY {
global::set_tracer_provider(NoopTracerProvider::new()); global::set_tracer_provider(NoopTracerProvider::new());
return Ok(None); return Ok(None);
+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==3.1.2 airlock_libs==4.0.1