Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: first batch of client APIs #231

Merged
merged 10 commits into from
Jan 13, 2025
14 changes: 14 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ tokio = { version = "1.19", features = [
], optional = true }
tokio-util = { version = "0.7.3", features = ["codec", "io"], optional = true }
tokio-rustls = { version = "0.26", optional = true, default-features = false, features = ["logging", "tls12"]}
rustls-pki-types = { version = "1.10", optional = true }
futures = { version = "0.3", optional = true }
async-trait = { version = "0.1", optional = true }
pin-project = { version = "1.1", optional = true }
rand = { version = "0.8", optional = true }
md5 = { version = "0.7", optional = true }
hex = { version = "0.4", optional = true }
Expand All @@ -44,6 +46,8 @@ postgres-types = { version = "0.2", features = [
chrono = { version = "0.4", features = ["std"], optional = true }
rust_decimal = { version = "1.35", features = ["db-postgres"], optional = true }
lazy-regex = {version = "3.3", default-features = false, features = ["lite"]}
## config
percent-encoding = { version = "2.0", optional = true }

[features]
default = ["server-api-aws-lc-rs"]
Expand All @@ -63,6 +67,16 @@ server-api = [
]
server-api-ring = ["server-api", "_ring"]
server-api-aws-lc-rs = ["server-api", "_aws-lc-rs"]
client-api = [
"dep:percent-encoding",
"dep:pin-project",
"dep:tokio",
"dep:tokio-util",
"dep:futures",
"dep:async-trait",
]
client-api-ring = ["client-api", "_ring", "dep:rustls-pki-types"]
client-api-aws-lc-rs = ["client-api", "_aws-lc-rs", "dep:rustls-pki-types"]
scram = ["dep:base64", "dep:stringprep", "dep:x509-certificate"]
_duckdb = []
_sqlite = []
Expand Down
24 changes: 24 additions & 0 deletions src/api/client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
mod auth;
pub(crate) mod config;

use std::sync::Arc;

pub use config::Config;

/// The collection of all client handlers
pub trait PgWireClientHandlers {
type StartupHandler: auth::StartupHandler;

fn startup_handler(&self) -> Arc<Self::StartupHandler>;
}

impl<T> PgWireClientHandlers for Arc<T>
where
T: PgWireClientHandlers,
{
type StartupHandler = T::StartupHandler;

fn startup_handler(&self) -> Arc<Self::StartupHandler> {
(**self).startup_handler()
}
}
20 changes: 20 additions & 0 deletions src/api/client/auth.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use async_trait::async_trait;

use crate::error::PgWireResult;
use crate::messages::response::{ReadyForQuery, SslResponse};
use crate::messages::startup::{Authentication, BackendKeyData, ParameterStatus};

use super::Config;

#[async_trait]
pub trait StartupHandler: Send + Sync {
async fn startup(&self, config: &Config) -> PgWireResult<()>;

async fn on_authentication(&self, message: Authentication) -> PgWireResult<()>;

async fn on_parameter_status(&self, message: ParameterStatus) -> PgWireResult<()>;

async fn on_backend_key(&self, message: BackendKeyData) -> PgWireResult<()>;

async fn on_ready_for_query(&self, message: ReadyForQuery) -> PgWireResult<()>;
}
Loading
Loading