Skip to content

Commit fa24387

Browse files
committed
feat: [#243] convert HTTP API admin token and SSH test password to secret types
1 parent 7521a4f commit fa24387

File tree

9 files changed

+37
-25
lines changed

9 files changed

+37
-25
lines changed

src/application/command_handlers/create/config/tracker/http_api_section.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ use serde::{Deserialize, Serialize};
55

66
use crate::application::command_handlers::create::config::errors::CreateConfigError;
77
use crate::domain::tracker::HttpApiConfig;
8+
use crate::shared::secrets::PlainApiToken;
89

910
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, JsonSchema)]
1011
pub struct HttpApiSection {
1112
pub bind_address: String,
12-
pub admin_token: String,
13+
pub admin_token: PlainApiToken,
1314
}
1415

1516
impl HttpApiSection {
@@ -38,7 +39,7 @@ impl HttpApiSection {
3839
// Domain type now uses SocketAddr (Step 0.7 completed)
3940
Ok(HttpApiConfig {
4041
bind_address,
41-
admin_token: self.admin_token.clone(),
42+
admin_token: self.admin_token.clone().into(),
4243
})
4344
}
4445
}
@@ -62,7 +63,7 @@ mod tests {
6263
config.bind_address,
6364
"0.0.0.0:1212".parse::<SocketAddr>().unwrap()
6465
);
65-
assert_eq!(config.admin_token, "MyAccessToken");
66+
assert_eq!(config.admin_token.expose_secret(), "MyAccessToken");
6667
}
6768

6869
#[test]

src/domain/environment/context.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,11 @@ impl EnvironmentContext {
328328
/// Returns the admin token
329329
#[must_use]
330330
pub fn admin_token(&self) -> &str {
331-
&self.user_inputs.tracker.http_api.admin_token
331+
self.user_inputs
332+
.tracker
333+
.http_api
334+
.admin_token
335+
.expose_secret()
332336
}
333337

334338
/// Returns the Prometheus configuration if enabled

src/domain/tracker/config.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::net::SocketAddr;
88
use serde::{Deserialize, Serialize};
99

1010
use super::{DatabaseConfig, SqliteConfig};
11+
use crate::shared::ApiToken;
1112

1213
/// Tracker deployment configuration
1314
///
@@ -37,7 +38,7 @@ use super::{DatabaseConfig, SqliteConfig};
3738
/// ],
3839
/// http_api: HttpApiConfig {
3940
/// bind_address: "0.0.0.0:1212".parse().unwrap(),
40-
/// admin_token: "MyAccessToken".to_string(),
41+
/// admin_token: "MyAccessToken".to_string().into(),
4142
/// },
4243
/// };
4344
/// ```
@@ -99,7 +100,7 @@ pub struct HttpApiConfig {
99100
pub bind_address: SocketAddr,
100101

101102
/// Admin access token for HTTP API authentication
102-
pub admin_token: String,
103+
pub admin_token: ApiToken,
103104
}
104105

105106
impl Default for TrackerConfig {
@@ -129,7 +130,7 @@ impl Default for TrackerConfig {
129130
}],
130131
http_api: HttpApiConfig {
131132
bind_address: "0.0.0.0:1212".parse().expect("valid address"),
132-
admin_token: "MyAccessToken".to_string(),
133+
admin_token: "MyAccessToken".to_string().into(),
133134
},
134135
}
135136
}
@@ -171,7 +172,7 @@ mod tests {
171172
}],
172173
http_api: HttpApiConfig {
173174
bind_address: "0.0.0.0:1212".parse().unwrap(),
174-
admin_token: "test_token".to_string(),
175+
admin_token: "test_token".to_string().into(),
175176
},
176177
};
177178

@@ -194,7 +195,7 @@ mod tests {
194195
http_trackers: vec![],
195196
http_api: HttpApiConfig {
196197
bind_address: "0.0.0.0:1212".parse().unwrap(),
197-
admin_token: "token123".to_string(),
198+
admin_token: "token123".to_string().into(),
198199
},
199200
};
200201

@@ -233,6 +234,6 @@ mod tests {
233234
config.http_api.bind_address,
234235
"0.0.0.0:1212".parse::<SocketAddr>().unwrap()
235236
);
236-
assert_eq!(config.http_api.admin_token, "MyAccessToken");
237+
assert_eq!(config.http_api.admin_token.expose_secret(), "MyAccessToken");
237238
}
238239
}

src/domain/tracker/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
//! ],
3838
//! http_api: HttpApiConfig {
3939
//! bind_address: "0.0.0.0:1212".parse().unwrap(),
40-
//! admin_token: "MyToken".to_string(),
40+
//! admin_token: "MyToken".to_string().into(),
4141
//! },
4242
//! };
4343
//! ```

src/infrastructure/templating/ansible/template/wrappers/variables/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ mod tests {
201201
}],
202202
http_api: HttpApiConfig {
203203
bind_address: "0.0.0.0:1212".parse().unwrap(),
204-
admin_token: "MyAccessToken".to_string(),
204+
admin_token: "MyAccessToken".to_string().into(),
205205
},
206206
};
207207

@@ -229,7 +229,7 @@ mod tests {
229229
http_trackers: vec![],
230230
http_api: HttpApiConfig {
231231
bind_address: "0.0.0.0:1212".parse().unwrap(),
232-
admin_token: "Token123".to_string(),
232+
admin_token: "Token123".to_string().into(),
233233
},
234234
};
235235

