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
15 changes: 4 additions & 11 deletions proxy/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ pub(crate) struct GetCertsFromBroker {
}

impl GetCertsFromBroker {
pub fn new(client: SamplyHttpClient, config: Config) -> Self {
Self { client, config }
}

async fn request(&self, path: &str) -> Result<reqwest::Response, SamplyBeamError> {
let uri = Uri::builder()
.scheme(self.config.broker_uri.scheme())
Expand Down Expand Up @@ -95,17 +99,6 @@ impl GetCerts for GetCertsFromBroker {
}
}

pub(crate) fn build_cert_getter(
config: Config,
client: SamplyHttpClient,
) -> Result<GetCertsFromBroker, SamplyBeamError> {
let client = client;
Ok(GetCertsFromBroker {
client,
config,
})
}

pub async fn init_public_crypto_for_proxy(
config: &Config
) -> Result<(ProxyCertInfo, config::ConfigCrypto), SamplyBeamError> {
Expand Down
13 changes: 7 additions & 6 deletions proxy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use tracing::{debug, error, info, warn};
use tryhard::{backoff_strategies::ExponentialBackoff, RetryFuture, RetryFutureConfig};

use crate::config::{CliArgs, Config};
use crate::crypto::GetCertsFromBroker;
use crate::serve_tasks::sign_request;

mod auth;
Expand Down Expand Up @@ -69,7 +70,11 @@ pub async fn main() -> anyhow::Result<()> {
info!("Connected to Broker: {}", &config.broker_uri);
}

let result = retry_notify(|| init_crypto(&config, &client), |err, dur| {
shared::crypto::init_cert_getter(GetCertsFromBroker::new(
client.clone(),
config.clone(),
));
let result = retry_notify(|| init_crypto(&config), |err, dur| {
warn!("Still trying to initialize certificate chain: {err}. Retrying in {}s", dur.as_secs());
}).await;
let config = match result {
Expand Down Expand Up @@ -105,11 +110,7 @@ where
.on_retry(Box::new(move |_, b, e| futures::future::ready(on_error(e, b.unwrap_or(Duration::MAX)))))
}

async fn init_crypto(config: &Config, client: &SamplyHttpClient) -> Result<config::ConfigCrypto, SamplyBeamError> {
shared::crypto::init_cert_getter(crypto::build_cert_getter(
config.clone(),
client.clone(),
)?);
async fn init_crypto(config: &Config) -> Result<config::ConfigCrypto, SamplyBeamError> {
shared::crypto::init_ca_chain(&config.rootcert).await?;

let _public_info: Vec<_> =
Expand Down
Loading