diff --git a/Cargo.lock b/Cargo.lock index 9a5f720..f4c756e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/crates/cni/Cargo.toml b/crates/cni/Cargo.toml index 0cbb13d..982e4aa 100644 --- a/crates/cni/Cargo.toml +++ b/crates/cni/Cargo.toml @@ -6,4 +6,5 @@ edition = "2024" # authors.workspace = true [dependencies] -serde_json = "1.0" \ No newline at end of file +serde_json = "1.0" +my-workspace-hack = { version = "0.1", path = "../my-workspace-hack" } \ No newline at end of file diff --git a/crates/cni/src/cni_network.rs b/crates/cni/src/cni_network.rs index 6b358fe..0a7d09d 100644 --- a/crates/cni/src/cni_network.rs +++ b/crates/cni/src/cni_network.rs @@ -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 { - match fs::metadata(path) { - Ok(metadata) => Some(metadata), - Err(_) => None, - } + fs::metadata(path).ok() } #[allow(unused)] diff --git a/crates/my-workspace-hack/Cargo.toml b/crates/my-workspace-hack/Cargo.toml index 0e57c55..02f5775 100644 --- a/crates/my-workspace-hack/Cargo.toml +++ b/crates/my-workspace-hack/Cargo.toml @@ -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"] } diff --git a/crates/provider/Cargo.toml b/crates/provider/Cargo.toml index 149a0d2..22f0cd6 100644 --- a/crates/provider/Cargo.toml +++ b/crates/provider/Cargo.toml @@ -26,4 +26,5 @@ base64 = "0.13" futures-util = "0.3" service = { path = "../service" } async-trait = "0.1" -lazy_static = "1.4.0" \ No newline at end of file +lazy_static = "1.4.0" +my-workspace-hack = { version = "0.1", path = "../my-workspace-hack" } \ No newline at end of file diff --git a/crates/provider/src/auth/mod.rs b/crates/provider/src/auth/mod.rs index 521009f..8744c42 100644 --- a/crates/provider/src/auth/mod.rs +++ b/crates/provider/src/auth/mod.rs @@ -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的调用不一样 diff --git a/crates/provider/src/bootstrap/mod.rs b/crates/provider/src/bootstrap/mod.rs index 12cf09d..02fd6bc 100644 --- a/crates/provider/src/bootstrap/mod.rs +++ b/crates/provider/src/bootstrap/mod.rs @@ -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; diff --git a/crates/provider/src/handlers/deploy.rs b/crates/provider/src/handlers/deploy.rs index 59e4a3f..bff9d91 100644 --- a/crates/provider/src/handlers/deploy.rs +++ b/crates/provider/src/handlers/deploy.rs @@ -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(); diff --git a/crates/provider/src/handlers/mod.rs b/crates/provider/src/handlers/mod.rs index 0c00718..26b5ff5 100644 --- a/crates/provider/src/handlers/mod.rs +++ b/crates/provider/src/handlers/mod.rs @@ -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("函数列表") diff --git a/crates/provider/src/metrics/mod.rs b/crates/provider/src/metrics/mod.rs index 6362eb4..bb4ebbd 100644 --- a/crates/provider/src/metrics/mod.rs +++ b/crates/provider/src/metrics/mod.rs @@ -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 { diff --git a/crates/provider/src/types/config.rs b/crates/provider/src/types/config.rs index de24f43..1567bec 100644 --- a/crates/provider/src/types/config.rs +++ b/crates/provider/src/types/config.rs @@ -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 { diff --git a/crates/service/src/lib.rs b/crates/service/src/lib.rs index 59b3766..99226c7 100644 --- a/crates/service/src/lib.rs +++ b/crates/service/src/lib.rs @@ -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, ns: &str) -> Option { - 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, ns: &str) -> Option { - 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)); diff --git a/crates/service/src/systemd.rs b/crates/service/src/systemd.rs index 16c5da5..ed33829 100644 --- a/crates/service/src/systemd.rs +++ b/crates/service/src/systemd.rs @@ -58,7 +58,7 @@ impl Systemd { } pub fn install_unit(name: String, tokens: HashMap) -> 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()); }