diff --git a/airlock_libs/Cargo.lock b/airlock_libs/Cargo.lock index 7d41bb2..6551e5e 100644 --- a/airlock_libs/Cargo.lock +++ b/airlock_libs/Cargo.lock @@ -26,7 +26,7 @@ dependencies = [ [[package]] name = "airlock_libs" -version = "3.2.0" +version = "4.0.0" dependencies = [ "chrono", "indicatif", diff --git a/airlock_libs/Cargo.toml b/airlock_libs/Cargo.toml index 7ae3aaa..967f0a2 100644 --- a/airlock_libs/Cargo.toml +++ b/airlock_libs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "airlock_libs" -version = "3.2.0" +version = "4.0.0" edition = "2024" [lib] diff --git a/airlock_libs/pyproject.toml b/airlock_libs/pyproject.toml index 32a8a0d..c56d78e 100644 --- a/airlock_libs/pyproject.toml +++ b/airlock_libs/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "maturin" [project] name = "airlock_libs" -version = "3.2.0" +version = "4.0.0" description = "Airlock Digital API Wrapper" readme = "README.md" license = { text = "AGPL-3.0-only" } diff --git a/airlock_libs/src/services.rs b/airlock_libs/src/services.rs index 7d1c1a5..6c6d68d 100644 --- a/airlock_libs/src/services.rs +++ b/airlock_libs/src/services.rs @@ -32,6 +32,27 @@ struct TelemetryConfig { TELEM_URL: Option, } +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::(&contents).unwrap_or(Self { + TELEMETRY: false, + TELEM_URL: None, + }), + Err(_) => Self { + TELEMETRY: false, + TELEM_URL: None, + }, + } + } +} #[derive(Debug, Deserialize, Serialize)] struct ApiResponse { error: String, @@ -92,7 +113,7 @@ pub fn pull_policy_exec_histories( && !parent_dir.exists() { match fs::create_dir_all(parent_dir) { - Ok(_) => {}, + Ok(_) => {} Err(e) => { println!("Failed to Create Directory {:?}: {}", parent_dir, e); std::process::abort(); @@ -100,7 +121,7 @@ pub fn pull_policy_exec_histories( } } match fs::File::create(&file_path) { - Ok(_) => {}, + Ok(_) => {} Err(e) => { println!("Failed to Create Directory {:?}: {}", &file_path, e); std::process::abort(); @@ -167,7 +188,7 @@ pub fn pull_policy_exec_histories( span.set_attribute(Key::new("Days").string(days.to_string().to_string())); loop { match f.seek(SeekFrom::Start(0)) { - Ok(_) => {}, + Ok(_) => {} Err(e) => { println!("Failed to seek start of {:?}: {}", f, e); std::process::abort(); @@ -360,30 +381,8 @@ fn skipback(days: i64) -> ObjectId { 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::(&contents).unwrap_or(TelemetryConfig { - TELEMETRY: false, - TELEM_URL: None, - }) - } - Err(_) => TelemetryConfig { - TELEMETRY: false, - TELEM_URL: None, - }, - } -} - fn init_tracer() -> Result, TraceError> { - let cfg = load_telemetry_config(); + let cfg = TelemetryConfig::load(); if !cfg.TELEMETRY { global::set_tracer_provider(NoopTracerProvider::new()); return Ok(None); diff --git a/requirements.txt b/requirements.txt index 7110c1e..dda7a4e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,4 +11,4 @@ urllib3==2.5.0 pyperclip==1.11.0 --extra-index-url https://git.racooncity.org/api/packages/brotoskyj/pypi/simple/ -airlock_libs==3.2.0 \ No newline at end of file +airlock_libs==4.0.0 \ No newline at end of file