Skip to content

Commit 5134fb3

Browse files
committed
Fix no-authorization build warnings
1 parent 74f0249 commit 5134fb3

2 files changed

Lines changed: 28 additions & 12 deletions

File tree

server/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ fn main() {
8787
},
8888
};
8989

90+
#[cfg(any(feature = "jwt", feature = "sigs"))]
9091
let mut authorizer: Option<Arc<dyn Authorizer>> = None;
92+
#[cfg(not(any(feature = "jwt", feature = "sigs")))]
93+
let authorizer: Option<Arc<dyn Authorizer>> = None;
9194
#[cfg(feature = "jwt")]
9295
{
9396
if let Some(rsa_pem) = config.rsa_pem {

server/src/util/config.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const BIND_ADDR_VAR: &str = "VSS_BIND_ADDRESS";
66
const MAX_REQUEST_BODY_SIZE_VAR: &str = "VSS_MAX_REQUEST_BODY_SIZE";
77
const LOG_FILE_VAR: &str = "VSS_LOG_FILE";
88
const LOG_LEVEL_VAR: &str = "VSS_LOG_LEVEL";
9+
#[cfg(feature = "jwt")]
910
const JWT_RSA_PEM_VAR: &str = "VSS_JWT_RSA_PEM";
1011
const PSQL_USER_VAR: &str = "VSS_PSQL_USERNAME";
1112
const PSQL_PASS_VAR: &str = "VSS_PSQL_PASSWORD";
@@ -21,6 +22,7 @@ const PSQL_CERT_PEM_VAR: &str = "VSS_PSQL_CRT_PEM";
2122
struct TomlConfig {
2223
server_config: Option<ServerConfig>,
2324
log_config: Option<LogConfig>,
25+
#[cfg(feature = "jwt")]
2426
jwt_auth_config: Option<JwtAuthConfig>,
2527
postgresql_config: Option<PostgreSQLConfig>,
2628
}
@@ -31,6 +33,7 @@ struct ServerConfig {
3133
max_request_body_size: Option<usize>,
3234
}
3335

36+
#[cfg(feature = "jwt")]
3437
#[derive(Deserialize)]
3538
struct JwtAuthConfig {
3639
rsa_pem: Option<String>,
@@ -61,6 +64,7 @@ struct LogConfig {
6164
pub(crate) struct Configuration {
6265
pub(crate) bind_address: String,
6366
pub(crate) max_request_body_size: Option<usize>,
67+
#[cfg(feature = "jwt")]
6468
pub(crate) rsa_pem: Option<String>,
6569
pub(crate) postgresql_prefix: String,
6670
pub(crate) default_db: String,
@@ -90,16 +94,21 @@ fn read_config<'a, T: std::fmt::Display>(
9094
}
9195

9296
pub(crate) fn load_configuration(config_file_path: Option<&str>) -> Result<Configuration, String> {
93-
let TomlConfig { server_config, log_config, jwt_auth_config, postgresql_config } =
94-
match config_file_path {
95-
Some(path) => {
96-
let config_file = std::fs::read_to_string(path)
97-
.map_err(|e| format!("Failed to read configuration file: {}", e))?;
98-
toml::from_str(&config_file)
99-
.map_err(|e| format!("Failed to parse configuration file: {}", e))?
100-
},
101-
None => TomlConfig::default(), // All fields are set to `None`
102-
};
97+
let TomlConfig {
98+
server_config,
99+
log_config,
100+
#[cfg(feature = "jwt")]
101+
jwt_auth_config,
102+
postgresql_config,
103+
} = match config_file_path {
104+
Some(path) => {
105+
let config_file = std::fs::read_to_string(path)
106+
.map_err(|e| format!("Failed to read configuration file: {}", e))?;
107+
toml::from_str(&config_file)
108+
.map_err(|e| format!("Failed to parse configuration file: {}", e))?
109+
},
110+
None => TomlConfig::default(), // All fields are set to `None`
111+
};
103112

104113
let (bind_address_config, max_request_body_size_config) = match server_config {
105114
Some(c) => (c.bind_address, c.max_request_body_size),
@@ -151,8 +160,11 @@ pub(crate) fn load_configuration(config_file_path: Option<&str>) -> Result<Confi
151160
let log_file_config: Option<PathBuf> = log_config.and_then(|config| config.file);
152161
let log_file = log_file_env.or(log_file_config).unwrap_or(PathBuf::from("vss.log"));
153162

154-
let rsa_pem_env = read_env(JWT_RSA_PEM_VAR)?;
155-
let rsa_pem = rsa_pem_env.or(jwt_auth_config.and_then(|config| config.rsa_pem));
163+
#[cfg(feature = "jwt")]
164+
let rsa_pem = {
165+
let rsa_pem_env = read_env(JWT_RSA_PEM_VAR)?;
166+
rsa_pem_env.or(jwt_auth_config.and_then(|config| config.rsa_pem))
167+
};
156168

157169
let username_env = read_env(PSQL_USER_VAR)?;
158170
let password_env = read_env(PSQL_PASS_VAR)?;
@@ -206,6 +218,7 @@ pub(crate) fn load_configuration(config_file_path: Option<&str>) -> Result<Confi
206218
max_request_body_size,
207219
log_file,
208220
log_level,
221+
#[cfg(feature = "jwt")]
209222
rsa_pem,
210223
postgresql_prefix,
211224
default_db,

0 commit comments

Comments
 (0)