@@ -267,7 +267,7 @@ mod tests {
267267
}],
268268
http_api: HttpApiConfig {
269269
bind_address: "0.0.0.0:1212".parse().unwrap(),
270-
admin_token: "Token".to_string(),
270+
admin_token: "Token".to_string().into(),
271271
},
272272
};
273273

src/infrastructure/templating/prometheus/template/renderer/project_generator.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,11 @@ impl PrometheusProjectGenerator {
153153
tracker_config: &TrackerConfig,
154154
) -> PrometheusContext {
155155
let scrape_interval = prometheus_config.scrape_interval;
156-
let api_token = tracker_config.http_api.admin_token.clone();
156+
let api_token = tracker_config
157+
.http_api
158+
.admin_token
159+
.expose_secret()
160+
.to_string();
157161

158162
// Extract port from SocketAddr
159163
let api_port = tracker_config.http_api.bind_address.port();
@@ -204,7 +208,7 @@ scrape_configs:
204208
TrackerConfig {
205209
http_api: HttpApiConfig {
206210
bind_address: "0.0.0.0:1212".parse().expect("valid address"),
207-
admin_token: "test_admin_token".to_string(),
211+
admin_token: "test_admin_token".to_string().into(),
208212
},
209213
..Default::default()
210214
}
@@ -321,7 +325,7 @@ scrape_configs:
321325

322326
let prometheus_config = PrometheusConfig::default();
323327
let mut tracker_config = create_test_tracker_config();
324-
tracker_config.http_api.admin_token = "custom_admin_token_123".to_string();
328+
tracker_config.http_api.admin_token = "custom_admin_token_123".to_string().into();
325329

326330
generator
327331
.render(&prometheus_config, &tracker_config)

src/infrastructure/templating/tracker/template/renderer/project_generator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ mod tests {
227227
}],
228228
http_api: HttpApiConfig {
229229
bind_address: "0.0.0.0:1212".parse().unwrap(),
230-
admin_token: "test_token".to_string(),
230+
admin_token: "test_token".to_string().into(),
231231
},
232232
};
233233

@@ -274,7 +274,7 @@ mod tests {
274274
}],
275275
http_api: HttpApiConfig {
276276
bind_address: "0.0.0.0:1212".parse().unwrap(),
277-
admin_token: "test_token".to_string(),
277+
admin_token: "test_token".to_string().into(),
278278
},
279279
};
280280

src/infrastructure/templating/tracker/template/wrapper/tracker_config/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use crate::domain::environment::TrackerConfig;
4242
/// ],
4343
/// http_api: HttpApiConfig {
4444
/// bind_address: "0.0.0.0:1212".parse().unwrap(),
45-
/// admin_token: "MyToken".to_string(),
45+
/// admin_token: "MyToken".to_string().into(),
4646
/// },
4747
/// };
4848
/// let context = TrackerContext::from_config(&tracker_config);
@@ -220,7 +220,7 @@ mod tests {
220220
}],
221221
http_api: HttpApiConfig {
222222
bind_address: "0.0.0.0:1212".parse().unwrap(),
223-
admin_token: "test_admin_token".to_string(),
223+
admin_token: "test_admin_token".to_string().into(),
224224
},
225225
}
226226
}
@@ -266,7 +266,7 @@ mod tests {
266266
}],
267267
http_api: HttpApiConfig {
268268
bind_address: "0.0.0.0:1212".parse().unwrap(),
269-
admin_token: "test_token".to_string(),
269+
admin_token: "test_token".to_string().into(),
270270
},
271271
};
272272

src/testing/integration/ssh_server/config.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
33
use std::path::PathBuf;
44

5+
use crate::shared::secrets::PlainPassword;
6+
57
use super::constants::{
68
CONTAINER_STARTUP_WAIT_SECS, DEFAULT_TEST_PASSWORD, DEFAULT_TEST_USERNAME, DOCKERFILE_DIR,
79
MOCK_SSH_PORT, SSH_SERVER_IMAGE_NAME, SSH_SERVER_IMAGE_TAG,
@@ -40,7 +42,7 @@ pub struct SshServerConfig {
4042
pub username: String,
4143

4244
/// Test password configured in the SSH server
43-
pub password: String,
45+
pub password: PlainPassword,
4446

4547
/// Container startup wait time in seconds
4648
pub startup_wait_secs: u64,
@@ -119,7 +121,7 @@ pub struct SshServerConfigBuilder {
119121
image_name: Option<String>,
120122
image_tag: Option<String>,
121123
username: Option<String>,
122-
password: Option<String>,
124+
password: Option<PlainPassword>,
123125
startup_wait_secs: Option<u64>,
124126
dockerfile_dir: Option<PathBuf>,
125127
mock_port: Option<u16>,
@@ -149,7 +151,7 @@ impl SshServerConfigBuilder {
149151

150152
/// Set the test password
151153
#[must_use]
152-
pub fn password(mut self, password: impl Into<String>) -> Self {
154+
pub fn password(mut self, password: impl Into<PlainPassword>) -> Self {
153155
self.password = Some(password.into());
154156
self
155157
}

0 commit comments

Comments
 (0)