Skip to content

Commit e578218

Browse files
committed
clippy fix
Signed-off-by: Tuan Anh Tran <[email protected]>
1 parent 7dcfef1 commit e578218

File tree

2 files changed

+34
-50
lines changed

2 files changed

+34
-50
lines changed

src/oci.rs

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ fn build_auth(reference: &Reference) -> RegistryAuth {
6262
Err(CredentialRetrievalError::NoCredentialConfigured) => RegistryAuth::Anonymous,
6363
Err(e) => {
6464
log::info!(
65-
"Error retrieving docker credentials: {}. Using anonymous auth",
66-
e
65+
"Error retrieving docker credentials: {e}. Using anonymous auth"
6766
);
6867
RegistryAuth::Anonymous
6968
}
@@ -87,7 +86,7 @@ async fn setup_trust_repository(cli: &Cli) -> Result<Box<dyn TrustRoot>, anyhow:
8786
match SigstoreTrustRoot::new(None).await {
8887
Ok(repo) => return Ok(Box::new(repo)),
8988
Err(e) => {
90-
log::warn!("Failed to initialize TUF trust repository: {}", e);
89+
log::warn!("Failed to initialize TUF trust repository: {e}");
9190
log::info!("Falling back to manual trust repository");
9291
}
9392
}
@@ -104,10 +103,10 @@ async fn setup_trust_repository(cli: &Cli) -> Result<Box<dyn TrustRoot>, anyhow:
104103
log::info!("Added Rekor public key");
105104
data.rekor_keys.push(content);
106105
}
107-
Err(e) => log::warn!("Failed to read Rekor public keys file: {}", e),
106+
Err(e) => log::warn!("Failed to read Rekor public keys file: {e}"),
108107
}
109108
} else {
110-
log::warn!("Rekor public keys file not found: {:?}", rekor_keys_path);
109+
log::warn!("Rekor public keys file not found: {rekor_keys_path:?}");
111110
}
112111
}
113112

@@ -126,15 +125,14 @@ async fn setup_trust_repository(cli: &Cli) -> Result<Box<dyn TrustRoot>, anyhow:
126125
log::info!("Added Fulcio certificate");
127126
data.fulcio_certs.push(cert);
128127
}
129-
Err(e) => log::warn!("Failed to parse Fulcio certificate: {}", e),
128+
Err(e) => log::warn!("Failed to parse Fulcio certificate: {e}"),
130129
}
131130
}
132-
Err(e) => log::warn!("Failed to read Fulcio certificates file: {}", e),
131+
Err(e) => log::warn!("Failed to read Fulcio certificates file: {e}"),
133132
}
134133
} else {
135134
log::warn!(
136-
"Fulcio certificates file not found: {:?}",
137-
fulcio_certs_path
135+
"Fulcio certificates file not found: {fulcio_certs_path:?}"
138136
);
139137
}
140138
}
@@ -143,7 +141,7 @@ async fn setup_trust_repository(cli: &Cli) -> Result<Box<dyn TrustRoot>, anyhow:
143141
}
144142

