Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ rand = { default-features = false, version = "0.9.0" }
futures-util = { version = "0.3", default-features = false, features = ["std"] }
tryhard = "0.5"


# Logging
tracing = { version = "0.1.37", default-features = false }
tracing-subscriber = { version = "0.3.11", default-features = false, features = [
Expand Down Expand Up @@ -58,17 +59,13 @@ sqlx = { version = "0.8.2", features = [
"chrono",
"rust_decimal",
"uuid",
], optional = true }
]}
kurtbuilds_sqlx_serde = { version = "0.3.2", features = [
"json",
"decimal",
"chrono",
"uuid",
], optional = true }

[features]
default = ["query-sql"]
query-sql = ["dep:sqlx", "dep:kurtbuilds_sqlx_serde"]
]}

[dev-dependencies]
pretty_assertions = "1.4.0"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ AUTH_HEADER = "[Auth Type] XXXX" #Authorization header for accessing the store;
EXPORTER_API_KEY = "XXXX" # Value of header x-api-key for accessing the Exporter application
```

In order to use Postgres querying, a Docker image built with the feature "dktk" needs to be used and this optional variable set:
In order to use Postgres querying this optional variable needs to be set:
```bash
POSTGRES_CONNECTION_STRING = "postgresql://postgres:Test.123@localhost:5432/postgres" # Postgres connection string
```
Expand Down
13 changes: 0 additions & 13 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ pub enum EndpointType {
Omop, // endpoint is URL of a query mediator translating AST to provider specific SQL
EucaimApi, // endpoint is URL of custom API for querying EUCAIM provider
EucaimBeacon,
#[cfg(feature = "query-sql")]
EucaimSql,
#[cfg(feature = "query-sql")]
BlazeAndSql,
#[cfg(feature = "query-sql")]
Sql,
}

Expand All @@ -39,11 +36,8 @@ impl fmt::Display for EndpointType {
EndpointType::Omop => write!(f, "omop"),
EndpointType::EucaimApi => write!(f, "eucaim_api"),
EndpointType::EucaimBeacon => write!(f, "eucaim_beacon"),
#[cfg(feature = "query-sql")]
EndpointType::EucaimSql => write!(f, "eucaim_sql"),
#[cfg(feature = "query-sql")]
EndpointType::BlazeAndSql => write!(f, "blaze_and_sql"),
#[cfg(feature = "query-sql")]
EndpointType::Sql => write!(f, "sql"),
}
}
Expand Down Expand Up @@ -190,12 +184,10 @@ struct CliArgs {
exporter_api_key: Option<String>,

/// Postgres connection string
#[cfg(feature = "query-sql")]
#[clap(long, env, value_parser)]
postgres_connection_string: Option<String>,

/// Max number of attempts to connect to the database
#[cfg(feature = "query-sql")]
#[clap(long, env, value_parser, default_value = "8")]
max_db_attempts: u32,
}
Expand Down Expand Up @@ -229,9 +221,7 @@ pub(crate) struct Config {
pub provider_icon: Option<String>,
pub auth_header: Option<String>,
pub exporter_api_key: Option<String>,
#[cfg(feature = "query-sql")]
pub postgres_connection_string: Option<String>,
#[cfg(feature = "query-sql")]
pub max_db_attempts: u32,
}

Expand All @@ -256,7 +246,6 @@ impl Config {
api_key: cli_args.api_key,
retry_count: cli_args.retry_count,
endpoint_url: match cli_args.endpoint_type{
#[cfg(feature = "query-sql")]
EndpointType::Sql|EndpointType::EucaimSql => {Url::parse("http://localhost").unwrap()} // dummy value, never used, only Postgres connection string is used in those cases
_ => {
cli_args.endpoint_url.unwrap_or_else(|| cli_args.blaze_url.expect("Look, mate, you need to set endpoint-url or blaze-url, can't work without, sry"))
Expand Down Expand Up @@ -284,9 +273,7 @@ impl Config {
provider_icon: cli_args.provider_icon,
auth_header: cli_args.auth_header,
exporter_api_key: cli_args.exporter_api_key,
#[cfg(feature = "query-sql")]
postgres_connection_string: cli_args.postgres_connection_string,
#[cfg(feature = "query-sql")]
max_db_attempts: cli_args.max_db_attempts,
client,
};
Expand Down
1 change: 0 additions & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ pub enum FocusError {
QueryNotAllowed(String),
#[error("CQL lang not enabled")]
CqlLangNotEnabled,
#[cfg(feature = "query-sql")]
#[error("Error executing SQL query: {0}")]
ErrorExecutingSqlQuery(sqlx::Error),
#[error("Unknown project: {0}")]
Expand Down
28 changes: 2 additions & 26 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,17 @@ mod errors;
mod graceful_shutdown;
mod logger;

mod db;
mod eucaim_api;
mod eucaim_beacon;
mod eucaim_sql;
mod exporter;
mod flavours;
mod intermediate_rep;
mod mr;
mod task_processing;
mod transformed;
mod util;

#[cfg(feature = "query-sql")]
mod db;

#[cfg(feature = "query-sql")]
mod eucaim_sql;

#[cfg(feature = "query-sql")]
use sqlx::Row;

use base64::engine::general_purpose;
Expand Down Expand Up @@ -198,18 +192,8 @@ pub async fn main() -> ExitCode {
}
}

#[cfg(not(feature = "query-sql"))]
type DbPool = ();

#[cfg(feature = "query-sql")]
type DbPool = sqlx::PgPool;

#[cfg(not(feature = "query-sql"))]
async fn get_db_pool() -> Result<Option<DbPool>, ExitCode> {
Ok(None)
}

#[cfg(feature = "query-sql")]
async fn get_db_pool() -> Result<Option<DbPool>, ExitCode> {
use tracing::info;

Expand Down Expand Up @@ -242,11 +226,8 @@ async fn main_loop() -> ExitCode {
EndpointType::Omop | EndpointType::EucaimApi | EndpointType::EucaimBeacon => {
|| async { true }.boxed()
} // TODO health check
#[cfg(feature = "query-sql")]
EndpointType::EucaimSql => || async { true }.boxed(),
#[cfg(feature = "query-sql")]
EndpointType::BlazeAndSql => || blaze::check_availability().boxed(),
#[cfg(feature = "query-sql")]
EndpointType::Sql => || async { true }.boxed(),
};
let mut failures = 0;
Expand Down Expand Up @@ -353,7 +334,6 @@ async fn process_task(
)
.await
}
#[cfg(feature = "query-sql")]
EndpointType::BlazeAndSql => {
let mut generated_from_ast: bool = false;
let data = base64_decode(&task.body)?;
Expand Down Expand Up @@ -400,7 +380,6 @@ async fn process_task(
}
}
}
#[cfg(feature = "query-sql")]
EndpointType::Sql => {
let data = base64_decode(&task.body)?;
let query_maybe: Result<db::SqlQuery, serde_json::Error> =
Expand Down Expand Up @@ -465,7 +444,6 @@ async fn process_task(

Ok(run_eucaim_api_query(task, ast).await?)
}
#[cfg(feature = "query-sql")]
EndpointType::EucaimSql => {
let decoded = util::base64_decode(&task.body)?;
let intermediate_rep_query: intermediate_rep::IntermediateRepQuery =
Expand Down Expand Up @@ -504,7 +482,6 @@ async fn process_task(
}
}

#[cfg(feature = "query-sql")]
async fn run_eucaim_sql_query(
task: &TaskRequest<String>,
pool: sqlx::Pool<sqlx::Postgres>,
Expand Down Expand Up @@ -591,7 +568,6 @@ async fn run_eucaim_sql_query(
}
}

#[cfg(feature = "query-sql")]
async fn run_sql_key_query(
task: &TaskRequest<String>,
pool: sqlx::Pool<sqlx::Postgres>,
Expand Down
Loading