Skip to content

Commit 2c6ad9f

Browse files
Merge pull request #139 from reddevilmidzy/revert-135-dependabot/cargo/rook/secrecy-0.10.3
Revert "chore(deps): bump secrecy from 0.8.0 to 0.10.3 in /rook"
2 parents aba728b + 3de0565 commit 2c6ad9f

File tree

6 files changed

+22
-31
lines changed

6 files changed

+22
-31
lines changed

rook/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rook/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ shuttle-runtime = { version = "0.55.0", default-features = false } # see https:/
2828
shuttle-shared-db = { version = "0.55.0", features = ["postgres", "sqlx"] }
2929

3030
validator = "0.20"
31-
secrecy = { version = "0.10", features = ["serde"] }
31+
secrecy = { version = "0.8", features = ["serde"] }
3232
sqlx = { version = "0.8", features = ["runtime-tokio-rustls", "postgres", "chrono", "uuid"] }
3333
dotenvy = "0.15"
3434
chrono = { version = "0.4.41", features = ["serde"] }

rook/src/configuration.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::domain::SubscriberEmail;
22
use config::{Config, File, FileFormat};
3-
use secrecy::SecretBox;
3+
use secrecy::Secret;
44
use serde::Deserialize;
55
use std::time::Duration;
66

@@ -20,7 +20,7 @@ pub struct EmailClientSettings {
2020
pub base_url: String,
2121
pub sender_email: String,
2222
#[serde(deserialize_with = "deserialize_secret")]
23-
pub authorization_token: SecretBox<String>,
23+
pub authorization_token: Secret<String>,
2424
pub timeout_seconds: u64,
2525
}
2626

@@ -34,12 +34,12 @@ pub struct RepositoryCheckerSettings {
3434
pub interval_seconds: u64,
3535
}
3636

37-
fn deserialize_secret<'de, D>(deserializer: D) -> Result<SecretBox<String>, D::Error>
37+
fn deserialize_secret<'de, D>(deserializer: D) -> Result<Secret<String>, D::Error>
3838
where
3939
D: serde::Deserializer<'de>,
4040
{
4141
let s = String::deserialize(deserializer)?;
42-
Ok(SecretBox::init_with(|| s))
42+
Ok(Secret::new(s))
4343
}
4444

