From c7c58a3855f9b44cfdd3c0cb78ee58636c98d8f8 Mon Sep 17 00:00:00 2001 From: Michael <12646562+mbround18@users.noreply.github.com> Date: Mon, 29 Apr 2024 09:52:52 -0700 Subject: [PATCH] 781 rework api logic (#811) --- Cargo.lock | 488 +++++++++++++----- Dockerfile.odin | 2 + Makefile | 7 +- README.md | 2 + src/odin/Cargo.toml | 7 +- src/odin/commands/status.rs | 5 +- src/odin/mods/mod.rs | 8 +- .../notifications/enums/notification_event.rs | 9 +- src/odin/utils/fetch_public_ip_address.rs | 203 +++++++- test.sh | 11 - 10 files changed, 558 insertions(+), 184 deletions(-) delete mode 100644 test.sh diff --git a/Cargo.lock b/Cargo.lock index 1b3affc4..89cbe657 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,7 +10,7 @@ checksum = "76911d40887d602df08b917182480dcc5d091a679e8f36fce5a4f9944d6e77b2" dependencies = [ "byteorder", "bzip2", - "crc", + "crc 1.8.1", "thiserror", ] @@ -112,6 +112,25 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" +dependencies = [ + "derive_arbitrary", +] + +[[package]] +name = "assert-json-diff" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e4f2b81832e72834d7518d8487a0396a28cc408186a2e8854c0f98011faf12" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "autocfg" version = "1.2.0" @@ -140,10 +159,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] -name = "base64ct" -version = "1.6.0" +name = "base64" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" [[package]] name = "bitflags" @@ -299,6 +318,15 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" +[[package]] +name = "cmake" +version = "0.1.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130" +dependencies = [ + "cc", +] + [[package]] name = "colorchoice" version = "1.0.0" @@ -306,20 +334,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] -name = "constant_time_eq" -version = "0.1.5" +name = "colored" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" +checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" +dependencies = [ + "lazy_static", + "windows-sys 0.48.0", +] [[package]] -name = "core-foundation" -version = "0.9.4" +name = "constant_time_eq" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] +checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" [[package]] name = "core-foundation-sys" @@ -345,6 +373,21 @@ dependencies = [ "build_const", ] +[[package]] +name = "crc" +version = "3.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69e6e4d7b33a94f0991c26729976b10ebde1d34c3ee82408fb536164fa10d636" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + [[package]] name = "crc32fast" version = "1.4.0" @@ -414,25 +457,18 @@ dependencies = [ "syn", ] -[[package]] -name = "dashmap" -version = "5.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" -dependencies = [ - "cfg-if", - "hashbrown 0.14.3", - "lock_api", - "once_cell", - "parking_lot_core", -] - [[package]] name = "data-encoding" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" +[[package]] +name = "deflate64" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83ace6c86376be0b6cdcf3fb41882e81d94b31587573d1cfa9d01cd06bba210d" + [[package]] name = "deranged" version = "0.3.11" @@ -443,6 +479,17 @@ dependencies = [ "serde", ] +[[package]] +name = "derive_arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "digest" version = "0.10.7" @@ -499,17 +546,18 @@ checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.4.1", "windows-sys 0.52.0", ] [[package]] name = "flate2" -version = "1.0.28" +version = "1.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" +checksum = "4556222738635b7a3417ae6130d8f52201e45a0c4d1a907f0826383adb5f85e7" dependencies = [ "crc32fast", + "libz-ng-sys", "miniz_oxide", ] @@ -695,7 +743,7 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06683b93020a07e3dbcf5f8c0f6d40080d725bea7936fc01ad345c01b97dc270" dependencies = [ - "base64", + "base64 0.21.7", "bytes", "headers-core", "http 0.2.12", @@ -782,6 +830,29 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "http-body" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +dependencies = [ + "bytes", + "http 1.1.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0475f8b2ac86659c21b64320d5d653f9efe42acd2a4e560073ec61a155a34f1d" +dependencies = [ + "bytes", + "futures-core", + "http 1.1.0", + "http-body 1.0.0", + "pin-project-lite", +] + [[package]] name = "httparse" version = "1.8.0" @@ -817,7 +888,7 @@ dependencies = [ "futures-util", "h2", "http 0.2.12", - "http-body", + "http-body 0.4.6", "httparse", "httpdate", "itoa", @@ -829,18 +900,60 @@ dependencies = [ "want", ] +[[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", + "http 1.1.0", + "http-body 1.0.0", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + [[package]] name = "hyper-rustls" -version = "0.24.2" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" +checksum = "a0bea761b46ae2b24eb4aef630d8d1c398157b6fc29e6350ecf090a0b70c952c" dependencies = [ "futures-util", - "http 0.2.12", - "hyper", + "http 1.1.0", + "hyper 1.3.1", + "hyper-util", "rustls", + "rustls-pki-types", "tokio", "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "hyper 1.3.1", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", ] [[package]] @@ -933,9 +1046,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "jobserver" -version = "0.1.30" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "685a7d121ee3f65ae4fddd72b25a04bb36b6af81bc0828f7d5434c0fe60fa3a2" +checksum = "d2b099aaa34a9751c5bf0878add70444e1ed2dd73f347be99003d4577277de6e" dependencies = [ "libc", ] @@ -961,6 +1074,16 @@ version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +[[package]] +name = "libz-ng-sys" +version = "1.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6409efc61b12687963e602df8ecf70e8ddacf95bc6576bcf16e3ac6328083c5" +dependencies = [ + "cmake", + "libc", +] + [[package]] name = "linux-raw-sys" version = "0.4.13" @@ -969,9 +1092,9 @@ checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -983,6 +1106,16 @@ version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +[[package]] +name = "lzma-rs" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "297e814c836ae64db86b36cf2a557ba54368d03f6afcd7d947c266692f71115e" +dependencies = [ + "byteorder", + "crc 3.2.1", +] + [[package]] name = "md5" version = "0.7.0" @@ -1031,6 +1164,25 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "mockito" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2f6e023aa5bdf392aa06c78e4a4e6d498baab5138d0c993503350ebbc37bf1e" +dependencies = [ + "assert-json-diff", + "colored", + "futures-core", + "hyper 0.14.28", + "log", + "rand", + "regex", + "serde_json", + "serde_urlencoded", + "similar", + "tokio", +] + [[package]] name = "multer" version = "2.1.0" @@ -1107,8 +1259,10 @@ dependencies = [ "glob", "handlebars", "inflections", + "lazy_static", "log", "md5", + "mockito", "once_cell", "rand", "regex", @@ -1131,9 +1285,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "parking_lot" -version = "0.12.1" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" dependencies = [ "lock_api", "parking_lot_core", @@ -1141,38 +1295,25 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.9" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.5.1", "smallvec", - "windows-targets 0.48.5", -] - -[[package]] -name = "password-hash" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" -dependencies = [ - "base64ct", - "rand_core", - "subtle", + "windows-targets 0.52.5", ] [[package]] name = "pbkdf2" -version = "0.11.0" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" dependencies = [ "digest", "hmac", - "password-hash", - "sha2", ] [[package]] @@ -1333,6 +1474,15 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags 2.5.0", +] + [[package]] name = "regex" version = "1.10.4" @@ -1364,20 +1514,21 @@ checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] name = "reqwest" -version = "0.11.27" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62" +checksum = "566cafdd92868e0939d3fb961bd0dc25fcfaaed179291093b3d43e6b3150ea10" dependencies = [ - "base64", + "base64 0.22.0", "bytes", - "encoding_rs", + "futures-channel", "futures-core", "futures-util", - "h2", - "http 0.2.12", - "http-body", - "hyper", + "http 1.1.0", + "http-body 1.0.0", + "http-body-util", + "hyper 1.3.1", "hyper-rustls", + "hyper-util", "ipnet", "js-sys", "log", @@ -1387,11 +1538,11 @@ dependencies = [ "pin-project-lite", "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", "tokio-rustls", "tower-service", @@ -1426,9 +1577,9 @@ checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustix" -version = "0.38.32" +version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ "bitflags 2.5.0", "errno", @@ -1439,32 +1590,42 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.11" +version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fecbfb7b1444f477b345853b1fce097a2c6fb637b2bfb87e6bc5db0f043fae4" +checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432" dependencies = [ "log", "ring", + "rustls-pki-types", "rustls-webpki", - "sct", + "subtle", + "zeroize", ] [[package]] name = "rustls-pemfile" -version = "1.0.4" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" +checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d" dependencies = [ - "base64", + "base64 0.22.0", + "rustls-pki-types", ] +[[package]] +name = "rustls-pki-types" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "beb461507cee2c2ff151784c52762cf4d9ff6a61f3e80968600ed24fa837fa54" + [[package]] name = "rustls-webpki" -version = "0.101.7" +version = "0.102.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +checksum = "f3bce581c0dd41bce533ce695a1437fa16a7ab5ac3ccfa99fe1a620a7885eabf" dependencies = [ "ring", + "rustls-pki-types", "untrusted", ] @@ -1474,6 +1635,15 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" +[[package]] +name = "scc" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec96560eea317a9cc4e0bb1f6a2c93c09a19b8c4fc5cb3fcc0ec1c094cd783e2" +dependencies = [ + "sdd", +] + [[package]] name = "scoped-tls" version = "1.0.1" @@ -1487,29 +1657,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] -name = "sct" -version = "0.7.1" +name = "sdd" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" -dependencies = [ - "ring", - "untrusted", -] +checksum = "b84345e4c9bd703274a082fb80caaa99b7612be48dfaa1dd9266577ec412309d" [[package]] name = "serde" -version = "1.0.198" +version = "1.0.199" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" +checksum = "0c9f6e76df036c77cd94996771fb40db98187f096dd0b9af39c6c6e452ba966a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.198" +version = "1.0.199" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" +checksum = "11bd257a6541e141e42ca6d24ae26f7714887b47e89aa739099104c7e4d3b7fc" dependencies = [ "proc-macro2", "quote", @@ -1541,11 +1707,11 @@ dependencies = [ [[package]] name = "serde_with" -version = "3.7.0" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee80b0e361bbf88fd2f6e242ccd19cfda072cb0faa6ae694ecee08199938569a" +checksum = "2c85f8e96d1d6857f13768fcbd895fcb06225510022a2774ed8b5150581847b0" dependencies = [ - "base64", + "base64 0.22.0", "chrono", "hex", "indexmap 1.9.3", @@ -1559,9 +1725,9 @@ dependencies = [ [[package]] name = "serde_with_macros" -version = "3.7.0" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6561dc161a9224638a31d876ccdfefbc1df91d3f3a8342eddb35f055d48c7655" +checksum = "c8b3a576c4eb2924262d5951a3b737ccaf16c931e39a2810c36f9a7e25575557" dependencies = [ "darling", "proc-macro2", @@ -1571,23 +1737,23 @@ dependencies = [ [[package]] name = "serial_test" -version = "3.0.0" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ad9342b3aaca7cb43c45c097dd008d4907070394bd0751a0aa8817e5a018d" +checksum = "4b4b487fe2acf240a021cf57c6b2b4903b1e78ca0ecd862a71b71d2a51fed77d" dependencies = [ - "dashmap", "futures", - "lazy_static", "log", + "once_cell", "parking_lot", + "scc", "serial_test_derive", ] [[package]] name = "serial_test_derive" -version = "3.0.0" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b93fb4adc70021ac1b47f7d45e8cc4169baaa7ea58483bc5b721d19a26202212" +checksum = "82fe9db325bcef1fbcde82e078a5cc4efdf787e96b3b9cf45b50b529f2083d67" dependencies = [ "proc-macro2", "quote", @@ -1618,13 +1784,25 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" dependencies = [ "libc", ] +[[package]] +name = "simd-adler32" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" + +[[package]] +name = "similar" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa42c91313f1d05da9b26f267f931cf178d4aba455b4c4622dd7355eb80c6640" + [[package]] name = "slab" version = "0.4.9" @@ -1705,27 +1883,6 @@ dependencies = [ "windows", ] -[[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 = "tar" version = "0.4.40" @@ -1835,11 +1992,12 @@ dependencies = [ [[package]] name = "tokio-rustls" -version = "0.24.1" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" +checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f" dependencies = [ "rustls", + "rustls-pki-types", "tokio", ] @@ -1869,6 +2027,28 @@ dependencies = [ "tracing", ] +[[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" @@ -1920,6 +2100,12 @@ dependencies = [ "utf-8", ] +[[package]] +name = "typed-arena" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a" + [[package]] name = "typenum" version = "1.17.0" @@ -2017,7 +2203,7 @@ dependencies = [ "futures-util", "headers", "http 0.2.12", - "hyper", + "hyper 0.14.28", "log", "mime", "mime_guess", @@ -2119,9 +2305,12 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.25.4" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" +checksum = "b3de34ae270483955a94f4b21bdaaeb83d508bb84a01435f393818edb0012009" +dependencies = [ + "rustls-pki-types", +] [[package]] name = "which" @@ -2317,9 +2506,9 @@ checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "winreg" -version = "0.50.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" dependencies = [ "cfg-if", "windows-sys 0.48.0", @@ -2342,42 +2531,63 @@ dependencies = [ "rustix", ] +[[package]] +name = "zeroize" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" + [[package]] name = "zip" -version = "0.6.6" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261" +checksum = "f2655979068a1f8fa91cb9e8e5b9d3ee54d18e0ddc358f2f4a395afc0929a84b" dependencies = [ "aes", + "arbitrary", "byteorder", "bzip2", "constant_time_eq", "crc32fast", "crossbeam-utils", + "deflate64", "flate2", "hmac", + "lzma-rs", "pbkdf2", "sha1", "time", + "zopfli", "zstd", ] +[[package]] +name = "zopfli" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c1f48f3508a3a3f2faee01629564400bc12260f6214a056d06a3aaaa6ef0736" +dependencies = [ + "crc32fast", + "log", + "simd-adler32", + "typed-arena", +] + [[package]] name = "zstd" -version = "0.11.2+zstd.1.5.2" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" +checksum = "2d789b1514203a1120ad2429eae43a7bd32b90976a7bb8a05f7ec02fa88cc23a" dependencies = [ "zstd-safe", ] [[package]] name = "zstd-safe" -version = "5.0.2+zstd.1.5.2" +version = "7.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db" +checksum = "1cd99b45c6bc03a018c8b8a86025678c87e55526064e38f9df301989dce7ec0a" dependencies = [ - "libc", "zstd-sys", ] diff --git a/Dockerfile.odin b/Dockerfile.odin index a52692ee..9f50abeb 100644 --- a/Dockerfile.odin +++ b/Dockerfile.odin @@ -14,6 +14,7 @@ RUN cargo chef prepare --recipe-path recipe.json # ------------------ # FROM lukemathwalker/cargo-chef:latest-rust-${RUST_VERSION} as cacher WORKDIR /data/odin +RUN apt-get update && apt-get install -y cmake COPY --from=planner /data/odin/recipe.json recipe.json RUN cargo chef cook --release --recipe-path recipe.json @@ -23,6 +24,7 @@ RUN cargo chef cook --release --recipe-path recipe.json # ------------------ # FROM rust:${RUST_VERSION} as builder WORKDIR /data/odin +RUN apt-get update && apt-get install -y cmake COPY . . # Copy over the cached dependencies COPY --from=cacher /data/odin/target target diff --git a/Makefile b/Makefile index 24da1bc7..fc1d6870 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # Makefile -.PHONY: setup member_format member_clippy docker-build docker-up docker-down docker-push start start-dev build-dev access access-admin release-odin release-http-server release +.PHONY: setup member_format member_clippy docker-build docker-up docker-down docker-push start start-dev build-dev access access-admin release-odin release-http-server release test docker-dev setup: @if [ ! -f "$$PWD/docker-compose.dev.yml" ]; then \ @@ -11,6 +11,9 @@ setup: lint: member_format docker run --rm -v "$$PWD:/app" -w /app node:lts sh -c 'npx -y prettier --write .' +test: + cargo test + member_format: cargo fmt @@ -28,6 +31,8 @@ docker-down: setup docker-push: setup docker compose -f ./docker-compose.dev.yml push +docker-dev: setup + docker compose -f ./docker-compose.dev.yml up --build start: member_format member_clippy docker-up diff --git a/README.md b/README.md index 2d9bdb86..d0364f10 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,9 @@ + [![All Contributors](https://img.shields.io/badge/all_contributors-14-orange.svg?style=flat-square)](#contributors-) + ## Table of Contents diff --git a/src/odin/Cargo.toml b/src/odin/Cargo.toml index 1b948275..f42965e4 100644 --- a/src/odin/Cargo.toml +++ b/src/odin/Cargo.toml @@ -40,19 +40,22 @@ tar = "0.4" flate2 = "1.0" inflections = "1.1.1" md5 = "0.7" -reqwest = { version = "0.11", default_features = false, features = ["blocking", "json", "rustls-tls"] } +reqwest = { version = "0.12.4", default_features = false, features = ["blocking", "json", "rustls-tls"] } chrono = "0.4" -zip = { version = "0.6" } +zip = { version = "1.1.1" } fs_extra = "1.3" glob = "0.3" a2s = "0.5" serde_with = "3" regex = "1" + [dev-dependencies] once_cell = "1" rand = "0.8" serial_test = "3" +mockito = "1.4.0" +lazy_static = "1.4.0" [dev-dependencies.cargo-husky] version = "1.5.0" diff --git a/src/odin/commands/status.rs b/src/odin/commands/status.rs index 3e729ab0..75e516a6 100644 --- a/src/odin/commands/status.rs +++ b/src/odin/commands/status.rs @@ -21,9 +21,8 @@ pub fn invoke(output_json: bool, use_local: bool, supplied_address: Option { fn extract_sub_dir_custom>(&mut self, dst_dir: P, sub_dir: &str) -> ZipResult<()> { for i in 0..self.len() { let mut file = self.by_index(i)?; - let filepath = match file + let enclosed_name = file .enclosed_name() - .ok_or(ZipError::InvalidArchive("Invalid file path"))? - .strip_prefix(sub_dir) - { + .ok_or(ZipError::InvalidArchive("Invalid file path"))?; + + let filepath = match enclosed_name.strip_prefix(sub_dir) { Ok(path) => path, Err(_) => continue, }; diff --git a/src/odin/notifications/enums/notification_event.rs b/src/odin/notifications/enums/notification_event.rs index 2074aab9..04dd5ce4 100644 --- a/src/odin/notifications/enums/notification_event.rs +++ b/src/odin/notifications/enums/notification_event.rs @@ -64,13 +64,8 @@ fn is_webhook_include_public_ip() -> bool { pub fn parse_server_name_for_notification() -> String { if is_webhook_include_public_ip() { - let public_address = fetch_public_address().unwrap(); - format!( - "{} - {}:{}", - get_server_name(), - public_address.ip(), - public_address.port() - 1 - ) + let ip = fetch_public_address(); + format!("{} - {}:{}", get_server_name(), &ip.ip, &ip.port) } else { get_server_name() } diff --git a/src/odin/utils/fetch_public_ip_address.rs b/src/odin/utils/fetch_public_ip_address.rs index ca555fcb..7a47d55a 100644 --- a/src/odin/utils/fetch_public_ip_address.rs +++ b/src/odin/utils/fetch_public_ip_address.rs @@ -1,21 +1,190 @@ -use crate::utils::environment::fetch_var; -use std::env; -use std::net::{AddrParseError, SocketAddrV4}; -use std::str::FromStr; +use log::{debug, error}; +use reqwest::blocking::Client; +use std::env::VarError; +use std::{env, fmt}; -// Standardized way of fetching public address -pub fn fetch_public_address() -> Result { - let current_port: u16 = fetch_var("PORT", "2456").parse().unwrap(); - let current_ip = match env::var("ADDRESS") { - Ok(found_address) => found_address, - Err(_) => { - // Make request - match reqwest::blocking::get("https://api.ipify.org") { - Ok(result) => String::from(&result.text().unwrap()), - // Fallback to local IP address - Err(_) => String::from("127.0.0.1"), +#[derive(Debug, serde::Deserialize, serde::Serialize)] +struct IPResponse { + ip: String, +} + +pub struct IPConfig { + pub(crate) ip: String, + pub(crate) port: u16, +} + +impl fmt::Display for IPConfig { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}:{}", self.ip, self.port) + } +} + +impl IPConfig { + fn new(ip: String, port: u16) -> IPConfig { + IPConfig { ip, port } + } + + fn default() -> IPConfig { + IPConfig::new("127.0.0.1".to_string(), 2456) + } + + fn get_ip_from_env(&self) -> Result { + env::var("ADDRESS") + } + + fn get_port_from_env(&self) -> Result { + env::var("PORT").map(|port| port.parse().unwrap()) + } + + pub fn to_string_from_env(&self) -> Result { + match self.get_ip_from_env() { + Ok(ip) => match self.get_port_from_env() { + Ok(port) => { + if ip.is_empty() { + error!("IP address is empty"); + Err(VarError::NotPresent) + } else if port.to_string().is_empty() { + error!("Port is empty"); + Err(VarError::NotPresent) + } else { + Ok(IPConfig::new(ip, port)) + } + } + Err(e) => Err(e), + }, + Err(e) => Err(e), + } + } + + pub fn fetch_ip_from_api(&self, client: &Client) -> Result> { + let urls = [ + "https://api.ipify.org?format=json", + "https://api.seeip.org/jsonip?", + "https://ipinfo.io", + ]; + + for url in urls { + match client.get(url).send() { + Ok(response) => match response.json::() { + Ok(json) => return Ok(json.ip.to_string()), + Err(e) => { + debug!("Failed to parse JSON: {}", e); + continue; + } + }, + Err(e) => { + debug!("Request failed: {}", e); + continue; + } } } - }; - SocketAddrV4::from_str(&format!("{}:{}", current_ip, current_port + 1)) + + Err(Box::new(std::io::Error::new( + std::io::ErrorKind::NotFound, + "All IP fetch attempts failed", + ))) + } +} + +// Standardized way of fetching public address +pub fn fetch_public_address() -> IPConfig { + let client = Client::new(); + let mut ip_config = IPConfig::default(); + debug!("Checking for address in env"); + match ip_config.to_string_from_env() { + Ok(ip) => { + debug!("Fetched IP: {}", ip); + ip + } + Err(_) => match ip_config.fetch_ip_from_api(&client) { + Ok(ip) => { + debug!("Fetched IP: {}", ip); + ip_config.ip = ip; + ip_config + } + Err(e) => { + debug!("Failed to fetch IP: {}", e); + ip_config + } + }, + } +} + +#[cfg(test)] +mod tests { + use super::*; + use lazy_static::lazy_static; + use std::env; + use std::sync::Mutex; + + lazy_static! { + static ref ENV_LOCK: Mutex<()> = Mutex::new(()); + } + + #[test] + fn test_new() { + let ip_config = IPConfig::new("192.168.1.1".to_string(), 3000); + assert_eq!(ip_config.ip, "192.168.1.1"); + assert_eq!(ip_config.port, 3000); + } + + #[test] + fn test_default() { + let ip_config = IPConfig::default(); + assert_eq!(ip_config.ip, "127.0.0.1"); + assert_eq!(ip_config.port, 2456); + } + + #[test] + fn test_get_ip_from_env() { + let _guard = ENV_LOCK.lock().unwrap(); + env::set_var("ADDRESS", "192.168.1.1"); + + let ip_config = IPConfig::default(); + let result = ip_config.get_ip_from_env(); + assert_eq!(result.unwrap(), "192.168.1.1"); + + env::remove_var("ADDRESS"); + } + + #[test] + fn test_get_port_from_env() { + let _guard = ENV_LOCK.lock().unwrap(); + env::set_var("PORT", "3000"); + + let ip_config = IPConfig::default(); + let result = ip_config.get_port_from_env(); + assert_eq!(result.unwrap(), 3000); + + env::remove_var("PORT"); + } + + #[test] + fn test_to_string_from_env() { + let _guard = ENV_LOCK.lock().unwrap(); + env::set_var("ADDRESS", "192.168.1.1"); + env::set_var("PORT", "3000"); + + let ip_config = IPConfig::default(); + let result = ip_config.to_string_from_env().unwrap(); + assert_eq!(result.ip, "192.168.1.1"); + assert_eq!(result.port, 3000); + + env::remove_var("ADDRESS"); + env::remove_var("PORT"); + } + + #[test] + fn test_fetch_ip_from_api() { + let client = Client::new(); + let ip_config = IPConfig::default(); + let result = ip_config.fetch_ip_from_api(&client); + assert!(result.is_ok()); + } + + #[test] + fn test_display_for_ip_config() { + let ip_config = IPConfig::new("192.168.1.1".to_string(), 3000); + assert_eq!(ip_config.to_string(), "192.168.1.1:3000"); + } } diff --git a/test.sh b/test.sh deleted file mode 100644 index 07ef268b..00000000 --- a/test.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - - - -export MODIFIERS=" -raids=muchmore -combat=hard -deathpenalty=casual -" - -echo "${MODIFIERS}" | xargs echo -n | tr ' ' ',' | sed 's/,,/,/g' \ No newline at end of file