lite-rpc/lite-rpc/src/postgres_logger/postgres_config.rs

58 lines
1.7 KiB
Rust
Raw Normal View History

use anyhow::Context;
use std::env;
use tokio_postgres::config::SslMode;
#[derive(serde::Deserialize, Debug, Clone)]
pub struct PostgresSessionConfig {
pub pg_config: String,
pub ssl: Option<PostgresSessionSslConfig>,
}
#[derive(serde::Deserialize, Debug, Clone)]
pub struct PostgresSessionSslConfig {
pub ca_pem_b64: String,
pub client_pks_b64: String,
pub client_pks_pass: String,
}
impl PostgresSessionConfig {
pub fn new_from_env() -> anyhow::Result<Option<Self>> {
// pg not enabled
if env::var("PG_ENABLED").is_err() {
return Ok(None);
}
Production into main (#303) * fix: panic on geyser close, multiplex bug https://github.com/blockworks-foundation/geyser-grpc-connector/issues/3 * update Cargo.lock * reverting cargo.lock * Fix issues with grpc and postgres * Solving merge issues * Fixing cargo fmt * Increase finish quic timeout (#280) (#281) * integrate geyser slot subscription (#283) * Increase finish quic timeout (#280) * Moving geyser slot subscription from stream to channels (#282) * Moving geyser slot subscription from stream to channels * Closing all the slot subscription tasks incase of restart * Making slot channel unbounded (bug) * remove block_debug_listen caused a panic - need more time to investigate 2024-01-17T20:31:42.913 app[683d392fd45368] ams [info] thread 'tokio-runtime-worker' panicked at cluster-endpoints/src/grpc_inspect.rs:59:21: 2024-01-17T20:31:42.913 app[683d392fd45368] ams [info] Error receiving block: Closed 2024-01-17T20:31:42.922 app[683d392fd45368] ams [info] 2024-01-17T20:31:42.912597Z ERROR lite_rpc: Services quit unexpectedly Err(cluster endpoint failure (Err(JoinError::Panic(Id(20), ...)), 1, [JoinHandle { id: Id(19) }, JoinHandle { id: Id(23) }]) * Update cargolock file * Fixing clippy removing grpc_inspect * merging main with production (#290) * remove block_debug_listen (#286) * remove block_debug_listen caused a panic - need more time to investigate 2024-01-17T20:31:42.913 app[683d392fd45368] ams [info] thread 'tokio-runtime-worker' panicked at cluster-endpoints/src/grpc_inspect.rs:59:21: 2024-01-17T20:31:42.913 app[683d392fd45368] ams [info] Error receiving block: Closed 2024-01-17T20:31:42.922 app[683d392fd45368] ams [info] 2024-01-17T20:31:42.912597Z ERROR lite_rpc: Services quit unexpectedly Err(cluster endpoint failure (Err(JoinError::Panic(Id(20), ...)), 1, [JoinHandle { id: Id(19) }, JoinHandle { id: Id(23) }]) * clippy * Fixing message too long and overflow panics (#288) * Update geyser grpc connector commit (#289) --------- Co-authored-by: Groovie | Mango <95291500+grooviegermanikus@users.noreply.github.com> * Merging MTU changes and setting up transportation config (#293) * remove block_debug_listen (#286) * remove block_debug_listen caused a panic - need more time to investigate 2024-01-17T20:31:42.913 app[683d392fd45368] ams [info] thread 'tokio-runtime-worker' panicked at cluster-endpoints/src/grpc_inspect.rs:59:21: 2024-01-17T20:31:42.913 app[683d392fd45368] ams [info] Error receiving block: Closed 2024-01-17T20:31:42.922 app[683d392fd45368] ams [info] 2024-01-17T20:31:42.912597Z ERROR lite_rpc: Services quit unexpectedly Err(cluster endpoint failure (Err(JoinError::Panic(Id(20), ...)), 1, [JoinHandle { id: Id(19) }, JoinHandle { id: Id(23) }]) * clippy * Fixing message too long and overflow panics (#288) * Update geyser grpc connector commit (#289) * Updating the transport config to match with solana endpoint (#292) * Updating the transport config to match with solana endpoint * Setting max MTU after groovies comments --------- Co-authored-by: Groovie | Mango <95291500+grooviegermanikus@users.noreply.github.com> * Making block subscription processed and moving confirmed block subscr… (#291) * Making block subscription processed and moving confirmed block subscription to meta * Sending both processed and confirmed blocks, if block has already been confirmed * Minor bug, subscribing to processed blocks instead of confirmed (#295) --------- Co-authored-by: Groovie | Mango <95291500+grooviegermanikus@users.noreply.github.com> Co-authored-by: GroovieGermanikus <groovie@mango.markets>
2024-01-26 04:56:33 -08:00
let enable_pg = env::var("PG_ENABLED").context("PG_ENABLED")?;
if enable_pg != *"true" {
return Ok(None);
}
let env_pg_config = env::var("PG_CONFIG").context("PG_CONFIG not found")?;
let ssl_config = if env_pg_config
.parse::<tokio_postgres::Config>()?
.get_ssl_mode()
.eq(&SslMode::Disable)
{
None
} else {
let env_ca_pem_b64 = env::var("CA_PEM_B64").context("CA_PEM_B64 not found")?;
let env_client_pks_b64 =
env::var("CLIENT_PKS_B64").context("CLIENT_PKS_B64 not found")?;
let env_client_pks_pass =
env::var("CLIENT_PKS_PASS").context("CLIENT_PKS_PASS not found")?;
Some(PostgresSessionSslConfig {
ca_pem_b64: env_ca_pem_b64,
client_pks_b64: env_client_pks_b64,
client_pks_pass: env_client_pks_pass,
})
};
Ok(Some(Self {
pg_config: env_pg_config,
ssl: ssl_config,
}))
}
}