fix(fmt & dep): clippy & hakari

This commit is contained in:
Samuka007 2025-03-27 17:24:01 +08:00 committed by Samuel Dai
parent 9fa472c8c6
commit 3a513b525c
13 changed files with 52 additions and 33 deletions

9
Cargo.lock generated
View File

@ -517,6 +517,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
name = "cni" name = "cni"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"my-workspace-hack",
"serde_json", "serde_json",
] ]
@ -1620,6 +1621,9 @@ dependencies = [
"actix-router", "actix-router",
"bitflags 2.8.0", "bitflags 2.8.0",
"bytes", "bytes",
"futures-channel",
"futures-task",
"futures-util",
"getrandom 0.2.15", "getrandom 0.2.15",
"libc", "libc",
"log", "log",
@ -1630,7 +1634,11 @@ dependencies = [
"regex-automata", "regex-automata",
"regex-syntax", "regex-syntax",
"serde 1.0.217", "serde 1.0.217",
"smallvec",
"syn 2.0.96", "syn 2.0.96",
"tokio",
"tokio-util",
"tower 0.4.13",
"tracing", "tracing",
"tracing-core", "tracing-core",
] ]
@ -2033,6 +2041,7 @@ dependencies = [
"futures-util", "futures-util",
"hyper 0.14.32", "hyper 0.14.32",
"lazy_static", "lazy_static",
"my-workspace-hack",
"prometheus", "prometheus",
"regex", "regex",
"reqwest", "reqwest",

View File

@ -7,3 +7,4 @@ edition = "2024"
[dependencies] [dependencies]
serde_json = "1.0" serde_json = "1.0"
my-workspace-hack = { version = "0.1", path = "../my-workspace-hack" }

View File

@ -104,14 +104,12 @@ pub fn create_cni_network(cid: String, ns: String) -> Result<(String, String), E
}; };
if let Some(ips) = json.get("ips").and_then(|ips| ips.as_array()) { if let Some(ips) = json.get("ips").and_then(|ips| ips.as_array()) {
if let Some(first_ip) = ips if let Some(first_ip) = ips
.get(0) .first()
.and_then(|ip| ip.get("address")) .and_then(|ip| ip.get("address"))
.and_then(|addr| addr.as_str()) .and_then(|addr| addr.as_str())
{ {
ip = first_ip.to_string(); ip = first_ip.to_string();
} else {
} }
} else {
} }
} }
Err(e) => { Err(e) => {
@ -142,14 +140,11 @@ pub fn delete_cni_network(ns: &str, cid: &str) {
} }
fn dir_exists(dirname: &Path) -> bool { fn dir_exists(dirname: &Path) -> bool {
path_exists(dirname).map_or(false, |info| info.is_dir()) path_exists(dirname).is_some_and(|info| info.is_dir())
} }
fn path_exists(path: &Path) -> Option<fs::Metadata> { fn path_exists(path: &Path) -> Option<fs::Metadata> {
match fs::metadata(path) { fs::metadata(path).ok()
Ok(metadata) => Some(metadata),
Err(_) => None,
}
} }
#[allow(unused)] #[allow(unused)]

View File

@ -17,14 +17,21 @@ publish = false
[dependencies] [dependencies]
actix-router = { version = "0.5", default-features = false, features = ["http", "unicode"] } actix-router = { version = "0.5", default-features = false, features = ["http", "unicode"] }
bytes = { version = "1" } bytes = { version = "1" }
futures-channel = { version = "0.3", features = ["sink"] }
futures-task = { version = "0.3", default-features = false, features = ["std"] }
futures-util = { version = "0.3", features = ["channel", "io", "sink"] }
log = { version = "0.4", default-features = false, features = ["std"] } log = { version = "0.4", default-features = false, features = ["std"] }
memchr = { version = "2" } memchr = { version = "2", features = ["use_std"] }
mio = { version = "1", features = ["net", "os-ext"] } mio = { version = "1", features = ["net", "os-ext"] }
prost = { version = "0.13", features = ["prost-derive"] } prost = { version = "0.13", features = ["prost-derive"] }
regex = { version = "1" } regex = { version = "1" }
regex-automata = { version = "0.4", default-features = false, features = ["dfa-onepass", "hybrid", "meta", "nfa-backtrack", "perf-inline", "perf-literal", "unicode"] } regex-automata = { version = "0.4", default-features = false, features = ["dfa-onepass", "hybrid", "meta", "nfa-backtrack", "perf-inline", "perf-literal", "unicode"] }
regex-syntax = { version = "0.8" } regex-syntax = { version = "0.8" }
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
smallvec = { version = "1", default-features = false, features = ["const_new"] }
tokio = { version = "1", features = ["full"] }
tokio-util = { version = "0.7", features = ["codec", "io"] }
tower = { version = "0.4", features = ["balance", "buffer", "limit", "util"] }
tracing = { version = "0.1", features = ["log"] } tracing = { version = "0.1", features = ["log"] }
tracing-core = { version = "0.1", default-features = false, features = ["std"] } tracing-core = { version = "0.1", default-features = false, features = ["std"] }
@ -32,7 +39,7 @@ tracing-core = { version = "0.1", default-features = false, features = ["std"] }
actix-router = { version = "0.5", default-features = false, features = ["http", "unicode"] } actix-router = { version = "0.5", default-features = false, features = ["http", "unicode"] }
bytes = { version = "1" } bytes = { version = "1" }
log = { version = "0.4", default-features = false, features = ["std"] } log = { version = "0.4", default-features = false, features = ["std"] }
memchr = { version = "2" } memchr = { version = "2", features = ["use_std"] }
prost = { version = "0.13", features = ["prost-derive"] } prost = { version = "0.13", features = ["prost-derive"] }
regex = { version = "1" } regex = { version = "1" }
regex-automata = { version = "0.4", default-features = false, features = ["dfa-onepass", "hybrid", "meta", "nfa-backtrack", "perf-inline", "perf-literal", "unicode"] } regex-automata = { version = "0.4", default-features = false, features = ["dfa-onepass", "hybrid", "meta", "nfa-backtrack", "perf-inline", "perf-literal", "unicode"] }

View File

@ -27,3 +27,4 @@ futures-util = "0.3"
service = { path = "../service" } service = { path = "../service" }
async-trait = "0.1" async-trait = "0.1"
lazy_static = "1.4.0" lazy_static = "1.4.0"
my-workspace-hack = { version = "0.1", path = "../my-workspace-hack" }

View File

@ -1,10 +1,5 @@
use actix_web::dev::{Service, Transform}; use actix_web::{Error, HttpMessage, HttpResponse, dev::ServiceRequest};
use actix_web::http::header::HeaderValue;
use actix_web::{Error, HttpMessage, HttpResponse, dev::ServiceRequest, dev::ServiceResponse};
use futures_util::future::{LocalBoxFuture, Ready, ok};
use std::collections::HashMap; use std::collections::HashMap;
use std::rc::Rc;
use std::task::{Context, Poll};
//写到使用actix-web-httpauth作为中间件还没有解决read_basic_auth函数的实现返回值和之前在bootstrap的调用不一样 //写到使用actix-web-httpauth作为中间件还没有解决read_basic_auth函数的实现返回值和之前在bootstrap的调用不一样

View File

@ -1,4 +1,4 @@
use actix_web::{App, HttpResponse, HttpServer, Responder, guard, middleware, web}; use actix_web::{App, HttpServer, middleware, web};
use prometheus::Registry; use prometheus::Registry;
use std::collections::HashMap; use std::collections::HashMap;

View File

@ -17,8 +17,7 @@ impl IAmHandler for DeployHandler {
let cid = input.container_id.clone(); let cid = input.container_id.clone();
let image = input.image.clone(); let image = input.image.clone();
let ns = input.ns.clone(); let ns = input.ns.clone();
let _ = self self.service
.service
.create_container(&image, &cid, &ns) .create_container(&image, &cid, &ns)
.await .await
.unwrap(); .unwrap();

View File

@ -1,11 +1,9 @@
pub mod deploy; pub mod deploy;
pub mod function_list; pub mod function_list;
pub mod namespace_list; pub mod namespace_list;
use lazy_static::lazy_static;
use std::collections::HashMap;
use actix_web::{HttpRequest, HttpResponse, Responder}; use actix_web::{HttpRequest, HttpResponse, Responder};
use serde::{Serialize, de::DeserializeOwned}; use serde::de::DeserializeOwned;
pub async fn function_lister(_req: HttpRequest) -> impl Responder { pub async fn function_lister(_req: HttpRequest) -> impl Responder {
HttpResponse::Ok().body("函数列表") HttpResponse::Ok().body("函数列表")

View File

@ -11,6 +11,12 @@ pub struct HttpMetrics {
pub requests_total: prometheus::IntCounterVec, pub requests_total: prometheus::IntCounterVec,
} }
impl Default for HttpMetrics {
fn default() -> Self {
Self::new()
}
}
impl HttpMetrics { impl HttpMetrics {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {

View File

@ -32,6 +32,12 @@ pub struct FaaSConfig {
pub max_idle_conns_per_host: usize, pub max_idle_conns_per_host: usize,
} }
impl Default for FaaSConfig {
fn default() -> Self {
Self::new()
}
}
impl FaaSConfig { impl FaaSConfig {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {

View File

@ -98,7 +98,7 @@ impl Service {
let _mount = self.prepare_snapshot(cid, ns).await?; let _mount = self.prepare_snapshot(cid, ns).await?;
let (env, args) = self.get_env_and_args(image_name, ns).await?; let (env, args) = self.get_env_and_args(image_name, ns).await?;
let spec_path = generate_spec(&cid, ns, args, env).unwrap(); let spec_path = generate_spec(cid, ns, args, env).unwrap();
let spec = fs::read_to_string(spec_path).unwrap(); let spec = fs::read_to_string(spec_path).unwrap();
let spec = Any { let spec = Any {
@ -430,10 +430,12 @@ impl Service {
}; };
c.transfer(with_namespace!(req, namespace)) c.transfer(with_namespace!(req, namespace))
.await .await
.expect(&format!( .unwrap_or_else(|_| {
panic!(
"Unable to transfer image {} to namespace {}", "Unable to transfer image {} to namespace {}",
image_name, namespace image_name, namespace
)); )
});
Ok(()) Ok(())
} }
@ -443,7 +445,7 @@ impl Service {
} }
async fn handle_index(&self, data: &Vec<u8>, ns: &str) -> Option<ImageConfiguration> { async fn handle_index(&self, data: &Vec<u8>, ns: &str) -> Option<ImageConfiguration> {
let image_index: ImageIndex = ::serde_json::from_slice(&data).unwrap(); let image_index: ImageIndex = ::serde_json::from_slice(data).unwrap();
let img_manifest_dscr = image_index let img_manifest_dscr = image_index
.manifests() .manifests()
.iter() .iter()
@ -485,7 +487,7 @@ impl Service {
} }
async fn handle_manifest(&self, data: &Vec<u8>, ns: &str) -> Option<ImageConfiguration> { async fn handle_manifest(&self, data: &Vec<u8>, ns: &str) -> Option<ImageConfiguration> {
let img_manifest: ImageManifest = ::serde_json::from_slice(&data).unwrap(); let img_manifest: ImageManifest = ::serde_json::from_slice(data).unwrap();
let img_manifest_dscr = img_manifest.config(); let img_manifest_dscr = img_manifest.config();
let req = ReadContentRequest { let req = ReadContentRequest {
@ -598,7 +600,7 @@ impl Service {
.next() .next()
.map_or_else(String::new, |layer_digest| layer_digest.clone()); .map_or_else(String::new, |layer_digest| layer_digest.clone());
while let Some(layer_digest) = iter.next() { for layer_digest in iter {
let mut hasher = Sha256::new(); let mut hasher = Sha256::new();
hasher.update(ret.as_bytes()); hasher.update(ret.as_bytes());
ret.push_str(&format!(",{}", layer_digest)); ret.push_str(&format!(",{}", layer_digest));

View File

@ -58,7 +58,7 @@ impl Systemd {
} }
pub fn install_unit(name: String, tokens: HashMap<String, String>) -> Result<(), Err> { pub fn install_unit(name: String, tokens: HashMap<String, String>) -> Result<(), Err> {
if tokens.get("Cwd").map_or(true, |v| v.is_empty()) { if tokens.get("Cwd").is_none_or(|v| v.is_empty()) {
return Err("key Cwd expected in tokens parameter".into()); return Err("key Cwd expected in tokens parameter".into());
} }