From 67b54ac1eb3df336cf9a4d76ee08ca8aaa139403 Mon Sep 17 00:00:00 2001 From: J M <2364004+Blu-J@users.noreply.github.com> Date: Wed, 9 Nov 2022 12:19:08 -0700 Subject: [PATCH] feat: Exposing the rsync that we have to the js (#1907) chore: Make the commit do by checksum. chore: Remove the logging at the start chore: use the defaults of the original. chore: Convert the error into just the source. chore: Remove some of the unwraps --- .github/workflows/backend.yaml | 1 + Makefile | 2 +- backend/Cargo.lock | 13 + backend/Cargo.toml | 2 +- backend/src/error.rs | 332 +---- backend/src/os_install.rs | 2 +- backend/src/procedure/js_scripts.rs | 48 + backend/src/setup.rs | 2 +- backend/src/update/mod.rs | 3 +- backend/src/util/io.rs | 28 - backend/src/util/mod.rs | 1 - .../scripts/test-package/0.3.0.3/embassy.js | 59 + .../data/main/testing-rsync/someFile.txt | 1 + libs/Cargo.lock | 1216 ++++++++++++++++- libs/Cargo.toml | 4 +- libs/build-arm-v8-snapshot.sh | 4 +- libs/build-v8-snapshot.sh | 2 +- .../Cargo.toml | 0 .../src/lib.rs | 8 +- .../src/main.rs | 20 +- libs/helpers/Cargo.toml | 5 +- libs/helpers/src/byte_replacement_reader.rs | 31 + libs/helpers/src/lib.rs | 4 + .../src/util => libs/helpers/src}/rsync.rs | 51 +- libs/js_engine/Cargo.toml | 2 +- libs/js_engine/src/artifacts/loadModule.js | 36 +- libs/js_engine/src/lib.rs | 154 ++- libs/models/Cargo.toml | 21 +- libs/models/src/errors.rs | 388 ++++++ libs/models/src/lib.rs | 2 + .../Cargo.toml | 2 +- .../src/main.rs | 0 32 files changed, 2003 insertions(+), 441 deletions(-) create mode 100644 backend/test/js_action_execute/package-data/volumes/test-package/data/main/testing-rsync/someFile.txt rename libs/{embassy-container-init => embassy_container_init}/Cargo.toml (100%) rename libs/{embassy-container-init => embassy_container_init}/src/lib.rs (90%) rename libs/{embassy-container-init => embassy_container_init}/src/main.rs (94%) create mode 100644 libs/helpers/src/byte_replacement_reader.rs rename {backend/src/util => libs/helpers/src}/rsync.rs (63%) create mode 100644 libs/models/src/errors.rs rename libs/{snapshot-creator => snapshot_creator}/Cargo.toml (91%) rename libs/{snapshot-creator => snapshot_creator}/src/main.rs (100%) diff --git a/.github/workflows/backend.yaml b/.github/workflows/backend.yaml index 8f22d75e1..15329a415 100644 --- a/.github/workflows/backend.yaml +++ b/.github/workflows/backend.yaml @@ -221,6 +221,7 @@ jobs: sh -c ' apt-get update && apt-get install -y ca-certificates && + apt-get install -y rsync && cd /home/rust/src && mkdir -p ~/.cargo/bin && tar -zxvf nextest-aarch64.tar.gz -C ${CARGO_HOME:-~/.cargo}/bin && diff --git a/Makefile b/Makefile index 114f8c056..ab9082752 100644 --- a/Makefile +++ b/Makefile @@ -112,7 +112,7 @@ product_key.txt: if [ "$(KEY)" != "" ]; then $(shell which echo) -n "$(KEY)" > product_key.txt; fi echo >> product_key.txt -snapshots: libs/snapshot-creator/Cargo.toml +snapshots: libs/snapshot_creator/Cargo.toml cd libs/ && ./build-v8-snapshot.sh cd libs/ && ./build-arm-v8-snapshot.sh diff --git a/backend/Cargo.lock b/backend/Cargo.lock index fa2f71579..cf0630b07 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -1746,7 +1746,10 @@ dependencies = [ "futures", "models", "pin-project", + "serde", "tokio", + "tokio-stream", + "tracing", ] [[package]] @@ -2452,13 +2455,23 @@ dependencies = [ name = "models" version = "0.1.0" dependencies = [ + "bollard", + "color-eyre", + "ed25519-dalek", "embassy_container_init", "emver", + "mbrman", + "openssl", "patch-db", "rand 0.8.5", + "rpc-toolkit", "serde", + "serde_json", + "sqlx", "thiserror", "tokio", + "torut", + "tracing", ] [[package]] diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 11eb0a077..46d1abfaa 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -76,7 +76,7 @@ fd-lock-rs = "0.1.4" futures = "0.3.21" git-version = "0.3.5" helpers = { path = "../libs/helpers" } -embassy_container_init = { path = "../libs/embassy-container-init" } +embassy_container_init = { path = "../libs/embassy_container_init" } hex = "0.4.3" hmac = "0.12.1" http = "0.2.8" diff --git a/backend/src/error.rs b/backend/src/error.rs index d250a6bbb..d4286339d 100644 --- a/backend/src/error.rs +++ b/backend/src/error.rs @@ -1,295 +1,5 @@ -use std::fmt::Display; - use color_eyre::eyre::eyre; -use http::uri::InvalidUri; -use models::InvalidId; -use patch_db::Revision; -use rpc_toolkit::yajrc::RpcError; - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum ErrorKind { - Unknown = 1, - Filesystem = 2, - Docker = 3, - ConfigSpecViolation = 4, - ConfigRulesViolation = 5, - NotFound = 6, - IncorrectPassword = 7, - VersionIncompatible = 8, - Network = 9, - Registry = 10, - Serialization = 11, - Deserialization = 12, - Utf8 = 13, - ParseVersion = 14, - IncorrectDisk = 15, - // Nginx = 16, - Dependency = 17, - ParseS9pk = 18, - ParseUrl = 19, - DiskNotAvailable = 20, - BlockDevice = 21, - InvalidOnionAddress = 22, - Pack = 23, - ValidateS9pk = 24, - DiskCorrupted = 25, // Remove - Tor = 26, - ConfigGen = 27, - ParseNumber = 28, - Database = 29, - InvalidPackageId = 30, - InvalidSignature = 31, - Backup = 32, - Restore = 33, - Authorization = 34, - AutoConfigure = 35, - Action = 36, - RateLimited = 37, - InvalidRequest = 38, - MigrationFailed = 39, - Uninitialized = 40, - ParseNetAddress = 41, - ParseSshKey = 42, - SoundError = 43, - ParseTimestamp = 44, - ParseSysInfo = 45, - Wifi = 46, - Journald = 47, - DiskManagement = 48, - OpenSsl = 49, - PasswordHashGeneration = 50, - DiagnosticMode = 51, - ParseDbField = 52, - Duplicate = 53, - MultipleErrors = 54, - Incoherent = 55, - InvalidBackupTargetId = 56, - ProductKeyMismatch = 57, - LanPortConflict = 58, - Javascript = 59, - Pem = 60, - TLSInit = 61, - HttpRange = 62, - ContentLength = 63, - BytesError = 64, - InvalidIP = 65, - JoinError = 66, - AsciiError = 67, - NoHost = 68, - SignError = 69, -} -impl ErrorKind { - pub fn as_str(&self) -> &'static str { - use ErrorKind::*; - match self { - Unknown => "Unknown Error", - Filesystem => "Filesystem I/O Error", - Docker => "Docker Error", - ConfigSpecViolation => "Config Spec Violation", - ConfigRulesViolation => "Config Rules Violation", - NotFound => "Not Found", - IncorrectPassword => "Incorrect Password", - VersionIncompatible => "Version Incompatible", - Network => "Network Error", - Registry => "Registry Error", - Serialization => "Serialization Error", - Deserialization => "Deserialization Error", - Utf8 => "UTF-8 Parse Error", - ParseVersion => "Version Parsing Error", - IncorrectDisk => "Incorrect Disk", - // Nginx => "Nginx Error", - Dependency => "Dependency Error", - ParseS9pk => "S9PK Parsing Error", - ParseUrl => "URL Parsing Error", - DiskNotAvailable => "Disk Not Available", - BlockDevice => "Block Device Error", - InvalidOnionAddress => "Invalid Onion Address", - Pack => "Pack Error", - ValidateS9pk => "S9PK Validation Error", - DiskCorrupted => "Disk Corrupted", // Remove - Tor => "Tor Daemon Error", - ConfigGen => "Config Generation Error", - ParseNumber => "Number Parsing Error", - Database => "Database Error", - InvalidPackageId => "Invalid Package ID", - InvalidSignature => "Invalid Signature", - Backup => "Backup Error", - Restore => "Restore Error", - Authorization => "Unauthorized", - AutoConfigure => "Auto-Configure Error", - Action => "Action Failed", - RateLimited => "Rate Limited", - InvalidRequest => "Invalid Request", - MigrationFailed => "Migration Failed", - Uninitialized => "Uninitialized", - ParseNetAddress => "Net Address Parsing Error", - ParseSshKey => "SSH Key Parsing Error", - SoundError => "Sound Interface Error", - ParseTimestamp => "Timestamp Parsing Error", - ParseSysInfo => "System Info Parsing Error", - Wifi => "WiFi Internal Error", - Journald => "Journald Error", - DiskManagement => "Disk Management Error", - OpenSsl => "OpenSSL Internal Error", - PasswordHashGeneration => "Password Hash Generation Error", - DiagnosticMode => "Embassy is in Diagnostic Mode", - ParseDbField => "Database Field Parse Error", - Duplicate => "Duplication Error", - MultipleErrors => "Multiple Errors", - Incoherent => "Incoherent", - InvalidBackupTargetId => "Invalid Backup Target ID", - ProductKeyMismatch => "Incompatible Product Keys", - LanPortConflict => "Incompatible LAN Port Configuration", - Javascript => "Javascript Engine Error", - Pem => "PEM Encoding Error", - TLSInit => "TLS Backend Initialize Error", - HttpRange => "No Support for Web Server HTTP Ranges", - ContentLength => "Request has no content length header", - BytesError => "Could not get the bytes for this request", - InvalidIP => "Could not parse this IP address", - JoinError => "Join Handle Error", - AsciiError => "Could not parse ascii text", - NoHost => "No Host header ", - SignError => "Signing error", - } - } -} -impl Display for ErrorKind { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.as_str()) - } -} - -#[derive(Debug)] -pub struct Error { - pub source: color_eyre::eyre::Error, - pub kind: ErrorKind, - pub revision: Option, -} - -impl Display for Error { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}: {}", self.kind.as_str(), self.source) - } -} -impl Error { - pub fn new>(source: E, kind: ErrorKind) -> Self { - Error { - source: source.into(), - kind, - revision: None, - } - } -} -impl From for Error { - fn from(err: InvalidId) -> Self { - Error::new(err, crate::error::ErrorKind::InvalidPackageId) - } -} -impl From for Error { - fn from(e: std::io::Error) -> Self { - Error::new(e, ErrorKind::Filesystem) - } -} -impl From for Error { - fn from(e: std::str::Utf8Error) -> Self { - Error::new(e, ErrorKind::Utf8) - } -} -impl From for Error { - fn from(e: std::string::FromUtf8Error) -> Self { - Error::new(e, ErrorKind::Utf8) - } -} -impl From for Error { - fn from(e: emver::ParseError) -> Self { - Error::new(e, ErrorKind::ParseVersion) - } -} -impl From for Error { - fn from(e: rpc_toolkit::url::ParseError) -> Self { - Error::new(e, ErrorKind::ParseUrl) - } -} -impl From for Error { - fn from(e: std::num::ParseIntError) -> Self { - Error::new(e, ErrorKind::ParseNumber) - } -} -impl From for Error { - fn from(e: std::num::ParseFloatError) -> Self { - Error::new(e, ErrorKind::ParseNumber) - } -} -impl From for Error { - fn from(e: patch_db::Error) -> Self { - Error::new(e, ErrorKind::Database) - } -} -impl From for Error { - fn from(e: sqlx::Error) -> Self { - Error::new(e, ErrorKind::Database) - } -} -impl From for Error { - fn from(e: ed25519_dalek::SignatureError) -> Self { - Error::new(e, ErrorKind::InvalidSignature) - } -} -impl From for Error { - fn from(e: bollard::errors::Error) -> Self { - Error::new(e, ErrorKind::Docker) - } -} -impl From for Error { - fn from(e: torut::control::ConnError) -> Self { - Error::new(eyre!("{:?}", e), ErrorKind::Tor) - } -} -impl From for Error { - fn from(e: std::net::AddrParseError) -> Self { - Error::new(e, ErrorKind::ParseNetAddress) - } -} -impl From for Error { - fn from(e: openssl::error::ErrorStack) -> Self { - Error::new(eyre!("{}", e), ErrorKind::OpenSsl) - } -} -impl From for Error { - fn from(e: mbrman::Error) -> Self { - Error::new(e, ErrorKind::DiskManagement) - } -} - -impl From for Error { - fn from(e: InvalidUri) -> Self { - Error::new(eyre!("{}", e), ErrorKind::ParseUrl) - } -} - -impl From for RpcError { - fn from(e: Error) -> Self { - let mut data_object = serde_json::Map::with_capacity(3); - data_object.insert("details".to_owned(), format!("{}", e.source).into()); - data_object.insert("debug".to_owned(), format!("{:?}", e.source).into()); - data_object.insert( - "revision".to_owned(), - match serde_json::to_value(&e.revision) { - Ok(a) => a, - Err(e) => { - tracing::warn!("Error serializing revision for Error object: {}", e); - serde_json::Value::Null - } - }, - ); - RpcError { - code: e.kind as i32, - message: e.kind.as_str().into(), - data: Some(data_object.into()), - } - } -} +pub use models::{Error, ErrorKind, ResultExt}; #[derive(Debug, Default)] pub struct ErrorCollection(Vec); @@ -340,46 +50,6 @@ impl std::fmt::Display for ErrorCollection { } } -pub trait ResultExt -where - Self: Sized, -{ - fn with_kind(self, kind: ErrorKind) -> Result; - fn with_ctx (ErrorKind, D), D: Display + Send + Sync + 'static>( - self, - f: F, - ) -> Result; -} -impl ResultExt for Result -where - color_eyre::eyre::Error: From, -{ - fn with_kind(self, kind: ErrorKind) -> Result { - self.map_err(|e| Error { - source: e.into(), - kind, - revision: None, - }) - } - - fn with_ctx (ErrorKind, D), D: Display + Send + Sync + 'static>( - self, - f: F, - ) -> Result { - self.map_err(|e| { - let (kind, ctx) = f(&e); - let source = color_eyre::eyre::Error::from(e); - let ctx = format!("{}: {}", ctx, source); - let source = source.wrap_err(ctx); - Error { - kind, - source: source.into(), - revision: None, - } - }) - } -} - #[macro_export] macro_rules! ensure_code { ($x:expr, $c:expr, $fmt:expr $(, $arg:expr)*) => { diff --git a/backend/src/os_install.rs b/backend/src/os_install.rs index c670ea75d..29038c5f1 100644 --- a/backend/src/os_install.rs +++ b/backend/src/os_install.rs @@ -2,6 +2,7 @@ use std::path::{Path, PathBuf}; use color_eyre::eyre::eyre; use mbrman::{MBRPartitionEntry, CHS, MBR}; +use models::Error; use rpc_toolkit::command; use serde::{Deserialize, Serialize}; use tokio::process::Command; @@ -14,7 +15,6 @@ use crate::disk::mount::guard::{MountGuard, TmpMountGuard}; use crate::disk::OsPartitionInfo; use crate::util::serde::IoFormat; use crate::util::{display_none, Invoke}; -use crate::{Error, ResultExt}; #[derive(Debug, Deserialize, Serialize)] #[serde(rename_all = "kebab-case")] diff --git a/backend/src/procedure/js_scripts.rs b/backend/src/procedure/js_scripts.rs index 70a1a7b77..b76e70d01 100644 --- a/backend/src/procedure/js_scripts.rs +++ b/backend/src/procedure/js_scripts.rs @@ -556,3 +556,51 @@ async fn js_action_test_deep_dir_escape() { .unwrap() .unwrap(); } + +#[tokio::test] +async fn js_rsync() { + let js_action = JsProcedure { args: vec![] }; + let path: PathBuf = "test/js_action_execute/" + .parse::() + .unwrap() + .canonicalize() + .unwrap(); + let package_id = "test-package".parse().unwrap(); + let package_version: Version = "0.3.0.3".parse().unwrap(); + let name = ProcedureName::Action("test-rsync".parse().unwrap()); + let volumes: Volumes = serde_json::from_value(serde_json::json!({ + "main": { + "type": "data" + }, + "compat": { + "type": "assets" + }, + "filebrowser" :{ + "package-id": "filebrowser", + "path": "data", + "readonly": true, + "type": "pointer", + "volume-id": "main", + } + })) + .unwrap(); + let input: Option = None; + let timeout = Some(Duration::from_secs(10)); + js_action + .execute::( + &path, + &package_id, + &package_version, + name, + &volumes, + input, + timeout, + Arc::new(|_, _, _, _| { + Box::pin(async move { Err("Can't run commands in test".to_string()) }) + }), + Arc::new(|_| Box::pin(async move { Err("Can't run commands in test".to_string()) })), + ) + .await + .unwrap() + .unwrap(); +} diff --git a/backend/src/setup.rs b/backend/src/setup.rs index 4f65a9062..c4a74cecf 100644 --- a/backend/src/setup.rs +++ b/backend/src/setup.rs @@ -4,6 +4,7 @@ use std::sync::Arc; use color_eyre::eyre::eyre; use futures::future::BoxFuture; use futures::{StreamExt, TryFutureExt}; +use helpers::{Rsync, RsyncOptions}; use josekit::jwk::Jwk; use openssl::x509::X509; use patch_db::DbHandle; @@ -33,7 +34,6 @@ use crate::init::init; use crate::middleware::encrypt::EncryptedWire; use crate::net::ssl::SslManager; use crate::sound::BEETHOVEN; -use crate::util::rsync::{Rsync, RsyncOptions}; use crate::{Error, ErrorKind, ResultExt}; #[instrument(skip(secrets))] diff --git a/backend/src/update/mod.rs b/backend/src/update/mod.rs index 948f27a86..5c9435606 100644 --- a/backend/src/update/mod.rs +++ b/backend/src/update/mod.rs @@ -4,6 +4,7 @@ use std::sync::Arc; use clap::ArgMatches; use color_eyre::eyre::{eyre, Result}; use emver::Version; +use helpers::{Rsync, RsyncOptions}; use lazy_static::lazy_static; use patch_db::{DbHandle, LockType, Revision}; use reqwest::Url; @@ -25,7 +26,7 @@ use crate::sound::{ CIRCLE_OF_5THS_SHORT, UPDATE_FAILED_1, UPDATE_FAILED_2, UPDATE_FAILED_3, UPDATE_FAILED_4, }; use crate::update::latest_information::LatestInformation; -use crate::util::rsync::{Rsync, RsyncOptions}; + use crate::util::Invoke; use crate::version::{Current, VersionT}; use crate::{Error, ErrorKind, ResultExt}; diff --git a/backend/src/util/io.rs b/backend/src/util/io.rs index d30bdaaf5..af3b5b7da 100644 --- a/backend/src/util/io.rs +++ b/backend/src/util/io.rs @@ -295,31 +295,3 @@ impl AsyncRead for BufferedWriteReader { } } } - -#[pin_project::pin_project] -pub struct ByteReplacementReader { - pub replace: u8, - pub with: u8, - #[pin] - pub inner: R, -} -impl AsyncRead for ByteReplacementReader { - fn poll_read( - self: std::pin::Pin<&mut Self>, - cx: &mut std::task::Context<'_>, - buf: &mut ReadBuf<'_>, - ) -> std::task::Poll> { - let this = self.project(); - match this.inner.poll_read(cx, buf) { - Poll::Ready(Ok(())) => { - for idx in 0..buf.filled().len() { - if buf.filled()[idx] == *this.replace { - buf.filled_mut()[idx] = *this.with; - } - } - Poll::Ready(Ok(())) - } - a => a, - } - } -} diff --git a/backend/src/util/mod.rs b/backend/src/util/mod.rs index afa65baa2..ebfb14192 100644 --- a/backend/src/util/mod.rs +++ b/backend/src/util/mod.rs @@ -27,7 +27,6 @@ pub mod config; pub mod http_reader; pub mod io; pub mod logger; -pub mod rsync; pub mod serde; #[derive(Clone, Copy, Debug)] diff --git a/backend/test/js_action_execute/package-data/scripts/test-package/0.3.0.3/embassy.js b/backend/test/js_action_execute/package-data/scripts/test-package/0.3.0.3/embassy.js index 729d47d19..d5e3a7a57 100644 --- a/backend/test/js_action_execute/package-data/scripts/test-package/0.3.0.3/embassy.js +++ b/backend/test/js_action_execute/package-data/scripts/test-package/0.3.0.3/embassy.js @@ -915,4 +915,63 @@ export const action = { }, }; }, + + + /** + * Want to test that rsync works + * @param {*} effects + * @param {*} _input + * @returns + */ + async "test-rsync"(effects, _input) { + try { + await effects + .removeDir({ + volumeId: "main", + path: "test-rsync-out", + }) + .catch(() => {}); + const runningRsync = effects.runRsync({ + srcVolume: "main", + srcPath: "testing-rsync", + dstVolume: "main", + dstPath: "test-rsync-out", + options: { + delete: true, + force: true, + ignoreExisting: false, + } + }); + assert(await runningRsync.id() >= 1, "Expect that we have an id"); + const progress = await runningRsync.progress() + assert(progress >= 0 && progress <= 1, `Expect progress to be 0 <= progress(${progress}) <= 1`); + await runningRsync.wait(); + assert((await effects.readFile({ + volumeId: "main", + path: "test-rsync-out/testing-rsync/someFile.txt", + })).length > 0, 'Asserting that we read in the file "test_rsync/test-package/0.3.0.3/embassy.js"'); + + + return { + result: { + copyable: false, + message: "Done", + version: "0", + qr: false, + }, + }; + } + catch (e) { + throw e; + } + finally { + await effects + .removeDir({ + volumeId: "main", + path: "test-rsync-out", + }) + .catch(() => {}); + } + }, + }; diff --git a/backend/test/js_action_execute/package-data/volumes/test-package/data/main/testing-rsync/someFile.txt b/backend/test/js_action_execute/package-data/volumes/test-package/data/main/testing-rsync/someFile.txt new file mode 100644 index 000000000..ac0bb024c --- /dev/null +++ b/backend/test/js_action_execute/package-data/volumes/test-package/data/main/testing-rsync/someFile.txt @@ -0,0 +1 @@ +Here's something in this file for the rsync \ No newline at end of file diff --git a/libs/Cargo.lock b/libs/Cargo.lock index cb2fcb093..103b00415 100644 --- a/libs/Cargo.lock +++ b/libs/Cargo.lock @@ -33,7 +33,7 @@ version = "0.7.6" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" dependencies = [ - "getrandom", + "getrandom 0.2.8", "once_cell", "version_check", ] @@ -47,6 +47,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anyhow" version = "1.0.66" @@ -59,7 +68,7 @@ version = "0.7.7" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "bc4c00309ed1c8104732df4a5fa9acc3b796b6f8531dfbd5ce0078c86f997244" dependencies = [ - "darling", + "darling 0.10.2", "pmutil", "proc-macro2", "quote", @@ -99,6 +108,26 @@ dependencies = [ "syn", ] +[[package]] +name = "atoi" +version = "1.0.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "d7c57d12312ff59c811c0643f4d80830505833c9ffaebd193d819392b265be8e" +dependencies = [ + "num-traits", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -120,6 +149,12 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base32" +version = "0.4.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "23ce669cd6c8588f79e15cf450314f9638f967fc5770ff1c7c1deb0925ea7cfa" + [[package]] name = "base64" version = "0.11.0" @@ -141,6 +176,15 @@ dependencies = [ "scoped-tls", ] +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -156,6 +200,28 @@ dependencies = [ "typenum", ] +[[package]] +name = "bitvec" +version = "0.22.3" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "5237f00a8c86130a0cc317830e558b966dd7850d48a953d998c813f01a41b527" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "block-padding", + "generic-array", +] + [[package]] name = "block-buffer" version = "0.10.3" @@ -165,12 +231,62 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block-padding" +version = "0.2.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" + +[[package]] +name = "bollard" +version = "0.13.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "d82e7850583ead5f8bbef247e2a3c37a19bd576e8420cd262a6711921827e1e5" +dependencies = [ + "base64 0.13.1", + "bollard-stubs", + "bytes", + "futures-core", + "futures-util", + "hex", + "http", + "hyper", + "hyperlocal", + "log", + "pin-project-lite", + "serde", + "serde_derive", + "serde_json", + "serde_urlencoded", + "thiserror", + "tokio", + "tokio-util", + "url", + "winapi", +] + +[[package]] +name = "bollard-stubs" +version = "1.42.0-rc.3" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "ed59b5c00048f48d7af971b71f800fdf23e858844a6f9e4d32ca72e9399e7864" +dependencies = [ + "serde", + "serde_with", +] + [[package]] name = "bumpalo" version = "3.11.1" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + [[package]] name = "bytes" version = "1.2.1" @@ -189,6 +305,52 @@ version = "1.0.0" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.22" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1" +dependencies = [ + "iana-time-zone", + "num-integer", + "num-traits", + "winapi", +] + +[[package]] +name = "clap" +version = "3.2.23" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" +dependencies = [ + "atty", + "bitflags", + "clap_lex", + "indexmap", + "strsim 0.10.0", + "termcolor", + "textwrap", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] + +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + [[package]] name = "color-eyre" version = "0.6.2" @@ -247,6 +409,40 @@ dependencies = [ "libc", ] +[[package]] +name = "crc" +version = "3.0.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "53757d12b596c16c78b83458d732a5d1a17ab3f53f2f7412f6fb57cc8a140ab3" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.1.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "2d0165d2900ae6778e36e80bbc4da3b5eefccee9ba939761f9c2882a5d9af3ff" + +[[package]] +name = "crossbeam-queue" +version = "0.3.6" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "1cd42583b04998a5363558e5f9291ee5a5ff6b49944332103f251e7479a82aa7" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.12" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac" +dependencies = [ + "cfg-if", +] + [[package]] name = "crypto-common" version = "0.1.6" @@ -257,14 +453,91 @@ dependencies = [ "typenum", ] +[[package]] +name = "crypto-mac" +version = "0.11.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" +dependencies = [ + "generic-array", + "subtle", +] + +[[package]] +name = "curve25519-dalek" +version = "3.2.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "90f9d052967f590a76e62eb387bd0bbb1b000182c3cefe5364db6b7211651bc0" +dependencies = [ + "byteorder", + "digest 0.9.0", + "rand_core 0.5.1", + "subtle", + "zeroize", +] + +[[package]] +name = "cxx" +version = "1.0.80" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "6b7d4e43b25d3c994662706a1d4fcfc32aaa6afd287502c111b237093bb23f3a" +dependencies = [ + "cc", + "cxxbridge-flags", + "cxxbridge-macro", + "link-cplusplus", +] + +[[package]] +name = "cxx-build" +version = "1.0.80" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "84f8829ddc213e2c1368e51a2564c552b65a8cb6a28f31e576270ac81d5e5827" +dependencies = [ + "cc", + "codespan-reporting", + "once_cell", + "proc-macro2", + "quote", + "scratch", + "syn", +] + +[[package]] +name = "cxxbridge-flags" +version = "1.0.80" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "e72537424b474af1460806647c41d4b6d35d09ef7fe031c5c2fa5766047cc56a" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.80" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "309e4fb93eed90e1e14bea0da16b209f81813ba9fc7830c20ed151dd7bc0a4d7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "darling" version = "0.10.2" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" dependencies = [ - "darling_core", - "darling_macro", + "darling_core 0.10.2", + "darling_macro 0.10.2", +] + +[[package]] +name = "darling" +version = "0.13.4" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" +dependencies = [ + "darling_core 0.13.4", + "darling_macro 0.13.4", ] [[package]] @@ -277,7 +550,21 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim", + "strsim 0.9.3", + "syn", +] + +[[package]] +name = "darling_core" +version = "0.13.4" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim 0.10.0", "syn", ] @@ -287,7 +574,18 @@ version = "0.10.2" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" dependencies = [ - "darling_core", + "darling_core 0.10.2", + "quote", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.13.4" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" +dependencies = [ + "darling_core 0.13.4", "quote", "syn", ] @@ -302,7 +600,7 @@ dependencies = [ "hashbrown", "lock_api", "once_cell", - "parking_lot_core", + "parking_lot_core 0.9.4", ] [[package]] @@ -352,7 +650,7 @@ dependencies = [ "libc", "log", "once_cell", - "parking_lot", + "parking_lot 0.12.1", "pin-project", "serde", "serde_json", @@ -387,16 +685,52 @@ dependencies = [ "syn", ] +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + [[package]] name = "digest" version = "0.10.5" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "adfbc57365a37acbd2ebf2b64d7e69bb766e2fea813521ed536f5d0520dcf86c" dependencies = [ - "block-buffer", + "block-buffer 0.10.3", "crypto-common", + "subtle", ] +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "dotenvy" +version = "0.15.6" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "03d8c417d7a8cb362e0c37e5d815f5eb7c37f79ff93707329d5a194e42e54ca0" + [[package]] name = "dprint-swc-ext" version = "0.1.1" @@ -412,11 +746,39 @@ dependencies = [ "text_lines", ] +[[package]] +name = "ed25519" +version = "1.5.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "1e9c280362032ea4203659fc489832d0204ef09f247a0506f170dafcac08c369" +dependencies = [ + "serde", + "signature", +] + +[[package]] +name = "ed25519-dalek" +version = "1.0.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" +dependencies = [ + "curve25519-dalek", + "ed25519", + "rand 0.7.3", + "serde", + "serde_bytes", + "sha2 0.9.9", + "zeroize", +] + [[package]] name = "either" version = "1.8.0" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +dependencies = [ + "serde", +] [[package]] name = "embassy_container_init" @@ -467,6 +829,12 @@ dependencies = [ "syn", ] +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + [[package]] name = "eyre" version = "0.6.8" @@ -531,7 +899,7 @@ version = "0.1.9" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "338a5feb6c7248603dfa3da758da4e99abb65e792a157fe1d657e7c2f5fbcd0b" dependencies = [ - "itertools", + "itertools 0.8.2", ] [[package]] @@ -556,6 +924,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "funty" +version = "1.2.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "1847abb9cb65d566acd5942e94aea9c8f547ad02c98e1649326fc0e8910b8b1e" + [[package]] name = "futures" version = "0.3.25" @@ -598,6 +972,17 @@ dependencies = [ "futures-util", ] +[[package]] +name = "futures-intrusive" +version = "0.4.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "a604f7a68fbf8103337523b1fadc8ade7361ee3f112f7c680ad179651616aed5" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot 0.11.2", +] + [[package]] name = "futures-io" version = "0.3.25" @@ -655,6 +1040,17 @@ dependencies = [ "version_check", ] +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + [[package]] name = "getrandom" version = "0.2.8" @@ -663,7 +1059,7 @@ checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ "cfg-if", "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", ] [[package]] @@ -702,6 +1098,18 @@ name = "hashbrown" version = "0.12.3" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashlink" +version = "0.8.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "69fe1fcf8b4278d860ad0548329f892a3631fb63f82574df68275f34cdbe0ffa" +dependencies = [ + "hashbrown", +] [[package]] name = "heck" @@ -712,6 +1120,15 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "helpers" version = "0.1.0" @@ -720,7 +1137,10 @@ dependencies = [ "futures", "models", "pin-project", + "serde", "tokio", + "tokio-stream", + "tracing", ] [[package]] @@ -732,6 +1152,40 @@ dependencies = [ "libc", ] +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hkdf" +version = "0.12.3" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "791a029f6b9fc27657f6f188ec6e5e43f6911f6f878e0dc5501396e09809d437" +dependencies = [ + "hmac 0.12.1", +] + +[[package]] +name = "hmac" +version = "0.11.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" +dependencies = [ + "crypto-mac", + "digest 0.9.0", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.5", +] + [[package]] name = "http" version = "0.2.8" @@ -803,6 +1257,43 @@ dependencies = [ "tokio-native-tls", ] +[[package]] +name = "hyperlocal" +version = "0.8.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "0fafdf7b2b2de7c9784f76e02c0935e65a8117ec3b768644379983ab333ac98c" +dependencies = [ + "futures-util", + "hex", + "hyper", + "pin-project", + "tokio", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.53" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "winapi", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" +dependencies = [ + "cxx", + "cxx-build", +] + [[package]] name = "ident_case" version = "1.0.1" @@ -832,7 +1323,7 @@ source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "543682c9082b25e63d03b5acbd65ad111fd49dd93e70843e5175db4ff81d606b" dependencies = [ "bitmaps", - "rand_core", + "rand_core 0.6.4", "rand_xoshiro", "sized-chunks", "typenum", @@ -892,6 +1383,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.4" @@ -922,7 +1422,7 @@ dependencies = [ "reqwest", "serde", "serde_json", - "sha2", + "sha2 0.10.6", "swc_atoms", "swc_common", "swc_config", @@ -968,6 +1468,12 @@ dependencies = [ "thiserror", ] +[[package]] +name = "keccak" +version = "0.1.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "f9b7d56ba4a8344d6be9729995e6b06f928af29998cdf79fe390cbf6b1fee838" + [[package]] name = "lazy_static" version = "1.4.0" @@ -1053,6 +1559,15 @@ version = "0.2.137" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" +[[package]] +name = "link-cplusplus" +version = "1.0.7" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369" +dependencies = [ + "cc", +] + [[package]] name = "lock_api" version = "0.4.9" @@ -1087,6 +1602,28 @@ version = "0.1.9" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" +[[package]] +name = "mbrman" +version = "0.5.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "cdee9caaf6ebb0bae8ae1cb6b591e5553b6cf5a34c7ea07bb6f24c1a80619819" +dependencies = [ + "bincode", + "bitvec", + "serde", + "serde-big-array", + "thiserror", +] + +[[package]] +name = "md-5" +version = "0.10.5" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "6365506850d44bff6e2fbcb5176cf63650e48bd45ef2fe2665ae1570e0f4b9ca" +dependencies = [ + "digest 0.10.5", +] + [[package]] name = "memchr" version = "2.5.0" @@ -1131,7 +1668,7 @@ checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" dependencies = [ "libc", "log", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys 0.42.0", ] @@ -1139,13 +1676,23 @@ dependencies = [ name = "models" version = "0.1.0" dependencies = [ + "bollard", + "color-eyre", + "ed25519-dalek", "embassy_container_init", "emver", + "mbrman", + "openssl", "patch-db", - "rand", + "rand 0.8.5", + "rpc-toolkit", "serde", + "serde_json", + "sqlx", "thiserror", "tokio", + "torut", + "tracing", ] [[package]] @@ -1273,6 +1820,12 @@ version = "1.16.0" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + [[package]] name = "openssl" version = "0.10.42" @@ -1305,6 +1858,15 @@ version = "0.1.5" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +[[package]] +name = "openssl-src" +version = "111.24.0+1.1.1s" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "3498f259dab01178c6228c6b00dcef0ed2a2d5e20d648c017861227773ea4abd" +dependencies = [ + "cc", +] + [[package]] name = "openssl-sys" version = "0.9.77" @@ -1314,10 +1876,17 @@ dependencies = [ "autocfg", "cc", "libc", + "openssl-src", "pkg-config", "vcpkg", ] +[[package]] +name = "os_str_bytes" +version = "6.3.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "3baf96e39c5359d2eb0dd6ccb42c62b91d9678aa68160d261b9e0ccbf9e9dea9" + [[package]] name = "overload" version = "0.1.1" @@ -1330,6 +1899,17 @@ version = "3.5.0" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core 0.8.5", +] + [[package]] name = "parking_lot" version = "0.12.1" @@ -1337,7 +1917,21 @@ source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core", + "parking_lot_core 0.9.4", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.5" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +dependencies = [ + "cfg-if", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", ] [[package]] @@ -1353,6 +1947,12 @@ dependencies = [ "windows-sys 0.42.0", ] +[[package]] +name = "paste" +version = "1.0.9" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1" + [[package]] name = "patch-db" version = "0.1.0" @@ -1367,7 +1967,7 @@ dependencies = [ "nix 0.23.1", "patch-db-macro", "serde", - "serde_cbor", + "serde_cbor 0.11.1", "serde_json", "thiserror", "tokio", @@ -1388,7 +1988,7 @@ dependencies = [ name = "patch-db-macro-internals" version = "0.1.0" dependencies = [ - "heck", + "heck 0.3.3", "proc-macro2", "quote", "syn", @@ -1418,7 +2018,7 @@ source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" dependencies = [ "phf_shared", - "rand", + "rand 0.8.5", ] [[package]] @@ -1540,6 +2140,25 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "radium" +version = "0.6.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "643f8f41a8ebc4c5dc4515c82bb8abd397b527fc20fd681b7c011c2aee5d44fb" + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom 0.1.16", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc", +] + [[package]] name = "rand" version = "0.8.5" @@ -1547,8 +2166,18 @@ source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha", - "rand_core", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", ] [[package]] @@ -1558,7 +2187,16 @@ source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.16", ] [[package]] @@ -1567,7 +2205,16 @@ version = "0.6.4" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom", + "getrandom 0.2.8", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", ] [[package]] @@ -1576,7 +2223,7 @@ version = "0.6.0" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa" dependencies = [ - "rand_core", + "rand_core 0.6.4", ] [[package]] @@ -1588,6 +2235,17 @@ dependencies = [ "bitflags", ] +[[package]] +name = "redox_users" +version = "0.4.3" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +dependencies = [ + "getrandom 0.2.8", + "redox_syscall", + "thiserror", +] + [[package]] name = "regex" version = "1.7.0" @@ -1660,6 +2318,65 @@ dependencies = [ "winreg", ] +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin", + "untrusted", + "web-sys", + "winapi", +] + +[[package]] +name = "rpc-toolkit" +version = "0.2.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "5353673ffd8265292281141560d2b851e4da49e83e2f5e255fd473736d45ee10" +dependencies = [ + "clap", + "futures", + "hyper", + "lazy_static", + "openssl", + "reqwest", + "rpc-toolkit-macro", + "serde", + "serde_cbor 0.11.2", + "serde_json", + "thiserror", + "tokio", + "url", + "yajrc", +] + +[[package]] +name = "rpc-toolkit-macro" +version = "0.2.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "f8e4b9cb00baf2d61bcd35e98d67dcb760382a3b4540df7e63b38d053c8a7b8b" +dependencies = [ + "proc-macro2", + "rpc-toolkit-macro-internals", + "syn", +] + +[[package]] +name = "rpc-toolkit-macro-internals" +version = "0.2.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "d3e2ce21b936feaecdab9c9a8e75b9dca64374ccc11951a58045ad6559b75f42" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "rustc-demangle" version = "0.1.21" @@ -1690,6 +2407,27 @@ dependencies = [ "semver 1.0.14", ] +[[package]] +name = "rustls" +version = "0.20.7" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "539a2bfe908f471bfa933876bd1eb6a19cf2176d375f82ef7f99530a40e48c2c" +dependencies = [ + "log", + "ring", + "sct", + "webpki", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "0864aeff53f8c05aa08d86e5ef839d3dfcf07aeba2db32f12db0ef716e87bd55" +dependencies = [ + "base64 0.13.1", +] + [[package]] name = "ryu" version = "1.0.11" @@ -1713,10 +2451,26 @@ source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" [[package]] -name = "scopeguard" -version = "1.1.0" +name = "scopeguard" +version = "1.1.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "scratch" +version = "1.0.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" + +[[package]] +name = "sct" +version = "0.7.0" source = "registry+/~https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +dependencies = [ + "ring", + "untrusted", +] [[package]] name = "security-framework" @@ -1771,6 +2525,24 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-big-array" +version = "0.4.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "3323f09a748af288c3dc2474ea6803ee81f118321775bffa3ac8f7e65c5e90e7" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_bytes" +version = "0.11.7" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "cfc50e8183eeeb6178dcb167ae34a8051d63535023ae38b5d8d12beae193d37b" +dependencies = [ + "serde", +] + [[package]] name = "serde_cbor" version = "0.11.1" @@ -1779,6 +2551,16 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_cbor" +version = "0.11.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5" +dependencies = [ + "half", + "serde", +] + [[package]] name = "serde_derive" version = "1.0.147" @@ -1826,6 +2608,28 @@ dependencies = [ "v8", ] +[[package]] +name = "serde_with" +version = "1.14.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "678b5a069e50bf00ecd22d0cd8ddf7c236f68581b03db652061ed5eb13a312ff" +dependencies = [ + "serde", + "serde_with_macros", +] + +[[package]] +name = "serde_with_macros" +version = "1.5.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082" +dependencies = [ + "darling 0.13.4", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "sha-1" version = "0.10.0" @@ -1834,7 +2638,31 @@ checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f" dependencies = [ "cfg-if", "cpufeatures", - "digest", + "digest 0.10.5", +] + +[[package]] +name = "sha1" +version = "0.10.5" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.5", +] + +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if", + "cpufeatures", + "digest 0.9.0", + "opaque-debug", ] [[package]] @@ -1845,7 +2673,19 @@ checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" dependencies = [ "cfg-if", "cpufeatures", - "digest", + "digest 0.10.5", +] + +[[package]] +name = "sha3" +version = "0.9.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" +dependencies = [ + "block-buffer 0.9.0", + "digest 0.9.0", + "keccak", + "opaque-debug", ] [[package]] @@ -1866,6 +2706,12 @@ dependencies = [ "libc", ] +[[package]] +name = "signature" +version = "1.6.4" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" + [[package]] name = "siphasher" version = "0.3.10" @@ -1898,7 +2744,7 @@ source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] -name = "snapshot-creator" +name = "snapshot_creator" version = "0.1.0" dependencies = [ "dashmap", @@ -1932,6 +2778,120 @@ dependencies = [ "url", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + +[[package]] +name = "sqlformat" +version = "0.2.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "f87e292b4291f154971a43c3774364e2cbcaec599d3f5bf6fa9d122885dbc38a" +dependencies = [ + "itertools 0.10.5", + "nom", + "unicode_categories", +] + +[[package]] +name = "sqlx" +version = "0.6.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "9249290c05928352f71c077cc44a464d880c63f26f7534728cca008e135c0428" +dependencies = [ + "sqlx-core", + "sqlx-macros", +] + +[[package]] +name = "sqlx-core" +version = "0.6.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "dcbc16ddba161afc99e14d1713a453747a2b07fc097d2009f4c300ec99286105" +dependencies = [ + "ahash", + "atoi", + "base64 0.13.1", + "bitflags", + "byteorder", + "bytes", + "chrono", + "crc", + "crossbeam-queue", + "dirs", + "dotenvy", + "either", + "event-listener", + "futures-channel", + "futures-core", + "futures-intrusive", + "futures-util", + "hashlink", + "hex", + "hkdf", + "hmac 0.12.1", + "indexmap", + "itoa", + "libc", + "log", + "md-5", + "memchr", + "once_cell", + "paste", + "percent-encoding", + "rand 0.8.5", + "rustls", + "rustls-pemfile", + "serde", + "serde_json", + "sha1", + "sha2 0.10.6", + "smallvec", + "sqlformat", + "sqlx-rt", + "stringprep", + "thiserror", + "tokio-stream", + "url", + "webpki-roots", + "whoami", +] + +[[package]] +name = "sqlx-macros" +version = "0.6.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "b850fa514dc11f2ee85be9d055c512aa866746adfacd1cb42d867d68e6a5b0d9" +dependencies = [ + "dotenvy", + "either", + "heck 0.4.0", + "hex", + "once_cell", + "proc-macro2", + "quote", + "serde", + "serde_json", + "sha2 0.10.6", + "sqlx-core", + "sqlx-rt", + "syn", + "url", +] + +[[package]] +name = "sqlx-rt" +version = "0.6.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "24c5b2d25fa654cc5f841750b8e1cdedbe21189bf9a9382ee90bfa9dd3562396" +dependencies = [ + "once_cell", + "tokio", + "tokio-rustls", +] + [[package]] name = "static_assertions" version = "1.1.0" @@ -1946,7 +2906,7 @@ checksum = "213494b7a2b503146286049378ce02b482200519accc31872ee8be91fa820a08" dependencies = [ "new_debug_unreachable", "once_cell", - "parking_lot", + "parking_lot 0.12.1", "phf_shared", "precomputed-hash", "serde", @@ -1977,12 +2937,34 @@ dependencies = [ "syn", ] +[[package]] +name = "stringprep" +version = "0.1.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "8ee348cb74b87454fff4b551cbf727025810a004f88aeacae7f85b87f4e9a1c1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "strsim" version = "0.9.3" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "subtle" +version = "2.4.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" + [[package]] name = "swc_atoms" version = "0.2.11" @@ -2341,6 +3323,24 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "synstructure" +version = "0.12.6" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "unicode-xid", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + [[package]] name = "tempfile" version = "3.3.0" @@ -2355,6 +3355,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + [[package]] name = "text_lines" version = "0.4.1" @@ -2364,6 +3373,12 @@ dependencies = [ "serde", ] +[[package]] +name = "textwrap" +version = "0.16.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" + [[package]] name = "thiserror" version = "1.0.37" @@ -2420,7 +3435,7 @@ dependencies = [ "memchr", "mio", "num_cpus", - "parking_lot", + "parking_lot 0.12.1", "pin-project-lite", "signal-hook-registry", "socket2", @@ -2449,6 +3464,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-rustls" +version = "0.23.4" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +dependencies = [ + "rustls", + "tokio", + "webpki", +] + [[package]] name = "tokio-stream" version = "0.1.11" @@ -2458,6 +3484,7 @@ dependencies = [ "futures-core", "pin-project-lite", "tokio", + "tokio-util", ] [[package]] @@ -2483,6 +3510,26 @@ dependencies = [ "serde", ] +[[package]] +name = "torut" +version = "0.2.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "99febc413f26cf855b3a309c5872edff5c31e0ffe9c2fce5681868761df36f69" +dependencies = [ + "base32", + "base64 0.13.1", + "derive_more", + "ed25519-dalek", + "hex", + "hmac 0.11.0", + "rand 0.7.3", + "serde", + "serde_derive", + "sha2 0.9.9", + "sha3", + "tokio", +] + [[package]] name = "tower-service" version = "0.3.2" @@ -2658,6 +3705,18 @@ version = "0.1.10" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "unicode_categories" +version = "0.1.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" + [[package]] name = "unreachable" version = "0.1.1" @@ -2667,6 +3726,12 @@ dependencies = [ "void", ] +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + [[package]] name = "url" version = "2.3.1" @@ -2726,6 +3791,12 @@ dependencies = [ "try-lock", ] +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -2808,6 +3879,25 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki" +version = "0.22.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "webpki-roots" +version = "0.22.5" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "368bfe657969fb01238bb756d351dcade285e0f6fcbd36dcb23359a5169975be" +dependencies = [ + "webpki", +] + [[package]] name = "which" version = "4.3.0" @@ -2819,6 +3909,17 @@ dependencies = [ "once_cell", ] +[[package]] +name = "whoami" +version = "1.2.3" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "d6631b6a2fd59b1841b622e8f1a7ad241ef0a46f2d580464ce8140ac94cbd571" +dependencies = [ + "bumpalo", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "winapi" version = "0.3.9" @@ -2835,6 +3936,15 @@ version = "0.4.0" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -2949,3 +4059,45 @@ checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" dependencies = [ "winapi", ] + +[[package]] +name = "wyz" +version = "0.4.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "129e027ad65ce1453680623c3fb5163cbf7107bfe1aa32257e7d0e63f9ced188" +dependencies = [ + "tap", +] + +[[package]] +name = "yajrc" +version = "0.1.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "b40687b4c165cb760e35730055c8840f36897e7c98099b2d3d66ba8cb624c79a" +dependencies = [ + "anyhow", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "zeroize" +version = "1.3.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.3.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "3f8f187641dad4f680d25c4bfc4225b418165984179f26ca76ec4fb6441d3a17" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] diff --git a/libs/Cargo.toml b/libs/Cargo.toml index 650a2c5b1..907cd1e6a 100644 --- a/libs/Cargo.toml +++ b/libs/Cargo.toml @@ -1,9 +1,9 @@ [workspace] members = [ - "snapshot-creator", + "snapshot_creator", "models", "js_engine", "helpers", - "embassy-container-init", + "embassy_container_init", ] diff --git a/libs/build-arm-v8-snapshot.sh b/libs/build-arm-v8-snapshot.sh index 71c9ea901..438f3484a 100755 --- a/libs/build-arm-v8-snapshot.sh +++ b/libs/build-arm-v8-snapshot.sh @@ -15,11 +15,11 @@ fi echo "Building " cd .. -docker run --rm $USE_TTY -v "$HOME/.cargo/registry":/root/.cargo/registry -v "$(pwd)":/home/rust/src start9/rust-arm-cross:aarch64 sh -c "(cd libs/ && cargo build -p snapshot-creator --release )" +docker run --rm $USE_TTY -v "$HOME/.cargo/registry":/root/.cargo/registry -v "$(pwd)":/home/rust/src start9/rust-arm-cross:aarch64 sh -c "(cd libs/ && cargo build -p snapshot_creator --release )" cd - echo "Creating Arm v8 Snapshot" -docker run $USE_TTY --platform linux/arm64/v8 --mount type=bind,src=$(pwd),dst=/mnt arm64v8/ubuntu:20.04 /bin/sh -c "cd /mnt && /mnt/target/aarch64-unknown-linux-gnu/release/snapshot-creator" +docker run $USE_TTY --platform linux/arm64/v8 --mount type=bind,src=$(pwd),dst=/mnt arm64v8/ubuntu:20.04 /bin/sh -c "cd /mnt && /mnt/target/aarch64-unknown-linux-gnu/release/snapshot_creator" sudo chown -R $USER target sudo chown -R $USER ~/.cargo sudo chown $USER JS_SNAPSHOT.bin diff --git a/libs/build-v8-snapshot.sh b/libs/build-v8-snapshot.sh index 33a5dea48..7715b503a 100755 --- a/libs/build-v8-snapshot.sh +++ b/libs/build-v8-snapshot.sh @@ -9,7 +9,7 @@ if [ "$0" != "./build-v8-snapshot.sh" ]; then fi echo "Creating v8 Snapshot" -cargo run -p snapshot-creator --release +cargo run -p snapshot_creator --release sudo chown -R $USER target sudo chown -R $USER ~/.cargo sudo chown $USER JS_SNAPSHOT.bin diff --git a/libs/embassy-container-init/Cargo.toml b/libs/embassy_container_init/Cargo.toml similarity index 100% rename from libs/embassy-container-init/Cargo.toml rename to libs/embassy_container_init/Cargo.toml diff --git a/libs/embassy-container-init/src/lib.rs b/libs/embassy_container_init/src/lib.rs similarity index 90% rename from libs/embassy-container-init/src/lib.rs rename to libs/embassy_container_init/src/lib.rs index e49c20778..21723f1bf 100644 --- a/libs/embassy-container-init/src/lib.rs +++ b/libs/embassy_container_init/src/lib.rs @@ -7,11 +7,14 @@ pub type InputJsonRpc = JsonRpc; pub type OutputJsonRpc = JsonRpc; /// Based on the jsonrpc spec, but we are limiting the rpc to a subset -#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, Serialize, Copy, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)] #[serde(untagged)] pub enum RpcId { UInt(u32), } +/// Know what the process is called +#[derive(Debug, Serialize, Deserialize, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] +pub struct ProcessId(pub u32); /// We use the JSON rpc as the format to share between the stdin and stdout for the executable. /// Note: We are not allowing the id to not exist, used to ensure all pairs of messages are tracked @@ -76,6 +79,9 @@ where #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] #[serde(tag = "method", content = "params", rename_all = "camelCase")] pub enum Output { + /// Will be called almost right away and only once per RpcId. Indicates what + /// was spawned in the container. + ProcessId(ProcessId), /// This is the line buffered output of the command Line(String), /// This is some kind of error with the program diff --git a/libs/embassy-container-init/src/main.rs b/libs/embassy_container_init/src/main.rs similarity index 94% rename from libs/embassy-container-init/src/main.rs rename to libs/embassy_container_init/src/main.rs index 4aaf9b0cf..c659a8c99 100644 --- a/libs/embassy-container-init/src/main.rs +++ b/libs/embassy_container_init/src/main.rs @@ -3,7 +3,9 @@ use std::process::Stdio; use std::sync::Arc; use async_stream::stream; -use embassy_container_init::{Input, InputJsonRpc, JsonRpc, Output, OutputJsonRpc, RpcId}; +use embassy_container_init::{ + Input, InputJsonRpc, JsonRpc, Output, OutputJsonRpc, ProcessId, RpcId, +}; use futures::{pin_mut, Stream, StreamExt}; use tokio::io::{AsyncBufReadExt, BufReader}; use tokio::process::{Child, Command}; @@ -36,6 +38,9 @@ impl ChildAndRpc { child: command.spawn()?, }) } + fn id(&self) -> Option { + self.child.id().map(ProcessId) + } async fn wait(&mut self) -> DoneProgram { let status = DoneProgramStatus::Wait(self.child.wait().await); DoneProgram { @@ -63,7 +68,7 @@ impl ChildAndRpc { #[derive(Debug, Clone)] struct Io { commands: Arc>>>, - ids: Arc>>, + ids: Arc>>, } impl Io { @@ -107,8 +112,9 @@ impl Io { Ok(a) => a, }; - if let Some(child_id) = child_and_rpc.child.id() { - io.ids.lock().await.insert(id.clone(), child_id); + if let Some(child_id) = child_and_rpc.id() { + io.ids.lock().await.insert(id.clone(), child_id.clone()); + yield JsonRpc::new(id.clone(), Output::ProcessId(child_id)); } let stdout = child_and_rpc.child @@ -218,7 +224,7 @@ impl Io { async fn clean_id( &self, done_program: &DoneProgram, - ) -> (Option, Option>) { + ) -> (Option, Option>) { ( self.ids.lock().await.remove(&done_program.id), self.commands.lock().await.remove(&done_program.id), @@ -230,7 +236,7 @@ impl Io { let output = match self.remove_cmd_id(rpc).await { Some(id) => { let mut cmd = tokio::process::Command::new("kill"); - cmd.arg(format!("{id}")); + cmd.arg(format!("{}", id.0)); cmd.output().await } None => return, @@ -252,7 +258,7 @@ impl Io { } } - async fn remove_cmd_id(&self, rpc: &RpcId) -> Option { + async fn remove_cmd_id(&self, rpc: &RpcId) -> Option { self.ids.lock().await.remove(rpc) } } diff --git a/libs/helpers/Cargo.toml b/libs/helpers/Cargo.toml index 1fb991afd..31bb07326 100644 --- a/libs/helpers/Cargo.toml +++ b/libs/helpers/Cargo.toml @@ -8,6 +8,9 @@ edition = "2021" [dependencies] color-eyre = "0.6.2" futures = "0.3.21" +models = { path = "../models" } pin-project = "1.0.11" +serde = { version = "1.0", features = ["derive", "rc"] } tokio = { version = "1.19.2", features = ["full"] } -models = { path = "../models" } +tokio-stream = { version = "0.1.9", features = ["io-util", "sync"] } +tracing = "0.1.35" diff --git a/libs/helpers/src/byte_replacement_reader.rs b/libs/helpers/src/byte_replacement_reader.rs new file mode 100644 index 000000000..d50c272ad --- /dev/null +++ b/libs/helpers/src/byte_replacement_reader.rs @@ -0,0 +1,31 @@ +use std::task::Poll; + +use tokio::io::{AsyncRead, ReadBuf}; + +#[pin_project::pin_project] +pub struct ByteReplacementReader { + pub replace: u8, + pub with: u8, + #[pin] + pub inner: R, +} +impl AsyncRead for ByteReplacementReader { + fn poll_read( + self: std::pin::Pin<&mut Self>, + cx: &mut std::task::Context<'_>, + buf: &mut ReadBuf<'_>, + ) -> std::task::Poll> { + let this = self.project(); + match this.inner.poll_read(cx, buf) { + Poll::Ready(Ok(())) => { + for idx in 0..buf.filled().len() { + if buf.filled()[idx] == *this.replace { + buf.filled_mut()[idx] = *this.with; + } + } + Poll::Ready(Ok(())) + } + a => a, + } + } +} diff --git a/libs/helpers/src/lib.rs b/libs/helpers/src/lib.rs index 5da97063c..30336f258 100644 --- a/libs/helpers/src/lib.rs +++ b/libs/helpers/src/lib.rs @@ -9,7 +9,11 @@ use tokio::fs::File; use tokio::sync::oneshot; use tokio::task::{JoinError, JoinHandle, LocalSet}; +mod byte_replacement_reader; +mod rsync; mod script_dir; +pub use byte_replacement_reader::*; +pub use rsync::*; pub use script_dir::*; pub fn to_tmp_path(path: impl AsRef) -> Result { diff --git a/backend/src/util/rsync.rs b/libs/helpers/src/rsync.rs similarity index 63% rename from backend/src/util/rsync.rs rename to libs/helpers/src/rsync.rs index 83ba739be..805138d0d 100644 --- a/backend/src/util/rsync.rs +++ b/libs/helpers/src/rsync.rs @@ -1,15 +1,15 @@ use color_eyre::eyre::eyre; use std::path::Path; -use helpers::NonDetachingJoinHandle; +use crate::{ByteReplacementReader, NonDetachingJoinHandle}; +use models::{Error, ErrorKind}; use tokio::io::{AsyncBufReadExt, AsyncReadExt, BufReader}; use tokio::process::{Child, Command}; use tokio::sync::watch; use tokio_stream::wrappers::WatchStream; -use crate::util::io::ByteReplacementReader; -use crate::{Error, ErrorKind}; - +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +#[serde(rename_all = "camelCase")] pub struct RsyncOptions { pub delete: bool, pub force: bool, @@ -56,8 +56,24 @@ impl Rsync { .stdout(std::process::Stdio::piped()) .stderr(std::process::Stdio::piped()) .spawn()?; - let cmd_stdout = command.stdout.take().unwrap(); - let mut cmd_stderr = command.stderr.take().unwrap(); + let cmd_stdout = match command.stdout.take() { + None => { + return Err(Error::new( + eyre!("rsync command stdout is none"), + ErrorKind::Filesystem, + )) + } + Some(a) => a, + }; + let mut cmd_stderr = match command.stderr.take() { + None => { + return Err(Error::new( + eyre!("rsync command stderr is none"), + ErrorKind::Filesystem, + )) + } + Some(a) => a, + }; let (send, recv) = watch::channel(0.0); let stderr = tokio::spawn(async move { let mut res = String::new(); @@ -77,7 +93,12 @@ impl Rsync { .split_ascii_whitespace() .find_map(|col| col.strip_suffix("%")) { - send.send(percentage.parse::()? / 100.0).unwrap(); + if let Err(err) = send.send(percentage.parse::()? / 100.0) { + return Err(Error::new( + eyre!("rsync progress send error: {}", err), + ErrorKind::Filesystem, + )); + } } } Ok(()) @@ -92,12 +113,24 @@ impl Rsync { } pub async fn wait(mut self) -> Result<(), Error> { let status = self.command.wait().await?; - let stderr = self.stderr.await.unwrap()?; + let stderr = match self.stderr.await { + Err(err) => { + return Err(Error::new( + eyre!("rsync stderr error: {}", err), + ErrorKind::Filesystem, + )) + } + Ok(a) => a?, + }; if status.success() { tracing::info!("rsync: {}", stderr); } else { return Err(Error::new( - eyre!("rsync error: {}", stderr), + eyre!( + "rsync error: {} {} ", + status.code().map(|x| x.to_string()).unwrap_or_default(), + stderr + ), ErrorKind::Filesystem, )); } diff --git a/libs/js_engine/Cargo.toml b/libs/js_engine/Cargo.toml index b7c8fbb2d..582f3a258 100644 --- a/libs/js_engine/Cargo.toml +++ b/libs/js_engine/Cargo.toml @@ -11,7 +11,7 @@ dashmap = "5.3.4" deno_core = "=0.136.0" deno_ast = { version = "=0.15.0", features = ["transpiling"] } dprint-swc-ext = "=0.1.1" -embassy_container_init = { path = "../embassy-container-init" } +embassy_container_init = { path = "../embassy_container_init" } reqwest = { version = "0.11.11" } swc_atoms = "=0.2.11" swc_common = "=0.18.7" diff --git a/libs/js_engine/src/artifacts/loadModule.js b/libs/js_engine/src/artifacts/loadModule.js index 5db8a1a1c..67359761d 100644 --- a/libs/js_engine/src/artifacts/loadModule.js +++ b/libs/js_engine/src/artifacts/loadModule.js @@ -44,14 +44,18 @@ const runDaemon = ( { command = requireParam("command"), args = [] } = requireParam("options"), ) => { let id = Deno.core.opAsync("start_command", command, args); + let rpcId = id.then(x => x.rpcId) + let processId = id.then(x => x.processId) let waitPromise = null; return { + processId, + rpcId, async wait() { - waitPromise = waitPromise || Deno.core.opAsync("wait_command", await id) + waitPromise = waitPromise || Deno.core.opAsync("wait_command", await rpcId) return waitPromise }, async term() { - return Deno.core.opAsync("term_command", await id) + return Deno.core.opAsync("term_command", await rpcId) } } }; @@ -128,6 +132,31 @@ const fetch = async (url = requireParam ('url'), options = null) => { }; }; +const runRsync = ( + { + srcVolume = requireParam("srcVolume"), + dstVolume = requireParam("dstVolume"), + srcPath = requireParam("srcPath"), + dstPath = requireParam("dstPath"), + options = requireParam("options"), + } = requireParam("options"), +) => { + let id = Deno.core.opAsync("rsync", srcVolume, srcPath, dstVolume, dstPath, options); + let waitPromise = null; + return { + async id() { + return id + }, + async wait() { + waitPromise = waitPromise || Deno.core.opAsync("rsync_wait", await id) + return waitPromise + }, + async progress() { + return Deno.core.opAsync("rsync_progress", await id) + } + } +}; + const currentFunction = Deno.core.opSync("current_function"); const input = Deno.core.opSync("get_input"); const variable_args = Deno.core.opSync("get_variable_args"); @@ -151,7 +180,8 @@ const effects = { rename, runCommand, sleep, - runDaemon + runDaemon, + runRsync }; const runFunction = jsonPointerValue(mainModule, currentFunction); diff --git a/libs/js_engine/src/lib.rs b/libs/js_engine/src/lib.rs index 760a752d8..fa906da5f 100644 --- a/libs/js_engine/src/lib.rs +++ b/libs/js_engine/src/lib.rs @@ -11,7 +11,8 @@ use deno_core::{ resolve_import, Extension, JsRuntime, ModuleLoader, ModuleSource, ModuleSourceFuture, ModuleSpecifier, ModuleType, OpDecl, RuntimeOptions, Snapshot, }; -use helpers::{script_dir, spawn_local}; +use embassy_container_init::RpcId; +use helpers::{script_dir, spawn_local, Rsync}; use models::{ExecCommand, PackageId, ProcedureName, TermCommand, Version, VolumeId}; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -83,7 +84,7 @@ const SNAPSHOT_BYTES: &[u8] = include_bytes!("./artifacts/JS_SNAPSHOT.bin"); #[cfg(target_arch = "aarch64")] const SNAPSHOT_BYTES: &[u8] = include_bytes!("./artifacts/ARM_JS_SNAPSHOT.bin"); -type WaitFns = Arc>>>>>; +type WaitFns = Arc>>>>>; #[derive(Clone)] struct JsContext { @@ -98,6 +99,7 @@ struct JsContext { command_inserter: ExecCommand, term_command: TermCommand, wait_fns: WaitFns, + rsyncs: Arc)>>, } #[derive(Debug, Clone, serde::Deserialize, serde::Serialize)] #[serde(rename_all = "kebab-case")] @@ -262,13 +264,13 @@ impl JsExecutionEnvironment { Err(err) => { tracing::error!("{}", err); tracing::debug!("{:?}", err); - return Err(( + Err(( JsError::BoundryLayerSerDe, format!( "Couldn't convert output = {:#?} to the correct type", serde_json::to_string_pretty(&output).unwrap_or_default() ), - )); + )) } } } @@ -296,6 +298,9 @@ impl JsExecutionEnvironment { fns::wait_command::decl(), fns::sleep::decl(), fns::term_command::decl(), + fns::rsync::decl(), + fns::rsync_wait::decl(), + fns::rsync_progress::decl(), ] } @@ -328,6 +333,7 @@ impl JsExecutionEnvironment { command_inserter: self.command_inserter.clone(), term_command: self.term_command.clone(), wait_fns: Default::default(), + rsyncs: Default::default(), }; let ext = Extension::builder() .ops(Self::declarations()) @@ -382,9 +388,10 @@ mod fns { use deno_core::anyhow::{anyhow, bail}; use deno_core::error::AnyError; use deno_core::*; - use embassy_container_init::RpcId; - use helpers::{to_tmp_path, AtomicFile}; + use embassy_container_init::{ProcessId, RpcId}; + use helpers::{to_tmp_path, AtomicFile, Rsync, RsyncOptions}; use models::{TermCommand, VolumeId}; + use serde::{Deserialize, Serialize}; use serde_json::Value; use tokio::io::AsyncWriteExt; @@ -644,6 +651,106 @@ mod fns { tokio::fs::rename(old_file, new_file).await?; Ok(()) } + + #[op] + async fn rsync( + state: Rc>, + src_volume: VolumeId, + src_path: PathBuf, + dst_volume: VolumeId, + dst_path: PathBuf, + options: RsyncOptions, + ) -> Result { + let (volumes, volume_path, volume_path_out, rsyncs) = { + let state = state.borrow(); + let ctx: &JsContext = state.borrow(); + let volume_path = ctx + .volumes + .path_for(&ctx.datadir, &ctx.package_id, &ctx.version, &src_volume) + .ok_or_else(|| anyhow!("There is no {} in volumes", src_volume))?; + let volume_path_out = ctx + .volumes + .path_for(&ctx.datadir, &ctx.package_id, &ctx.version, &dst_volume) + .ok_or_else(|| anyhow!("There is no {} in volumes", dst_volume))?; + ( + ctx.volumes.clone(), + volume_path, + volume_path_out, + ctx.rsyncs.clone(), + ) + }; + if volumes.readonly(&dst_volume) { + bail!("Volume {} is readonly", dst_volume); + } + + let src = volume_path.join(src_path); + // With the volume check + if !is_subset(&volume_path, &src).await? { + bail!( + "Path '{}' has broken away from parent '{}'", + src.to_string_lossy(), + volume_path.to_string_lossy(), + ); + } + if let Err(_) = tokio::fs::metadata(&src).await { + bail!("Source at {} does not exists", src.to_string_lossy()); + } + + let dst = volume_path_out.join(dst_path); + // With the volume check + if !is_subset(&volume_path_out, &dst).await? { + bail!( + "Path '{}' has broken away from parent '{}'", + dst.to_string_lossy(), + volume_path_out.to_string_lossy(), + ); + } + + let running_rsync = + Rsync::new(src, dst, options).map_err(|e| anyhow::anyhow!("{:?}", e.source))?; + let insert_id = { + let mut rsyncs = rsyncs.lock().await; + let next = rsyncs.0 + 1; + rsyncs.0 = next; + rsyncs.1.insert(next, running_rsync); + next + }; + Ok(insert_id) + } + + #[op] + async fn rsync_wait(state: Rc>, id: usize) -> Result<(), AnyError> { + let rsyncs = { + let state = state.borrow(); + let ctx: &JsContext = state.borrow(); + ctx.rsyncs.clone() + }; + let running_rsync = match rsyncs.lock().await.1.remove(&id) { + Some(a) => a, + None => bail!("Couldn't find rsync at id {id}"), + }; + running_rsync + .wait() + .await + .map_err(|x| anyhow::anyhow!("{}", x.source))?; + Ok(()) + } + #[op] + async fn rsync_progress(state: Rc>, id: usize) -> Result { + use futures::StreamExt; + let rsyncs = { + let state = state.borrow(); + let ctx: &JsContext = state.borrow(); + ctx.rsyncs.clone() + }; + let mut running_rsync = match rsyncs.lock().await.1.remove(&id) { + Some(a) => a, + None => bail!("Couldn't find rsync at id {id}"), + }; + let progress = running_rsync.progress.next().await.unwrap_or_default(); + rsyncs.lock().await.1.insert(id, running_rsync); + Ok(progress) + } #[op] async fn remove_file( state: Rc>, @@ -835,13 +942,20 @@ mod fns { Ok(()) } + #[derive(Debug, Clone, Serialize, Deserialize)] + #[serde(rename_all = "camelCase")] + pub struct StartCommand { + rpc_id: RpcId, + process_id: ProcessId, + } + #[op] async fn start_command( state: Rc>, command: String, args: Vec, timeout: Option, - ) -> Result { + ) -> Result { use embassy_container_init::Output; let (command_inserter, wait_fns) = { let state = state.borrow(); @@ -850,7 +964,7 @@ mod fns { }; let (sender, mut receiver) = tokio::sync::mpsc::unbounded_channel::(); - let id = match command_inserter( + let rpc_id = match command_inserter( command, args.into_iter().collect(), sender, @@ -859,15 +973,28 @@ mod fns { .await { Err(err) => bail!(err), - Ok(RpcId::UInt(a)) => a, + Ok(rpc_id) => rpc_id, }; + let (process_id_send, process_id_recv) = tokio::sync::oneshot::channel::(); + let wait = async move { let mut answer = String::new(); let mut command_error = String::new(); let mut status: Option = None; + let mut process_id_send = Some(process_id_send); while let Some(output) = receiver.recv().await { match output { + Output::ProcessId(process_id) => { + if let Some(process_id_send) = process_id_send.take() { + if let Err(err) = process_id_send.send(process_id) { + tracing::error!( + "Could not get a process id {process_id:?} sent for {rpc_id:?}" + ); + tracing::debug!("{err:?}"); + } + } + } Output::Line(value) => { answer.push_str(&value); answer.push('\n'); @@ -892,12 +1019,13 @@ mod fns { ResultType::Result(serde_json::Value::String(answer)) }; - wait_fns.lock().await.insert(id, Box::pin(wait)); - Ok(id) + wait_fns.lock().await.insert(rpc_id, Box::pin(wait)); + let process_id = process_id_recv.await?; + Ok(StartCommand { rpc_id, process_id }) } #[op] - async fn wait_command(state: Rc>, id: u32) -> Result { + async fn wait_command(state: Rc>, id: RpcId) -> Result { let wait_fns = { let state = state.borrow(); let ctx = state.borrow::(); @@ -906,7 +1034,7 @@ mod fns { let found_future = match wait_fns.lock().await.remove(&id) { Some(a) => a, - None => bail!("No future for id {id}, could have been removed already"), + None => bail!("No future for id {id:?}, could have been removed already"), }; Ok(found_future.await) diff --git a/libs/models/Cargo.toml b/libs/models/Cargo.toml index 59a90ec19..1f93b7c13 100644 --- a/libs/models/Cargo.toml +++ b/libs/models/Cargo.toml @@ -6,14 +6,29 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -embassy_container_init = { path = "../embassy-container-init" } +bollard = "0.13.0" +color-eyre = "0.6.1" +ed25519-dalek = { version = "1.0.1", features = ["serde"] } +mbrman = "0.5.0" +embassy_container_init = { path = "../embassy_container_init" } emver = { version = "0.1", git = "/~https://github.com/Start9Labs/emver-rs.git", features = [ "serde", ] } +openssl = { version = "0.10.41", features = ["vendored"] } patch-db = { version = "*", path = "../../patch-db/patch-db", features = [ "trace", ] } -serde = { version = "1.0", features = ["derive", "rc"] } rand = "0.8" -tokio = { version = "1", features = ["full"] } +rpc-toolkit = "0.2.1" +serde = { version = "1.0", features = ["derive", "rc"] } +serde_json = "1.0.82" +sqlx = { version = "0.6.0", features = [ + "chrono", + "offline", + "runtime-tokio-rustls", + "postgres", +] } thiserror = "1.0" +tokio = { version = "1", features = ["full"] } +torut = "0.2.1" +tracing = "0.1.35" diff --git a/libs/models/src/errors.rs b/libs/models/src/errors.rs new file mode 100644 index 000000000..31ad54156 --- /dev/null +++ b/libs/models/src/errors.rs @@ -0,0 +1,388 @@ +use std::fmt::Display; + +use crate::InvalidId; +use color_eyre::eyre::eyre; +use patch_db::Revision; +use rpc_toolkit::{hyper::http::uri::InvalidUri, yajrc::RpcError}; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum ErrorKind { + Unknown = 1, + Filesystem = 2, + Docker = 3, + ConfigSpecViolation = 4, + ConfigRulesViolation = 5, + NotFound = 6, + IncorrectPassword = 7, + VersionIncompatible = 8, + Network = 9, + Registry = 10, + Serialization = 11, + Deserialization = 12, + Utf8 = 13, + ParseVersion = 14, + IncorrectDisk = 15, + // Nginx = 16, + Dependency = 17, + ParseS9pk = 18, + ParseUrl = 19, + DiskNotAvailable = 20, + BlockDevice = 21, + InvalidOnionAddress = 22, + Pack = 23, + ValidateS9pk = 24, + DiskCorrupted = 25, // Remove + Tor = 26, + ConfigGen = 27, + ParseNumber = 28, + Database = 29, + InvalidPackageId = 30, + InvalidSignature = 31, + Backup = 32, + Restore = 33, + Authorization = 34, + AutoConfigure = 35, + Action = 36, + RateLimited = 37, + InvalidRequest = 38, + MigrationFailed = 39, + Uninitialized = 40, + ParseNetAddress = 41, + ParseSshKey = 42, + SoundError = 43, + ParseTimestamp = 44, + ParseSysInfo = 45, + Wifi = 46, + Journald = 47, + DiskManagement = 48, + OpenSsl = 49, + PasswordHashGeneration = 50, + DiagnosticMode = 51, + ParseDbField = 52, + Duplicate = 53, + MultipleErrors = 54, + Incoherent = 55, + InvalidBackupTargetId = 56, + ProductKeyMismatch = 57, + LanPortConflict = 58, + Javascript = 59, + Pem = 60, + TLSInit = 61, + HttpRange = 62, + ContentLength = 63, + BytesError = 64, + InvalidIP = 65, + JoinError = 66, + AsciiError = 67, + NoHost = 68, + SignError = 69, +} +impl ErrorKind { + pub fn as_str(&self) -> &'static str { + use ErrorKind::*; + match self { + Unknown => "Unknown Error", + Filesystem => "Filesystem I/O Error", + Docker => "Docker Error", + ConfigSpecViolation => "Config Spec Violation", + ConfigRulesViolation => "Config Rules Violation", + NotFound => "Not Found", + IncorrectPassword => "Incorrect Password", + VersionIncompatible => "Version Incompatible", + Network => "Network Error", + Registry => "Registry Error", + Serialization => "Serialization Error", + Deserialization => "Deserialization Error", + Utf8 => "UTF-8 Parse Error", + ParseVersion => "Version Parsing Error", + IncorrectDisk => "Incorrect Disk", + // Nginx => "Nginx Error", + Dependency => "Dependency Error", + ParseS9pk => "S9PK Parsing Error", + ParseUrl => "URL Parsing Error", + DiskNotAvailable => "Disk Not Available", + BlockDevice => "Block Device Error", + InvalidOnionAddress => "Invalid Onion Address", + Pack => "Pack Error", + ValidateS9pk => "S9PK Validation Error", + DiskCorrupted => "Disk Corrupted", // Remove + Tor => "Tor Daemon Error", + ConfigGen => "Config Generation Error", + ParseNumber => "Number Parsing Error", + Database => "Database Error", + InvalidPackageId => "Invalid Package ID", + InvalidSignature => "Invalid Signature", + Backup => "Backup Error", + Restore => "Restore Error", + Authorization => "Unauthorized", + AutoConfigure => "Auto-Configure Error", + Action => "Action Failed", + RateLimited => "Rate Limited", + InvalidRequest => "Invalid Request", + MigrationFailed => "Migration Failed", + Uninitialized => "Uninitialized", + ParseNetAddress => "Net Address Parsing Error", + ParseSshKey => "SSH Key Parsing Error", + SoundError => "Sound Interface Error", + ParseTimestamp => "Timestamp Parsing Error", + ParseSysInfo => "System Info Parsing Error", + Wifi => "WiFi Internal Error", + Journald => "Journald Error", + DiskManagement => "Disk Management Error", + OpenSsl => "OpenSSL Internal Error", + PasswordHashGeneration => "Password Hash Generation Error", + DiagnosticMode => "Embassy is in Diagnostic Mode", + ParseDbField => "Database Field Parse Error", + Duplicate => "Duplication Error", + MultipleErrors => "Multiple Errors", + Incoherent => "Incoherent", + InvalidBackupTargetId => "Invalid Backup Target ID", + ProductKeyMismatch => "Incompatible Product Keys", + LanPortConflict => "Incompatible LAN Port Configuration", + Javascript => "Javascript Engine Error", + Pem => "PEM Encoding Error", + TLSInit => "TLS Backend Initialize Error", + HttpRange => "No Support for Web Server HTTP Ranges", + ContentLength => "Request has no content length header", + BytesError => "Could not get the bytes for this request", + InvalidIP => "Could not parse this IP address", + JoinError => "Join Handle Error", + AsciiError => "Could not parse ascii text", + NoHost => "No Host header ", + SignError => "Signing error", + } + } +} +impl Display for ErrorKind { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.as_str()) + } +} + +#[derive(Debug)] +pub struct Error { + pub source: color_eyre::eyre::Error, + pub kind: ErrorKind, + pub revision: Option, +} + +impl Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}: {}", self.kind.as_str(), self.source) + } +} +impl Error { + pub fn new>(source: E, kind: ErrorKind) -> Self { + Error { + source: source.into(), + kind, + revision: None, + } + } +} +impl From for Error { + fn from(err: InvalidId) -> Self { + Error::new(err, ErrorKind::InvalidPackageId) + } +} +impl From for Error { + fn from(e: std::io::Error) -> Self { + Error::new(e, ErrorKind::Filesystem) + } +} +impl From for Error { + fn from(e: std::str::Utf8Error) -> Self { + Error::new(e, ErrorKind::Utf8) + } +} +impl From for Error { + fn from(e: std::string::FromUtf8Error) -> Self { + Error::new(e, ErrorKind::Utf8) + } +} +impl From for Error { + fn from(e: emver::ParseError) -> Self { + Error::new(e, ErrorKind::ParseVersion) + } +} +impl From for Error { + fn from(e: rpc_toolkit::url::ParseError) -> Self { + Error::new(e, ErrorKind::ParseUrl) + } +} +impl From for Error { + fn from(e: std::num::ParseIntError) -> Self { + Error::new(e, ErrorKind::ParseNumber) + } +} +impl From for Error { + fn from(e: std::num::ParseFloatError) -> Self { + Error::new(e, ErrorKind::ParseNumber) + } +} +impl From for Error { + fn from(e: patch_db::Error) -> Self { + Error::new(e, ErrorKind::Database) + } +} +impl From for Error { + fn from(e: sqlx::Error) -> Self { + Error::new(e, ErrorKind::Database) + } +} +impl From for Error { + fn from(e: ed25519_dalek::SignatureError) -> Self { + Error::new(e, ErrorKind::InvalidSignature) + } +} +impl From for Error { + fn from(e: bollard::errors::Error) -> Self { + Error::new(e, ErrorKind::Docker) + } +} +impl From for Error { + fn from(e: torut::control::ConnError) -> Self { + Error::new(eyre!("{:?}", e), ErrorKind::Tor) + } +} +impl From for Error { + fn from(e: std::net::AddrParseError) -> Self { + Error::new(e, ErrorKind::ParseNetAddress) + } +} +impl From for Error { + fn from(e: openssl::error::ErrorStack) -> Self { + Error::new(eyre!("{}", e), ErrorKind::OpenSsl) + } +} +impl From for Error { + fn from(e: mbrman::Error) -> Self { + Error::new(e, ErrorKind::DiskManagement) + } +} +impl From for Error { + fn from(e: InvalidUri) -> Self { + Error::new(eyre!("{}", e), ErrorKind::ParseUrl) + } +} + +impl From for RpcError { + fn from(e: Error) -> Self { + let mut data_object = serde_json::Map::with_capacity(3); + data_object.insert("details".to_owned(), format!("{}", e.source).into()); + data_object.insert("debug".to_owned(), format!("{:?}", e.source).into()); + data_object.insert( + "revision".to_owned(), + match serde_json::to_value(&e.revision) { + Ok(a) => a, + Err(e) => { + tracing::warn!("Error serializing revision for Error object: {}", e); + serde_json::Value::Null + } + }, + ); + RpcError { + code: e.kind as i32, + message: e.kind.as_str().into(), + data: Some(data_object.into()), + } + } +} + +#[derive(Debug, Default)] +pub struct ErrorCollection(Vec); +impl ErrorCollection { + pub fn new() -> Self { + Self::default() + } + + pub fn handle>(&mut self, result: Result) -> Option { + match result { + Ok(a) => Some(a), + Err(e) => { + self.0.push(e.into()); + None + } + } + } + + pub fn into_result(self) -> Result<(), Error> { + if self.0.is_empty() { + Ok(()) + } else { + Err(Error::new(eyre!("{}", self), ErrorKind::MultipleErrors)) + } + } +} +impl From for Result<(), Error> { + fn from(e: ErrorCollection) -> Self { + e.into_result() + } +} +impl> Extend> for ErrorCollection { + fn extend>>(&mut self, iter: I) { + for item in iter { + self.handle(item); + } + } +} +impl std::fmt::Display for ErrorCollection { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + for (idx, e) in self.0.iter().enumerate() { + if idx > 0 { + write!(f, "; ")?; + } + write!(f, "{}", e)?; + } + Ok(()) + } +} + +pub trait ResultExt +where + Self: Sized, +{ + fn with_kind(self, kind: ErrorKind) -> Result; + fn with_ctx (ErrorKind, D), D: Display + Send + Sync + 'static>( + self, + f: F, + ) -> Result; +} +impl ResultExt for Result +where + color_eyre::eyre::Error: From, +{ + fn with_kind(self, kind: ErrorKind) -> Result { + self.map_err(|e| Error { + source: e.into(), + kind, + revision: None, + }) + } + + fn with_ctx (ErrorKind, D), D: Display + Send + Sync + 'static>( + self, + f: F, + ) -> Result { + self.map_err(|e| { + let (kind, ctx) = f(&e); + let source = color_eyre::eyre::Error::from(e); + let ctx = format!("{}: {}", ctx, source); + let source = source.wrap_err(ctx); + Error { + kind, + source, + revision: None, + } + }) + } +} + +#[macro_export] +macro_rules! ensure_code { + ($x:expr, $c:expr, $fmt:expr $(, $arg:expr)*) => { + if !($x) { + return Err(Error::new(color_eyre::eyre::eyre!($fmt, $($arg, )*), $c)); + } + }; +} diff --git a/libs/models/src/lib.rs b/libs/models/src/lib.rs index 0de5d6abb..28bf659ae 100644 --- a/libs/models/src/lib.rs +++ b/libs/models/src/lib.rs @@ -1,4 +1,5 @@ mod action_id; +mod errors; mod health_check_id; mod id; mod id_unchecked; @@ -11,6 +12,7 @@ mod version; mod volume_id; pub use action_id::*; +pub use errors::*; pub use health_check_id::*; pub use id::*; pub use id_unchecked::*; diff --git a/libs/snapshot-creator/Cargo.toml b/libs/snapshot_creator/Cargo.toml similarity index 91% rename from libs/snapshot-creator/Cargo.toml rename to libs/snapshot_creator/Cargo.toml index 7d508fa7b..cfc468954 100644 --- a/libs/snapshot-creator/Cargo.toml +++ b/libs/snapshot_creator/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "snapshot-creator" +name = "snapshot_creator" version = "0.1.0" edition = "2021" diff --git a/libs/snapshot-creator/src/main.rs b/libs/snapshot_creator/src/main.rs similarity index 100% rename from libs/snapshot-creator/src/main.rs rename to libs/snapshot_creator/src/main.rs