Skip to content

Commit

Permalink
chore!: Remove deprecated items in preparation of 0.4 release (#253)
Browse files Browse the repository at this point in the history
In preparation for the next semver breaking release, this PR removes
some things:

- An export alias for health check structs that were moved
- Removes support for using `.` as the separate for in env var names
  • Loading branch information
spencewenski authored Jun 30, 2024
1 parent 880d850 commit b05d377
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 32 deletions.
10 changes: 3 additions & 7 deletions src/api/http/health.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::api::core::health::health_check;
use crate::api::core::health::{health_check, HeathCheckResponse};
#[cfg(all(feature = "open-api", any(feature = "db-sql", feature = "sidekiq")))]
use crate::api::core::health::{ResourceHealth, Status};
use crate::api::http::build_path;
use crate::app::context::AppContext;
use crate::error::RoadsterResult;
Expand All @@ -14,12 +16,6 @@ use axum::routing::get;
use axum::{Json, Router};
use tracing::instrument;

#[deprecated(
since = "0.3.1",
note = "Please import from `roadster::api::core::health` instead."
)]
pub use crate::api::core::health::{ErrorData, HeathCheckResponse, ResourceHealth, Status};

#[cfg(feature = "open-api")]
const TAG: &str = "Health";

Expand Down
8 changes: 0 additions & 8 deletions src/config/app_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,6 @@ impl AppConfig {
.convert_case(Case::Kebab)
.separator(ENV_VAR_SEPARATOR),
)
// This source is kept for backwards compatibility and may be removed in the next
// semver breaking release (0.4+)
.add_source(
config::Environment::default()
.prefix(ENV_VAR_PREFIX)
.convert_case(Case::Kebab)
.separator("."),
)
.set_override(ENVIRONMENT_ENV_VAR_NAME, environment_str)?
.build()?;
let config: AppConfig = config.try_deserialize()?;
Expand Down
23 changes: 6 additions & 17 deletions src/config/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,21 @@ pub(crate) const ENVIRONMENT_ENV_VAR_NAME: &str = "ENVIRONMENT";

const ENV_VAR_WITH_PREFIX: &str =
concatcp!(ENV_VAR_PREFIX, ENV_VAR_SEPARATOR, ENVIRONMENT_ENV_VAR_NAME);
// This env var is used for backwards compatibility and may be removed in the next
// semver breaking release (0.4+)
const ENV_VAR_WITH_PREFIX_OLD: &str = concatcp!(ENV_VAR_PREFIX, ".", ENVIRONMENT_ENV_VAR_NAME);

impl Environment {
// This runs before tracing is initialized, so we need to use `println` in order to
// log from this method.
#[allow(clippy::disallowed_macros)]
pub fn new() -> RoadsterResult<Self> {
// Get the stage, and validate it by parsing to the Environment enum
let environment = if let Ok(value) = env::var(ENV_VAR_WITH_PREFIX) {
println!("Using environment from `{ENV_VAR_WITH_PREFIX}` env var: {value:?}");
value
} else if let Ok(value) = env::var(ENV_VAR_WITH_PREFIX_OLD) {
// This env var is used for backwards compatibility and may be removed in the next
// semver breaking release (0.4+)
println!("Using environment from `{ENV_VAR_WITH_PREFIX_OLD}` env var: {value:?}");
value
} else {
Err(anyhow!("Neither `{ENV_VAR_WITH_PREFIX}` nor `{ENV_VAR_WITH_PREFIX_OLD}` env vars are defined."))?;
unreachable!()
};
let environment = env::var(ENV_VAR_WITH_PREFIX)
.map_err(|_| anyhow!("Env var `{ENV_VAR_WITH_PREFIX}` not defined."))?;
let environment = <Environment as FromStr>::from_str(&environment).map_err(|err| {
anyhow!("Unable to parse environment from env var value `{environment}`: {err}")
anyhow!(
"Unable to parse `{ENV_VAR_WITH_PREFIX}` env var with value `{environment}`: {err}"
)
})?;
println!("Parsed environment from env var: {environment:?}");
println!("Using environment from `{ENV_VAR_WITH_PREFIX}` env var: {environment:?}");
Ok(environment)
}
}

0 comments on commit b05d377

Please sign in to comment.