4545
impl EmailClientSettings {

rook/src/domain/email_verification.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use chrono::{DateTime, Duration, Utc};
22
use rand::{Rng, rngs::ThreadRng};
3-
use secrecy::{ExposeSecret, SecretBox};
3+
use secrecy::{ExposeSecret, Secret};
44
use serde::{Deserialize, Serialize};
55
use sqlx::{PgPool, postgres::PgQueryResult};
66

7-
#[derive(Debug, Serialize, Deserialize)]
7+
#[derive(Debug, Clone, Serialize, Deserialize)]
88
pub struct EmailVerification {
99
pub email: String,
1010
#[serde(skip_serializing)]
11-
pub code: SecretBox<String>,
11+
pub code: Secret<String>,
1212
pub created_at: DateTime<Utc>,
1313
pub expires_at: DateTime<Utc>,
1414
pub verified: bool,
@@ -75,12 +75,12 @@ impl EmailVerification {
7575
}
7676
}
7777

78-
fn generate_verification_code() -> SecretBox<String> {
78+
fn generate_verification_code() -> Secret<String> {
7979
let mut rng = ThreadRng::default();
8080
let code: String = (0..6)
8181
.map(|_| rng.random_range(0..10).to_string())
8282
.collect();
83-
SecretBox::init_with(|| code)
83+
Secret::new(code)
8484
}
8585

8686
#[derive(Debug)]
@@ -132,7 +132,7 @@ impl EmailVerificationStore {
132132

133133
Ok(record.map(|r| EmailVerification {
134134
email: r.email,
135-
code: SecretBox::init_with(|| r.verification_code.unwrap_or_default()),
135+
code: Secret::new(r.verification_code.unwrap_or_default()),
136136
created_at: r.verification_code_created_at.unwrap_or_else(Utc::now),
137137
expires_at: r.verification_code_expires_at.unwrap_or_else(Utc::now),
138138
verified: r.is_verified,

rook/src/email_client.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
use crate::domain::SubscriberEmail;
22
use reqwest::Client;
3-
use secrecy::{ExposeSecret, SecretBox};
3+
use secrecy::{ExposeSecret, Secret};
44
use std::time::Duration;
55

66
pub struct EmailClient {
77
http_client: Client,
88
base_url: String,
99
sender: SubscriberEmail,
10-
authorization_token: SecretBox<String>,
10+
authorization_token: Secret<String>,
1111
}
1212

1313
impl EmailClient {
1414
pub fn new(
1515
base_url: String,
1616
sender: SubscriberEmail,
17-
authorization_token: SecretBox<String>,
17+
authorization_token: Secret<String>,
1818
timeout: Duration,
1919
) -> Self {
2020
let http_client = Client::builder().timeout(timeout).build().unwrap();
@@ -130,15 +130,13 @@ mod tests {
130130
#[tokio::test]
131131
async fn send_email_sends_the_expected_request() {
132132
// Arrange
133-
// TODO mock server 세팅과 email_client 생성 메서드 추출해서 테스트 코드 간결하게 만들기
134133
let mock_server = MockServer::start().await;
135134
let sender = SubscriberEmail::new("sender@example.com").unwrap();
136135
let recipient = SubscriberEmail::new("recipient@example.com").unwrap();
137-
let auth_token = SecretBox::init_with(|| "test-token".to_string());
138136
let email_client = EmailClient::new(
139137
mock_server.uri(),
140138
sender,
141-
auth_token,
139+
Secret::new("test-token".to_string()),
142140
Duration::from_secs(10),
143141
);
144142

@@ -180,7 +178,7 @@ mod tests {
180178
let email_client = EmailClient::new(
181179
mock_server.uri(),
182180
sender,
183-
SecretBox::init_with(|| "test-token".to_string()),
181+
Secret::new("test-token".to_string()),
184182
Duration::from_secs(10),
185183
);
186184

@@ -214,7 +212,7 @@ mod tests {
214212
let email_client = EmailClient::new(
215213
mock_server.uri(),
216214
sender,
217-
SecretBox::init_with(|| "test-token".to_string()),
215+
Secret::new("test-token".to_string()),
218216
Duration::from_secs(10),
219217
);
220218

@@ -246,7 +244,7 @@ mod tests {
246244
let email_client = EmailClient::new(
247245
mock_server.uri(),
248246
sender,
249-
SecretBox::init_with(|| "test-token".to_string()),
247+
Secret::new("test-token".to_string()),
250248
Duration::from_secs(10),
251249
);
252250

@@ -285,7 +283,7 @@ mod tests {
285283
let email_client = EmailClient::new(
286284
mock_server.uri(),
287285
sender,
288-
SecretBox::init_with(|| "test-token".to_string()),
286+
Secret::new("test-token".to_string()),
289287
Duration::from_secs(10),
290288
);
291289

rook/src/main.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use axum::{
1616
routing::{delete, get, post},
1717
};
1818
use chrono::{FixedOffset, Utc};
19-
use secrecy::{ExposeSecret, SecretBox};
2019
use sqlx::PgPool;
2120
use std::{fmt, sync::Arc, time::Duration};
2221
use tower_http::cors::CorsLayer;
@@ -150,13 +149,7 @@ async fn main(#[shuttle_shared_db::Postgres] pool: PgPool) -> shuttle_axum::Shut
150149
let email_client = EmailClient::new(
151150
configuration.email_client.base_url.clone(),
152151
sender,
153-
SecretBox::init_with(|| {
154-
configuration
155-
.email_client
156-
.authorization_token
157-
.expose_secret()
158-
.clone()
159-
}),
152+
configuration.email_client.authorization_token.clone(),
160153
configuration.email_client.timeout(),
161154
);
162155

0 commit comments

Comments
 (0)