Skip to content

Commit 2520d1b

Browse files
authored
Merge pull request #37 from unikmhz/config-maint-mode
feat: Configurable maintenance mode
2 parents 43f83c0 + bebed64 commit 2520d1b

File tree

15 files changed

+19
-47
lines changed

15 files changed

+19
-47
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "uxum"
3-
version = "0.6.1"
3+
version = "0.7.0"
44
authors = ["Alex Unigovsky <unik@devrandom.ru>"]
55
license = "MIT OR Apache-2.0"
66
edition = "2021"
@@ -37,7 +37,7 @@ sign-tag = false
3737
tag-message = "uxum {{version}}"
3838

3939
[dependencies]
40-
uxum-macros = { path = "uxum-macros", version = "0.4" }
40+
uxum-macros = { path = "uxum-macros", version = "=0.4.1" }
4141

4242
argon2 = "0.5"
4343
askama = "0.13"

examples/advanced_server/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,14 +380,14 @@ mod hello {
380380
#[handler]
381381
async fn name_from_text_body(state: State<HelloState>, body: String) -> String {
382382
state.log_name(&body);
383-
format!("Hello {}!", body)
383+
format!("Hello {body}!")
384384
}
385385

386386
/// Greet someone using a name from a binary body.
387387
#[handler]
388388
async fn name_from_binary_body(state: State<HelloState>, body: Bytes) -> String {
389389
state.log_name(std::str::from_utf8(&body).unwrap_or(""));
390-
format!("Hello {:?}!", body)
390+
format!("Hello {body:?}!")
391391
}
392392

393393
/// Greet someone using a name from a URL path element.

src/auth/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ mod serde_impls {
152152
{
153153
PasswordHashString::new(v)
154154
.map(Into::into)
155-
.map_err(|err| E::custom(format!("unable to parse PHC format: {}", err)))
155+
.map_err(|err| E::custom(format!("unable to parse PHC format: {err}")))
156156
}
157157
}
158158
}

src/auth/extractor.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ impl AuthExtractor for NoOpAuthExtractor {
6464
Ok(((), ()))
6565
}
6666

67-
#[must_use]
6867
fn error_response(&self, err: AuthError) -> Response<Body> {
6968
// This shuld never get executed for a NoOp extractor
7069
error!("tried to generate auth error response for NoOpAuthExtractor");
@@ -106,7 +105,6 @@ impl AuthExtractor for BasicAuthExtractor {
106105
}
107106
}
108107

