From 585691bc51ba62db0da4dfe13c8cf9e9b582697b Mon Sep 17 00:00:00 2001 From: Zeragamba Date: Wed, 3 Jul 2024 08:54:34 -0400 Subject: [PATCH 01/24] start rust version of OG Injector --- .idea/inspectionProfiles/Project_Default.xml | 1 + .idea/prettier.xml | 7 + packages/og-injector-rust/.gitignore | 1 + packages/og-injector-rust/Cargo.lock | 1600 ++++++++++++++++++ packages/og-injector-rust/Cargo.toml | 12 + packages/og-injector-rust/src/client.rs | 15 + packages/og-injector-rust/src/main.rs | 50 + packages/og-injector-rust/src/ssl.rs | 30 + 8 files changed, 1716 insertions(+) create mode 100644 .idea/prettier.xml create mode 100644 packages/og-injector-rust/.gitignore create mode 100644 packages/og-injector-rust/Cargo.lock create mode 100644 packages/og-injector-rust/Cargo.toml create mode 100644 packages/og-injector-rust/src/client.rs create mode 100644 packages/og-injector-rust/src/main.rs create mode 100644 packages/og-injector-rust/src/ssl.rs diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index cb3e5c5..91a3179 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -26,6 +26,7 @@ + diff --git a/.idea/prettier.xml b/.idea/prettier.xml new file mode 100644 index 0000000..0c83ac4 --- /dev/null +++ b/.idea/prettier.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/packages/og-injector-rust/.gitignore b/packages/og-injector-rust/.gitignore new file mode 100644 index 0000000..2f7896d --- /dev/null +++ b/packages/og-injector-rust/.gitignore @@ -0,0 +1 @@ +target/ diff --git a/packages/og-injector-rust/Cargo.lock b/packages/og-injector-rust/Cargo.lock new file mode 100644 index 0000000..51349b1 --- /dev/null +++ b/packages/og-injector-rust/Cargo.lock @@ -0,0 +1,1600 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "arc-swap" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" + +[[package]] +name = "async-trait" +version = "0.1.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "axum" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a6c9af12842a67734c9a2e355436e5d03b22383ed60cf13cd0c18fbfe3dcbcf" +dependencies = [ + "async-trait", + "axum-core", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper 1.0.1", + "tokio", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-core" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper 0.1.2", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-server" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1ad46c3ec4e12f4a4b6835e173ba21c25e484c9d02b49770bf006ce5367c036" +dependencies = [ + "arc-swap", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "pin-project-lite", + "rustls 0.21.12", + "rustls-pemfile", + "tokio", + "tokio-rustls 0.24.1", + "tower", + "tower-service", +] + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "pin-utils", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "h2" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa82e28a107a8cc405f0839610bdc9b15f1e25ec7d696aa5cf173edbcb1486ab" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe575dd17d0862a9a33781c8c4696a55c320909004a67a00fb286ba8b1bc496d" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls 0.23.10", + "rustls-pki-types", + "tokio", + "tokio-rustls 0.26.0", + "tower-service", +] + +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b875924a60b96e5d7b9ae7b066540b1dd1cbd90d1828f54c92e02a283351c56" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", +] + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "ipnet" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "matchit" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "og-injector-rust" +version = "0.1.0" +dependencies = [ + "axum", + "axum-server", + "reqwest", + "tokio", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "openssl" +version = "0.10.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" +dependencies = [ + "bitflags 2.5.0", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "reqwest" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7d6d2a27d57148378eb5e111173f4276ad26340ecc5c49a4a2152167a2d6a37" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper 1.0.1", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags 2.5.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.21.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" +dependencies = [ + "log", + "ring", + "rustls-webpki 0.101.7", + "sct", +] + +[[package]] +name = "rustls" +version = "0.23.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05cff451f60db80f490f3c182b77c35260baace73209e9cdbbe526bfe3a4d402" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki 0.102.4", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d" +dependencies = [ + "base64", + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" + +[[package]] +name = "rustls-webpki" +version = "0.101.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "rustls-webpki" +version = "0.102.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "sct" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "security-framework" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" +dependencies = [ + "bitflags 2.5.0", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "serde" +version = "1.0.203" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.203" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_path_to_error" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af99884400da37c88f5e9146b7f1fd0fbcae8f6eec4e9da38b67d05486f814a6" +dependencies = [ + "itoa", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "subtle" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" + +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +dependencies = [ + "cfg-if", + "fastrand", + "rustix", + "windows-sys 0.52.0", +] + +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" +dependencies = [ + "rustls 0.21.12", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls 0.23.10", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "nu-ansi-term", + "sharded-slab", + "smallvec", + "thread_local", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +dependencies = [ + "tinyvec", +] + +[[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.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" + +[[package]] +name = "web-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" + +[[package]] +name = "winreg" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/packages/og-injector-rust/Cargo.toml b/packages/og-injector-rust/Cargo.toml new file mode 100644 index 0000000..1a7dcf7 --- /dev/null +++ b/packages/og-injector-rust/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "og-injector-rust" +version = "0.1.0" +edition = "2021" + +[dependencies] +axum = "0.7.5" +axum-server = { version = "0.6", features = ["tls-rustls"] } +tracing-subscriber = "0.3.18" +tokio = { version = "1.38.0", features = ["rt-multi-thread"] } +tracing = "0.1.40" +reqwest = { version = "0.12.5", features = ["json"] } diff --git a/packages/og-injector-rust/src/client.rs b/packages/og-injector-rust/src/client.rs new file mode 100644 index 0000000..b992eb5 --- /dev/null +++ b/packages/og-injector-rust/src/client.rs @@ -0,0 +1,15 @@ +use reqwest; + +use crate::ssl; + +pub async fn fetch_index_html() -> Result { + let client = reqwest::ClientBuilder::new() + .add_root_certificate(ssl::get_ssl_cert_path()) + .danger_accept_invalid_certs(true) + .build()?; + + let resp = client.get("https://localhost:3000").send().await?; + + println!("{resp:#?}"); + resp.text().await +} diff --git a/packages/og-injector-rust/src/main.rs b/packages/og-injector-rust/src/main.rs new file mode 100644 index 0000000..5ba4b1b --- /dev/null +++ b/packages/og-injector-rust/src/main.rs @@ -0,0 +1,50 @@ +use std::net::SocketAddr; +use std::path::PathBuf; + +use axum::{http::StatusCode, Router, routing::get}; +use axum_server::tls_rustls::RustlsConfig; + +mod client; +mod ssl; + +#[tokio::main] +async fn main() { + // initialize tracing + tracing_subscriber::fmt::init(); + + let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("..") + .join("..") + .canonicalize() + .expect("Unable to build path to root dir"); + let cert_dir = root_dir.join(".certs"); + + println!( + "Certs dir: {}", + cert_dir.to_str().expect("Error forming path") + ); + + let ssl_cert = ssl::get_ssl_cert_path(); + let ssl_key = ssl::get_ssl_key_path(); + let config = RustlsConfig::from_pem_file(ssl_cert, ssl_key) + .await + .unwrap(); + + // build our application with a route + let app = Router::new().route("/", get(get_index_html)); + + // run https server + let addr = SocketAddr::from(([0, 0, 0, 0], 3002)); + println!("listening on {}", addr); + axum_server::bind_rustls(addr, config) + .serve(app.into_make_service()) + .await + .unwrap(); +} + +async fn get_index_html() -> (StatusCode, String) { + return match client::fetch_index_html().await { + Ok(index_html) => (StatusCode::OK, index_html), + Err(error) => (StatusCode::INTERNAL_SERVER_ERROR, error.to_string()), + }; +} diff --git a/packages/og-injector-rust/src/ssl.rs b/packages/og-injector-rust/src/ssl.rs new file mode 100644 index 0000000..48ce783 --- /dev/null +++ b/packages/og-injector-rust/src/ssl.rs @@ -0,0 +1,30 @@ +use std::path::PathBuf; + +use reqwest::Certificate; +use tokio::fs::File; + +fn get_certs_dir() -> PathBuf { + PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("..") + .join("..") + .canonicalize() + .expect("Unable to build path to root dir") + .join(".certs") +} + +pub fn get_ssl_cert_path() -> PathBuf { + get_certs_dir().join("current.crt") +} + +pub fn get_ssl_key_path() -> PathBuf { + get_certs_dir().join("current.key") +} + +pub fn get_ssl_cert() -> reqwest::Result { + let path = get_ssl_cert_path().to_str(); + + let mut buf = Vec::new(); + File::open(path.to_str())?.read_to_end(&mut buf)?; + + Certificate::from_pem(&buf) +} From be65175aca60643a6fa579e543bbd96942d6bea2 Mon Sep 17 00:00:00 2001 From: Zeragamba Date: Sat, 6 Jul 2024 11:54:47 -0400 Subject: [PATCH 02/24] switch router to use rust injector --- docker-compose.shared.yml | 20 +++- docker-compose.yml | 12 +++ packages/og-injector-rust/.dockerignore | 2 + packages/og-injector-rust/.idea/.gitignore | 5 + .../inspectionProfiles/Project_Default.xml | 78 +++++++++++++++ packages/og-injector-rust/.idea/modules.xml | 8 ++ .../.idea/og-injector-rust.iml | 11 +++ packages/og-injector-rust/.idea/vcs.xml | 6 ++ packages/og-injector-rust/Dockerfile | 13 +++ packages/og-injector-rust/src/client.rs | 48 ++++++++- packages/og-injector-rust/src/main.rs | 97 +++++++++++++------ packages/og-injector-rust/src/ssl.rs | 56 +++++++++-- router/nginx.conf | 16 ++- 13 files changed, 327 insertions(+), 45 deletions(-) create mode 100644 packages/og-injector-rust/.dockerignore create mode 100644 packages/og-injector-rust/.idea/.gitignore create mode 100644 packages/og-injector-rust/.idea/inspectionProfiles/Project_Default.xml create mode 100644 packages/og-injector-rust/.idea/modules.xml create mode 100644 packages/og-injector-rust/.idea/og-injector-rust.iml create mode 100644 packages/og-injector-rust/.idea/vcs.xml create mode 100644 packages/og-injector-rust/Dockerfile diff --git a/docker-compose.shared.yml b/docker-compose.shared.yml index e5a7d69..10a8893 100644 --- a/docker-compose.shared.yml +++ b/docker-compose.shared.yml @@ -3,12 +3,16 @@ services: build: ./router depends_on: - server - - og-injector + - og-injector-rust volumes: - ./.volumes/images:/opt/images:ro - ./.volumes/client:/opt/client:ro - "${SSL_CRT}:/opt/ssl/current.crt:ro" - "${SSL_KEY}:/opt/ssl/current.key:ro" + develop: + watch: + - action: rebuild + path: ./router/nginx.conf server: build: ./server @@ -54,6 +58,20 @@ services: CLIENT_URL: "${APP_URL}" CLIENT_DIR: "/opt/client" + og-injector-rust: + build: packages/og-injector-rust + volumes: + - ./.volumes/client:/opt/client:ro + environment: + NODE_ENV: "${APP_ENV}" + SERVER_URL: "http://server:3000" # internal docker url + CLIENT_URL: "${APP_URL}" + CLIENT_DIR: "/opt/client" + develop: + watch: + - action: rebuild + path: ./packages/og-injector-rust/src + db: image: postgres:16 volumes: diff --git a/docker-compose.yml b/docker-compose.yml index 78092e1..1f47995 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -45,6 +45,18 @@ services: - ./.volumes/client:/opt/client:ro command: yarn watch + og-injector-rust: + extends: + file: docker-compose.shared.yml + service: og-injector-rust + volumes: + - ./packages/og-injector-rust:/opt/og-injector:rw + - ./.volumes/client:/opt/client:ro + environment: + SSL_CRT: /opt/ssl/current.crt + SSL_KEY: /opt/ssl/current.key + command: yarn watch + db: extends: file: docker-compose.shared.yml diff --git a/packages/og-injector-rust/.dockerignore b/packages/og-injector-rust/.dockerignore new file mode 100644 index 0000000..96ef862 --- /dev/null +++ b/packages/og-injector-rust/.dockerignore @@ -0,0 +1,2 @@ +target/ +.idea/ diff --git a/packages/og-injector-rust/.idea/.gitignore b/packages/og-injector-rust/.idea/.gitignore new file mode 100644 index 0000000..b58b603 --- /dev/null +++ b/packages/og-injector-rust/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/packages/og-injector-rust/.idea/inspectionProfiles/Project_Default.xml b/packages/og-injector-rust/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..8dd3b21 --- /dev/null +++ b/packages/og-injector-rust/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,78 @@ + + + + \ No newline at end of file diff --git a/packages/og-injector-rust/.idea/modules.xml b/packages/og-injector-rust/.idea/modules.xml new file mode 100644 index 0000000..21bf0e7 --- /dev/null +++ b/packages/og-injector-rust/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/packages/og-injector-rust/.idea/og-injector-rust.iml b/packages/og-injector-rust/.idea/og-injector-rust.iml new file mode 100644 index 0000000..cf84ae4 --- /dev/null +++ b/packages/og-injector-rust/.idea/og-injector-rust.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/packages/og-injector-rust/.idea/vcs.xml b/packages/og-injector-rust/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/packages/og-injector-rust/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/packages/og-injector-rust/Dockerfile b/packages/og-injector-rust/Dockerfile new file mode 100644 index 0000000..f3ca728 --- /dev/null +++ b/packages/og-injector-rust/Dockerfile @@ -0,0 +1,13 @@ +FROM rust as builder + +WORKDIR /usr/src/app +COPY . . +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/home/root/app/target \ + cargo build --release + +FROM ubuntu + +COPY --from=builder /usr/src/app/target/release/og-injector-rust /usr/bin + +CMD ["og-injector-rust"] diff --git a/packages/og-injector-rust/src/client.rs b/packages/og-injector-rust/src/client.rs index b992eb5..5002a12 100644 --- a/packages/og-injector-rust/src/client.rs +++ b/packages/og-injector-rust/src/client.rs @@ -1,15 +1,55 @@ +use std::{env, fmt}; +use std::env::VarError; +use std::fmt::Debug; + use reqwest; +use reqwest::Url; use crate::ssl; -pub async fn fetch_index_html() -> Result { +#[derive(Debug, Clone)] +pub struct ClientError { + msg: String, +} + +impl fmt::Display for ClientError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.msg) + } +} + +pub fn get_client_url() -> Result { + let client_url = match env::var("CLIENT_INDEX_URL") { + Ok(value) => Ok(value), + Err(err) => { + match err { + VarError::NotPresent => Ok("https://localhost:3001/index.html".parse().unwrap()), + VarError::NotUnicode(_) => Err(ClientError { msg: "Unable to read env var SSL_CRT".parse().unwrap() }) + } + } + }?; + + Url::parse(client_url.as_str()) + .map_err(|e| ClientError { msg: e.to_string() }) +} + + +pub async fn fetch_index_html() -> Result { + let root_cert = ssl::get_ssl_cert().await + .map_err(|e| ClientError { msg: e.to_string() })?; + let client = reqwest::ClientBuilder::new() - .add_root_certificate(ssl::get_ssl_cert_path()) + .add_root_certificate(root_cert) .danger_accept_invalid_certs(true) - .build()?; + .build() + .map_err(|e| ClientError { msg: e.to_string() })?; - let resp = client.get("https://localhost:3000").send().await?; + let client_url = get_client_url()?; + println!("fetching index from {}", client_url); + let resp = client.get(client_url).send().await + .map_err(|e| ClientError { msg: e.to_string() })?; println!("{resp:#?}"); resp.text().await + .map_err(|e| ClientError { msg: e.to_string() }) } diff --git a/packages/og-injector-rust/src/main.rs b/packages/og-injector-rust/src/main.rs index 5ba4b1b..e565327 100644 --- a/packages/og-injector-rust/src/main.rs +++ b/packages/og-injector-rust/src/main.rs @@ -1,50 +1,89 @@ +use std::env; +use std::env::VarError; use std::net::SocketAddr; -use std::path::PathBuf; use axum::{http::StatusCode, Router, routing::get}; +use axum::body::Body; +use axum::http::Request; +use axum::response::Response; use axum_server::tls_rustls::RustlsConfig; +use reqwest::header; mod client; mod ssl; +fn is_https_enabled() -> bool { + match env::var("HTTPS_ENABLED") { + Ok(value) => value == "true", + Err(err) => { + match err { + VarError::NotPresent => true, + VarError::NotUnicode(_) => panic!("HTTPS_ENABLED was not a unicode value"), + } + } + } +} + #[tokio::main] async fn main() { - // initialize tracing tracing_subscriber::fmt::init(); - let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .join("..") - .join("..") - .canonicalize() - .expect("Unable to build path to root dir"); - let cert_dir = root_dir.join(".certs"); - - println!( - "Certs dir: {}", - cert_dir.to_str().expect("Error forming path") - ); - - let ssl_cert = ssl::get_ssl_cert_path(); - let ssl_key = ssl::get_ssl_key_path(); - let config = RustlsConfig::from_pem_file(ssl_cert, ssl_key) - .await - .unwrap(); - // build our application with a route - let app = Router::new().route("/", get(get_index_html)); + let app = Router::new() + .route("/", get(get_index_html)) + .fallback(get(get_fallback)); // run https server - let addr = SocketAddr::from(([0, 0, 0, 0], 3002)); + let addr = SocketAddr::from(([0, 0, 0, 0], 3000)); println!("listening on {}", addr); - axum_server::bind_rustls(addr, config) - .serve(app.into_make_service()) - .await - .unwrap(); + + if is_https_enabled() { + let ssl_cert = ssl::get_ssl_cert_path() + .expect("Unable to read SSL Cert"); + let ssl_key = ssl::get_ssl_key_path() + .expect("Unable to read SSL Key"); + let config = RustlsConfig::from_pem_file(ssl_cert, ssl_key) + .await + .unwrap(); + axum_server::bind_rustls(addr, config) + .serve(app.into_make_service()) + .await + .unwrap(); + } else { + axum_server::bind(addr) + .serve(app.into_make_service()) + .await + .unwrap(); + }; } -async fn get_index_html() -> (StatusCode, String) { +async fn get_index_html(req: Request) -> Response { + println!("-> GET {}", req.uri()); + return match client::fetch_index_html().await { - Ok(index_html) => (StatusCode::OK, index_html), - Err(error) => (StatusCode::INTERNAL_SERVER_ERROR, error.to_string()), + Err(error) => { + Response::builder() + .status(StatusCode::INTERNAL_SERVER_ERROR) + .body(Body::from(error.to_string())) + .unwrap() + } + + Ok(index_html) => { + Response::builder() + .status(StatusCode::OK) + .header(header::CONTENT_TYPE, "text/html") + .header("x-generated-by", "rust") + .body(Body::from(index_html)) + .unwrap() + } }; } + +async fn get_fallback(req: Request) -> Response { + println!("-> GET {}", req.uri()); + + Response::builder() + .status(StatusCode::INTERNAL_SERVER_ERROR) + .body(Body::from("Unexpected request")) + .unwrap() +} diff --git a/packages/og-injector-rust/src/ssl.rs b/packages/og-injector-rust/src/ssl.rs index 48ce783..fe12cbe 100644 --- a/packages/og-injector-rust/src/ssl.rs +++ b/packages/og-injector-rust/src/ssl.rs @@ -1,9 +1,25 @@ +use std::{env, fmt}; +use std::env::VarError; use std::path::PathBuf; use reqwest::Certificate; use tokio::fs::File; +use tokio::io::AsyncReadExt; -fn get_certs_dir() -> PathBuf { +type Result = std::result::Result; + +#[derive(Debug, Clone)] +pub struct SslError { + msg: String, +} + +impl fmt::Display for SslError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.msg) + } +} + +fn get_default_certs_dir() -> PathBuf { PathBuf::from(env!("CARGO_MANIFEST_DIR")) .join("..") .join("..") @@ -12,19 +28,43 @@ fn get_certs_dir() -> PathBuf { .join(".certs") } -pub fn get_ssl_cert_path() -> PathBuf { - get_certs_dir().join("current.crt") +pub fn get_ssl_cert_path() -> Result { + match env::var("SSL_CRT") { + Ok(value) => Ok(PathBuf::from(value)), + Err(err) => { + match err { + VarError::NotPresent => Ok(get_default_certs_dir().join("current.crt")), + VarError::NotUnicode(_) => Err(SslError { msg: "Unable to read env var SSL_CRT".parse().unwrap() }) + } + } + } } -pub fn get_ssl_key_path() -> PathBuf { - get_certs_dir().join("current.key") +pub fn get_ssl_key_path() -> Result { + match env::var("SSL_KEY") { + Ok(value) => Ok(PathBuf::from(value)), + Err(err) => { + match err { + VarError::NotPresent => Ok(get_default_certs_dir().join("current.key")), + VarError::NotUnicode(_) => Err(SslError { msg: "Unable to read env var SSL_CRT".parse().unwrap() }) + } + } + } } -pub fn get_ssl_cert() -> reqwest::Result { - let path = get_ssl_cert_path().to_str(); +pub async fn get_ssl_cert() -> Result { + let cert_path = get_ssl_cert_path()?; + + let path: &str = cert_path + .to_str() + .ok_or(SslError { msg: "Expected to find a path".parse().unwrap() })?; let mut buf = Vec::new(); - File::open(path.to_str())?.read_to_end(&mut buf)?; + File::open(path).await + .map_err(|e| SslError { msg: e.to_string() })? + .read_to_end(&mut buf).await + .map_err(|e| SslError { msg: e.to_string() })?; Certificate::from_pem(&buf) + .map_err(|e| SslError { msg: e.to_string() }) } diff --git a/router/nginx.conf b/router/nginx.conf index d5fc91e..4f3a0d1 100644 --- a/router/nginx.conf +++ b/router/nginx.conf @@ -12,17 +12,27 @@ server { add_header Cache-Control public; root /opt/client; - try_files $uri @og-injector; + try_files $uri @og-injector-rust; } - location @og-injector { +# location @og-injector { +# expires -1; +# gzip_static on; +# add_header Cache-Control no-cache; +# +# proxy_set_header Host $host; +# proxy_set_header X-Real-IP $remote_addr; +# proxy_pass http://og-injector:3000; +# } + + location @og-injector-rust { expires -1; gzip_static on; add_header Cache-Control no-cache; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; - proxy_pass http://og-injector:3000; + proxy_pass http://og-injector-rust:3000; } location /images { From 67b58255887aae447add1e4227b2d6eb7215ae63 Mon Sep 17 00:00:00 2001 From: Zeragamba Date: Sat, 6 Jul 2024 14:34:30 -0400 Subject: [PATCH 03/24] refactor config --- packages/og-injector-rust/Cargo.lock | 7 ++ packages/og-injector-rust/Cargo.toml | 1 + packages/og-injector-rust/src/client.rs | 35 +++----- packages/og-injector-rust/src/config.rs | 87 +++++++++++++++++++ .../og-injector-rust/src/injector_ctrl.rs | 29 +++++++ packages/og-injector-rust/src/main.rs | 80 +++++------------ packages/og-injector-rust/src/ssl.rs | 70 --------------- 7 files changed, 162 insertions(+), 147 deletions(-) create mode 100644 packages/og-injector-rust/src/config.rs create mode 100644 packages/og-injector-rust/src/injector_ctrl.rs delete mode 100644 packages/og-injector-rust/src/ssl.rs diff --git a/packages/og-injector-rust/Cargo.lock b/packages/og-injector-rust/Cargo.lock index 51349b1..939ad60 100644 --- a/packages/og-injector-rust/Cargo.lock +++ b/packages/og-injector-rust/Cargo.lock @@ -197,6 +197,12 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "encoding_rs" version = "0.8.34" @@ -620,6 +626,7 @@ version = "0.1.0" dependencies = [ "axum", "axum-server", + "dotenv", "reqwest", "tokio", "tracing", diff --git a/packages/og-injector-rust/Cargo.toml b/packages/og-injector-rust/Cargo.toml index 1a7dcf7..bb2075c 100644 --- a/packages/og-injector-rust/Cargo.toml +++ b/packages/og-injector-rust/Cargo.toml @@ -10,3 +10,4 @@ tracing-subscriber = "0.3.18" tokio = { version = "1.38.0", features = ["rt-multi-thread"] } tracing = "0.1.40" reqwest = { version = "0.12.5", features = ["json"] } +dotenv = "0.15.0" diff --git a/packages/og-injector-rust/src/client.rs b/packages/og-injector-rust/src/client.rs index 5002a12..d74dc0e 100644 --- a/packages/og-injector-rust/src/client.rs +++ b/packages/og-injector-rust/src/client.rs @@ -1,12 +1,9 @@ use std::{env, fmt}; -use std::env::VarError; use std::fmt::Debug; use reqwest; use reqwest::Url; - -use crate::ssl; - +use crate::config; #[derive(Debug, Clone)] pub struct ClientError { msg: String, @@ -19,24 +16,16 @@ impl fmt::Display for ClientError { } pub fn get_client_url() -> Result { - let client_url = match env::var("CLIENT_INDEX_URL") { - Ok(value) => Ok(value), - Err(err) => { - match err { - VarError::NotPresent => Ok("https://localhost:3001/index.html".parse().unwrap()), - VarError::NotUnicode(_) => Err(ClientError { msg: "Unable to read env var SSL_CRT".parse().unwrap() }) - } - } - }?; - - Url::parse(client_url.as_str()) - .map_err(|e| ClientError { msg: e.to_string() }) -} + let client_url = match env::var_os("CLIENT_INDEX_URL") { + Some(value) => value.into_string().unwrap(), + None => "https://localhost:3001/index.html".to_owned(), + }; + Url::parse(&client_url).map_err(|e| ClientError { msg: e.to_string() }) +} pub async fn fetch_index_html() -> Result { - let root_cert = ssl::get_ssl_cert().await - .map_err(|e| ClientError { msg: e.to_string() })?; + let root_cert = config::get_ssl_cert().await; let client = reqwest::ClientBuilder::new() .add_root_certificate(root_cert) @@ -46,10 +35,14 @@ pub async fn fetch_index_html() -> Result { let client_url = get_client_url()?; println!("fetching index from {}", client_url); - let resp = client.get(client_url).send().await + let resp = client + .get(client_url) + .send() + .await .map_err(|e| ClientError { msg: e.to_string() })?; println!("{resp:#?}"); - resp.text().await + resp.text() + .await .map_err(|e| ClientError { msg: e.to_string() }) } diff --git a/packages/og-injector-rust/src/config.rs b/packages/og-injector-rust/src/config.rs new file mode 100644 index 0000000..515fab8 --- /dev/null +++ b/packages/og-injector-rust/src/config.rs @@ -0,0 +1,87 @@ +use std::env; +use std::net::{IpAddr, SocketAddr}; +use std::path::PathBuf; + +use reqwest::Certificate; +use tokio::fs::File; +use tokio::io::AsyncReadExt; + +pub enum FeatureFlag { + Enabled, + Disabled, +} + +fn load_env_str(key: &str) -> Option { + env::var_os(key).map(|value| value.to_str().unwrap_or_default().to_string()) +} + +fn load_env_num(key: &str) -> Option { + load_env_str(key).map(|value| value.parse().unwrap()) +} + +fn load_env_bool(key: &str) -> Option { + load_env_str(key).map(|value| value.parse().unwrap()) +} + +pub fn get_app_host() -> IpAddr { + load_env_str("APP_HOST") + .unwrap_or("0.0.0.0".to_string()) + .parse() + .expect("Unable to parse APP_HOST. Is it a valid IP Address?") +} + +pub fn get_app_port() -> u16 { + load_env_num("APP_PORT") + .unwrap_or(3000) + .try_into() + .expect("Unable to parse APP_PORT. Is it a valid port number?") +} + +pub fn get_app_socket() -> SocketAddr { + SocketAddr::new(get_app_host(), get_app_port()) +} + +pub fn is_https_enabled() -> FeatureFlag { + load_env_bool("HTTPS_ENABLED") + .map(|value| if value { FeatureFlag::Enabled } else { FeatureFlag::Disabled }) + .unwrap_or(FeatureFlag::Enabled) +} + +fn get_default_certs_dir() -> PathBuf { + PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("..") + .join("..") + .canonicalize() + .unwrap() + .join(".certs") +} + +pub fn get_ssl_cert_path() -> PathBuf { + load_env_str("SSL_CRT") + .map(|value| PathBuf::from(value)) + .unwrap_or_else(|| get_default_certs_dir().join("current.crt")) +} + +pub fn get_ssl_key_path() -> PathBuf { + load_env_str("SSL_KEY") + .map(|value| PathBuf::from(value)) + .unwrap_or_else(|| get_default_certs_dir().join("current.crt")) +} + +pub async fn get_ssl_cert() -> Certificate { + let cert_path = get_ssl_cert_path(); + + let path: &str = cert_path.to_str().unwrap(); + + let mut buf = Vec::new(); + File::open(path) + .await + .map_err(|e| panic!("{}", e)) + .unwrap() + .read_to_end(&mut buf) + .await + .map_err(|e| panic!("{}", e)) + .unwrap(); + + Certificate::from_pem(&buf).unwrap() +} diff --git a/packages/og-injector-rust/src/injector_ctrl.rs b/packages/og-injector-rust/src/injector_ctrl.rs new file mode 100644 index 0000000..f5f6a4b --- /dev/null +++ b/packages/og-injector-rust/src/injector_ctrl.rs @@ -0,0 +1,29 @@ +use axum::body::Body; +use axum::http::{header, Request, StatusCode}; +use axum::response::Response; +use axum::Router; +use axum::routing::get; + +use crate::client; + +pub fn router() -> Router { + Router::new().route("/", get(get_index_html)) +} + +pub async fn get_index_html(req: Request) -> Response { + println!("-> GET {}", req.uri()); + + match client::fetch_index_html().await { + Err(error) => Response::builder() + .status(StatusCode::INTERNAL_SERVER_ERROR) + .body(Body::from(error.to_string())) + .unwrap(), + + Ok(index_html) => Response::builder() + .status(StatusCode::OK) + .header(header::CONTENT_TYPE, "text/html") + .header("x-generated-by", "rust") + .body(Body::from(index_html)) + .unwrap(), + } +} diff --git a/packages/og-injector-rust/src/main.rs b/packages/og-injector-rust/src/main.rs index e565327..f8c572e 100644 --- a/packages/og-injector-rust/src/main.rs +++ b/packages/og-injector-rust/src/main.rs @@ -1,80 +1,48 @@ -use std::env; -use std::env::VarError; -use std::net::SocketAddr; - use axum::{http::StatusCode, Router, routing::get}; use axum::body::Body; use axum::http::Request; use axum::response::Response; use axum_server::tls_rustls::RustlsConfig; -use reqwest::header; +use dotenv::dotenv; -mod client; -mod ssl; +use crate::config::FeatureFlag::{Disabled, Enabled}; -fn is_https_enabled() -> bool { - match env::var("HTTPS_ENABLED") { - Ok(value) => value == "true", - Err(err) => { - match err { - VarError::NotPresent => true, - VarError::NotUnicode(_) => panic!("HTTPS_ENABLED was not a unicode value"), - } - } - } -} +mod client; +mod config; +mod injector_ctrl; #[tokio::main] async fn main() { + dotenv().ok(); tracing_subscriber::fmt::init(); - // build our application with a route let app = Router::new() - .route("/", get(get_index_html)) + .merge(injector_ctrl::router()) .fallback(get(get_fallback)); - // run https server - let addr = SocketAddr::from(([0, 0, 0, 0], 3000)); + let addr = config::get_app_socket(); println!("listening on {}", addr); - if is_https_enabled() { - let ssl_cert = ssl::get_ssl_cert_path() - .expect("Unable to read SSL Cert"); - let ssl_key = ssl::get_ssl_key_path() - .expect("Unable to read SSL Key"); - let config = RustlsConfig::from_pem_file(ssl_cert, ssl_key) - .await - .unwrap(); - axum_server::bind_rustls(addr, config) - .serve(app.into_make_service()) - .await - .unwrap(); - } else { - axum_server::bind(addr) - .serve(app.into_make_service()) - .await - .unwrap(); - }; -} + match config::is_https_enabled() { + Enabled => { + let ssl_cert = config::get_ssl_cert_path(); + let ssl_key = config::get_ssl_key_path(); -async fn get_index_html(req: Request) -> Response { - println!("-> GET {}", req.uri()); + let config = RustlsConfig::from_pem_file(ssl_cert, ssl_key) + .await + .unwrap(); - return match client::fetch_index_html().await { - Err(error) => { - Response::builder() - .status(StatusCode::INTERNAL_SERVER_ERROR) - .body(Body::from(error.to_string())) - .unwrap() + axum_server::bind_rustls(addr, config) + .serve(app.into_make_service()) + .await + .unwrap(); } - Ok(index_html) => { - Response::builder() - .status(StatusCode::OK) - .header(header::CONTENT_TYPE, "text/html") - .header("x-generated-by", "rust") - .body(Body::from(index_html)) - .unwrap() + Disabled => { + axum_server::bind(addr) + .serve(app.into_make_service()) + .await + .unwrap(); } }; } diff --git a/packages/og-injector-rust/src/ssl.rs b/packages/og-injector-rust/src/ssl.rs deleted file mode 100644 index fe12cbe..0000000 --- a/packages/og-injector-rust/src/ssl.rs +++ /dev/null @@ -1,70 +0,0 @@ -use std::{env, fmt}; -use std::env::VarError; -use std::path::PathBuf; - -use reqwest::Certificate; -use tokio::fs::File; -use tokio::io::AsyncReadExt; - -type Result = std::result::Result; - -#[derive(Debug, Clone)] -pub struct SslError { - msg: String, -} - -impl fmt::Display for SslError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.msg) - } -} - -fn get_default_certs_dir() -> PathBuf { - PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .join("..") - .join("..") - .canonicalize() - .expect("Unable to build path to root dir") - .join(".certs") -} - -pub fn get_ssl_cert_path() -> Result { - match env::var("SSL_CRT") { - Ok(value) => Ok(PathBuf::from(value)), - Err(err) => { - match err { - VarError::NotPresent => Ok(get_default_certs_dir().join("current.crt")), - VarError::NotUnicode(_) => Err(SslError { msg: "Unable to read env var SSL_CRT".parse().unwrap() }) - } - } - } -} - -pub fn get_ssl_key_path() -> Result { - match env::var("SSL_KEY") { - Ok(value) => Ok(PathBuf::from(value)), - Err(err) => { - match err { - VarError::NotPresent => Ok(get_default_certs_dir().join("current.key")), - VarError::NotUnicode(_) => Err(SslError { msg: "Unable to read env var SSL_CRT".parse().unwrap() }) - } - } - } -} - -pub async fn get_ssl_cert() -> Result { - let cert_path = get_ssl_cert_path()?; - - let path: &str = cert_path - .to_str() - .ok_or(SslError { msg: "Expected to find a path".parse().unwrap() })?; - - let mut buf = Vec::new(); - File::open(path).await - .map_err(|e| SslError { msg: e.to_string() })? - .read_to_end(&mut buf).await - .map_err(|e| SslError { msg: e.to_string() })?; - - Certificate::from_pem(&buf) - .map_err(|e| SslError { msg: e.to_string() }) -} From 75afa6f8b7e064099d3a7672d6ec983e2de8cb4a Mon Sep 17 00:00:00 2001 From: Zeragamba Date: Sat, 6 Jul 2024 15:40:42 -0400 Subject: [PATCH 04/24] load index.html from disk --- packages/og-injector-rust/.dockerignore | 1 + packages/og-injector-rust/.gitignore | 1 + packages/og-injector-rust/Cargo.lock | 546 +----------------------- packages/og-injector-rust/Cargo.toml | 1 - packages/og-injector-rust/src/client.rs | 39 +- packages/og-injector-rust/src/config.rs | 103 +++-- packages/og-injector-rust/src/main.rs | 10 +- 7 files changed, 80 insertions(+), 621 deletions(-) diff --git a/packages/og-injector-rust/.dockerignore b/packages/og-injector-rust/.dockerignore index 96ef862..b1661f4 100644 --- a/packages/og-injector-rust/.dockerignore +++ b/packages/og-injector-rust/.dockerignore @@ -1,2 +1,3 @@ target/ .idea/ +.env \ No newline at end of file diff --git a/packages/og-injector-rust/.gitignore b/packages/og-injector-rust/.gitignore index 2f7896d..16dbbb8 100644 --- a/packages/og-injector-rust/.gitignore +++ b/packages/og-injector-rust/.gitignore @@ -1 +1,2 @@ target/ +client/ diff --git a/packages/og-injector-rust/Cargo.lock b/packages/og-injector-rust/Cargo.lock index 939ad60..59829c4 100644 --- a/packages/og-injector-rust/Cargo.lock +++ b/packages/og-injector-rust/Cargo.lock @@ -116,10 +116,10 @@ dependencies = [ "hyper", "hyper-util", "pin-project-lite", - "rustls 0.21.12", + "rustls", "rustls-pemfile", "tokio", - "tokio-rustls 0.24.1", + "tokio-rustls", "tower", "tower-service", ] @@ -145,24 +145,6 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bumpalo" -version = "3.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" - [[package]] name = "bytes" version = "1.6.0" @@ -181,80 +163,24 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" - [[package]] name = "dotenv" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - [[package]] name = "equivalent" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -415,40 +341,6 @@ dependencies = [ "pin-project-lite", "smallvec", "tokio", - "want", -] - -[[package]] -name = "hyper-rustls" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155" -dependencies = [ - "futures-util", - "http", - "hyper", - "hyper-util", - "rustls 0.23.10", - "rustls-pki-types", - "tokio", - "tokio-rustls 0.26.0", - "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", ] [[package]] @@ -458,27 +350,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b875924a60b96e5d7b9ae7b066540b1dd1cbd90d1828f54c92e02a283351c56" dependencies = [ "bytes", - "futures-channel", "futures-util", "http", "http-body", "hyper", "pin-project-lite", - "socket2", "tokio", - "tower", - "tower-service", - "tracing", -] - -[[package]] -name = "idna" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" -dependencies = [ - "unicode-bidi", - "unicode-normalization", ] [[package]] @@ -491,27 +368,12 @@ dependencies = [ "hashbrown", ] -[[package]] -name = "ipnet" -version = "2.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" - [[package]] name = "itoa" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" -[[package]] -name = "js-sys" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" -dependencies = [ - "wasm-bindgen", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -524,12 +386,6 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "log" version = "0.4.21" @@ -574,23 +430,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -627,7 +466,6 @@ dependencies = [ "axum", "axum-server", "dotenv", - "reqwest", "tokio", "tracing", "tracing-subscriber", @@ -639,50 +477,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "openssl" -version = "0.10.64" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" -dependencies = [ - "bitflags 2.5.0", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.102" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "overload" version = "0.1.1" @@ -727,12 +521,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" - [[package]] name = "proc-macro2" version = "1.0.85" @@ -751,49 +539,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "reqwest" -version = "0.12.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d6d2a27d57148378eb5e111173f4276ad26340ecc5c49a4a2152167a2d6a37" -dependencies = [ - "base64", - "bytes", - "encoding_rs", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "http-body-util", - "hyper", - "hyper-rustls", - "hyper-tls", - "hyper-util", - "ipnet", - "js-sys", - "log", - "mime", - "native-tls", - "once_cell", - "percent-encoding", - "pin-project-lite", - "rustls-pemfile", - "serde", - "serde_json", - "serde_urlencoded", - "sync_wrapper 1.0.1", - "system-configuration", - "tokio", - "tokio-native-tls", - "tower-service", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "winreg", -] - [[package]] name = "ring" version = "0.17.8" @@ -815,19 +560,6 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "rustix" -version = "0.38.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags 2.5.0", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] - [[package]] name = "rustls" version = "0.21.12" @@ -836,23 +568,10 @@ checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ "log", "ring", - "rustls-webpki 0.101.7", + "rustls-webpki", "sct", ] -[[package]] -name = "rustls" -version = "0.23.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05cff451f60db80f490f3c182b77c35260baace73209e9cdbbe526bfe3a4d402" -dependencies = [ - "once_cell", - "rustls-pki-types", - "rustls-webpki 0.102.4", - "subtle", - "zeroize", -] - [[package]] name = "rustls-pemfile" version = "2.1.2" @@ -879,17 +598,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "rustls-webpki" -version = "0.102.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e" -dependencies = [ - "ring", - "rustls-pki-types", - "untrusted", -] - [[package]] name = "rustversion" version = "1.0.17" @@ -902,15 +610,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" -dependencies = [ - "windows-sys 0.52.0", -] - [[package]] name = "sct" version = "0.7.1" @@ -921,29 +620,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "security-framework" -version = "2.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" -dependencies = [ - "bitflags 2.5.0", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "serde" version = "1.0.203" @@ -1037,12 +713,6 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.66" @@ -1066,39 +736,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" -[[package]] -name = "system-configuration" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "tempfile" -version = "3.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" -dependencies = [ - "cfg-if", - "fastrand", - "rustix", - "windows-sys 0.52.0", -] - [[package]] name = "thread_local" version = "1.1.8" @@ -1109,21 +746,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "tinyvec" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - [[package]] name = "tokio" version = "1.38.0" @@ -1152,34 +774,13 @@ dependencies = [ "syn", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ - "rustls 0.21.12", - "tokio", -] - -[[package]] -name = "tokio-rustls" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" -dependencies = [ - "rustls 0.23.10", - "rustls-pki-types", + "rustls", "tokio", ] @@ -1282,153 +883,30 @@ dependencies = [ "tracing-log", ] -[[package]] -name = "try-lock" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" - -[[package]] -name = "unicode-bidi" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" - [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" -[[package]] -name = "unicode-normalization" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" -dependencies = [ - "tinyvec", -] - [[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.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", -] - [[package]] name = "valuable" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - -[[package]] -name = "want" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" -dependencies = [ - "try-lock", -] - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" -[[package]] -name = "wasm-bindgen" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" -dependencies = [ - "bumpalo", - "log", - "once_cell", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" - -[[package]] -name = "web-sys" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - [[package]] name = "winapi" version = "0.3.9" @@ -1589,19 +1067,3 @@ name = "windows_x86_64_msvc" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" - -[[package]] -name = "winreg" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" -dependencies = [ - "cfg-if", - "windows-sys 0.48.0", -] - -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/packages/og-injector-rust/Cargo.toml b/packages/og-injector-rust/Cargo.toml index bb2075c..34530d4 100644 --- a/packages/og-injector-rust/Cargo.toml +++ b/packages/og-injector-rust/Cargo.toml @@ -9,5 +9,4 @@ axum-server = { version = "0.6", features = ["tls-rustls"] } tracing-subscriber = "0.3.18" tokio = { version = "1.38.0", features = ["rt-multi-thread"] } tracing = "0.1.40" -reqwest = { version = "0.12.5", features = ["json"] } dotenv = "0.15.0" diff --git a/packages/og-injector-rust/src/client.rs b/packages/og-injector-rust/src/client.rs index d74dc0e..2a45804 100644 --- a/packages/og-injector-rust/src/client.rs +++ b/packages/og-injector-rust/src/client.rs @@ -1,9 +1,10 @@ -use std::{env, fmt}; +use std::fmt; use std::fmt::Debug; +use std::fs::File; +use std::io::Read; -use reqwest; -use reqwest::Url; use crate::config; + #[derive(Debug, Clone)] pub struct ClientError { msg: String, @@ -15,34 +16,14 @@ impl fmt::Display for ClientError { } } -pub fn get_client_url() -> Result { - let client_url = match env::var_os("CLIENT_INDEX_URL") { - Some(value) => value.into_string().unwrap(), - None => "https://localhost:3001/index.html".to_owned(), - }; - - Url::parse(&client_url).map_err(|e| ClientError { msg: e.to_string() }) -} - pub async fn fetch_index_html() -> Result { - let root_cert = config::get_ssl_cert().await; - - let client = reqwest::ClientBuilder::new() - .add_root_certificate(root_cert) - .danger_accept_invalid_certs(true) - .build() - .map_err(|e| ClientError { msg: e.to_string() })?; + let index_file = config::client_dir().join("index.html"); - let client_url = get_client_url()?; - println!("fetching index from {}", client_url); - let resp = client - .get(client_url) - .send() - .await + let mut buf = String::new(); + File::open(index_file) + .map_err(|e| ClientError { msg: e.to_string() })? + .read_to_string(&mut buf) .map_err(|e| ClientError { msg: e.to_string() })?; - println!("{resp:#?}"); - resp.text() - .await - .map_err(|e| ClientError { msg: e.to_string() }) + Ok(buf) } diff --git a/packages/og-injector-rust/src/config.rs b/packages/og-injector-rust/src/config.rs index 515fab8..656764b 100644 --- a/packages/og-injector-rust/src/config.rs +++ b/packages/og-injector-rust/src/config.rs @@ -2,10 +2,6 @@ use std::env; use std::net::{IpAddr, SocketAddr}; use std::path::PathBuf; -use reqwest::Certificate; -use tokio::fs::File; -use tokio::io::AsyncReadExt; - pub enum FeatureFlag { Enabled, Disabled, @@ -23,65 +19,82 @@ fn load_env_bool(key: &str) -> Option { load_env_str(key).map(|value| value.parse().unwrap()) } -pub fn get_app_host() -> IpAddr { - load_env_str("APP_HOST") - .unwrap_or("0.0.0.0".to_string()) - .parse() - .expect("Unable to parse APP_HOST. Is it a valid IP Address?") +fn load_env_path(key: &str) -> Option { + load_env_str(key).map(|value| { + PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join(value) + .canonicalize() + .unwrap() + }) +} + +pub fn get_injector_host() -> IpAddr { + let addr = load_env_str("INJECTOR_HOST").unwrap_or("0.0.0.0".to_string()); + + println!("INJECTOR_HOST: {}", addr); + + match addr.parse() { + Ok(addr) => addr, + Err(e) => panic!("{}", e), + } } pub fn get_app_port() -> u16 { - load_env_num("APP_PORT") - .unwrap_or(3000) - .try_into() - .expect("Unable to parse APP_PORT. Is it a valid port number?") + let port = load_env_num("INJECTOR_PORT") + .unwrap_or(3000); + + println!("INJECTOR_PORT: {}", port); + + match port.try_into() { + Ok(addr) => addr, + Err(_) => panic!("Unable to parse APP_PORT. Is it a valid port number?"), + } } pub fn get_app_socket() -> SocketAddr { - SocketAddr::new(get_app_host(), get_app_port()) + SocketAddr::new(get_injector_host(), get_app_port()) } pub fn is_https_enabled() -> FeatureFlag { load_env_bool("HTTPS_ENABLED") - .map(|value| if value { FeatureFlag::Enabled } else { FeatureFlag::Disabled }) - .unwrap_or(FeatureFlag::Enabled) + .map(|value| { + if value { + FeatureFlag::Enabled + } else { + FeatureFlag::Disabled + } + }) + .unwrap_or(FeatureFlag::Disabled) } -fn get_default_certs_dir() -> PathBuf { - PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .join("..") - .join("..") - .canonicalize() - .unwrap() - .join(".certs") +pub fn get_certs_dir() -> PathBuf { + load_env_path("CERTS_DIR").unwrap_or_else(|| { + PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("../../.certs") + .canonicalize() + .unwrap() + .join(".certs") + }) } pub fn get_ssl_cert_path() -> PathBuf { - load_env_str("SSL_CRT") - .map(|value| PathBuf::from(value)) - .unwrap_or_else(|| get_default_certs_dir().join("current.crt")) + load_env_path("SSL_CRT").unwrap_or_else(|| get_certs_dir().join("current.crt")) } pub fn get_ssl_key_path() -> PathBuf { - load_env_str("SSL_KEY") - .map(|value| PathBuf::from(value)) - .unwrap_or_else(|| get_default_certs_dir().join("current.crt")) + load_env_path("SSL_KEY").unwrap_or_else(|| get_certs_dir().join("current.crt")) } -pub async fn get_ssl_cert() -> Certificate { - let cert_path = get_ssl_cert_path(); - - let path: &str = cert_path.to_str().unwrap(); - - let mut buf = Vec::new(); - File::open(path) - .await - .map_err(|e| panic!("{}", e)) - .unwrap() - .read_to_end(&mut buf) - .await - .map_err(|e| panic!("{}", e)) - .unwrap(); - - Certificate::from_pem(&buf).unwrap() +pub fn client_dir() -> PathBuf { + load_env_path("CLIENT_DIR") + .expect("The environment variable 'CLIENT_DIR' should be set in '.env'") } + +// pub fn client_url() -> Result { +// let client_url = match env::var_os("CLIENT_INDEX_URL") { +// Some(value) => value.into_string().unwrap(), +// None => "https://localhost:3001/index.html".to_owned(), +// }; +// +// Url::parse(&client_url).map_err(|e| ClientError { msg: e.to_string() }) +// } diff --git a/packages/og-injector-rust/src/main.rs b/packages/og-injector-rust/src/main.rs index f8c572e..84d7027 100644 --- a/packages/og-injector-rust/src/main.rs +++ b/packages/og-injector-rust/src/main.rs @@ -21,7 +21,6 @@ async fn main() { .fallback(get(get_fallback)); let addr = config::get_app_socket(); - println!("listening on {}", addr); match config::is_https_enabled() { Enabled => { @@ -32,6 +31,7 @@ async fn main() { .await .unwrap(); + println!("listening on https://{}", addr); axum_server::bind_rustls(addr, config) .serve(app.into_make_service()) .await @@ -39,6 +39,7 @@ async fn main() { } Disabled => { + println!("listening on http://{}", addr); axum_server::bind(addr) .serve(app.into_make_service()) .await @@ -48,10 +49,11 @@ async fn main() { } async fn get_fallback(req: Request) -> Response { - println!("-> GET {}", req.uri()); + let uri = req.uri(); + println!("-> GET {}", uri); Response::builder() - .status(StatusCode::INTERNAL_SERVER_ERROR) - .body(Body::from("Unexpected request")) + .status(StatusCode::NOT_FOUND) + .body(Body::from("Not Found")) .unwrap() } From 97185faf114c47b0024a1d3ec8340ba1da3afaa8 Mon Sep 17 00:00:00 2001 From: Zeragamba Date: Sat, 6 Jul 2024 19:59:33 -0400 Subject: [PATCH 05/24] move files into modules --- .../inspectionProfiles/Project_Default.xml | 1 + packages/og-injector-rust/Cargo.lock | 10 +- packages/og-injector-rust/Cargo.toml | 2 + packages/og-injector-rust/src/client.rs | 29 ------ packages/og-injector-rust/src/config.rs | 37 ++------ .../og-injector-rust/src/injector/injector.rs | 95 +++++++++++++++++++ .../src/injector/injector_error.rs | 18 ++++ packages/og-injector-rust/src/injector/mod.rs | 5 + .../og-injector-rust/src/injector_ctrl.rs | 29 ------ packages/og-injector-rust/src/main.rs | 35 +++++-- .../og-injector-rust/src/open_graph/mod.rs | 5 + .../src/open_graph/open_graph_data.rs | 82 ++++++++++++++++ .../src/open_graph/open_graph_image_data.rs | 16 ++++ 13 files changed, 269 insertions(+), 95 deletions(-) delete mode 100644 packages/og-injector-rust/src/client.rs create mode 100644 packages/og-injector-rust/src/injector/injector.rs create mode 100644 packages/og-injector-rust/src/injector/injector_error.rs create mode 100644 packages/og-injector-rust/src/injector/mod.rs delete mode 100644 packages/og-injector-rust/src/injector_ctrl.rs create mode 100644 packages/og-injector-rust/src/open_graph/mod.rs create mode 100644 packages/og-injector-rust/src/open_graph/open_graph_data.rs create mode 100644 packages/og-injector-rust/src/open_graph/open_graph_image_data.rs diff --git a/packages/og-injector-rust/.idea/inspectionProfiles/Project_Default.xml b/packages/og-injector-rust/.idea/inspectionProfiles/Project_Default.xml index 8dd3b21..52bec63 100644 --- a/packages/og-injector-rust/.idea/inspectionProfiles/Project_Default.xml +++ b/packages/og-injector-rust/.idea/inspectionProfiles/Project_Default.xml @@ -74,5 +74,6 @@ + \ No newline at end of file diff --git a/packages/og-injector-rust/Cargo.lock b/packages/og-injector-rust/Cargo.lock index 59829c4..f6e22ea 100644 --- a/packages/og-injector-rust/Cargo.lock +++ b/packages/og-injector-rust/Cargo.lock @@ -466,6 +466,8 @@ dependencies = [ "axum", "axum-server", "dotenv", + "serde", + "serde_json", "tokio", "tracing", "tracing-subscriber", @@ -622,18 +624,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.203" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" +checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.203" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" +checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", diff --git a/packages/og-injector-rust/Cargo.toml b/packages/og-injector-rust/Cargo.toml index 34530d4..513841d 100644 --- a/packages/og-injector-rust/Cargo.toml +++ b/packages/og-injector-rust/Cargo.toml @@ -10,3 +10,5 @@ tracing-subscriber = "0.3.18" tokio = { version = "1.38.0", features = ["rt-multi-thread"] } tracing = "0.1.40" dotenv = "0.15.0" +serde_json = "1.0" +serde = { version = "1.0.204", features = ["derive"] } diff --git a/packages/og-injector-rust/src/client.rs b/packages/og-injector-rust/src/client.rs deleted file mode 100644 index 2a45804..0000000 --- a/packages/og-injector-rust/src/client.rs +++ /dev/null @@ -1,29 +0,0 @@ -use std::fmt; -use std::fmt::Debug; -use std::fs::File; -use std::io::Read; - -use crate::config; - -#[derive(Debug, Clone)] -pub struct ClientError { - msg: String, -} - -impl fmt::Display for ClientError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.msg) - } -} - -pub async fn fetch_index_html() -> Result { - let index_file = config::client_dir().join("index.html"); - - let mut buf = String::new(); - File::open(index_file) - .map_err(|e| ClientError { msg: e.to_string() })? - .read_to_string(&mut buf) - .map_err(|e| ClientError { msg: e.to_string() })?; - - Ok(buf) -} diff --git a/packages/og-injector-rust/src/config.rs b/packages/og-injector-rust/src/config.rs index 656764b..1f66e8b 100644 --- a/packages/og-injector-rust/src/config.rs +++ b/packages/og-injector-rust/src/config.rs @@ -39,9 +39,8 @@ pub fn get_injector_host() -> IpAddr { } } -pub fn get_app_port() -> u16 { - let port = load_env_num("INJECTOR_PORT") - .unwrap_or(3000); +pub fn get_injector_port() -> u16 { + let port = load_env_num("INJECTOR_PORT").unwrap_or(3000); println!("INJECTOR_PORT: {}", port); @@ -51,8 +50,8 @@ pub fn get_app_port() -> u16 { } } -pub fn get_app_socket() -> SocketAddr { - SocketAddr::new(get_injector_host(), get_app_port()) +pub fn get_injector_socket() -> SocketAddr { + SocketAddr::new(get_injector_host(), get_injector_port()) } pub fn is_https_enabled() -> FeatureFlag { @@ -67,34 +66,18 @@ pub fn is_https_enabled() -> FeatureFlag { .unwrap_or(FeatureFlag::Disabled) } -pub fn get_certs_dir() -> PathBuf { - load_env_path("CERTS_DIR").unwrap_or_else(|| { - PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .join("../../.certs") - .canonicalize() - .unwrap() - .join(".certs") - }) -} - pub fn get_ssl_cert_path() -> PathBuf { - load_env_path("SSL_CRT").unwrap_or_else(|| get_certs_dir().join("current.crt")) + load_env_path("SSL_CRT").expect("The environment variable 'SSL_CRT' should be set") } pub fn get_ssl_key_path() -> PathBuf { - load_env_path("SSL_KEY").unwrap_or_else(|| get_certs_dir().join("current.crt")) + load_env_path("SSL_KEY").expect("The environment variable 'SSL_KEY' should be set") } pub fn client_dir() -> PathBuf { - load_env_path("CLIENT_DIR") - .expect("The environment variable 'CLIENT_DIR' should be set in '.env'") + load_env_path("CLIENT_DIR").expect("The environment variable 'CLIENT_DIR' should be set") } -// pub fn client_url() -> Result { -// let client_url = match env::var_os("CLIENT_INDEX_URL") { -// Some(value) => value.into_string().unwrap(), -// None => "https://localhost:3001/index.html".to_owned(), -// }; -// -// Url::parse(&client_url).map_err(|e| ClientError { msg: e.to_string() }) -// } +pub fn app_url() -> String { + load_env_str("APP_URL").expect("The environment variable 'APP_URL' should be set") +} diff --git a/packages/og-injector-rust/src/injector/injector.rs b/packages/og-injector-rust/src/injector/injector.rs new file mode 100644 index 0000000..a9bdf58 --- /dev/null +++ b/packages/og-injector-rust/src/injector/injector.rs @@ -0,0 +1,95 @@ +use crate::client::{ClientFiles, ClientManifest}; +use crate::injector::InjectorError; +use crate::injector::InjectorError::{HeadNotFoundError, IndexReadError, ManifestReadError}; +use crate::open_graph::OpenGraphData; + +pub type Result = std::result::Result; + +pub async fn inject_meta(meta: &OpenGraphData) -> Result { + println!("Injecting OG Data: {}", meta); + + let html = ClientFiles::index_html() + .await + .map_err(|e| IndexReadError { msg: e.to_string() })?; + + if !html.contains("") { + return Err(HeadNotFoundError); + }; + + let app_manifest = ClientManifest::load() + .await + .map_err(|e| ManifestReadError { msg: e.to_string() })?; + + let mut meta_tags = MetaTags::new(); + meta_tags.add("og:type", meta.og_type.as_deref().unwrap_or("website")); + + let title = meta + .title + .as_deref() + .or(app_manifest.name.as_deref()) + .map(str::trim); + meta_tags.add_optional("og:title", title); + meta_tags.add_optional("twitter:title", title); + + let url = meta + .url + .as_deref() + .or(app_manifest.start_url.as_deref()) + .map(str::trim); + meta_tags.add_optional("og:url", url); + meta_tags.add_optional("twitter:url", url); + + let description = meta + .description + .as_deref() + .or(app_manifest.description.as_deref()) + .map(str::trim); + meta_tags.add_optional("og:description", description); + meta_tags.add_optional("twitter:description", description); + + match &meta.image { + Some(image_meta) => { + meta_tags.add("twitter:card", "summary_large_image"); + meta_tags.add("og:image", &image_meta.url); + meta_tags.add("og:image:type", &image_meta.mime_type); + meta_tags.add("og:image:height", &image_meta.height); + meta_tags.add("og:image:width", &image_meta.width); + meta_tags.add("twitter:image", &image_meta.url); + } + None => meta_tags.add("twitter:card", "summary"), + }; + + let replacement = format!("{}", meta_tags.to_string()); + let html = html.replace("", &replacement); + + Ok(html) +} + +struct MetaTags { + tags: Vec, +} + +impl MetaTags { + fn new() -> MetaTags { + MetaTags { tags: vec![] } + } + + fn create_meta_tag(&self, name: &str, content: &str) -> String { + format!("") + } + + fn add_optional(&mut self, name: &str, content: Option<&str>) { + if content.is_some() { + let tag = self.create_meta_tag(name, content.unwrap()); + self.tags.push(tag); + } + } + + fn add(&mut self, name: &str, content: &str) { + self.add_optional(name, Some(content)) + } + + fn to_string(&self) -> String { + self.tags.join("") + } +} diff --git a/packages/og-injector-rust/src/injector/injector_error.rs b/packages/og-injector-rust/src/injector/injector_error.rs new file mode 100644 index 0000000..0f7484e --- /dev/null +++ b/packages/og-injector-rust/src/injector/injector_error.rs @@ -0,0 +1,18 @@ +use std::fmt; +use std::fmt::Formatter; + +pub enum InjectorError { + HeadNotFoundError, + IndexReadError { + msg: String + }, + ManifestReadError { + msg: String + }, +} + +impl fmt::Display for InjectorError { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + write!(f, "{}", self) + } +} diff --git a/packages/og-injector-rust/src/injector/mod.rs b/packages/og-injector-rust/src/injector/mod.rs new file mode 100644 index 0000000..1945c5f --- /dev/null +++ b/packages/og-injector-rust/src/injector/mod.rs @@ -0,0 +1,5 @@ +mod injector_error; +mod injector; + +pub use injector::inject_meta; +pub use injector_error::InjectorError; diff --git a/packages/og-injector-rust/src/injector_ctrl.rs b/packages/og-injector-rust/src/injector_ctrl.rs deleted file mode 100644 index f5f6a4b..0000000 --- a/packages/og-injector-rust/src/injector_ctrl.rs +++ /dev/null @@ -1,29 +0,0 @@ -use axum::body::Body; -use axum::http::{header, Request, StatusCode}; -use axum::response::Response; -use axum::Router; -use axum::routing::get; - -use crate::client; - -pub fn router() -> Router { - Router::new().route("/", get(get_index_html)) -} - -pub async fn get_index_html(req: Request) -> Response { - println!("-> GET {}", req.uri()); - - match client::fetch_index_html().await { - Err(error) => Response::builder() - .status(StatusCode::INTERNAL_SERVER_ERROR) - .body(Body::from(error.to_string())) - .unwrap(), - - Ok(index_html) => Response::builder() - .status(StatusCode::OK) - .header(header::CONTENT_TYPE, "text/html") - .header("x-generated-by", "rust") - .body(Body::from(index_html)) - .unwrap(), - } -} diff --git a/packages/og-injector-rust/src/main.rs b/packages/og-injector-rust/src/main.rs index 84d7027..c53b295 100644 --- a/packages/og-injector-rust/src/main.rs +++ b/packages/og-injector-rust/src/main.rs @@ -1,26 +1,29 @@ use axum::{http::StatusCode, Router, routing::get}; use axum::body::Body; -use axum::http::Request; +use axum::http::{header, Request}; use axum::response::Response; use axum_server::tls_rustls::RustlsConfig; use dotenv::dotenv; -use crate::config::FeatureFlag::{Disabled, Enabled}; +use config::FeatureFlag::{Disabled, Enabled}; +use injector::inject_meta; +use open_graph::OpenGraphData; mod client; mod config; -mod injector_ctrl; +mod injector; +mod open_graph; #[tokio::main] async fn main() { - dotenv().ok(); tracing_subscriber::fmt::init(); + dotenv().ok(); let app = Router::new() - .merge(injector_ctrl::router()) + .route("/", get(get_index_html)) .fallback(get(get_fallback)); - let addr = config::get_app_socket(); + let addr = config::get_injector_socket(); match config::is_https_enabled() { Enabled => { @@ -48,6 +51,26 @@ async fn main() { }; } +async fn get_index_html(req: Request) -> Response { + println!("-> GET {}", req.uri()); + + let meta_data = OpenGraphData::builder().build(); + + match inject_meta(&meta_data).await { + Err(error) => Response::builder() + .status(StatusCode::INTERNAL_SERVER_ERROR) + .body(Body::from(error.to_string())) + .unwrap(), + + Ok(body) => Response::builder() + .status(StatusCode::OK) + .header(header::CONTENT_TYPE, "text/html") + .header("x-generated-by", "rust") + .body(Body::from(body)) + .unwrap(), + } +} + async fn get_fallback(req: Request) -> Response { let uri = req.uri(); println!("-> GET {}", uri); diff --git a/packages/og-injector-rust/src/open_graph/mod.rs b/packages/og-injector-rust/src/open_graph/mod.rs new file mode 100644 index 0000000..0e728c6 --- /dev/null +++ b/packages/og-injector-rust/src/open_graph/mod.rs @@ -0,0 +1,5 @@ +pub mod open_graph_data; +pub mod open_graph_image_data; + +pub use open_graph_image_data::OpenGraphImageData; +pub use open_graph_data::OpenGraphData; \ No newline at end of file diff --git a/packages/og-injector-rust/src/open_graph/open_graph_data.rs b/packages/og-injector-rust/src/open_graph/open_graph_data.rs new file mode 100644 index 0000000..044fec7 --- /dev/null +++ b/packages/og-injector-rust/src/open_graph/open_graph_data.rs @@ -0,0 +1,82 @@ +use std::fmt; +use std::fmt::Formatter; + +use crate::config; +use crate::open_graph::OpenGraphImageData; + +#[derive(Debug)] +pub struct OpenGraphData { + pub og_type: Option, + pub title: Option, + pub description: Option, + pub url: Option, + pub image: Option, +} + +impl fmt::Display for OpenGraphData { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + write!(f, "{:#?}", self) + } +} + +impl OpenGraphData { + pub fn builder() -> OpenGraphDataBuilder { + OpenGraphDataBuilder::new() + } +} + +#[derive(Default)] +pub struct OpenGraphDataBuilder { + og_type: Option, + title: Option, + description: Option, + url: Option, + image: Option, +} + +impl OpenGraphDataBuilder { + pub fn new() -> OpenGraphDataBuilder { + OpenGraphDataBuilder { + og_type: None, + title: None, + description: None, + url: Some(config::app_url()), + image: None, + } + } + + pub fn title(mut self, title: &str) -> OpenGraphDataBuilder { + self.title = Some(title.to_string()); + self + } + + pub fn og_type(mut self, og_type: &str) -> OpenGraphDataBuilder { + self.og_type = Some(og_type.to_string()); + self + } + + pub fn description(mut self, description: &str) -> OpenGraphDataBuilder { + self.description = Some(description.to_string()); + self + } + + pub fn url(mut self, url: &str) -> OpenGraphDataBuilder { + self.url = Some(url.to_string()); + self + } + + pub fn image(mut self, image: OpenGraphImageData) -> OpenGraphDataBuilder { + self.image = Some(image); + self + } + + pub fn build(self) -> OpenGraphData { + OpenGraphData { + og_type: self.og_type, + title: self.title, + description: self.description, + url: self.url, + image: self.image, + } + } +} diff --git a/packages/og-injector-rust/src/open_graph/open_graph_image_data.rs b/packages/og-injector-rust/src/open_graph/open_graph_image_data.rs new file mode 100644 index 0000000..660b4c6 --- /dev/null +++ b/packages/og-injector-rust/src/open_graph/open_graph_image_data.rs @@ -0,0 +1,16 @@ +use std::fmt; +use std::fmt::Formatter; + +#[derive(Default, Debug)] +pub struct OpenGraphImageData { + pub url: String, + pub mime_type: String, + pub height: String, + pub width: String, +} + +impl fmt::Display for OpenGraphImageData { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + write!(f, "{}", self) + } +} From ef2fab118d2c0ec3f5e0cc9ae5911269f9803a9a Mon Sep 17 00:00:00 2001 From: Zeragamba Date: Sat, 6 Jul 2024 22:19:31 -0400 Subject: [PATCH 06/24] clean up config --- packages/og-injector-rust/.gitignore | 1 - .../inspectionProfiles/Project_Default.xml | 1 + packages/og-injector-rust/Cargo.lock | 546 +++++++++++++++++- packages/og-injector-rust/Cargo.toml | 1 + .../src/client/client_config.rs | 28 + .../src/client/client_error.rs | 12 + .../src/client/client_files.rs | 31 + .../src/client/client_manifest.rs | 21 + packages/og-injector-rust/src/client/mod.rs | 11 + packages/og-injector-rust/src/config.rs | 84 +-- .../og-injector-rust/src/injector/injector.rs | 8 +- .../src/injector/injector_config.rs | 50 ++ .../src/injector/injector_error.rs | 14 +- packages/og-injector-rust/src/injector/mod.rs | 10 +- packages/og-injector-rust/src/main.rs | 28 +- .../src/open_graph/open_graph_data.rs | 10 +- packages/og-injector-rust/src/server/mod.rs | 8 + .../og-injector-rust/src/server/server_api.rs | 25 + .../src/server/server_config.rs | 58 ++ .../src/server/server_error.rs | 27 + 20 files changed, 874 insertions(+), 100 deletions(-) create mode 100644 packages/og-injector-rust/src/client/client_config.rs create mode 100644 packages/og-injector-rust/src/client/client_error.rs create mode 100644 packages/og-injector-rust/src/client/client_files.rs create mode 100644 packages/og-injector-rust/src/client/client_manifest.rs create mode 100644 packages/og-injector-rust/src/client/mod.rs create mode 100644 packages/og-injector-rust/src/injector/injector_config.rs create mode 100644 packages/og-injector-rust/src/server/mod.rs create mode 100644 packages/og-injector-rust/src/server/server_api.rs create mode 100644 packages/og-injector-rust/src/server/server_config.rs create mode 100644 packages/og-injector-rust/src/server/server_error.rs diff --git a/packages/og-injector-rust/.gitignore b/packages/og-injector-rust/.gitignore index 16dbbb8..2f7896d 100644 --- a/packages/og-injector-rust/.gitignore +++ b/packages/og-injector-rust/.gitignore @@ -1,2 +1 @@ target/ -client/ diff --git a/packages/og-injector-rust/.idea/inspectionProfiles/Project_Default.xml b/packages/og-injector-rust/.idea/inspectionProfiles/Project_Default.xml index 52bec63..fcc81f3 100644 --- a/packages/og-injector-rust/.idea/inspectionProfiles/Project_Default.xml +++ b/packages/og-injector-rust/.idea/inspectionProfiles/Project_Default.xml @@ -39,6 +39,7 @@ +