Skip to content

Commit b01065e

Browse files
committed
style(rust): apply cargo fmt across all crates
Unbreaks Rust CI's cargo fmt --check job on main.
1 parent 84e4408 commit b01065e

3 files changed

Lines changed: 88 additions & 44 deletions

File tree

rgtv-cli/src/main.rs

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,10 @@ struct Config {
9292

9393
impl Config {
9494
fn from_env() -> Result<Self, String> {
95-
let base_url = env::var("RGTV_URL")
96-
.unwrap_or_else(|_| "http://127.0.0.1:9100".to_string());
97-
let agent_token = env::var("RGTV_AGENT_TOKEN")
98-
.map_err(|_| "RGTV_AGENT_TOKEN must be set".to_string())?;
99-
let broker_bin = env::var("RGTV_BROKER_BIN")
100-
.unwrap_or_else(|_| "vault-broker".to_string());
95+
let base_url = env::var("RGTV_URL").unwrap_or_else(|_| "http://127.0.0.1:9100".to_string());
96+
let agent_token =
97+
env::var("RGTV_AGENT_TOKEN").map_err(|_| "RGTV_AGENT_TOKEN must be set".to_string())?;
98+
let broker_bin = env::var("RGTV_BROKER_BIN").unwrap_or_else(|_| "vault-broker".to_string());
10199
Ok(Config {
102100
base_url,
103101
agent_token: Zeroizing::new(agent_token),
@@ -155,7 +153,8 @@ fn get_credentials(cfg: &Config) -> Result<CredentialsResponse, String> {
155153
.set("Authorization", &bearer(&cfg.agent_token))
156154
.call()
157155
.map_err(ureq_err)?;
158-
resp.into_json().map_err(|e| format!("parse credentials: {e}"))
156+
resp.into_json()
157+
.map_err(|e| format!("parse credentials: {e}"))
159158
}
160159

161160
fn post_grant(cfg: &Config, hint: &str) -> Result<GrantResponse, String> {
@@ -203,7 +202,10 @@ fn log_file() -> PathBuf {
203202

204203
fn write_pid(pid: u32) -> std::io::Result<()> {
205204
let path = pid_file();
206-
fs::create_dir_all(path.parent().expect("invariant: pid_file() path always has a parent"))?;
205+
fs::create_dir_all(
206+
path.parent()
207+
.expect("invariant: pid_file() path always has a parent"),
208+
)?;
207209
let mut f = fs::File::create(&path)?;
208210
write!(f, "{pid}")
209211
}
@@ -248,10 +250,7 @@ fn cmd_get(cfg: &Config, args: &[String]) {
248250
(rest[1].clone(), &rest[2..])
249251
} else {
250252
// Default env var name: hint uppercased, dashes and dots → underscores.
251-
let default_var = hint
252-
.to_uppercase()
253-
.replace('-', "_")
254-
.replace('.', "_");
253+
let default_var = hint.to_uppercase().replace('-', "_").replace('.', "_");
255254
(default_var, rest)
256255
};
257256

@@ -365,8 +364,10 @@ fn cmd_verify(cfg: &Config, args: &[String]) {
365364
use zeroize::Zeroize;
366365
value.zeroize();
367366

368-
println!("ok — hint '{hint}' is redeemable (grant {}, TTL {}s)",
369-
grant.grant_id, grant.expires_in_secs);
367+
println!(
368+
"ok — hint '{hint}' is redeemable (grant {}, TTL {}s)",
369+
grant.grant_id, grant.expires_in_secs
370+
);
370371
}
371372

372373
/// `rgtv audit [--max <n>]`
@@ -417,7 +418,12 @@ fn cmd_daemon_start(cfg: &Config) {
417418
}
418419

419420
let log_path = log_file();
420-
fs::create_dir_all(log_path.parent().expect("invariant: log_file() path always has a parent")).unwrap_or_else(|e| {
421+
fs::create_dir_all(
422+
log_path
423+
.parent()
424+
.expect("invariant: log_file() path always has a parent"),
425+
)
426+
.unwrap_or_else(|e| {
421427
eprintln!("error: could not create state dir: {e}");
422428
process::exit(1);
423429
});
@@ -462,7 +468,10 @@ fn cmd_daemon_start(cfg: &Config) {
462468
for i in 0..10 {
463469
std::thread::sleep(Duration::from_secs(1));
464470
if let Ok(h) = get_health(cfg) {
465-
println!("vault-broker ready: {} ({} credentials loaded)", h.status, h.credential_count);
471+
println!(
472+
"vault-broker ready: {} ({} credentials loaded)",
473+
h.status, h.credential_count
474+
);
466475
println!("logs: {}", log_path.display());
467476
return;
468477
}
@@ -548,8 +557,8 @@ fn cmd_daemon_status(cfg: &Config) {
548557
fn cmd_daemon(cfg: &Config, args: &[String]) {
549558
let sub = args.first().map(String::as_str).unwrap_or("");
550559
match sub {
551-
"start" => cmd_daemon_start(cfg),
552-
"stop" => cmd_daemon_stop(),
560+
"start" => cmd_daemon_start(cfg),
561+
"stop" => cmd_daemon_stop(),
553562
"status" => cmd_daemon_status(cfg),
554563
other => {
555564
eprintln!("Unknown daemon sub-command: '{other}'");
@@ -602,11 +611,11 @@ fn main() {
602611
});
603612

604613
match args[1].as_str() {
605-
"get" => cmd_get(&cfg, &args[2..]),
606-
"list" => cmd_list(&cfg),
614+
"get" => cmd_get(&cfg, &args[2..]),
615+
"list" => cmd_list(&cfg),
607616
"status" => cmd_status(&cfg),
608617
"verify" => cmd_verify(&cfg, &args[2..]),
609-
"audit" => cmd_audit(&args[2..]),
618+
"audit" => cmd_audit(&args[2..]),
610619
"rotate" => cmd_rotate(&args[2..]),
611620
"daemon" => cmd_daemon(&cfg, &args[2..]),
612621
"--version" | "version" => println!("rgtv 0.1.0"),

vault-broker/src/main.rs

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,13 @@ async fn list_credentials(
181181
headers: HeaderMap,
182182
) -> impl IntoResponse {
183183
if let Err(code) = authenticate(&headers, &state.agent_token) {
184-
return (code, Json(ErrorResponse { error: "unauthorized".into() })).into_response();
184+
return (
185+
code,
186+
Json(ErrorResponse {
187+
error: "unauthorized".into(),
188+
}),
189+
)
190+
.into_response();
185191
}
186192
let mut hints: Vec<String> = state.credentials.keys().cloned().collect();
187193
hints.sort();
@@ -191,7 +197,11 @@ async fn list_credentials(
191197

192198
async fn health(State(state): State<SharedState>) -> impl IntoResponse {
193199
let cred_count = state.credentials.len();
194-
let grants_active = state.grants.lock().expect("invariant: mutex is not poisoned").len();
200+
let grants_active = state
201+
.grants
202+
.lock()
203+
.expect("invariant: mutex is not poisoned")
204+
.len();
195205
info!(cred_count, grants_active, "health check");
196206
Json(HealthResponse {
197207
status: "ok",
@@ -209,7 +219,13 @@ async fn create_grant(
209219
Json(req): Json<GrantRequest>,
210220
) -> impl IntoResponse {
211221
if let Err(code) = authenticate(&headers, &state.agent_token) {
212-
return (code, Json(ErrorResponse { error: "unauthorized".into() })).into_response();
222+
return (
223+
code,
224+
Json(ErrorResponse {
225+
error: "unauthorized".into(),
226+
}),
227+
)
228+
.into_response();
213229
}
214230

215231
// Validate hint exists.
@@ -228,7 +244,10 @@ async fn create_grant(
228244
let expires_at = SystemTime::now() + state.grant_ttl;
229245

230246
{
231-
let mut grants = state.grants.lock().expect("invariant: mutex is not poisoned");
247+
let mut grants = state
248+
.grants
249+
.lock()
250+
.expect("invariant: mutex is not poisoned");
232251

233252
// Purge expired grants to keep memory tidy.
234253
let now = SystemTime::now();
@@ -267,12 +286,21 @@ async fn redeem_grant(
267286
Path(grant_id): Path<String>,
268287
) -> impl IntoResponse {
269288
if let Err(code) = authenticate(&headers, &state.agent_token) {
270-
return (code, Json(ErrorResponse { error: "unauthorized".into() })).into_response();
289+
return (
290+
code,
291+
Json(ErrorResponse {
292+
error: "unauthorized".into(),
293+
}),
294+
)
295+
.into_response();
271296
}
272297

273298
// Retrieve and immediately remove the grant.
274299
let hint = {
275-
let mut grants = state.grants.lock().expect("invariant: mutex is not poisoned");
300+
let mut grants = state
301+
.grants
302+
.lock()
303+
.expect("invariant: mutex is not poisoned");
276304
match grants.remove(&grant_id) {
277305
None => {
278306
warn!(%grant_id, "redeem: grant not found or already redeemed");
@@ -344,15 +372,16 @@ async fn redeem_grant(
344372
async fn main() {
345373
tracing_subscriber::fmt()
346374
.with_env_filter(
347-
tracing_subscriber::EnvFilter::try_from_default_env()
348-
.unwrap_or_else(|_| "vault_broker=info,tower_http=warn".parse().expect("invariant: hardcoded filter string is valid")),
375+
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| {
376+
"vault_broker=info,tower_http=warn"
377+
.parse()
378+
.expect("invariant: hardcoded filter string is valid")
379+
}),
349380
)
350381
.init();
351382

352-
let agent_token = Zeroizing::new(
353-
env::var("RGTV_AGENT_TOKEN")
354-
.expect("RGTV_AGENT_TOKEN must be set"),
355-
);
383+
let agent_token =
384+
Zeroizing::new(env::var("RGTV_AGENT_TOKEN").expect("RGTV_AGENT_TOKEN must be set"));
356385
let grant_ttl_secs: u64 = env::var("RGTV_GRANT_TTL_SECS")
357386
.ok()
358387
.and_then(|v| v.parse().ok())
@@ -384,6 +413,10 @@ async fn main() {
384413
let addr = SocketAddr::from(([0, 0, 0, 0, 0, 0, 0, 0], port));
385414
info!(%addr, grant_ttl_secs, "vault-broker starting");
386415

387-
let listener = tokio::net::TcpListener::bind(addr).await.expect("invariant: bind to [::]:port succeeds");
388-
axum::serve(listener, app).await.expect("invariant: axum server runs until shutdown");
416+
let listener = tokio::net::TcpListener::bind(addr)
417+
.await
418+
.expect("invariant: bind to [::]:port succeeds");
419+
axum::serve(listener, app)
420+
.await
421+
.expect("invariant: axum server runs until shutdown");
389422
}

vault-worker/src/lib.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,13 @@ fn check_auth(req: &Request, env: &Env) -> std::result::Result<(), Response> {
167167
Ok(v) => v.to_string(),
168168
Err(_) => {
169169
// Fail closed — if the secret is missing, reject every request.
170-
return Err(Response::error(
171-
"server misconfigured: RGTV_AGENT_TOKEN not set",
172-
500,
173-
)
174-
.unwrap_or_else(|_| Response::empty().expect("invariant: Response::empty() construction always succeeds")));
170+
return Err(
171+
Response::error("server misconfigured: RGTV_AGENT_TOKEN not set", 500)
172+
.unwrap_or_else(|_| {
173+
Response::empty()
174+
.expect("invariant: Response::empty() construction always succeeds")
175+
}),
176+
);
175177
}
176178
};
177179
let expected = format!("Bearer {token}");
@@ -181,8 +183,9 @@ fn check_auth(req: &Request, env: &Env) -> std::result::Result<(), Response> {
181183
.unwrap_or_default()
182184
.unwrap_or_default();
183185
if auth != expected {
184-
Err(Response::error("unauthorized", 401)
185-
.unwrap_or_else(|_| Response::empty().expect("invariant: Response::empty() construction always succeeds")))
186+
Err(Response::error("unauthorized", 401).unwrap_or_else(|_| {
187+
Response::empty().expect("invariant: Response::empty() construction always succeeds")
188+
}))
186189
} else {
187190
Ok(())
188191
}
@@ -308,8 +311,7 @@ async fn handle_create_grant(mut req: Request, ctx: RouteContext<()>) -> Result<
308311
};
309312

310313
// Store the grant record in its DO instance.
311-
let body_str = serde_json::to_string(&record)
312-
.map_err(|e| Error::RustError(e.to_string()))?;
314+
let body_str = serde_json::to_string(&record).map_err(|e| Error::RustError(e.to_string()))?;
313315
let ns = ctx.durable_object("GRANTS")?;
314316
let stub = ns.id_from_name(&grant_id)?.get_stub()?;
315317
stub.fetch_with_request(do_put_request(&body_str)?).await?;

0 commit comments

Comments
 (0)