diff --git a/README.md b/README.md index d4f6d95..e7fd985 100644 --- a/README.md +++ b/README.md @@ -47,8 +47,9 @@ EPSILON = "0.1" # Privacy budget parameter for obfuscating the counts in the str ROUNDING_STEP = "10" # The granularity of the rounding of the obfuscated values, has no effect if OBFUSCATE = "no", default value: 10 PROJECTS_NO_OBFUSCATION = "exliquid;dktk_supervisors" # Projects for which the results are not to be obfuscated, separated by ;, default value: "exliquid; dktk_supervisors" QUERIES_TO_CACHE_FILE_PATH = "resources/bbmri" # The path to the file containing BASE64 encoded queries whose results are to be cached, if not set, no results are cached -PROVIDER = "" #OMOP provider name -PROVIDER_ICON = "" #Base64 encoded OMOP provider icon +PROVIDER = "name" #OMOP provider name +PROVIDER_ICON = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=" #Base64 encoded OMOP provider icon +AUTH_HEADER = "ApiKey XXXX" #Authorization header ``` Obfuscating zero counts is by default switched off. To enable obfuscating zero counts, set the env. variable `OBFUSCATE_ZERO`. diff --git a/src/config.rs b/src/config.rs index f2c1458..b02cfe7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -130,13 +130,17 @@ struct CliArgs { tls_ca_certificates_dir: Option, /// OMOP provider name - #[clap(long, env, value_parser, default_value = "")] + #[clap(long, env, value_parser)] provider: Option, /// Base64 encoded OMOP provider icon - #[clap(long, env, value_parser, default_value = "")] + #[clap(long, env, value_parser)] provider_icon: Option, + /// Authorization header + #[clap(long, env, value_parser)] + auth_header: Option, + } pub(crate) struct Config { @@ -162,6 +166,7 @@ pub(crate) struct Config { pub client: Client, pub provider: Option, pub provider_icon: Option, + pub auth_header: Option, } impl Config { @@ -199,6 +204,7 @@ impl Config { tls_ca_certificates, provider: cli_args.provider, provider_icon: cli_args.provider_icon, + auth_header: cli_args.auth_header, client, }; Ok(config) diff --git a/src/errors.rs b/src/errors.rs index a11f00d..6888210 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -46,4 +46,7 @@ pub enum FocusError { AstOperatorValueMismatch(), #[error("Invalid date format: {0}")] AstInvalidDateFormat(String), + #[error("Invalid Header Value: {0}")] + InvalidHeaderValue(http::header::InvalidHeaderValue), + } diff --git a/src/omop.rs b/src/omop.rs index e87a579..283f9a3 100644 --- a/src/omop.rs +++ b/src/omop.rs @@ -1,4 +1,7 @@ +use http::HeaderMap; +use http::HeaderValue; use http::StatusCode; +use http::header; use serde::Deserialize; use serde::Serialize; use tracing::{debug, warn}; @@ -24,10 +27,26 @@ pub async fn post_ast(ast: ast::Ast) -> Result { debug!("{}", ast_string.clone()); + let mut headers = HeaderMap::new(); + + headers.insert(header::CONTENT_TYPE, + HeaderValue::from_str("application/json") + .map_err(|e| FocusError::InvalidHeaderValue(e))?); + + match CONFIG.auth_header.clone() { + Some(auth_header_value) => { + headers.insert(header::AUTHORIZATION, + HeaderValue::from_str(auth_header_value.as_str()) + .map_err(|e| FocusError::InvalidHeaderValue(e))?); + }, + + None => {} + } + let resp = CONFIG .client .post(format!("{}", CONFIG.endpoint_url)) - .header("Content-Type", "application/json") + .headers(headers) .body(ast_string.clone()) .send() .await