Skip to content

Commit dda9cc2

Browse files
chore: clippy fix
1 parent b96c800 commit dda9cc2

File tree

3 files changed

+42
-48
lines changed

3 files changed

+42
-48
lines changed

src/auth/git_http.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn try_userpass_authentication(username_from_url: Option<&str>) -> Result<Cr
1616
Error::new(
1717
ErrorCode::Auth,
1818
ErrorClass::Net,
19-
format!("Failed to read username: {}", e),
19+
format!("Failed to read username: {e}"),
2020
)
2121
})?
2222
};
@@ -28,7 +28,7 @@ pub fn try_userpass_authentication(username_from_url: Option<&str>) -> Result<Cr
2828
Error::new(
2929
ErrorCode::Auth,
3030
ErrorClass::Net,
31-
format!("Failed to read token: {}", e),
31+
format!("Failed to read token: {e}"),
3232
)
3333
})?;
3434

@@ -40,7 +40,7 @@ pub fn try_userpass_authentication(username_from_url: Option<&str>) -> Result<Cr
4040
Ok(cred)
4141
}
4242
Err(e) => {
43-
debug!("Username/token authentication failed: {}", e);
43+
debug!("Username/token authentication failed: {e}");
4444
Err(e)
4545
}
4646
}

src/auth/git_ssh.rs

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,15 @@ pub fn ssh_authenticate_git(
1212
attempt_count: usize,
1313
) -> Result<Cred, Error> {
1414
debug!(
15-
"Git authentication attempt #{} for URL: {}",
16-
attempt_count, url
15+
"Git authentication attempt #{attempt_count} for URL: {url}"
1716
);
18-
debug!("Username from URL: {:?}", username_from_url);
19-
debug!("Allowed credential types: {:?}", allowed_types);
17+
debug!("Username from URL: {username_from_url:?}");
18+
debug!("Allowed credential types: {allowed_types:?}");
2019

2120
// Prevent infinite loops
2221
if attempt_count > 3 {
2322
debug!(
24-
"Too many authentication attempts ({}), failing to prevent infinite loop",
25-
attempt_count
23+
"Too many authentication attempts ({attempt_count}), failing to prevent infinite loop"
2624
);
2725
return Err(Error::new(
2826
ErrorCode::Auth,
@@ -40,7 +38,7 @@ pub fn ssh_authenticate_git(
4038
debug!("Second attempt: trying to add SSH keys to agent before authentication");
4139
if std::env::var("SSH_AUTH_SOCK").is_ok() {
4240
if let Err(e) = add_all_ssh_keys() {
43-
debug!("Failed to add keys to ssh-agent on second attempt: {}", e);
41+
debug!("Failed to add keys to ssh-agent on second attempt: {e}");
4442
} else {
4543
debug!("Keys added to ssh-agent, proceeding with authentication");
4644
}
@@ -56,18 +54,17 @@ pub fn ssh_authenticate_git(
5654
}
5755

5856
debug!(
59-
"All authentication methods failed for attempt {}",
60-
attempt_count
57+
"All authentication methods failed for attempt {attempt_count}"
6158
);
6259
Err(Error::new(
6360
ErrorCode::Auth,
6461
ErrorClass::Net,
65-
format!("Authentication failed - attempt {}", attempt_count),
62+
format!("Authentication failed - attempt {attempt_count}"),
6663
))
6764
}
6865

6966
fn try_ssh_agent_auth(username: &str) -> Result<Cred, Error> {
70-
debug!("Attempting SSH agent authentication for user: {}", username);
67+
debug!("Attempting SSH agent authentication for user: {username}");
7168

7269
if std::env::var("SSH_AUTH_SOCK").is_err() {
7370
debug!("SSH_AUTH_SOCK not set, attempting to spawn ssh-agent and add keys");
@@ -81,7 +78,7 @@ fn try_ssh_agent_auth(username: &str) -> Result<Cred, Error> {
8178
Ok(cred)
8279
}
8380
Err(e) => {
84-
debug!("SSH agent authentication failed: {}", e);
81+
debug!("SSH agent authentication failed: {e}");
8582

8683
// Fallback to trying SSH key files directly
8784
debug!("Falling back to direct SSH key file authentication");
@@ -97,7 +94,7 @@ fn spawn_ssh_agent_and_add_keys() -> Result<(), Error> {
9794
Error::new(
9895
ErrorCode::Auth,
9996
ErrorClass::Net,
100-
format!("Failed to spawn ssh-agent: {}", e),
97+
format!("Failed to spawn ssh-agent: {e}"),
10198
)
10299
})?;
103100

@@ -110,15 +107,15 @@ fn spawn_ssh_agent_and_add_keys() -> Result<(), Error> {
110107
}
111108

112109
let agent_output = String::from_utf8_lossy(&output.stdout);
113-
debug!("ssh-agent output: {}", agent_output);
110+
debug!("ssh-agent output: {agent_output}");
114111

115112
let env_vars = parse_ssh_agent_output(&agent_output);
116113

117114
for (key, value) in &env_vars {
118115
unsafe {
119116
std::env::set_var(key, value);
120117
}
121-
debug!("Set environment variable: {}={}", key, value);
118+
debug!("Set environment variable: {key}={value}");
122119
}
123120

124121
if !env_vars.contains_key("SSH_AUTH_SOCK") {
@@ -144,7 +141,7 @@ fn add_all_ssh_keys() -> Result<(), Error> {
144141
let ssh_dir = Path::new(&home_dir).join(".ssh");
145142

146143
if !ssh_dir.exists() {
147-
debug!("SSH directory {:?} does not exist", ssh_dir);
144+
debug!("SSH directory {ssh_dir:?} does not exist");
148145
return Ok(());
149146
}
150147

@@ -155,7 +152,7 @@ fn add_all_ssh_keys() -> Result<(), Error> {
155152
let key_path = ssh_dir.join(key_name);
156153

157154
if key_path.exists() {
158-
debug!("Found SSH key: {:?}", key_path);
155+
debug!("Found SSH key: {key_path:?}");
159156

160157
// First try a quick non-interactive add (for keys without passphrase)
161158
let quick_result = Command::new("ssh-add")
@@ -171,58 +168,56 @@ fn add_all_ssh_keys() -> Result<(), Error> {
171168

172169
match quick_result {
173170
Ok(output) if output.status.success() => {
174-
debug!("Successfully added key without interaction: {}", key_name);
171+
debug!("Successfully added key without interaction: {key_name}");
175172
added_count += 1;
176173
}
177174
Ok(output) => {
178175
let stderr = String::from_utf8_lossy(&output.stderr);
179-
debug!("Quick add failed for {}: {}", key_name, stderr);
176+
debug!("Quick add failed for {key_name}: {stderr}");
180177

181178
debug!(
182-
"Key {} appears to need passphrase, trying interactive add",
183-
key_name
179+
"Key {key_name} appears to need passphrase, trying interactive add"
184180
);
185181

186182
match add_key_interactive(&key_path, key_name) {
187183
Ok(true) => {
188-
debug!("Successfully added key interactively: {}", key_name);
184+
debug!("Successfully added key interactively: {key_name}");
189185
added_count += 1;
190186
}
191187
Ok(false) => {
192-
debug!("User skipped key: {}", key_name);
188+
debug!("User skipped key: {key_name}");
193189
}
194190
Err(e) => {
195-
debug!("Interactive add failed for {}: {}", key_name, e);
191+
debug!("Interactive add failed for {key_name}: {e}");
196192
}
197193
}
198194
}
199195
Err(e) => {
200-
debug!("Error running ssh-add for {}: {}", key_name, e);
196+
debug!("Error running ssh-add for {key_name}: {e}");
201197
}
202198
}
203199
} else {
204-
debug!("SSH key not found: {:?}", key_path);
200+
debug!("SSH key not found: {key_path:?}");
205201
}
206202
}
207203

208-
debug!("Added {} SSH keys to ssh-agent", added_count);
204+
debug!("Added {added_count} SSH keys to ssh-agent");
209205

210206
if added_count == 0 {
211207
debug!("No SSH keys were added");
212208
println!("No SSH keys were added to ssh-agent.");
213209
println!("You may need to generate SSH keys or check your ~/.ssh directory.");
214210
} else {
215211
println!(
216-
"Successfully added {} SSH key(s) to ssh-agent.",
217-
added_count
212+
"Successfully added {added_count} SSH key(s) to ssh-agent."
218213
);
219214
}
220215

221216
Ok(())
222217
}
223218

224219
fn try_ssh_key_files_directly(username: &str) -> Result<Cred, Error> {
225-
debug!("Trying SSH key files directly for user: {}", username);
220+
debug!("Trying SSH key files directly for user: {username}");
226221

227222
let home_dir = std::env::var("HOME")
228223
.or_else(|_| std::env::var("USERPROFILE"))
@@ -233,10 +228,10 @@ fn try_ssh_key_files_directly(username: &str) -> Result<Cred, Error> {
233228

234229
for key_name in &key_files {
235230
let private_key_path = ssh_dir.join(key_name);
236-
let public_key_path = ssh_dir.join(format!("{}.pub", key_name));
231+
let public_key_path = ssh_dir.join(format!("{key_name}.pub"));
237232

238233
if private_key_path.exists() && public_key_path.exists() {
239-
debug!("Trying SSH key pair: {} / {}.pub", key_name, key_name);
234+
debug!("Trying SSH key pair: {key_name} / {key_name}.pub");
240235

241236
match Cred::ssh_key(
242237
username,
@@ -245,11 +240,11 @@ fn try_ssh_key_files_directly(username: &str) -> Result<Cred, Error> {
245240
None, // No passphrase for now
246241
) {
247242
Ok(cred) => {
248-
debug!("SSH key authentication succeeded with {}", key_name);
243+
debug!("SSH key authentication succeeded with {key_name}");
249244
return Ok(cred);
250245
}
251246
Err(e) => {
252-
debug!("SSH key authentication failed with {}: {}", key_name, e);
247+
debug!("SSH key authentication failed with {key_name}: {e}");
253248
}
254249
}
255250
}

src/auth/ssh_utils.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,29 @@ pub fn parse_ssh_agent_output(output: &str) -> HashMap<String, String> {
2626
}
2727

2828
pub fn add_key_interactive(key_path: &Path, key_name: &str) -> Result<bool, Error> {
29-
debug!("Trying interactive ssh-add for key: {}", key_name);
29+
debug!("Trying interactive ssh-add for key: {key_name}");
3030

3131
// Ask user if they want to add this key interactively
3232
let should_add = Confirm::with_theme(&ColorfulTheme::default())
3333
.with_prompt(format!(
34-
"Add SSH key '{}' to ssh-agent? (you may be prompted for passphrase)",
35-
key_name
34+
"Add SSH key '{key_name}' to ssh-agent? (you may be prompted for passphrase)"
3635
))
3736
.default(true)
3837
.interact()
3938
.map_err(|e| {
4039
Error::new(
4140
ErrorCode::Auth,
4241
ErrorClass::Net,
43-
format!("Failed to get user confirmation: {}", e),
42+
format!("Failed to get user confirmation: {e}"),
4443
)
4544
})?;
4645

4746
if !should_add {
48-
debug!("User chose not to add key: {}", key_name);
47+
debug!("User chose not to add key: {key_name}");
4948
return Ok(false);
5049
}
5150

52-
println!("Adding SSH key: {}", key_name);
51+
println!("Adding SSH key: {key_name}");
5352
println!("If the key is passphrase-protected, you will be prompted to enter it.");
5453

5554
// Use interactive ssh-add - this will prompt the user directly in the terminal
@@ -67,17 +66,17 @@ pub fn add_key_interactive(key_path: &Path, key_name: &str) -> Result<bool, Erro
6766
Error::new(
6867
ErrorCode::Auth,
6968
ErrorClass::Net,
70-
format!("Failed to spawn ssh-add: {}", e),
69+
format!("Failed to spawn ssh-add: {e}"),
7170
)
7271
})?;
7372

7473
if status.success() {
75-
debug!("Successfully added key: {}", key_name);
76-
println!("✓ SSH key '{}' added successfully!", key_name);
74+
debug!("Successfully added key: {key_name}");
75+
println!("✓ SSH key '{key_name}' added successfully!");
7776
Ok(true)
7877
} else {
79-
debug!("Interactive ssh-add failed for key: {}", key_name);
80-
println!("✗ Failed to add SSH key '{}'", key_name);
78+
debug!("Interactive ssh-add failed for key: {key_name}");
79+
println!("✗ Failed to add SSH key '{key_name}'");
8180
Ok(false)
8281
}
8382
}

0 commit comments

Comments
 (0)