Skip to content

Commit

Permalink
rm_old_config_keys
Browse files Browse the repository at this point in the history
  • Loading branch information
epompeii committed Sep 20, 2023
1 parent e81a3e3 commit c8c5e55
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 62 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ heading: "Bencher Changelog"
sortOrder: 4
---

## Pending `v0.3.11`
- Add strongly typed IDs for database entities
- Remove deprecated configuration keys (`endpoint` => `console.url` and `secret_key` => `security.secret_key`)

## `v0.3.10`
- Add optional error monitoring with [Sentry](https://sentry.io)
- Start API error message improvement
Expand Down
14 changes: 4 additions & 10 deletions lib/bencher_json/src/system/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bencher_valid::{Sanitize, Secret, Url};
use bencher_valid::Sanitize;
#[cfg(feature = "schema")]
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -33,14 +33,8 @@ pub struct JsonUpdateConfig {
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
pub struct JsonConfig {
// TODO Remove deprecated endpoint
pub endpoint: Option<Url>,
// TODO Remove deprecated secret_key
pub secret_key: Option<Secret>,
// TODO Make mandatory
pub console: Option<JsonConsole>,
// TODO Make mandatory
pub security: Option<JsonSecurity>,
pub console: JsonConsole,
pub security: JsonSecurity,
pub server: JsonServer,
pub logging: JsonLogging,
pub database: JsonDatabase,
Expand All @@ -52,7 +46,7 @@ pub struct JsonConfig {

impl Sanitize for JsonConfig {
fn sanitize(&mut self) {
self.secret_key.sanitize();
self.security.sanitize();
self.database.sanitize();
self.smtp.sanitize();
#[cfg(feature = "plus")]
Expand Down
45 changes: 1 addition & 44 deletions services/api/src/config/config_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use dropshot::{
ApiDescription, ConfigDropshot, ConfigLogging, ConfigLoggingIfExists, ConfigLoggingLevel,
ConfigTls, HttpServer,
};
use slog::{debug, error, info, warn, Logger};
use slog::{debug, error, info, Logger};
use tokio::sync::mpsc::Sender;

use crate::{
Expand Down Expand Up @@ -54,8 +54,6 @@ fn into_inner(log: &Logger, config_tx: ConfigTx) -> Result<HttpServer<ApiContext
let ConfigTx { config, restart_tx } = config_tx;

let Config(JsonConfig {
endpoint,
secret_key,
console,
security,
mut server,
Expand All @@ -67,47 +65,6 @@ fn into_inner(log: &Logger, config_tx: ConfigTx) -> Result<HttpServer<ApiContext
plus,
}) = config;

// TODO Remove deprecated endpoint
let console = if let Some(console) = console {
if endpoint.is_some() {
warn!(
log,
"DEPRECATED: The `endpoint` is now `console.url`. This value will be ignored."
);
}
console
} else if let Some(endpoint) = endpoint {
warn!(
log,
"DEPRECATED: The `endpoint` is now `console.url`. This value will be used for now."
);
JsonConsole { url: endpoint }
} else {
return Err(ApiError::MissingConfigKey("console.url".into()));
};

// TODO Remove deprecated secret_key
let security = if let Some(security) = security {
if secret_key.is_some() {
warn!(
log,
"DEPRECATED: The `secret_key` is now `security.secret_key`. This value will be ignored."
);
}
security
} else if let Some(secret_key) = secret_key {
warn!(
log,
"DEPRECATED: The `secret_key` is now `security.secret_key`. This value will be used for now."
);
JsonSecurity {
issuer: None,
secret_key,
}
} else {
return Err(ApiError::MissingConfigKey("security.secret_key".into()));
};

debug!(log, "Creating internal configuration");
let private = into_private(
log,
Expand Down
10 changes: 4 additions & 6 deletions services/api/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,13 @@ impl Config {
impl Default for Config {
fn default() -> Self {
Self(JsonConfig {
endpoint: None,
secret_key: None,
console: Some(JsonConsole {
console: JsonConsole {
url: DEFAULT_CONSOLE_URL.clone().into(),
}),
security: Some(JsonSecurity {
},
security: JsonSecurity {
issuer: Some(BENCHER_DOT_DEV.into()),
secret_key: DEFAULT_SECRET_KEY.clone(),
}),
},
server: JsonServer {
bind_address: *DEFAULT_BIND_ADDRESS,
request_body_max_bytes: DEFAULT_MAX_BODY_SIZE,
Expand Down
2 changes: 0 additions & 2 deletions services/api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ pub enum ApiError {

#[error("Failed to cast integer: {0}")]
IntError(#[from] std::num::TryFromIntError),
#[error("Missing configuration key: {0}")]
MissingConfigKey(String),
#[error("Failed to parse integer: {0}")]
BadInt(i64),
#[error("Failed to parse URL encoding: {0}")]
Expand Down

0 comments on commit c8c5e55

Please sign in to comment.