Skip to content

Commit d939754

Browse files
jeremymanningclaude
andcommitted
style: apply cargo fmt formatting fixes
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent bc2e0e2 commit d939754

27 files changed

Lines changed: 161 additions & 387 deletions

src/cli/admin.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ pub fn execute(cmd: &AdminCommand) -> String {
4949
)
5050
}
5151
AdminCommand::Resume => {
52-
"Resume requested. Requires OnCallResponder role and active admin service connection.".into()
52+
"Resume requested. Requires OnCallResponder role and active admin service connection."
53+
.into()
5354
}
5455
AdminCommand::Ban { subject_id, reason } => {
5556
format!(

src/cli/donor.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,8 @@ pub enum DonorCommand {
4747
pub fn execute(cmd: &DonorCommand) -> String {
4848
match cmd {
4949
DonorCommand::Join { consent } => {
50-
let classes: Vec<AcceptableUseClass> = consent
51-
.split(',')
52-
.filter_map(|s| parse_use_class(s.trim()))
53-
.collect();
50+
let classes: Vec<AcceptableUseClass> =
51+
consent.split(',').filter_map(|s| parse_use_class(s.trim())).collect();
5452

5553
if classes.is_empty() {
5654
return "Error: no valid consent classes provided. Valid classes: scientific, public-good-ml, rendering, indexing, self-improvement, general".into();
@@ -72,12 +70,8 @@ pub fn execute(cmd: &DonorCommand) -> String {
7270
DonorCommand::Status => {
7371
"Donor status: agent daemon not running. Start with `worldcompute donor join`.".into()
7472
}
75-
DonorCommand::Pause => {
76-
"Pause: agent daemon not running. Nothing to pause.".into()
77-
}
78-
DonorCommand::Resume => {
79-
"Resume: agent daemon not running. Nothing to resume.".into()
80-
}
73+
DonorCommand::Pause => "Pause: agent daemon not running. Nothing to pause.".into(),
74+
DonorCommand::Resume => "Resume: agent daemon not running. Nothing to resume.".into(),
8175
DonorCommand::Leave => {
8276
"Leave: agent daemon not running. No cluster state to clean up.".into()
8377
}

src/cli/governance.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ pub fn execute(cmd: &GovernanceCommand) -> String {
6060
proposal_type_parsed,
6161
"cli-user",
6262
) {
63-
Ok(id) => format!("Proposal submitted.\n ID: {id}\n Title: {title}\n Type: {proposal_type}"),
63+
Ok(id) => format!(
64+
"Proposal submitted.\n ID: {id}\n Title: {title}\n Type: {proposal_type}"
65+
),
6466
Err(e) => format!("Error submitting proposal: {e}"),
6567
}
6668
}
@@ -73,7 +75,8 @@ pub fn execute(cmd: &GovernanceCommand) -> String {
7375
} else {
7476
let mut output = format!("Proposals ({}):\n", proposals.len());
7577
for p in &proposals {
76-
output.push_str(&format!(" {} — {} [{:?}]\n", p.proposal_id, p.title, p.state));
78+
output
79+
.push_str(&format!(" {} — {} [{:?}]\n", p.proposal_id, p.title, p.state));
7780
}
7881
output
7982
}
@@ -83,7 +86,9 @@ pub fn execute(cmd: &GovernanceCommand) -> String {
8386
"yes" => "Yes",
8487
"no" => "No",
8588
"abstain" => "Abstain",
86-
_ => return format!("Error: invalid vote choice '{choice}'. Use: yes, no, abstain"),
89+
_ => {
90+
return format!("Error: invalid vote choice '{choice}'. Use: yes, no, abstain")
91+
}
8792
};
8893
format!("Vote '{vote_choice}' registered for proposal {proposal_id} (awaiting governance service connection).")
8994
}

src/cli/submitter.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,20 @@ pub enum JobCommand {
4242
/// Execute a job CLI command. Returns a human-readable status string.
4343
pub fn execute(cmd: &JobCommand) -> String {
4444
match cmd {
45-
JobCommand::Submit { manifest_path } => {
46-
match std::fs::read_to_string(manifest_path) {
47-
Ok(content) => {
48-
match serde_json::from_str::<crate::scheduler::manifest::JobManifest>(&content) {
49-
Ok(manifest) => {
50-
format!(
45+
JobCommand::Submit { manifest_path } => match std::fs::read_to_string(manifest_path) {
46+
Ok(content) => {
47+
match serde_json::from_str::<crate::scheduler::manifest::JobManifest>(&content) {
48+
Ok(manifest) => {
49+
format!(
5150
"Job validated.\n Name: {}\n Workload: {:?}\n Inputs: {}\n Use classes: {:?}\n Submitted (awaiting coordinator connection).",
5251
manifest.name, manifest.workload_type, manifest.inputs.len(), manifest.acceptable_use_classes
5352
)
54-
}
55-
Err(e) => format!("Error: invalid manifest JSON: {e}"),
5653
}
54+
Err(e) => format!("Error: invalid manifest JSON: {e}"),
5755
}
58-
Err(e) => format!("Error: cannot read manifest file '{manifest_path}': {e}"),
5956
}
60-
}
57+
Err(e) => format!("Error: cannot read manifest file '{manifest_path}': {e}"),
58+
},
6159
JobCommand::Status { job_id } => {
6260
format!("Job {job_id}: no coordinator connection. Start a donor node first.")
6361
}

src/identity/oauth2.rs

Lines changed: 19 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,7 @@ impl OAuth2ProviderConfig {
103103
let token_url = std::env::var(format!("OAUTH2_{prefix}_TOKEN_URL"))
104104
.unwrap_or_else(|_| provider.default_token_url().to_string());
105105

106-
let scopes = provider
107-
.default_scopes()
108-
.into_iter()
109-
.map(String::from)
110-
.collect();
106+
let scopes = provider.default_scopes().into_iter().map(String::from).collect();
111107

112108
Some(Self {
113109
provider,
@@ -125,8 +121,7 @@ impl OAuth2ProviderConfig {
125121
let client = BasicClient::new(
126122
ClientId::new(self.client_id.clone()),
127123
Some(ClientSecret::new(self.client_secret.clone())),
128-
AuthUrl::new(self.auth_url.clone())
129-
.map_err(|e| format!("Invalid auth URL: {e}"))?,
124+
AuthUrl::new(self.auth_url.clone()).map_err(|e| format!("Invalid auth URL: {e}"))?,
130125
Some(
131126
TokenUrl::new(self.token_url.clone())
132127
.map_err(|e| format!("Invalid token URL: {e}"))?,
@@ -144,10 +139,7 @@ impl OAuth2ProviderConfig {
144139
#[derive(Debug, Clone)]
145140
pub enum OAuth2Result {
146141
/// Successfully verified — provider confirmed the account.
147-
Verified {
148-
provider: OAuth2Provider,
149-
account_id: String,
150-
},
142+
Verified { provider: OAuth2Provider, account_id: String },
151143
/// Verification failed (e.g., invalid token, denied).
152144
Failed(String),
153145
/// Provider is unavailable (credentials missing or service unreachable).
@@ -187,11 +179,7 @@ pub fn generate_auth_url(
187179
/// This function performs the full OAuth2 authorization code exchange using
188180
/// the `oauth2` crate, then queries the provider's user-info endpoint to
189181
/// obtain the account identifier.
190-
pub fn exchange_code(
191-
provider: OAuth2Provider,
192-
redirect_uri: &str,
193-
code: &str,
194-
) -> OAuth2Result {
182+
pub fn exchange_code(provider: OAuth2Provider, redirect_uri: &str, code: &str) -> OAuth2Result {
195183
let config = match OAuth2ProviderConfig::from_env(provider, redirect_uri) {
196184
Some(c) => c,
197185
None => {
@@ -211,9 +199,8 @@ pub fn exchange_code(
211199

212200
// Exchange code for token using the oauth2 crate's built-in blocking HTTP client
213201
let http_client = oauth2::reqwest::http_client;
214-
let token_result = client
215-
.exchange_code(oauth2::AuthorizationCode::new(code.to_string()))
216-
.request(http_client);
202+
let token_result =
203+
client.exchange_code(oauth2::AuthorizationCode::new(code.to_string())).request(http_client);
217204

218205
let token_response = match token_result {
219206
Ok(t) => t,
@@ -224,10 +211,7 @@ pub fn exchange_code(
224211

225212
// Fetch user info from provider-specific endpoint
226213
match fetch_account_id(provider, &access_token) {
227-
Ok(account_id) => OAuth2Result::Verified {
228-
provider,
229-
account_id,
230-
},
214+
Ok(account_id) => OAuth2Result::Verified { provider, account_id },
231215
Err(e) => OAuth2Result::Failed(format!("Failed to fetch user info: {e}")),
232216
}
233217
}
@@ -238,15 +222,9 @@ fn fetch_account_id(provider: OAuth2Provider, access_token: &str) -> Result<Stri
238222

239223
let (url, id_field) = match provider {
240224
OAuth2Provider::GitHub => ("https://api.github.com/user", "id"),
241-
OAuth2Provider::Google => (
242-
"https://www.googleapis.com/oauth2/v2/userinfo",
243-
"id",
244-
),
225+
OAuth2Provider::Google => ("https://www.googleapis.com/oauth2/v2/userinfo", "id"),
245226
OAuth2Provider::Twitter => ("https://api.twitter.com/2/users/me", "id"),
246-
OAuth2Provider::Email => (
247-
"https://www.googleapis.com/oauth2/v2/userinfo",
248-
"email",
249-
),
227+
OAuth2Provider::Email => ("https://www.googleapis.com/oauth2/v2/userinfo", "email"),
250228
};
251229

252230
let response = http_client
@@ -258,22 +236,15 @@ fn fetch_account_id(provider: OAuth2Provider, access_token: &str) -> Result<Stri
258236
.map_err(|e| format!("HTTP request failed: {e}"))?;
259237

260238
if !response.status().is_success() {
261-
return Err(format!(
262-
"Provider returned HTTP {}",
263-
response.status()
264-
));
239+
return Err(format!("Provider returned HTTP {}", response.status()));
265240
}
266241

267-
let body: serde_json::Value = response
268-
.json()
269-
.map_err(|e| format!("Failed to parse response: {e}"))?;
242+
let body: serde_json::Value =
243+
response.json().map_err(|e| format!("Failed to parse response: {e}"))?;
270244

271245
// Twitter nests user data under "data"
272-
let user_data = if provider == OAuth2Provider::Twitter {
273-
body.get("data").unwrap_or(&body)
274-
} else {
275-
&body
276-
};
246+
let user_data =
247+
if provider == OAuth2Provider::Twitter { body.get("data").unwrap_or(&body) } else { &body };
277248

278249
user_data
279250
.get(id_field)
@@ -324,9 +295,7 @@ pub fn verify_oauth2(provider: OAuth2Provider, redirect_uri: &str) -> OAuth2Resu
324295
// Return as "Failed" with the auth URL — the caller needs to
325296
// redirect the user and then call exchange_code() with the code.
326297
// In a non-interactive context, we cannot complete the flow.
327-
OAuth2Result::Failed(format!(
328-
"Authorization required. Visit: {url}"
329-
))
298+
OAuth2Result::Failed(format!("Authorization required. Visit: {url}"))
330299
}
331300
}
332301
}
@@ -348,10 +317,8 @@ mod tests {
348317
#[test]
349318
fn config_from_env_returns_none_when_missing() {
350319
// With no env vars set, config should be None
351-
let config = OAuth2ProviderConfig::from_env(
352-
OAuth2Provider::GitHub,
353-
"https://localhost/callback",
354-
);
320+
let config =
321+
OAuth2ProviderConfig::from_env(OAuth2Provider::GitHub, "https://localhost/callback");
355322
// This will be None unless someone has OAUTH2_GITHUB_CLIENT_ID set
356323
if std::env::var("OAUTH2_GITHUB_CLIENT_ID").is_err() {
357324
assert!(config.is_none());
@@ -425,11 +392,7 @@ mod tests {
425392
#[test]
426393
fn exchange_code_returns_unavailable_without_credentials() {
427394
if std::env::var("OAUTH2_GITHUB_CLIENT_ID").is_err() {
428-
match exchange_code(
429-
OAuth2Provider::GitHub,
430-
"https://localhost/callback",
431-
"fake-code",
432-
) {
395+
match exchange_code(OAuth2Provider::GitHub, "https://localhost/callback", "fake-code") {
433396
OAuth2Result::ProviderUnavailable(msg) => {
434397
assert!(msg.contains("credentials not configured"));
435398
}
@@ -441,10 +404,7 @@ mod tests {
441404
#[test]
442405
fn generate_auth_url_returns_error_without_credentials() {
443406
if std::env::var("OAUTH2_GITHUB_CLIENT_ID").is_err() {
444-
let result = generate_auth_url(
445-
OAuth2Provider::GitHub,
446-
"https://localhost/callback",
447-
);
407+
let result = generate_auth_url(OAuth2Provider::GitHub, "https://localhost/callback");
448408
assert!(result.is_err());
449409
assert!(result.unwrap_err().contains("credentials not configured"));
450410
}

src/identity/personhood.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ pub fn brightid_link_url(context_id: &str) -> String {
6767
/// In production, it should be called at enrollment time and
6868
/// re-verified at trust score recalculation intervals.
6969
pub fn verify_personhood(context_id: &str) -> PersonhoodResult {
70-
let base_url = std::env::var("BRIGHTID_NODE_URL")
71-
.unwrap_or_else(|_| BRIGHTID_NODE_URL.to_string());
70+
let base_url =
71+
std::env::var("BRIGHTID_NODE_URL").unwrap_or_else(|_| BRIGHTID_NODE_URL.to_string());
7272
let url = format!("{base_url}/verifications/{BRIGHTID_CONTEXT}/{context_id}");
7373

7474
// Use a blocking HTTP client for simplicity.
@@ -134,14 +134,11 @@ fn ureq_get_brightid(url: &str) -> Result<BrightIdVerification, String> {
134134
return Err(format!("BrightID returned status {status}"));
135135
}
136136

137-
let api_response: BrightIdApiResponse = response
138-
.json()
139-
.map_err(|e| format!("BrightID response parse failed: {e}"))?;
137+
let api_response: BrightIdApiResponse =
138+
response.json().map_err(|e| format!("BrightID response parse failed: {e}"))?;
140139

141140
if let Some(true) = api_response.error {
142-
return Err(
143-
api_response.error_message.unwrap_or_else(|| "Unknown BrightID error".into())
144-
);
141+
return Err(api_response.error_message.unwrap_or_else(|| "Unknown BrightID error".into()));
145142
}
146143

147144
api_response.data.ok_or_else(|| "BrightID response missing data field".into())

src/identity/phone.rs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,12 @@ impl SmsProviderConfig {
3939
let account_sid = std::env::var("TWILIO_ACCOUNT_SID").ok()?;
4040
let auth_token = std::env::var("TWILIO_AUTH_TOKEN").ok()?;
4141
let verify_service_sid = std::env::var("TWILIO_VERIFY_SID").ok()?;
42-
Some(Self {
43-
account_sid,
44-
auth_token,
45-
verify_service_sid,
46-
})
42+
Some(Self { account_sid, auth_token, verify_service_sid })
4743
}
4844

4945
/// Twilio Verify API base URL for this service.
5046
fn verifications_url(&self) -> String {
51-
format!(
52-
"https://verify.twilio.com/v2/Services/{}/Verifications",
53-
self.verify_service_sid
54-
)
47+
format!("https://verify.twilio.com/v2/Services/{}/Verifications", self.verify_service_sid)
5548
}
5649

5750
/// Twilio Verify check URL for this service.
@@ -87,14 +80,11 @@ pub fn send_verification_code(phone_number: &str) -> Result<String, String> {
8780
if !response.status().is_success() {
8881
let status = response.status();
8982
let body = response.text().unwrap_or_default();
90-
return Err(format!(
91-
"Twilio API returned HTTP {status}: {body}"
92-
));
83+
return Err(format!("Twilio API returned HTTP {status}: {body}"));
9384
}
9485

95-
let body: serde_json::Value = response
96-
.json()
97-
.map_err(|e| format!("Failed to parse Twilio response: {e}"))?;
86+
let body: serde_json::Value =
87+
response.json().map_err(|e| format!("Failed to parse Twilio response: {e}"))?;
9888

9989
body.get("sid")
10090
.and_then(|v| v.as_str())
@@ -129,9 +119,7 @@ pub fn verify_code(phone_number: &str, code: &str) -> PhoneResult {
129119
{
130120
Ok(r) => r,
131121
Err(e) => {
132-
return PhoneResult::ProviderUnavailable(format!(
133-
"Failed to reach Twilio API: {e}"
134-
));
122+
return PhoneResult::ProviderUnavailable(format!("Failed to reach Twilio API: {e}"));
135123
}
136124
};
137125

@@ -156,10 +144,7 @@ pub fn verify_code(phone_number: &str, code: &str) -> PhoneResult {
156144
}
157145
};
158146

159-
let status = body
160-
.get("status")
161-
.and_then(|v| v.as_str())
162-
.unwrap_or("unknown");
147+
let status = body.get("status").and_then(|v| v.as_str()).unwrap_or("unknown");
163148

164149
match status {
165150
"approved" => {

src/ledger/transparency.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
//! placeholder so the rest of the system can be wired up without a live
66
//! Rekor endpoint.
77
8-
use base64::Engine;
98
use crate::error::{ErrorCode, WcError, WcResult};
109
use crate::ledger::entry::MerkleRoot;
1110
use crate::types::Timestamp;
11+
use base64::Engine;
1212
use sha2::{Digest, Sha256};
1313
use std::collections::HashMap;
1414

@@ -71,12 +71,8 @@ pub fn anchor_merkle_root(root: &MerkleRoot) -> WcResult<MerkleRootAnchor> {
7171
{
7272
Ok(resp) if resp.status().is_success() => {
7373
// Rekor returns { "<uuid>": { ... } }
74-
let parsed: HashMap<String, serde_json::Value> =
75-
resp.json().unwrap_or_default();
76-
parsed
77-
.into_keys()
78-
.next()
79-
.unwrap_or_else(|| offline_entry_id(&root.root_hash))
74+
let parsed: HashMap<String, serde_json::Value> = resp.json().unwrap_or_default();
75+
parsed.into_keys().next().unwrap_or_else(|| offline_entry_id(&root.root_hash))
8076
}
8177
_ => {
8278
// Network error or non-success status — fall back to offline ID.
@@ -125,10 +121,7 @@ pub fn verify_anchor(anchor: &MerkleRootAnchor) -> WcResult<bool> {
125121

126122
// Validate that the entry UUID is a valid hex string (Rekor UUIDs and
127123
// our offline IDs are both hex-encoded).
128-
let is_valid_hex = anchor
129-
.rekor_entry_id
130-
.chars()
131-
.all(|c| c.is_ascii_hexdigit());
124+
let is_valid_hex = anchor.rekor_entry_id.chars().all(|c| c.is_ascii_hexdigit());
132125

133126
if !is_valid_hex {
134127
return Err(WcError::new(

0 commit comments

Comments
 (0)