diff --git a/native/native_rust_library/Cargo.lock b/native/native_rust_library/Cargo.lock --- a/native/native_rust_library/Cargo.lock +++ b/native/native_rust_library/Cargo.lock @@ -174,12 +174,15 @@ version = "0.1.0" dependencies = [ "async-stream", + "bincode", "comm-lib", "derive_more", + "futures-util", "hex", "reqwest", "serde_json", "sha2", + "tokio-tungstenite", "url", ] @@ -189,6 +192,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + [[package]] name = "base64" version = "0.21.0" @@ -201,6 +210,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea2b2456fd614d856680dcd9fcc660a51a820fa09daef2e49772b56a193c8474" +[[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" @@ -293,7 +311,7 @@ version = "0.1.0" dependencies = [ "anyhow", - "base64", + "base64 0.21.0", "chrono", "constant_time_eq", "derive_more", @@ -838,9 +856,9 @@ "futures-util", "http", "hyper", - "rustls", + "rustls 0.21.7", "tokio", - "tokio-rustls", + "tokio-rustls 0.24.1", ] [[package]] @@ -1067,7 +1085,7 @@ dependencies = [ "argon2 0.5.1", "backup_client", - "base64", + "base64 0.21.0", "comm-opaque2", "cxx", "cxx-build", @@ -1442,7 +1460,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" dependencies = [ - "base64", + "base64 0.21.0", "bytes", "encoding_rs", "futures-core", @@ -1462,7 +1480,7 @@ "once_cell", "percent-encoding", "pin-project-lite", - "rustls", + "rustls 0.21.7", "rustls-pemfile", "serde", "serde_json", @@ -1470,7 +1488,7 @@ "system-configuration", "tokio", "tokio-native-tls", - "tokio-rustls", + "tokio-rustls 0.24.1", "tokio-util", "tower-service", "url", @@ -1491,12 +1509,26 @@ "cc", "libc", "once_cell", - "spin", - "untrusted", + "spin 0.5.2", + "untrusted 0.7.1", "web-sys", "winapi", ] +[[package]] +name = "ring" +version = "0.17.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "688c63d65483050968b2a8937f7995f443e27041a0f7700aa59b0822aedebb74" +dependencies = [ + "cc", + "getrandom", + "libc", + "spin 0.9.8", + "untrusted 0.9.0", + "windows-sys", +] + [[package]] name = "rustc-demangle" version = "0.1.23" @@ -1512,6 +1544,18 @@ "semver", ] +[[package]] +name = "rustls" +version = "0.20.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b80e3dec595989ea8510028f30c408a4630db12c9cbb8de34203b89d6577e99" +dependencies = [ + "log", + "ring 0.16.20", + "sct", + "webpki", +] + [[package]] name = "rustls" version = "0.21.7" @@ -1519,18 +1563,30 @@ checksum = "cd8d6c9f025a446bc4d18ad9632e69aec8f287aa84499ee335599fabd20c3fd8" dependencies = [ "log", - "ring", + "ring 0.16.20", "rustls-webpki 0.101.6", "sct", ] +[[package]] +name = "rustls-native-certs" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00" +dependencies = [ + "openssl-probe", + "rustls-pemfile", + "schannel", + "security-framework", +] + [[package]] name = "rustls-pemfile" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" dependencies = [ - "base64", + "base64 0.21.0", ] [[package]] @@ -1539,8 +1595,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f6a5fc258f1c1276dfe3016516945546e2d5383911efc0fc4f1cdc5df3a4ae3" dependencies = [ - "ring", - "untrusted", + "ring 0.16.20", + "untrusted 0.7.1", ] [[package]] @@ -1549,8 +1605,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c7d5dece342910d9ba34d259310cae3e0154b873b35408b787b59bce53d34fe" dependencies = [ - "ring", - "untrusted", + "ring 0.16.20", + "untrusted 0.7.1", ] [[package]] @@ -1586,8 +1642,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" dependencies = [ - "ring", - "untrusted", + "ring 0.16.20", + "untrusted 0.7.1", ] [[package]] @@ -1675,6 +1731,17 @@ "serde", ] +[[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.10.6" @@ -1736,6 +1803,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + [[package]] name = "subtle" version = "2.4.1" @@ -1826,6 +1899,26 @@ "winapi-util", ] +[[package]] +name = "thiserror" +version = "1.0.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + [[package]] name = "thread_local" version = "1.1.7" @@ -1899,13 +1992,24 @@ "tokio", ] +[[package]] +name = "tokio-rustls" +version = "0.23.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +dependencies = [ + "rustls 0.20.9", + "tokio", + "webpki", +] + [[package]] name = "tokio-rustls" version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ - "rustls", + "rustls 0.21.7", "tokio", ] @@ -1920,6 +2024,24 @@ "tokio", ] +[[package]] +name = "tokio-tungstenite" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54319c93411147bced34cb5609a80e0a8e44c5999c93903a81cd866630ec0bfd" +dependencies = [ + "futures-util", + "log", + "native-tls", + "rustls 0.20.9", + "rustls-native-certs", + "tokio", + "tokio-native-tls", + "tokio-rustls 0.23.4", + "tungstenite", + "webpki", +] + [[package]] name = "tokio-util" version = "0.7.4" @@ -1943,7 +2065,7 @@ "async-stream", "async-trait", "axum", - "base64", + "base64 0.21.0", "bytes", "futures-core", "futures-util", @@ -1957,7 +2079,7 @@ "prost", "rustls-pemfile", "tokio", - "tokio-rustls", + "tokio-rustls 0.24.1", "tokio-stream", "tower", "tower-layer", @@ -2079,6 +2201,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" +[[package]] +name = "tungstenite" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30ee6ab729cd4cf0fd55218530c4522ed30b7b6081752839b68fcec8d0960788" +dependencies = [ + "base64 0.13.1", + "byteorder", + "bytes", + "http", + "httparse", + "log", + "native-tls", + "rand", + "rustls 0.20.9", + "sha1", + "thiserror", + "url", + "utf-8", + "webpki", +] + [[package]] name = "typenum" version = "1.15.0" @@ -2133,6 +2277,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + [[package]] name = "url" version = "2.5.0" @@ -2144,6 +2294,12 @@ "percent-encoding", ] +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + [[package]] name = "uuid" version = "1.6.1" @@ -2295,6 +2451,16 @@ "wasm-bindgen", ] +[[package]] +name = "webpki" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed63aea5ce73d0ff405984102c42de94fc55a6b75765d621c65262469b3c9b53" +dependencies = [ + "ring 0.17.7", + "untrusted 0.9.0", +] + [[package]] name = "webpki-roots" version = "0.23.1" diff --git a/services/commtest/Cargo.lock b/services/commtest/Cargo.lock --- a/services/commtest/Cargo.lock +++ b/services/commtest/Cargo.lock @@ -162,12 +162,15 @@ version = "0.1.0" dependencies = [ "async-stream", + "bincode", "comm-lib", "derive_more", + "futures-util", "hex", "reqwest", "serde_json", "sha2", + "tokio-tungstenite", "url", ] @@ -195,6 +198,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[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" @@ -1878,7 +1890,9 @@ dependencies = [ "futures-util", "log", + "native-tls", "tokio", + "tokio-native-tls", "tungstenite", ] @@ -2108,6 +2122,7 @@ "http", "httparse", "log", + "native-tls", "rand", "sha1", "thiserror", diff --git a/shared/backup_client/Cargo.lock b/shared/backup_client/Cargo.lock --- a/shared/backup_client/Cargo.lock +++ b/shared/backup_client/Cargo.lock @@ -151,21 +151,39 @@ version = "0.1.0" dependencies = [ "async-stream", + "bincode", "comm-lib", "derive_more", + "futures-util", "hex", "reqwest", "serde_json", "sha2", + "tokio-tungstenite", "url", ] +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + [[package]] name = "base64" version = "0.21.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" +[[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" @@ -193,6 +211,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "bytes" version = "1.5.0" @@ -233,7 +257,7 @@ version = "0.1.0" dependencies = [ "anyhow", - "base64", + "base64 0.21.5", "chrono", "constant_time_eq", "derive_more", @@ -610,9 +634,9 @@ "futures-util", "http", "hyper", - "rustls", + "rustls 0.21.9", "tokio", - "tokio-rustls", + "tokio-rustls 0.24.1", ] [[package]] @@ -1143,7 +1167,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" dependencies = [ - "base64", + "base64 0.21.5", "bytes", "encoding_rs", "futures-core", @@ -1163,7 +1187,7 @@ "once_cell", "percent-encoding", "pin-project-lite", - "rustls", + "rustls 0.21.9", "rustls-pemfile", "serde", "serde_json", @@ -1171,7 +1195,7 @@ "system-configuration", "tokio", "tokio-native-tls", - "tokio-rustls", + "tokio-rustls 0.24.1", "tokio-util", "tower-service", "url", @@ -1240,6 +1264,18 @@ "windows-sys 0.52.0", ] +[[package]] +name = "rustls" +version = "0.20.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b80e3dec595989ea8510028f30c408a4630db12c9cbb8de34203b89d6577e99" +dependencies = [ + "log", + "ring 0.16.20", + "sct", + "webpki", +] + [[package]] name = "rustls" version = "0.21.9" @@ -1252,13 +1288,25 @@ "sct", ] +[[package]] +name = "rustls-native-certs" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00" +dependencies = [ + "openssl-probe", + "rustls-pemfile", + "schannel", + "security-framework", +] + [[package]] name = "rustls-pemfile" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ - "base64", + "base64 0.21.5", ] [[package]] @@ -1384,6 +1432,17 @@ "serde", ] +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "sha2" version = "0.10.8" @@ -1513,6 +1572,26 @@ "windows-sys 0.48.0", ] +[[package]] +name = "thiserror" +version = "1.0.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + [[package]] name = "thread_local" version = "1.1.7" @@ -1585,13 +1664,24 @@ "tokio", ] +[[package]] +name = "tokio-rustls" +version = "0.23.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +dependencies = [ + "rustls 0.20.9", + "tokio", + "webpki", +] + [[package]] name = "tokio-rustls" version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ - "rustls", + "rustls 0.21.9", "tokio", ] @@ -1606,6 +1696,24 @@ "tokio", ] +[[package]] +name = "tokio-tungstenite" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54319c93411147bced34cb5609a80e0a8e44c5999c93903a81cd866630ec0bfd" +dependencies = [ + "futures-util", + "log", + "native-tls", + "rustls 0.20.9", + "rustls-native-certs", + "tokio", + "tokio-native-tls", + "tokio-rustls 0.23.4", + "tungstenite", + "webpki", +] + [[package]] name = "tokio-util" version = "0.7.10" @@ -1629,7 +1737,7 @@ "async-stream", "async-trait", "axum", - "base64", + "base64 0.21.5", "bytes", "futures-core", "futures-util", @@ -1643,7 +1751,7 @@ "prost", "rustls-pemfile", "tokio", - "tokio-rustls", + "tokio-rustls 0.24.1", "tokio-stream", "tower", "tower-layer", @@ -1764,6 +1872,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" +[[package]] +name = "tungstenite" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30ee6ab729cd4cf0fd55218530c4522ed30b7b6081752839b68fcec8d0960788" +dependencies = [ + "base64 0.13.1", + "byteorder", + "bytes", + "http", + "httparse", + "log", + "native-tls", + "rand", + "rustls 0.20.9", + "sha1", + "thiserror", + "url", + "utf-8", + "webpki", +] + [[package]] name = "typenum" version = "1.17.0" @@ -1823,6 +1953,12 @@ "percent-encoding", ] +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + [[package]] name = "uuid" version = "1.6.1" @@ -1954,6 +2090,16 @@ "wasm-bindgen", ] +[[package]] +name = "webpki" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed63aea5ce73d0ff405984102c42de94fc55a6b75765d621c65262469b3c9b53" +dependencies = [ + "ring 0.17.6", + "untrusted 0.9.0", +] + [[package]] name = "webpki-roots" version = "0.23.1" diff --git a/shared/backup_client/Cargo.toml b/shared/backup_client/Cargo.toml --- a/shared/backup_client/Cargo.toml +++ b/shared/backup_client/Cargo.toml @@ -15,8 +15,11 @@ async-stream = "0.3.2" sha2 = "0.10" hex = "0.4.3" +tokio-tungstenite = "0.18.0" +futures-util = "0.3" +bincode = "1.3.3" [features] default = ["native-tls"] -native-tls = ["reqwest/native-tls"] -rustls-tls = ["reqwest/rustls-tls"] +native-tls = ["reqwest/native-tls", "tokio-tungstenite/native-tls"] +rustls-tls = ["reqwest/rustls-tls", "tokio-tungstenite/rustls-tls-native-roots"] diff --git a/shared/backup_client/src/lib.rs b/shared/backup_client/src/lib.rs --- a/shared/backup_client/src/lib.rs +++ b/shared/backup_client/src/lib.rs @@ -1,11 +1,27 @@ pub use comm_lib::auth::UserIdentity; -pub use comm_lib::backup::LatestBackupIDResponse; +pub use comm_lib::backup::{ + DownloadLogsRequest, LatestBackupIDResponse, LogWSRequest, LogWSResponse, + UploadLogRequest, +}; +pub use futures_util::{SinkExt, StreamExt, TryStreamExt}; + +use futures_util::{Sink, Stream}; use hex::ToHex; use reqwest::{ + header::InvalidHeaderValue, multipart::{Form, Part}, Body, }; use sha2::{Digest, Sha256}; +use tokio_tungstenite::{ + connect_async, + tungstenite::{ + client::IntoClientRequest, + http::{header, Request}, + Error as TungsteniteError, + Message::{Binary, Ping}, + }, +}; #[derive(Debug, Clone)] pub struct BackupClient { @@ -18,7 +34,10 @@ url: url.try_into()?, }) } +} +/// Backup functions +impl BackupClient { pub async fn upload_backup( &self, user_identity: &UserIdentity, @@ -94,6 +113,86 @@ } } +/// Log functions +impl BackupClient { + pub async fn upload_logs( + &self, + user_identity: &UserIdentity, + backup_id: &str, + ) -> Result< + ( + impl Sink, + impl Stream>, + ), + Error, + > { + let request = self.create_ws_request(user_identity, backup_id)?; + let (stream, response) = connect_async(request).await?; + + if response.status().is_client_error() { + return Err(Error::WSInitError(TungsteniteError::Http(response))); + } + + let (tx, rx) = stream.split(); + + let tx = tx.with(|request: UploadLogRequest| async { + let request = LogWSRequest::UploadLog(request); + let request = bincode::serialize(&request)?; + Ok(Binary(request)) + }); + + let rx = rx.filter_map(|msg| async { + let bytes = match msg { + Ok(Binary(bytes)) => bytes, + // Handled by tungstenite + Ok(Ping(_)) => return None, + Ok(_) => return Some(Err(WSError::InvalidWSMessage)), + Err(err) => return Some(Err(err.into())), + }; + + let response = match bincode::deserialize(&bytes) { + Ok(response) => response, + Err(err) => return Some(Err(err.into())), + }; + + match response { + LogWSResponse::LogUploaded { log_id } => Some(Ok(log_id)), + LogWSResponse::LogDownload { .. } + | LogWSResponse::LogDownloadFinished { .. } => { + Some(Err(WSError::InvalidBackupMessage)) + } + LogWSResponse::ServerError => Some(Err(WSError::ServerError)), + } + }); + + Ok((tx, rx)) + } + + fn create_ws_request( + &self, + user_identity: &UserIdentity, + backup_id: &str, + ) -> Result, Error> { + let mut url = self.url.clone(); + + match url.scheme() { + "http" => url.set_scheme("ws")?, + "https" => url.set_scheme("wss")?, + _ => (), + }; + let url = url.join("logs/")?.join(backup_id)?; + + let mut request = url.into_client_request().unwrap(); + + let token = user_identity.as_authorization_token()?; + request + .headers_mut() + .insert(header::AUTHORIZATION, format!("Bearer {token}").parse()?); + + Ok(request) + } +} + #[derive(Debug, Clone)] pub struct BackupData { pub backup_id: String, @@ -124,7 +223,26 @@ Debug, derive_more::Display, derive_more::Error, derive_more::From, )] pub enum Error { + InvalidAuthorizationHeader, UrlError(url::ParseError), ReqwestError(reqwest::Error), + WSInitError(TungsteniteError), JsonError(serde_json::Error), } + +impl From for Error { + fn from(_: InvalidHeaderValue) -> Self { + Self::InvalidAuthorizationHeader + } +} + +#[derive( + Debug, derive_more::Display, derive_more::Error, derive_more::From, +)] +pub enum WSError { + BincodeError(bincode::Error), + TungsteniteError(TungsteniteError), + InvalidWSMessage, + InvalidBackupMessage, + ServerError, +}