Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5698184291 |
@@ -1,4 +1,3 @@
|
||||
/target
|
||||
build.sh
|
||||
pythontest.py
|
||||
changelog.md
|
||||
pythontest.py
|
||||
Generated
+1
-1
@@ -26,7 +26,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "airlock_libs"
|
||||
version = "4.0.2"
|
||||
version = "3.1.2"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"indicatif",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "airlock_libs"
|
||||
version = "4.0.2"
|
||||
version = "3.1.2"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
|
||||
@@ -4,7 +4,7 @@ build-backend = "maturin"
|
||||
|
||||
[project]
|
||||
name = "airlock_libs"
|
||||
version = "4.0.2"
|
||||
version = "3.1.2"
|
||||
description = "Airlock Digital API Wrapper"
|
||||
readme = "README.md"
|
||||
license = { text = "AGPL-3.0-only" }
|
||||
|
||||
@@ -25,34 +25,12 @@ use std::{
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct TelemetryConfig {
|
||||
TELEMETRY: bool,
|
||||
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)]
|
||||
struct ApiResponse {
|
||||
error: String,
|
||||
@@ -96,13 +74,7 @@ pub fn pull_policy_exec_histories(
|
||||
exec_types: String,
|
||||
days: i64,
|
||||
) -> Py<PyString> {
|
||||
let rt = match tokio::runtime::Runtime::new() {
|
||||
Ok(rt) => rt,
|
||||
Err(e) => {
|
||||
println!("Failed to build Tokio Runtime: {:?}", e);
|
||||
std::process::abort();
|
||||
}
|
||||
};
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let _ = init_tracer();
|
||||
});
|
||||
@@ -114,25 +86,13 @@ pub fn pull_policy_exec_histories(
|
||||
)
|
||||
.into();
|
||||
let writeable_filepath = file_path.clone();
|
||||
if !&file_path.exists() {
|
||||
if let Some(parent_dir) = &file_path.parent()
|
||||
if !file_path.exists() {
|
||||
if let Some(parent_dir) = file_path.parent()
|
||||
&& !parent_dir.exists()
|
||||
{
|
||||
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::create_dir_all(parent_dir).unwrap();
|
||||
}
|
||||
fs::File::create(file_path).unwrap();
|
||||
}
|
||||
let data = ApiResponse {
|
||||
error: "Success".to_string(),
|
||||
@@ -141,13 +101,7 @@ pub fn pull_policy_exec_histories(
|
||||
},
|
||||
};
|
||||
let data_write = serde_json::to_string_pretty(&data).expect("Failed to serialize");
|
||||
match fs::write(writeable_filepath.clone(), data_write) {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
println!("Failed to write to: {:?}: {}", &writeable_filepath, e);
|
||||
std::process::abort();
|
||||
}
|
||||
}
|
||||
fs::write(writeable_filepath.clone(), data_write).unwrap();
|
||||
let mut checkpoint_number: String = skipback(days).to_string();
|
||||
let multi_progress = MultiProgress::new();
|
||||
multi_progress.set_draw_target(ProgressDrawTarget::stdout());
|
||||
@@ -181,32 +135,18 @@ pub fn pull_policy_exec_histories(
|
||||
);
|
||||
cx.span()
|
||||
.set_status(Status::error("Client Failed to Build"));
|
||||
println!("Failed to Build Client: {:?}", client_result);
|
||||
std::process::abort();
|
||||
panic!("Failed to Build Client: {:?}", client_result);
|
||||
}
|
||||
}
|
||||
});
|
||||
let api: Py<PyAny> = py_self;
|
||||
let cutoff = Local::now().naive_local() - Duration::days(days);
|
||||
let mut f = match File::open(&writeable_filepath) {
|
||||
Ok(f) => f,
|
||||
Err(e) => {
|
||||
println!("Failed to Access {:?}: {}", &writeable_filepath, e);
|
||||
std::process::abort();
|
||||
}
|
||||
};
|
||||
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()));
|
||||
span.set_attribute(KeyValue::new("Policy Name", policy_names.clone()));
|
||||
loop {
|
||||
match f.seek(SeekFrom::Start(0)) {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
println!("Failed to seek start of {:?}: {}", f, e);
|
||||
std::process::abort();
|
||||
}
|
||||
}
|
||||
f.seek(SeekFrom::Start(0)).unwrap();
|
||||
let execution_histories = tracer.in_span(checkpoint_number.to_string(), |cx| {
|
||||
let results: ApiResponse = history_logging(
|
||||
py,
|
||||
@@ -286,12 +226,7 @@ pub fn pull_policy_exec_histories(
|
||||
},
|
||||
};
|
||||
let data_write = serde_json::to_string_pretty(&final_response).unwrap();
|
||||
match fs::write(&writeable_filepath, data_write) {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
println!("Failed to write to: {:?}: {}", &writeable_filepath, e);
|
||||
}
|
||||
}
|
||||
fs::write(&writeable_filepath, data_write).unwrap();
|
||||
if let Some(last_item) = &final_response.response.exechistories.last()
|
||||
&& let Ok(last_date) = NaiveDate::parse_from_str(
|
||||
&last_item.datetime.replace(" +0000 UTC", ""),
|
||||
@@ -306,13 +241,7 @@ pub fn pull_policy_exec_histories(
|
||||
}
|
||||
});
|
||||
progress_bar.finish_with_message("All Checkpoints Complete");
|
||||
let return_data = match fs::read_to_string(&writeable_filepath) {
|
||||
Ok(return_data) => return_data,
|
||||
Err(e) => {
|
||||
println!("Failed to read data from: {:?}: {}", &writeable_filepath, e);
|
||||
std::process::abort();
|
||||
}
|
||||
};
|
||||
let return_data = fs::read_to_string(&writeable_filepath).unwrap();
|
||||
shutdown_tracer_provider();
|
||||
PyString::new(py, &return_data).into()
|
||||
}
|
||||
@@ -405,8 +334,30 @@ 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::<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> {
|
||||
let cfg = TelemetryConfig::load();
|
||||
let cfg = load_telemetry_config();
|
||||
if !cfg.TELEMETRY {
|
||||
global::set_tracer_provider(NoopTracerProvider::new());
|
||||
return Ok(None);
|
||||
|
||||
+1
-1
@@ -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==4.0.2
|
||||
airlock_libs==3.1.2
|
||||
Reference in New Issue
Block a user