Skip to content

Commit

Permalink
Merge pull request #156 from samply/develop
Browse files Browse the repository at this point in the history
more logging
  • Loading branch information
enola-dkfz authored Jul 17, 2024
2 parents c44d9b0 + 28c6a63 commit cce9c50
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
base64 = { version = "0.21.0", default_features = false }
base64 = "0.22.1"
http = "0.2"
reqwest = { version = "0.11", default_features = false, features = ["json", "default-tls"] }
serde = { version = "1.0.152", features = ["serde_derive"] }
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ Obfuscating zero counts is by default switched off. To enable obfuscating zero c

Optionally, you can provide the `TLS_CA_CERTIFICATES_DIR` environment variable to add additional trusted certificates, e.g., if you have a TLS-terminating proxy server in place. The application respects the `HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`, `NO_PROXY`, and their respective lowercase equivalents.

Log level can be set using the `RUST_LOG` environment variable.

## Usage

Creating a sample focus healthcheck task using curl (body can be any string and is ignored):
Expand Down
1 change: 0 additions & 1 deletion src/blaze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use serde::Serialize;
use serde_json::Value;
use tracing::{debug, warn, info};

use crate::BeamTask;
use crate::errors::FocusError;
use crate::util;
use crate::util::get_json_field;
Expand Down
2 changes: 0 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ pub(crate) struct Config {
pub rounding_step: usize,
pub unobfuscated: Vec<String>,
pub queries_to_cache: Option<PathBuf>,
tls_ca_certificates: Vec<Certificate>,
pub client: Client,
pub provider: Option<String>,
pub provider_icon: Option<String>,
Expand Down Expand Up @@ -217,7 +216,6 @@ impl Config {
rounding_step: cli_args.rounding_step,
unobfuscated: cli_args.projects_no_obfuscation.split(';').map(|s| s.to_string()).collect(),
queries_to_cache: cli_args.queries_to_cache,
tls_ca_certificates,
provider: cli_args.provider,
provider_icon: cli_args.provider_icon,
auth_header: cli_args.auth_header,
Expand Down
8 changes: 4 additions & 4 deletions src/cql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::projects::{
MANDATORY_CODE_SYSTEMS, OBSERVATION_LOINC_CODE, SAMPLE_TYPE_WORKAROUNDS,
};

use base64::{engine::general_purpose::STANDARD as BASE64, Engine as _};
use base64::{prelude::BASE64_STANDARD as BASE64, Engine as _};
use chrono::offset::Utc;
use chrono::DateTime;
use indexmap::set::IndexSet;
Expand All @@ -17,11 +17,11 @@ pub fn generate_body(ast: ast::Ast) -> Result<String, FocusError> {
.to_string()
.replace(
"{{LIBRARY_UUID}}",
format!("urn:uuid:{}", Uuid::new_v4().to_string()).as_str(),
format!("urn:uuid:{}", Uuid::new_v4()).as_str(),
)
.replace(
"{{MEASURE_UUID}}",
format!("urn:uuid:{}", Uuid::new_v4().to_string()).as_str(),
format!("urn:uuid:{}", Uuid::new_v4()).as_str(),
)
.replace(
"{{LIBRARY_ENCODED}}",
Expand Down Expand Up @@ -118,7 +118,7 @@ pub fn process(
if let Some(code_lists_vec) = code_lists_option {
for (index, code_list) in code_lists_vec.iter().enumerate() {
code_systems.insert(code_list);
let placeholder = format!("{{{{A{}}}}}", (index + 1).to_string()); //to keep compatibility with snippets in typescript
let placeholder = format!("{{{{A{}}}}}", (index + 1)); //to keep compatibility with snippets in typescript
condition_string = condition_string.replace(placeholder.as_str(), code_list);
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
use std::{process::exit, time::Duration};

use serde::{Deserialize, Serialize};
use tracing::{debug, error, warn};
use tracing::{debug, error, warn, trace};

// result cache
type SearchQuery = String;
Expand Down Expand Up @@ -103,6 +103,8 @@ pub async fn main() -> ExitCode {
};
banner::print_banner();

trace!("WARNING: You are running Focus in trace logging. This log level outputs unobfuscated result counts and is only intended for debugging the obfuscation. To avoid privacy risks, please check if that log level is appropriate. Consider using \"info\" or \"warn\".");

let _ = CONFIG.api_key; // Initialize config

tokio::select! {
Expand Down Expand Up @@ -174,7 +176,7 @@ async fn process_task(
return Err(FocusError::MissingExporterTaskType);
};
let body = &task.body;
return Ok(run_exporter_query(task, body, task_type).await?);
return run_exporter_query(task, body, task_type).await;
}

if CONFIG.endpoint_type == EndpointType::Blaze {
Expand Down Expand Up @@ -268,6 +270,8 @@ async fn run_cql_query(

let cql_result = blaze::run_cql_query(&query.lib, &query.measure).await?;

trace!("MeasureReport with unobfuscated values: {}", &cql_result);

let cql_result_new: String = match obfuscate {
true => obfuscate_counts_mr(
&cql_result,
Expand Down
6 changes: 4 additions & 2 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde_json::{json, Value};
use std::collections::HashMap;
use std::fs::File;
use std::io::{self, BufRead, BufReader};
use std::path::{Path};
use std::path::Path;
use tracing::warn;

#[derive(Debug, Deserialize, Serialize)]
Expand Down Expand Up @@ -114,6 +114,7 @@ pub(crate) fn is_cql_tampered_with(decoded_library: impl Into<String>) -> bool {
decoded_library.contains("define")
}

#[allow(clippy::too_many_arguments)]
pub fn obfuscate_counts_mr(
json_str: &str,
obf_cache: &mut ObfCache,
Expand All @@ -134,7 +135,7 @@ pub fn obfuscate_counts_mr(
2 => ObfuscateBelow10Mode::Obfuscate,
_ => ObfuscateBelow10Mode::Obfuscate,
};
let mut measure_report: MeasureReport = serde_json::from_str(&json_str)
let mut measure_report: MeasureReport = serde_json::from_str(json_str)
.map_err(|e| FocusError::DeserializationError(format!(r#"{}. Is obfuscation turned on when it shouldn't be? Is the metadata in the task formatted correctly, like this {{"project": "name"}}? Are there any other projects stated in the projects_no_obfuscation parameter in the bridgehead?"#, e)))?;
for g in &mut measure_report.group {
match &g.code.text[..] {
Expand Down Expand Up @@ -281,6 +282,7 @@ pub fn obfuscate_counts_mr(
Ok(measure_report_obfuscated)
}

#[allow(clippy::too_many_arguments)]
fn obfuscate_counts_recursive(
val: &mut Value,
delta: f64,
Expand Down

0 comments on commit cce9c50

Please sign in to comment.