Skip to content

Commit

Permalink
Make TLS connection builders take references to configs instead of cl…
Browse files Browse the repository at this point in the history
…oning (#1642)
  • Loading branch information
justinweng-instaclustr authored May 31, 2024
1 parent c1ee55f commit bb9f2b6
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion shotover-proxy/tests/cassandra_int_tests/cluster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub async fn run_topology_task(ca_path: Option<&str>, port: Option<u32>) -> Vec<
let (keyspaces_tx, _keyspaces_rx) = watch::channel(HashMap::new());
let (task_handshake_tx, task_handshake_rx) = mpsc::channel(1);
let tls = ca_path.map(|ca_path| {
TlsConnector::new(TlsConnectorConfig {
TlsConnector::new(&TlsConnectorConfig {
certificate_authority_path: ca_path.into(),
certificate_path: None,
private_key_path: None,
Expand Down
2 changes: 1 addition & 1 deletion shotover/src/sources/cassandra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl CassandraSource {
CassandraCodecBuilder::new(Direction::Source, name),
Arc::new(Semaphore::new(connection_limit.unwrap_or(512))),
trigger_shutdown_rx.clone(),
tls.map(TlsAcceptor::new).transpose()?,
tls.as_ref().map(TlsAcceptor::new).transpose()?,
timeout.map(Duration::from_secs),
transport.unwrap_or(Transport::Tcp),
)
Expand Down
2 changes: 1 addition & 1 deletion shotover/src/sources/kafka.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl KafkaSource {
KafkaCodecBuilder::new(Direction::Source, name),
Arc::new(Semaphore::new(connection_limit.unwrap_or(512))),
trigger_shutdown_rx.clone(),
tls.map(TlsAcceptor::new).transpose()?,
tls.as_ref().map(TlsAcceptor::new).transpose()?,
timeout.map(Duration::from_secs),
Transport::Tcp,
)
Expand Down
2 changes: 1 addition & 1 deletion shotover/src/sources/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl RedisSource {
RedisCodecBuilder::new(Direction::Source, name),
Arc::new(Semaphore::new(connection_limit.unwrap_or(512))),
trigger_shutdown_rx.clone(),
tls.map(TlsAcceptor::new).transpose()?,
tls.as_ref().map(TlsAcceptor::new).transpose()?,
timeout.map(Duration::from_secs),
Transport::Tcp,
)
Expand Down
6 changes: 3 additions & 3 deletions shotover/src/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ fn load_private_key(path: &str) -> Result<PrivateKeyDer<'static>> {
}

impl TlsAcceptor {
pub fn new(tls_config: TlsAcceptorConfig) -> Result<TlsAcceptor, Vec<String>> {
pub fn new(tls_config: &TlsAcceptorConfig) -> Result<TlsAcceptor, Vec<String>> {
// TODO: report multiple errors back to the user
// The validation and anyhow error reporting has merged here and they were originally intended to be seperate.
// We should probably replace the error reporting Vec<String> system with a better typed error system. (anyhow maybe?)
Self::new_inner(tls_config).map_err(|x| vec![format!("{x:?}")])
}

fn new_inner(tls_config: TlsAcceptorConfig) -> Result<TlsAcceptor> {
fn new_inner(tls_config: &TlsAcceptorConfig) -> Result<TlsAcceptor> {
let client_cert_verifier =
if let Some(path) = tls_config.certificate_authority_path.as_ref() {
let root_cert_store = load_ca(path).with_context(|| {
Expand Down Expand Up @@ -149,7 +149,7 @@ pub struct TlsConnector {
}

impl TlsConnector {
pub fn new(tls_config: TlsConnectorConfig) -> Result<TlsConnector> {
pub fn new(tls_config: &TlsConnectorConfig) -> Result<TlsConnector> {
let root_cert_store =
load_ca(&tls_config.certificate_authority_path).with_context(|| {
format!(
Expand Down
2 changes: 1 addition & 1 deletion shotover/src/transforms/cassandra/sink_cluster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl TransformConfig for CassandraSinkClusterConfig {
&self,
transform_context: TransformContextConfig,
) -> Result<Box<dyn TransformBuilder>> {
let tls = self.tls.clone().map(TlsConnector::new).transpose()?;
let tls = self.tls.as_ref().map(TlsConnector::new).transpose()?;
let mut shotover_nodes = self.shotover_nodes.clone();
let index = self
.shotover_nodes
Expand Down
2 changes: 1 addition & 1 deletion shotover/src/transforms/cassandra/sink_single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl TransformConfig for CassandraSinkSingleConfig {
&self,
transform_context: TransformContextConfig,
) -> Result<Box<dyn TransformBuilder>> {
let tls = self.tls.clone().map(TlsConnector::new).transpose()?;
let tls = self.tls.as_ref().map(TlsConnector::new).transpose()?;
Ok(Box::new(CassandraSinkSingleBuilder::new(
self.address.clone(),
transform_context.chain_name,
Expand Down
2 changes: 1 addition & 1 deletion shotover/src/transforms/kafka/sink_cluster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl TransformConfig for KafkaSinkClusterConfig {
&self,
transform_context: TransformContextConfig,
) -> Result<Box<dyn TransformBuilder>> {
let tls = self.tls.clone().map(TlsConnector::new).transpose()?;
let tls = self.tls.as_ref().map(TlsConnector::new).transpose()?;

let shotover_nodes: Result<Vec<_>> = self
.shotover_nodes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl AuthorizeScramOverMtlsConfig {
read_timeout: Option<Duration>,
) -> Result<AuthorizeScramOverMtlsBuilder> {
let mtls_connection_factory = ConnectionFactory::new(
Some(TlsConnector::new(self.tls.clone())?),
Some(TlsConnector::new(&self.tls)?),
connect_timeout,
read_timeout,
Arc::new(Notify::new()),
Expand Down
2 changes: 1 addition & 1 deletion shotover/src/transforms/kafka/sink_single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl TransformConfig for KafkaSinkSingleConfig {
&self,
transform_context: TransformContextConfig,
) -> Result<Box<dyn TransformBuilder>> {
let tls = self.tls.clone().map(TlsConnector::new).transpose()?;
let tls = self.tls.as_ref().map(TlsConnector::new).transpose()?;
Ok(Box::new(KafkaSinkSingleBuilder::new(
self.destination_port,
transform_context.chain_name,
Expand Down
2 changes: 1 addition & 1 deletion shotover/src/transforms/redis/sink_single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl TransformConfig for RedisSinkSingleConfig {
&self,
transform_context: TransformContextConfig,
) -> Result<Box<dyn TransformBuilder>> {
let tls = self.tls.clone().map(TlsConnector::new).transpose()?;
let tls = self.tls.as_ref().map(TlsConnector::new).transpose()?;
Ok(Box::new(RedisSinkSingleBuilder::new(
self.address.clone(),
tls,
Expand Down
2 changes: 1 addition & 1 deletion shotover/src/transforms/util/cluster_connection_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<C: CodecBuilder + 'static, A: Authenticator<T>, T: Token> ConnectionPool<C,
Ok(Self {
connect_timeout,
lanes: Arc::new(Mutex::new(HashMap::new())),
tls: tls.map(TlsConnector::new).transpose()?,
tls: tls.as_ref().map(TlsConnector::new).transpose()?,
codec,
authenticator,
})
Expand Down

0 comments on commit bb9f2b6

Please sign in to comment.