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

TC-1559 Enable TLS client CA certificate management #75

Merged
merged 1 commit into from
Jun 17, 2024
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ strum = "0.26.1"
strum_macros = "0.26.1"
thiserror = "1"
tokio = "1.36.0"
tonic = "0.11.0"
tonic = { version = "0.11.0", features = ["tls"] }
tonic-build = "0.11.0"

# Do not generate debuginfo for dependencies in `dev` and `test` profiles. This
Expand Down
14 changes: 13 additions & 1 deletion lib/src/collectsub/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::path::Path;
use std::time::SystemTime;

use serde::Serialize;
use tonic::transport::Channel;
use tonic::transport::{Certificate, Channel, ClientTlsConfig};

use grpc::colect_subscriber_service_client::ColectSubscriberServiceClient;
use grpc::CollectDataType;
Expand Down Expand Up @@ -81,6 +82,17 @@ impl CollectSubClient {
})
}

pub async fn new_with_ca_certificate(url: String, ca_certificate_pem_path: String) -> anyhow::Result<Self> {
let cert = std::fs::read_to_string(ca_certificate_pem_path)?;
Ok(Self {
client: grpc::colect_subscriber_service_client::ColectSubscriberServiceClient::connect(
tonic::transport::Endpoint::new(url)?
.tls_config(ClientTlsConfig::new().ca_certificate(Certificate::from_pem(cert)))?,
)
.await?,
})
}

pub async fn get(&mut self, filters: Vec<Filter>, since: SystemTime) -> anyhow::Result<Vec<Entry>> {
let filters = filters.iter().map(|e| e.into()).collect();

Expand Down