145143
async fn verify_image_signature(cli: &Cli, image_reference: &str) -> Result<bool, anyhow::Error> {
146-
log::info!("Verifying signature for {}", image_reference);
144+
log::info!("Verifying signature for {image_reference}");
147145

148146
// Set up the trust repository based on CLI arguments
149147
let repo = setup_trust_repository(cli).await?;
@@ -175,7 +173,7 @@ async fn verify_image_signature(cli: &Cli, image_reference: &str) -> Result<bool
175173
match client.triangulate(&image_ref, auth).await {
176174
Ok((sig_image, digest)) => (sig_image, digest),
177175
Err(e) => {
178-
log::warn!("Failed to triangulate image: {}", e);
176+
log::warn!("Failed to triangulate image: {e}");
179177
return Ok(false); // No signatures found
180178
}
181179
};
@@ -187,13 +185,13 @@ async fn verify_image_signature(cli: &Cli, image_reference: &str) -> Result<bool
187185
{
188186
Ok(layers) => layers,
189187
Err(e) => {
190-
log::warn!("Failed to get trusted signature layers: {}", e);
188+
log::warn!("Failed to get trusted signature layers: {e}");
191189
return Ok(false);
192190
}
193191
};
194192

195193
if signature_layers.is_empty() {
196-
log::warn!("No valid signatures found for {}", image_reference);
194+
log::warn!("No valid signatures found for {image_reference}");
197195
return Ok(false);
198196
}
199197

@@ -229,16 +227,14 @@ async fn verify_image_signature(cli: &Cli, image_reference: &str) -> Result<bool
229227
// Verify the constraints
230228
match verify_constraints(&signature_layers, verification_constraints.iter()) {
231229
Ok(()) => {
232-
log::info!("Signature verification successful for {}", image_reference);
230+
log::info!("Signature verification successful for {image_reference}");
233231
Ok(true)
234232
}
235233
Err(SigstoreVerifyConstraintsError {
236234
unsatisfied_constraints,
237235
}) => {
238236
log::warn!(
239-
"Signature verification failed for {}: {:?}",
240-
image_reference,
241-
unsatisfied_constraints
237+
"Signature verification failed for {image_reference}: {unsatisfied_constraints:?}"
242238
);
243239
Ok(false)
244240
}
@@ -253,14 +249,12 @@ pub async fn pull_and_extract_oci_image(
253249
) -> Result<(), Box<dyn std::error::Error>> {
254250
if Path::new(local_output_path).exists() {
255251
log::info!(
256-
"Plugin {} already cached at: {}. Skipping downloading.",
257-
image_reference,
258-
local_output_path
252+
"Plugin {image_reference} already cached at: {local_output_path}. Skipping downloading."
259253
);
260254
return Ok(());
261255
}
262256

263-
log::info!("Pulling {} ...", image_reference);
257+
log::info!("Pulling {image_reference} ...");
264258

265259
let client_config = oci_client::client::ClientConfig::default();
266260
let client = Client::new(client_config);
@@ -270,23 +264,22 @@ pub async fn pull_and_extract_oci_image(
270264

271265
// Verify the image signature if it's an OCI image and verification is enabled
272266
if !cli.insecure_skip_signature {
273-
log::info!("Signature verification enabled for {}", image_reference);
267+
log::info!("Signature verification enabled for {image_reference}");
274268
match verify_image_signature(cli, image_reference).await {
275269
Ok(verified) => {
276270
if !verified {
277271
return Err(format!(
278-
"No valid signatures found for the image {}",
279-
image_reference
272+
"No valid signatures found for the image {image_reference}"
280273
)
281274
.into());
282275
}
283276
}
284277
Err(e) => {
285-
return Err(format!("Image signature verification failed: {}", e).into());
278+
return Err(format!("Image signature verification failed: {e}").into());
286279
}
287280
}
288281
} else {
289-
log::warn!("Signature verification disabled for {}", image_reference);
282+
log::warn!("Signature verification disabled for {image_reference}");
290283
}
291284

292285
// Accept both OCI and Docker manifest types
@@ -327,12 +320,12 @@ pub async fn pull_and_extract_oci_image(
327320
let mut content = Vec::new();
328321
entry.read_to_end(&mut content)?;
329322
fs::write(local_output_path, content)?;
330-
log::info!("Successfully extracted to: {}", local_output_path);
323+
log::info!("Successfully extracted to: {local_output_path}");
331324
return Ok(());
332325
}
333326
}
334327
}
335-
Err(e) => log::info!("Error during extraction: {}", e),
328+
Err(e) => log::info!("Error during extraction: {e}"),
336329
}
337330
}
338331
}

