Skip to content

Commit

Permalink
style: variable renaming to match actual use
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-hagemann committed Nov 26, 2024
1 parent cf799f8 commit ce4dbec
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ pub struct Config {
pub jwt_secret: SecretString,
/// The base URI for snapcraft.io
pub snapcraft_io_uri: String,
/// The path to the tls certificate
pub tls_cert_path: Option<String>,
/// The path to the tls key
/// The path to the tls keychain
pub tls_keychain_path: Option<String>,
/// The path to the tls private key
pub tls_key_path: Option<String>,
}

Expand Down
1 change: 1 addition & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct Context {
pub config: Config,
pub jwt_encoder: JwtEncoder,
pub http_client: reqwest::Client,

/// In progress category updates that we need to block on
pub category_updates: Mutex<HashMap<String, Arc<Notify>>>,
}
Expand Down
14 changes: 7 additions & 7 deletions src/grpc/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{config, db, jwt::JwtVerifier, middleware::AuthLayer, Context};
use crate::{db, jwt::JwtVerifier, middleware::AuthLayer, Context};
use std::{fs::read_to_string, net::SocketAddr};
use tonic::{
transport::{Identity, Server, ServerTlsConfig},
Expand All @@ -24,18 +24,18 @@ pub async fn run_server(ctx: Context) -> Result<(), Box<dyn std::error::Error>>
let verifier = JwtVerifier::from_secret(&ctx.config.jwt_secret)?;
let addr: SocketAddr = ctx.config.socket().parse()?;

let cert_path = ctx.config.tls_cert_path.clone();
let keychain_path = ctx.config.tls_keychain_path.clone();
let key_path = ctx.config.tls_key_path.clone();

let builder = match (cert_path, key_path) {
(Some(cert_path), Some(key_path)) => {
let cert = read_to_string(cert_path)?;
let builder = match (keychain_path, key_path) {
(Some(keychain_path), Some(key_path)) => {
let keychain = read_to_string(keychain_path)?;
let key = read_to_string(key_path)?;
let identity = Identity::from_pem(cert, key);
let identity = Identity::from_pem(keychain, key);
Server::builder().tls_config(ServerTlsConfig::new().identity(identity))?
}
(Some(_), None) | (None, Some(_)) => {
panic!("Both TLS certificate and key must be provided, or neither.");
panic!("Both TLS keychain and private key must be provided, or neither.");
}
(None, None) => {
warn!("TLS is not configured as the environment variables are not set.");
Expand Down

0 comments on commit ce4dbec

Please sign in to comment.