109-
#[must_use]
110108
fn error_response(&self, err: AuthError) -> Response<Body> {
111109
let status = match err {
112110
AuthError::NoAuthProvided | AuthError::UserNotFound | AuthError::AuthFailed => {
@@ -135,7 +133,6 @@ impl AuthExtractor for BasicAuthExtractor {
135133
resp
136134
}
137135

138-
#[must_use]
139136
fn security_schemes(&self) -> BTreeMap<String, openapi3::SecurityScheme> {
140137
maplit::btreemap! {
141138
"basic".into() => openapi3::SecurityScheme {
@@ -240,7 +237,6 @@ impl AuthExtractor for HeaderAuthExtractor {
240237
Ok((user, tokens))
241238
}
242239

243-
#[must_use]
244240
fn error_response(&self, err: AuthError) -> Response<Body> {
245241
let status = match err {
246242
AuthError::NoAuthProvided
@@ -255,7 +251,6 @@ impl AuthExtractor for HeaderAuthExtractor {
255251
.into_response()
256252
}
257253

258-
#[must_use]
259254
fn security_schemes(&self) -> BTreeMap<String, openapi3::SecurityScheme> {
260255
maplit::btreemap! {
261256
"api-name".into() => openapi3::SecurityScheme {

src/layers/cors.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ mod serde_impls {
142142
match v.to_ascii_lowercase().as_str() {
143143
"any" => Ok(AnyOr::Any),
144144
other => Err(E::custom(format_args!(
145-
"expecting string 'any', got '{}'",
146-
other
145+
"expecting string 'any', got '{other}'"
147146
))),
148147
}
149148
}

src/layers/request_id.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ where
3030
{
3131
type Service = RecordRequestIdService<S>;
3232

33-
#[must_use]
3433
fn layer(&self, inner: S) -> Self::Service {
3534
RecordRequestIdService::new(inner)
3635
}

src/logging/json.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ pub(crate) struct ExtensibleJsonFormat<T = SystemTime> {
162162
}
163163

164164
impl Default for ExtensibleJsonFormat {
165-
#[must_use]
166165
fn default() -> Self {
167166
Self {
168167
timer: SystemTime,
@@ -507,7 +506,7 @@ where
507506
// If we *aren't* in debug mode, it's probably best not
508507
// crash the program, but let's at least make sure it's clear
509508
// that the fields are not supposed to be missing.
510-
Err(e) => serializer.serialize_entry("field_error", &format!("{}", e))?,
509+
Err(e) => serializer.serialize_entry("field_error", &format!("{e}"))?,
511510
};
512511
serializer.serialize_entry("name", self.0.metadata().name())?;
513512
serializer.end()

src/probes.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ pub struct ProbeConfig {
4545
/// Runtime watchdog configuration.
4646
#[serde(default, skip_serializing_if = "Option::is_none")]
4747
watchdog: Option<WatchdogConfig>,
48+
#[serde(default)]
49+
start_in_maintenance: bool,
4850
}
4951

5052
impl Default for ProbeConfig {
@@ -55,6 +57,7 @@ impl Default for ProbeConfig {
5557
maintenance_on_path: Self::default_maintenance_on_path(),
5658
maintenance_off_path: Self::default_maintenance_off_path(),
5759
watchdog: Some(WatchdogConfig::default()),
60+
start_in_maintenance: false,
5861
}
5962
}
6063
}
@@ -102,7 +105,7 @@ impl ProbeConfig {
102105
{
103106
// TODO: add toggle for probes, and possibly for maintenance mode.
104107
let _span = debug_span!("build_probes").entered();
105-
let state = ProbeState::new(self.watchdog.as_ref());
108+
let state = ProbeState::new(self.start_in_maintenance, self.watchdog.as_ref());
106109
Router::new()
107110
.route(&self.readiness_path, routing::get(readiness_probe))
108111
.route(&self.liveness_path, routing::get(liveness_probe))
@@ -148,9 +151,9 @@ impl Default for ProbeState {
148151
impl ProbeState {
149152
/// Create new [`ProbeState`] with optional [`WatchdogConfig`].
150153
#[must_use]
151-
pub fn new(watchdog: Option<&WatchdogConfig>) -> Self {
154+
pub fn new(in_maint: bool, watchdog: Option<&WatchdogConfig>) -> Self {
152155
Self(Arc::new(ProbeStateInner {
153-
in_maintenance: AtomicBool::new(true),
156+
in_maintenance: AtomicBool::new(in_maint),
154157
watchdog: watchdog.map(|wc| {
155158
let mut watchdog: Watchdog = wc.clone().into();
156159
watchdog.start();

src/response.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ mod impls {
4949
impl GetResponseSchemas for String {
5050
type ResponseIter = [ResponseSchema; 1];
5151

52-
#[must_use]
5352
fn get_response_schemas(gen: &mut SchemaGenerator) -> Self::ResponseIter {
5453
[ResponseSchema {
5554
status: StatusCode::OK,
@@ -70,7 +69,6 @@ mod impls {
7069
impl GetResponseSchemas for str {
7170
type ResponseIter = [ResponseSchema; 1];
7271

73-
#[must_use]
7472
fn get_response_schemas(gen: &mut SchemaGenerator) -> Self::ResponseIter {
7573
<String as GetResponseSchemas>::get_response_schemas(gen)
7674
}
@@ -79,7 +77,6 @@ mod impls {
7977
impl GetResponseSchemas for () {
8078
type ResponseIter = [ResponseSchema; 1];
8179

82-
#[must_use]
8380
fn get_response_schemas(_gen: &mut SchemaGenerator) -> Self::ResponseIter {
8481
[ResponseSchema {
8582
status: StatusCode::OK,
@@ -107,7 +104,6 @@ mod impls {
107104
{
108105
type ResponseIter = T::ResponseIter;
109106

110-
#[must_use]
111107
fn get_response_schemas(gen: &mut schemars::gen::SchemaGenerator) -> Self::ResponseIter {
112108
T::get_response_schemas(gen)
113109
}
@@ -119,7 +115,6 @@ mod impls {
119115
{
120116
type ResponseIter = [ResponseSchema; 1];
121117

122-
#[must_use]
123118
fn get_response_schemas(gen: &mut SchemaGenerator) -> Self::ResponseIter {
124119
[ResponseSchema {
125120
status: StatusCode::OK,
@@ -144,7 +139,6 @@ mod impls {
144139
{
145140
type ResponseIter = Vec<ResponseSchema>;
146141

147-
#[must_use]
148142
fn get_response_schemas(gen: &mut SchemaGenerator) -> Self::ResponseIter {
149143
T::get_response_schemas(gen)
150144
.into_iter()

uxum-macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "uxum-macros"
3-
version = "0.4.0"
3+
version = "0.4.1"
44
authors = ["Alex Unigovsky <unik@devrandom.ru>"]
55
license = "MIT OR Apache-2.0"
66
edition = "2021"

0 commit comments

Comments
 (0)