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

View File

@ -6,4 +6,5 @@ edition = "2024"
# authors.workspace = true
[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(first_ip) = ips
.get(0)
.first()
.and_then(|ip| ip.get("address"))
.and_then(|addr| addr.as_str())
{
ip = first_ip.to_string();
} else {
}
} else {
}
}
Err(e) => {
@ -142,14 +140,11 @@ pub fn delete_cni_network(ns: &str, cid: &str) {
}
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> {
match fs::metadata(path) {
Ok(metadata) => Some(metadata),
Err(_) => None,
}
fs::metadata(path).ok()
}
#[allow(unused)]

View File

@ -17,14 +17,21 @@ publish = false
[dependencies]
actix-router = { version = "0.5", default-features = false, features = ["http", "unicode"] }
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"] }
memchr = { version = "2" }
memchr = { version = "2", features = ["use_std"] }
mio = { version = "1", features = ["net", "os-ext"] }
prost = { version = "0.13", features = ["prost-derive"] }
regex = { version = "1" }
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" }
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-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"] }
bytes = { version = "1" }
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"] }
regex = { version = "1" }
regex-automata = { version = "0.4", default-features = false, features = ["dfa-onepass", "hybrid", "meta", "nfa-backtrack", "perf-inline", "perf-literal", "unicode"] }

View File

@ -26,4 +26,5 @@ base64 = "0.13"
futures-util = "0.3"
service = { path = "../service" }
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::http::header::HeaderValue;
use actix_web::{Error, HttpMessage, HttpResponse, dev::ServiceRequest, dev::ServiceResponse};
use futures_util::future::{LocalBoxFuture, Ready, ok};
use actix_web::{Error, HttpMessage, HttpResponse, dev::ServiceRequest};
use std::collections::HashMap;
use std::rc::Rc;
use std::task::{Context, Poll};
//写到使用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 std::collections::HashMap;

View File

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

View File

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

View File

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

View File

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

View File

@ -98,7 +98,7 @@ impl Service {
let _mount = self.prepare_snapshot(cid, 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 = Any {
@ -430,10 +430,12 @@ impl Service {
};
c.transfer(with_namespace!(req, namespace))
.await
.expect(&format!(
"Unable to transfer image {} to namespace {}",
image_name, namespace
));
.unwrap_or_else(|_| {
panic!(
"Unable to transfer image {} to namespace {}",
image_name, namespace
)
});
Ok(())
}
@ -443,7 +445,7 @@ impl Service {
}
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
.manifests()
.iter()
@ -485,7 +487,7 @@ impl Service {
}
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 req = ReadContentRequest {
@ -598,7 +600,7 @@ impl Service {
.next()
.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();
hasher.update(ret.as_bytes());
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> {
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());
}