src/plugins.rs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl PluginService {
7171
.pull_and_extract(image_reference, target_file_path, local_output_path)
7272
.await
7373
{
74-
log::error!("Error pulling oci plugin: {}", e);
74+
log::error!("Error pulling oci plugin: {e}");
7575
return Err(anyhow::anyhow!("Failed to pull OCI plugin: {}", e));
7676
}
7777
log::info!(
@@ -85,7 +85,7 @@ impl PluginService {
8585
};
8686
let mut manifest = Manifest::new([Wasm::data(wasm_content)]);
8787
if let Some(runtime_cfg) = &plugin_cfg.runtime_config {
88-
log::info!("runtime_cfg: {:?}", runtime_cfg);
88+
log::info!("runtime_cfg: {runtime_cfg:?}");
8989
if let Some(hosts) = &runtime_cfg.allowed_hosts {
9090
for host in hosts {
9191
manifest = manifest.with_allowed_host(host);
@@ -114,9 +114,7 @@ impl PluginService {
114114
}
115115
Err(e) => {
116116
log::error!(
117-
"Failed to parse memory_limit '{}': {}. Using default memory limit.",
118-
memory_limit,
119-
e
117+
"Failed to parse memory_limit '{memory_limit}': {e}. Using default memory limit."
120118
);
121119
}
122120
}
@@ -171,7 +169,7 @@ impl PluginService {
171169
.write()
172170
.await
173171
.insert(plugin_name.clone(), plugin);
174-
log::info!("Loaded plugin {}", plugin_name);
172+
log::info!("Loaded plugin {plugin_name}");
175173
}
176174
Ok(())
177175
}
@@ -218,9 +216,7 @@ impl ServerHandler for PluginService {
218216
// Strip the prefix to get the original tool name
219217
original_name = tool_name_str[tool_name_prefix.len()..].to_string();
220218
log::info!(
221-
"Found tool with prefix, stripping for internal call: {} -> {}",
222-
tool_name_str,
223-
original_name
219+
"Found tool with prefix, stripping for internal call: {tool_name_str} -> {original_name}"
224220
);
225221
break;
226222
}
@@ -236,9 +232,7 @@ impl ServerHandler for PluginService {
236232
// Strip the prefix to get the original tool name
237233
original_name = tool_name_str[tool_name_prefix.len()..].to_string();
238234
log::info!(
239-
"Stripping prefix from tool: {} -> {}",
240-
tool_name_str,
241-
original_name
235+
"Stripping prefix from tool: {tool_name_str} -> {original_name}"
242236
);
243237

244238
// Check if the original tool name is in the cache
@@ -279,18 +273,17 @@ impl ServerHandler for PluginService {
279273
Ok(Ok(result)) => match serde_json::from_str::<CallToolResult>(&result) {
280274
Ok(parsed) => Ok(parsed),
281275
Err(e) => Err(McpError::internal_error(
282-
format!("Failed to deserialize data: {}", e),
276+
format!("Failed to deserialize data: {e}"),
283277
None,
284278
)),
285279
},
286280
Ok(Err(e)) => Err(McpError::internal_error(
287-
format!("Failed to execute plugin {}: {}", plugin_name_clone, e),
281+
format!("Failed to execute plugin {plugin_name_clone}: {e}"),
288282
None,
289283
)),
290284
Err(e) => Err(McpError::internal_error(
291285
format!(
292-
"Failed to spawn blocking task for plugin {}: {}",
293-
plugin_name_clone, e
286+
"Failed to spawn blocking task for plugin {plugin_name_clone}: {e}"
294287
),
295288
None,
296289
)),
@@ -347,11 +340,9 @@ impl ServerHandler for PluginService {
347340
if let Some(runtime_cfg) = &plugin_cfg.runtime_config {
348341
if let Some(tool_name_prefix) = &runtime_cfg.tool_name_prefix {
349342
let prefixed_name =
350-
format!("{}{}", tool_name_prefix, original_name);
343+
format!("{tool_name_prefix}{original_name}");
351344
log::info!(
352-
"Adding prefix to tool: {} -> {}",
353-
original_name,
354-
prefixed_name
345+
"Adding prefix to tool: {original_name} -> {prefixed_name}"
355346
);
356347

357348
// Store both the original and prefixed tool names in the cache
@@ -371,10 +362,10 @@ impl ServerHandler for PluginService {
371362
}
372363
}
373364
Ok(Err(e)) => {
374-
log::error!("tool {} describe() error: {}", plugin_name, e);
365+
log::error!("tool {plugin_name} describe() error: {e}");
375366
}
376367
Err(e) => {
377-
log::error!("tool {} spawn_blocking error: {}", plugin_name, e);
368+
log::error!("tool {plugin_name} spawn_blocking error: {e}");
378369
}
379370
}
380371
}

0 commit comments

Comments
 (0)