diff --git a/.cargo/config.toml b/.cargo/config.toml index 9b60148..e0e3f5b 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -5,4 +5,4 @@ test_details = ["test", "--target", "aarch64-apple-darwin"] target = "wasm32-wasip1" [target.'cfg(all(target_arch = "wasm32"))'] -runner = "viceroy run -C fastly.toml -- " +runner = "viceroy run -C ../../fastly.toml -- " diff --git a/Cargo.lock b/Cargo.lock index 9973a9e..2522e62 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,9 +28,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.95" +version = "1.0.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" +checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f" [[package]] name = "arraydeque" @@ -46,7 +46,7 @@ checksum = "e539d3fca749fcee5236ab05e93a52867dd549cc157c8cb7f99595f3cedffdb5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.96", + "syn 2.0.100", ] [[package]] @@ -111,9 +111,9 @@ dependencies = [ [[package]] name = "bytes" -version = "1.9.0" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" +checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" [[package]] name = "cfg-if" @@ -225,7 +225,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.96", + "syn 2.0.100", ] [[package]] @@ -236,14 +236,14 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.96", + "syn 2.0.100", ] [[package]] name = "deranged" -version = "0.3.11" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +checksum = "28cfac68e08048ae1883171632c2aef3ebc555621ae56fbccce1cbf22dd7f058" dependencies = [ "powerfmt", "serde", @@ -267,7 +267,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.96", + "syn 2.0.100", ] [[package]] @@ -277,7 +277,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab63b0e2bf4d5928aff72e83a7dace85d7bba5fe12dcc3c5a572d78caffd3f3c" dependencies = [ "derive_builder_core", - "syn 2.0.96", + "syn 2.0.100", ] [[package]] @@ -308,7 +308,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.96", + "syn 2.0.100", ] [[package]] @@ -328,15 +328,15 @@ checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" [[package]] name = "either" -version = "1.13.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" [[package]] name = "elsa" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d98e71ae4df57d214182a2e5cb90230c0192c6ddfcaa05c36453d46a54713e10" +checksum = "9abf33c656a7256451ebb7d0082c5a471820c31269e49d807c538c252352186e" dependencies = [ "indexmap", "stable_deref_trait", @@ -353,9 +353,9 @@ dependencies = [ [[package]] name = "equivalent" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "fastly" @@ -548,7 +548,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.96", + "syn 2.0.100", ] [[package]] @@ -665,9 +665,9 @@ dependencies = [ [[package]] name = "http" -version = "1.2.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f16ca2af56261c99fba8bac40a10251ce8188205a4c448fbb745a2e4daa76fea" +checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565" dependencies = [ "bytes", "fnv", @@ -715,9 +715,9 @@ dependencies = [ [[package]] name = "icu_locid_transform_data" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" +checksum = "7515e6d781098bf9f7205ab3fc7e9709d34554ae0b21ddbcb5febfa4bc7df11d" [[package]] name = "icu_normalizer" @@ -739,9 +739,9 @@ dependencies = [ [[package]] name = "icu_normalizer_data" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" +checksum = "c5e8338228bdc8ab83303f16b797e177953730f601a96c25d10cb3ab0daa0cb7" [[package]] name = "icu_properties" @@ -760,9 +760,9 @@ dependencies = [ [[package]] name = "icu_properties_data" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" +checksum = "85fb8799753b75aee8d2a21d7c14d9f38921b54b3dbda10f5a3c7a7b82dba5e2" [[package]] name = "icu_provider" @@ -789,7 +789,7 @@ checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.96", + "syn 2.0.100", ] [[package]] @@ -821,9 +821,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.7.1" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652" +checksum = "3954d50fe15b02142bf25d3b8bdadb634ec3948f103d04ffe3031bc8fe9d7058" dependencies = [ "equivalent", "hashbrown 0.15.2", @@ -840,9 +840,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] name = "json5" @@ -863,21 +863,21 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.169" +version = "0.2.171" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" +checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6" [[package]] name = "litemap" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104" +checksum = "23fb14cb19457329c82206317a5663005a4d404783dc74f4252769b0d5f42856" [[package]] name = "log" -version = "0.4.25" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" [[package]] name = "log-fastly" @@ -943,9 +943,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.21.1" +version = "1.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d75b0bedcc4fe52caa0e03d9f1151a323e4aa5e2d78ba3580400cd3c9e2bc4bc" +checksum = "c2806eaa3524762875e21c3dcd057bc4b7bfa01ce4da8d46be1cd43649e1cc6b" [[package]] name = "opaque-debug" @@ -977,9 +977,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" -version = "2.7.15" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b7cafe60d6cf8e62e1b9b2ea516a089c008945bb5a275416789e7db0bc199dc" +checksum = "198db74531d58c70a361c42201efde7e2591e976d518caf7662a47dc5720e7b6" dependencies = [ "memchr", "thiserror 2.0.12", @@ -988,9 +988,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.7.15" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "816518421cfc6887a0d62bf441b6ffb4536fcc926395a69e1a85852d4363f57e" +checksum = "d725d9cfd79e87dccc9341a2ef39d1b6f6353d68c4b33c177febbe1a402c97c5" dependencies = [ "pest", "pest_generator", @@ -998,22 +998,22 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.7.15" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d1396fd3a870fc7838768d171b4616d5c91f6cc25e377b673d714567d99377b" +checksum = "db7d01726be8ab66ab32f9df467ae8b1148906685bbe75c82d1e65d7f5b3f841" dependencies = [ "pest", "pest_meta", "proc-macro2", "quote", - "syn 2.0.96", + "syn 2.0.100", ] [[package]] name = "pest_meta" -version = "2.7.15" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1e58089ea25d717bfd31fb534e4f3afcc2cc569c70de3e239778991ea3b7dea" +checksum = "7f9f832470494906d1fca5329f8ab5791cc60beb230c74815dff541cbd2b5ca0" dependencies = [ "once_cell", "pest", @@ -1032,26 +1032,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "potsi" -version = "0.1.0" -dependencies = [ - "config", - "cookie", - "fastly 0.11.2", - "futures", - "handlebars", - "hex", - "hmac", - "log", - "log-fastly", - "serde", - "serde_json", - "sha2 0.10.8", - "tokio", - "url", -] - [[package]] name = "powerfmt" version = "0.2.0" @@ -1060,18 +1040,18 @@ checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "proc-macro2" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" +checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.38" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" dependencies = [ "proc-macro2", ] @@ -1136,35 +1116,35 @@ checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "ryu" -version = "1.0.19" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ea1a2d0a644769cc99faa24c3ad26b379b786fe7c36fd3c546254801650e6dd" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" [[package]] name = "serde" -version = "1.0.217" +version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.217" +version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" dependencies = [ "proc-macro2", "quote", - "syn 2.0.96", + "syn 2.0.100", ] [[package]] name = "serde_json" -version = "1.0.138" +version = "1.0.140" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d434192e7da787e94a6ea7e9670b26a036d0ca41e0b7efb2676dd32bae872949" +checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" dependencies = [ "itoa", "memchr", @@ -1228,9 +1208,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.13.2" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd" [[package]] name = "stable_deref_trait" @@ -1263,9 +1243,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.96" +version = "2.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80" +checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" dependencies = [ "proc-macro2", "quote", @@ -1280,7 +1260,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.96", + "syn 2.0.100", ] [[package]] @@ -1309,7 +1289,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.96", + "syn 2.0.100", ] [[package]] @@ -1320,14 +1300,14 @@ checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.96", + "syn 2.0.100", ] [[package]] name = "time" -version = "0.3.37" +version = "0.3.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21" +checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40" dependencies = [ "deranged", "itoa", @@ -1340,15 +1320,15 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.2" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" +checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c" [[package]] name = "time-macros" -version = "0.2.19" +version = "0.2.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2834e6017e3e5e4b9834939793b282bc03b37a3336245fa820e35e233e2a85de" +checksum = "3526739392ec93fd8b359c8e98514cb3e8e021beb4e5f597b00a0221f8ed8a49" dependencies = [ "num-conv", "time-core", @@ -1375,9 +1355,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.43.0" +version = "1.44.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d61fa4ffa3de412bfea335c6ecff681de2b609ba3c77ef3e00e521813a9ed9e" +checksum = "f382da615b842244d4b8738c82ed1275e6c5dd90c459a30941cd07080b06c91a" dependencies = [ "backtrace", "bytes", @@ -1393,7 +1373,7 @@ checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.96", + "syn 2.0.100", ] [[package]] @@ -1436,11 +1416,46 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "343e926fc669bc8cde4fa3129ab681c63671bae288b1f1081ceee6d9d37904fc" +[[package]] +name = "trusted-server-common" +version = "0.1.0" +dependencies = [ + "config", + "cookie", + "fastly 0.11.2", + "futures", + "handlebars", + "hex", + "hmac", + "http", + "log", + "log-fastly", + "serde", + "serde_json", + "sha2 0.10.8", + "tokio", + "url", +] + +[[package]] +name = "trusted-server-fastly" +version = "0.1.0" +dependencies = [ + "fastly 0.11.2", + "futures", + "http", + "log", + "log-fastly", + "serde", + "serde_json", + "trusted-server-common", +] + [[package]] name = "typenum" -version = "1.17.0" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" [[package]] name = "ucd-trie" @@ -1450,9 +1465,9 @@ checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" [[package]] name = "unicode-ident" -version = "1.0.16" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] name = "unicode-segmentation" @@ -1582,9 +1597,9 @@ checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" [[package]] name = "yaml-rust2" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "232bdb534d65520716bef0bbb205ff8f2db72d807b19c0bc3020853b92a0cd4b" +checksum = "818913695e83ece1f8d2a1c52d54484b7b46d0f9c06beeb2649b9da50d9b512d" dependencies = [ "arraydeque", "encoding_rs", @@ -1611,28 +1626,28 @@ checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" dependencies = [ "proc-macro2", "quote", - "syn 2.0.96", + "syn 2.0.100", "synstructure", ] [[package]] name = "zerofrom" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cff3ee08c995dee1859d998dea82f7374f2826091dd9cd47def953cae446cd2e" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" dependencies = [ "zerofrom-derive", ] [[package]] name = "zerofrom-derive" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" dependencies = [ "proc-macro2", "quote", - "syn 2.0.96", + "syn 2.0.100", "synstructure", ] @@ -1655,5 +1670,5 @@ checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.96", + "syn 2.0.100", ] diff --git a/Cargo.toml b/Cargo.toml index 5341132..e0632e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,28 +1,6 @@ -[package] -name = "potsi" -version = "0.1.0" -authors = [] -edition = "2021" -# Remove this line if you want to be able to publish this crate as open source on crates.io. -# Otherwise, `publish = false` prevents an accidental `cargo publish` from revealing private source. -publish = false -license = "Apache-2.0" - -[profile.release] -debug = 1 - -[dependencies] -fastly = "0.11.2" -hmac = "0.12.1" -sha2 = "0.10.6" -hex = "0.4.3" -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0.91" -cookie = "0.18.1" -log = "0.4.20" -log-fastly = "0.10.0" -futures = "0.3" -tokio = { version = "1.0", features = ["sync", "macros", "io-util", "rt", "time"] } -url = "2.4.1" -config = "0.15.11" -handlebars = "6.3.2" +[workspace] +resolver = "2" +members = [ + "crates/common", + "crates/fastly", +] diff --git a/README.md b/README.md index 6495672..d0f652d 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ git clone git@github.com:IABTechLab/trusted-server.git :information_source: Note that you’ll have to edit the following files for your setup: - fastly.toml (service ID, author, description) -- potsi.toml (KV store ID names) +- trusted-server.toml (KV store ID names) ### Build diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml new file mode 100644 index 0000000..065f62f --- /dev/null +++ b/crates/common/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "trusted-server-common" +version = "0.1.0" +authors = [] +edition = "2021" +# Remove this line if you want to be able to publish this crate as open source on crates.io. +# Otherwise, `publish = false` prevents an accidental `cargo publish` from revealing private source. +publish = false +license = "Apache-2.0" + +[profile.release] +debug = 1 + +[dependencies] +config = "0.15.11" +cookie = "0.18.1" +fastly = "0.11.2" +futures = "0.3" +handlebars = "6.3.2" +hex = "0.4.3" +hmac = "0.12.1" +http = "1.3.1" +log = "0.4.20" +log-fastly = "0.10.0" +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0.91" +sha2 = "0.10.6" +tokio = { version = "1.0", features = ["sync", "macros", "io-util", "rt", "time"] } +url = "2.4.1" diff --git a/crates/common/src/constants.rs b/crates/common/src/constants.rs new file mode 100644 index 0000000..23a318d --- /dev/null +++ b/crates/common/src/constants.rs @@ -0,0 +1,6 @@ +use http::header::HeaderName; + +pub const HEADER_SYNTHETIC_FRESH: HeaderName = HeaderName::from_static("x-synthetic-fresh"); +pub const HEADER_SYNTHETIC_PUB_USER_ID: HeaderName = HeaderName::from_static("x-pub-user-id"); +pub const HEADER_SYNTHETIC_TRUSTED_SERVER: HeaderName = HeaderName::from_static("x-synthetic-trusted-server"); +pub const HEADER_X_FORWARDED_FOR: HeaderName = HeaderName::from_static("x-forwarded-for"); diff --git a/src/cookies.rs b/crates/common/src/cookies.rs similarity index 96% rename from src/cookies.rs rename to crates/common/src/cookies.rs index 3ec61fa..cfdace2 100644 --- a/src/cookies.rs +++ b/crates/common/src/cookies.rs @@ -1,6 +1,7 @@ use cookie::{Cookie, CookieJar}; use fastly::http::header; -use fastly::Request; + +use crate::http_wrapper::RequestWrapper; const COOKIE_MAX_AGE: i32 = 365 * 24 * 60 * 60; // 1 year @@ -17,7 +18,7 @@ pub fn parse_cookies_to_jar(s: &str) -> CookieJar { jar } -pub fn handle_request_cookies(req: &Request) -> Option { +pub fn handle_request_cookies(req: &T) -> Option { match req.get_header(header::COOKIE) { Some(header_value) => { let header_value_str: &str = header_value.to_str().unwrap_or(""); diff --git a/crates/common/src/http_wrapper.rs b/crates/common/src/http_wrapper.rs new file mode 100644 index 0000000..99c489b --- /dev/null +++ b/crates/common/src/http_wrapper.rs @@ -0,0 +1,20 @@ +use http::Method; +use http::header::{HeaderName, HeaderValue}; +use std::net::IpAddr; + +pub trait RequestWrapper { + fn get_client_ip_addr(&self) -> Option; + + fn get_header( + &self, + name: HeaderName, + ) -> Option<&HeaderValue>; + + fn get_headers(&self) -> impl Iterator; + + fn get_method(&self) -> &Method; + + fn get_path(&self) -> &str; + + fn set_header(&mut self, name: HeaderName, value: HeaderValue); +} diff --git a/crates/common/src/lib.rs b/crates/common/src/lib.rs new file mode 100644 index 0000000..ca54d8b --- /dev/null +++ b/crates/common/src/lib.rs @@ -0,0 +1,8 @@ +pub mod constants; +pub mod cookies; +pub mod http_wrapper; +pub mod models; +pub mod prebid; +pub mod settings; +pub mod synthetic; +pub mod templates; diff --git a/src/models.rs b/crates/common/src/models.rs similarity index 100% rename from src/models.rs rename to crates/common/src/models.rs diff --git a/src/prebid.rs b/crates/common/src/prebid.rs similarity index 89% rename from src/prebid.rs rename to crates/common/src/prebid.rs index ca5d8d0..8661653 100644 --- a/src/prebid.rs +++ b/crates/common/src/prebid.rs @@ -2,7 +2,8 @@ use fastly::http::{header, Method}; use fastly::{Error, Request, Response}; use serde_json::json; -use crate::constants::{SYNTHETIC_HEADER_FRESH, SYNTHETIC_HEADER_POTSI}; +use crate::constants::{HEADER_X_FORWARDED_FOR, HEADER_SYNTHETIC_FRESH, HEADER_SYNTHETIC_TRUSTED_SERVER}; +use crate::http_wrapper::RequestWrapper; use crate::settings::Settings; use crate::synthetic::generate_synthetic_id; @@ -28,10 +29,10 @@ impl PrebidRequest { /// /// # Returns /// * `Result` - New PrebidRequest or error - pub fn new(settings: &Settings, req: &Request) -> Result { + pub fn new(settings: &Settings, req: &T) -> Result { // Get the POTSI ID from header (which we just set in handle_prebid_test) let synthetic_id = req - .get_header(SYNTHETIC_HEADER_POTSI) + .get_header(HEADER_SYNTHETIC_TRUSTED_SERVER) .and_then(|h| h.to_str().ok()) .map(|s| s.to_string()) .unwrap_or_else(|| generate_synthetic_id(settings, req)); @@ -41,7 +42,7 @@ impl PrebidRequest { .get_client_ip_addr() .map(|ip| ip.to_string()) .unwrap_or_else(|| { - req.get_header("X-Forwarded-For") + req.get_header(HEADER_X_FORWARDED_FOR) .and_then(|h| h.to_str().ok()) .unwrap_or("") .split(',') // X-Forwarded-For can be a comma-separated list @@ -89,21 +90,21 @@ impl PrebidRequest { /// /// # Returns /// * `Result` - Prebid Server response or error - pub async fn send_bid_request( + pub async fn send_bid_request( &self, settings: &Settings, - incoming_req: &Request, + incoming_req: &T, ) -> Result { let mut req = Request::new(Method::POST, settings.prebid.server_url.to_owned()); // Get and store the POTSI ID value from the incoming request let potsi_id = incoming_req - .get_header(SYNTHETIC_HEADER_POTSI) + .get_header(HEADER_SYNTHETIC_TRUSTED_SERVER) .and_then(|h| h.to_str().ok()) .map(|s| s.to_string()) .unwrap_or_else(|| self.synthetic_id.clone()); - println!("Found POTSI ID from incoming request: {}", potsi_id); + println!("Found Truted Server ID from incoming request: {}", potsi_id); // Construct the OpenRTB2 bid request let prebid_body = json!({ @@ -169,8 +170,8 @@ impl PrebidRequest { req.set_header(header::CONTENT_TYPE, "application/json"); req.set_header("X-Forwarded-For", &self.client_ip); req.set_header(header::ORIGIN, &self.origin); - req.set_header(SYNTHETIC_HEADER_FRESH, &self.synthetic_id); - req.set_header(SYNTHETIC_HEADER_POTSI, &potsi_id); + req.set_header(HEADER_SYNTHETIC_FRESH, &self.synthetic_id); + req.set_header(HEADER_SYNTHETIC_TRUSTED_SERVER, &potsi_id); println!( "Sending prebid request with Fresh ID: {} and POTSI ID: {}", diff --git a/src/settings.rs b/crates/common/src/settings.rs similarity index 86% rename from src/settings.rs rename to crates/common/src/settings.rs index efd2af6..a3b70c3 100644 --- a/src/settings.rs +++ b/crates/common/src/settings.rs @@ -26,15 +26,15 @@ pub struct Synthetic { #[derive(Debug, Deserialize)] #[allow(unused)] -pub(crate) struct Settings { +pub struct Settings { pub ad_server: AdServer, pub prebid: Prebid, pub synthetic: Synthetic, } impl Settings { - pub(crate) fn new() -> Result { - let toml_bytes = include_bytes!("../potsi.toml"); + pub fn new() -> Result { + let toml_bytes = include_bytes!("../../../trusted-server.toml"); let toml_str = str::from_utf8(toml_bytes).unwrap(); let s = Config::builder() diff --git a/src/synthetic.rs b/crates/common/src/synthetic.rs similarity index 84% rename from src/synthetic.rs rename to crates/common/src/synthetic.rs index 64371ab..82a6abe 100644 --- a/src/synthetic.rs +++ b/crates/common/src/synthetic.rs @@ -1,18 +1,18 @@ use fastly::http::header; -use fastly::Request; use handlebars::Handlebars; use hmac::{Hmac, Mac}; use serde_json::json; use sha2::Sha256; -use crate::constants::{SYNTHETIC_HEADER_POTSI, SYNTHETIC_HEADER_PUB_USER_ID}; +use crate::constants::{HEADER_SYNTHETIC_PUB_USER_ID, HEADER_SYNTHETIC_TRUSTED_SERVER}; use crate::cookies::handle_request_cookies; +use crate::http_wrapper::RequestWrapper; use crate::settings::Settings; type HmacSha256 = Hmac; /// Generates a fresh synthetic_id based on request parameters -pub fn generate_synthetic_id(settings: &Settings, req: &Request) -> String { +pub fn generate_synthetic_id(settings: &Settings, req: &T) -> String { let user_agent = req .get_header(header::USER_AGENT) .map(|h| h.to_str().unwrap_or("unknown")); @@ -21,7 +21,7 @@ pub fn generate_synthetic_id(settings: &Settings, req: &Request) -> String { .map(|cookie| cookie.value().to_string()) }); let auth_user_id = req - .get_header(SYNTHETIC_HEADER_PUB_USER_ID) + .get_header(HEADER_SYNTHETIC_PUB_USER_ID) .map(|h| h.to_str().unwrap_or("anonymous")); let publisher_domain = req .get_header(header::HOST) @@ -58,22 +58,22 @@ pub fn generate_synthetic_id(settings: &Settings, req: &Request) -> String { } /// Gets or creates a synthetic_id from the request -pub fn get_or_generate_synthetic_id(settings: &Settings, req: &Request) -> String { +pub fn get_or_generate_synthetic_id(settings: &Settings, req: &T) -> String { // First try to get existing POTSI ID from header - if let Some(potsi) = req - .get_header(SYNTHETIC_HEADER_POTSI) + if let Some(synthetic_id) = req + .get_header(HEADER_SYNTHETIC_TRUSTED_SERVER) .and_then(|h| h.to_str().ok()) .map(|s| s.to_string()) { - log::info!("Using existing POTSI ID from header: {}", potsi); - return potsi; + log::info!("Using existing Synthetic ID from header: {}", synthetic_id); + return synthetic_id; } let req_cookie_jar: Option = handle_request_cookies(req); match req_cookie_jar { Some(jar) => { - let potsi_cookie = jar.get("synthetic_id"); - if let Some(cookie) = potsi_cookie { + let ts_cookie = jar.get("synthetic_id"); + if let Some(cookie) = ts_cookie { let potsi = cookie.value().to_string(); log::info!("Using existing POTSI ID from cookie: {}", potsi); return potsi; @@ -84,9 +84,12 @@ pub fn get_or_generate_synthetic_id(settings: &Settings, req: &Request) -> Strin } } - // If no existing POTSI ID found, generate a fresh one + // If no existing Synthetic ID found, generate a fresh one let fresh_id = generate_synthetic_id(settings, req); - log::info!("No existing POTSI ID found, using fresh ID: {}", fresh_id); + log::info!( + "No existing Synthetic ID found, using fresh ID: {}", + fresh_id + ); fresh_id } @@ -144,10 +147,13 @@ mod tests { #[test] fn test_get_or_generate_synthetic_id_with_header() { let settings = create_settings(); - let req = create_test_request(vec![(SYNTHETIC_HEADER_POTSI, "existing_potsi_id")]); + let req = create_test_request(vec![( + HEADER_SYNTHETIC_TRUSTED_SERVER, + "existing_synthetic_id", + )]); let synthetic_id = get_or_generate_synthetic_id(&settings, &req); - assert_eq!(synthetic_id, "existing_potsi_id"); + assert_eq!(synthetic_id, "existing_synthetic_id"); } #[test] diff --git a/src/templates.rs b/crates/common/src/templates.rs similarity index 100% rename from src/templates.rs rename to crates/common/src/templates.rs diff --git a/crates/fastly/Cargo.toml b/crates/fastly/Cargo.toml new file mode 100644 index 0000000..4f1650d --- /dev/null +++ b/crates/fastly/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "trusted-server-fastly" +version = "0.1.0" +edition = "2021" + +[dependencies] +fastly = "0.11.2" +futures = "0.3" +http = "1.3.1" +log = "0.4.20" +log-fastly = "0.10.0" +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0.91" +trusted-server-common = { path = "../common" } diff --git a/crates/fastly/src/http_wrapper.rs b/crates/fastly/src/http_wrapper.rs new file mode 100644 index 0000000..9093bbc --- /dev/null +++ b/crates/fastly/src/http_wrapper.rs @@ -0,0 +1,49 @@ +use fastly::Request as FastlyRequest; +use http::header::{HeaderName, HeaderValue}; +use http::Method; +use std::net::IpAddr; + +use trusted_server_common::http_wrapper::RequestWrapper; + +#[derive(Debug)] +pub struct FastlyRequestWrapper { + request: FastlyRequest, +} + +impl FastlyRequestWrapper { + pub fn new(request: FastlyRequest) -> Self { + FastlyRequestWrapper { request } + } +} + +impl RequestWrapper for FastlyRequestWrapper { + #[inline(always)] + fn get_client_ip_addr(&self) -> Option { + self.request.get_client_ip_addr() + } + + #[inline(always)] + fn get_header(&self, name: HeaderName) -> Option<&HeaderValue> { + self.request.get_header(name) + } + + #[inline(always)] + fn get_headers(&self) -> impl Iterator { + self.request.get_headers() + } + + #[inline(always)] + fn get_method(&self) -> &Method { + self.request.get_method() + } + + #[inline(always)] + fn get_path(&self) -> &str { + self.request.get_path() + } + + #[inline(always)] + fn set_header(&mut self, name: HeaderName, value: HeaderValue) { + self.request.set_header(name, value) + } +} diff --git a/src/main.rs b/crates/fastly/src/main.rs similarity index 86% rename from src/main.rs rename to crates/fastly/src/main.rs index 8abde4e..059f8ec 100644 --- a/src/main.rs +++ b/crates/fastly/src/main.rs @@ -1,23 +1,22 @@ use fastly::http::{header, Method, StatusCode}; use fastly::KVStore; use fastly::{Error, Request, Response}; +use http::header::HeaderValue; use log::LevelFilter::Info; use serde_json::json; +use trusted_server_common::http_wrapper::RequestWrapper; use std::env; -mod constants; -mod cookies; -use constants::{SYNTHETIC_HEADER_FRESH, SYNTHETIC_HEADER_POTSI}; -mod models; -use models::AdResponse; -mod prebid; -use prebid::PrebidRequest; -mod settings; -use settings::Settings; -mod synthetic; -use synthetic::generate_synthetic_id; -mod templates; -use templates::HTML_TEMPLATE; +use trusted_server_common::constants::{HEADER_X_FORWARDED_FOR, HEADER_SYNTHETIC_FRESH, HEADER_SYNTHETIC_TRUSTED_SERVER}; +use trusted_server_common::cookies::create_synthetic_cookie; +use trusted_server_common::models::AdResponse; +use trusted_server_common::prebid::PrebidRequest; +use trusted_server_common::settings::Settings; +use trusted_server_common::synthetic::{generate_synthetic_id, get_or_generate_synthetic_id}; +use trusted_server_common::templates::HTML_TEMPLATE; + +pub mod http_wrapper; +use crate::http_wrapper::FastlyRequestWrapper; #[fastly::main] fn main(req: Request) -> Result { @@ -41,7 +40,7 @@ fn main(req: Request) -> Result { }) } -fn handle_main_page(settings: &Settings, req: Request) -> Result { +fn handle_main_page(settings: &Settings, req: T) -> Result { println!( "Using ad_partner_url: {}, counter_store: {}", settings.ad_server.ad_partner_url, settings.synthetic.counter_store, @@ -50,33 +49,30 @@ fn handle_main_page(settings: &Settings, req: Request) -> Result Result Result { +fn handle_ad_request(settings: &Settings, req: T) -> Result { // Log headers for debugging let client_ip = req .get_client_ip_addr() .map(|ip| ip.to_string()) .unwrap_or_else(|| "Unknown".to_string()); let x_forwarded_for = req - .get_header("x-forwarded-for") + .get_header(HEADER_X_FORWARDED_FOR) .map(|h| h.to_str().unwrap_or("Unknown")); println!("Client IP: {}", client_ip); @@ -301,25 +297,25 @@ fn handle_ad_request(settings: &Settings, req: Request) -> Result Result { +async fn handle_prebid_test(settings: &Settings, mut req: T) -> Result { println!("Starting prebid test request handling"); // Calculate fresh ID - let fresh_id = synthetic::generate_synthetic_id(settings, &req); + let fresh_id = generate_synthetic_id(settings, &req); - // Check for existing POTSI ID in same order as handle_main_page - let synthetic_id = synthetic::get_or_generate_synthetic_id(settings, &req); + // Check for existing Synthetic ID in same order as handle_main_page + let synthetic_id = get_or_generate_synthetic_id(settings, &req); println!( "Existing POTSI header: {:?}", - req.get_header(SYNTHETIC_HEADER_POTSI) + req.get_header(HEADER_SYNTHETIC_TRUSTED_SERVER) ); println!("Generated Fresh ID: {}", fresh_id); println!("Using POTSI ID: {}", synthetic_id); // Set both IDs as headers - req.set_header(SYNTHETIC_HEADER_FRESH, &fresh_id); - req.set_header(SYNTHETIC_HEADER_POTSI, &synthetic_id); + req.set_header(HEADER_SYNTHETIC_FRESH, HeaderValue::from_str(&fresh_id).unwrap()); + req.set_header(HEADER_SYNTHETIC_TRUSTED_SERVER, HeaderValue::from_str(&synthetic_id).unwrap()); println!("Using POTSI ID: {}, Fresh ID: {}", synthetic_id, fresh_id); diff --git a/fastly.toml b/fastly.toml index 486c673..ef175e5 100644 --- a/fastly.toml +++ b/fastly.toml @@ -6,12 +6,12 @@ cloned_from = "https://github.com/fastly/compute-starter-kit-rust-default" description = "aslk" language = "rust" manifest_version = 3 -name = "potsi" +name = "trusted-server-fastly" service_id = "q9waEnTgJfqQV1a0cYOuo3" [scripts] build = """ - cargo build --bin potsi --release --target wasm32-wasip1 --color always && + cargo build --bin trusted-server-fastly --release --target wasm32-wasip1 --color always && ln -fs wasm32-wasip1 target/wasm32-wasi """ diff --git a/src/constants.rs b/src/constants.rs deleted file mode 100644 index 106d454..0000000 --- a/src/constants.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub const SYNTHETIC_HEADER_FRESH: &str = "X-Synthetic-Fresh"; -pub const SYNTHETIC_HEADER_POTSI: &str = "X-Synthetic-Potsi"; -pub const SYNTHETIC_HEADER_PUB_USER_ID: &str = "X-Pub-User-ID"; diff --git a/potsi.toml b/trusted-server.toml similarity index 95% rename from potsi.toml rename to trusted-server.toml index ae26266..7e75ae4 100644 --- a/potsi.toml +++ b/trusted-server.toml @@ -8,7 +8,7 @@ server_url = "http://68.183.113.79:8000/openrtb2/auction" [synthetic] counter_store = "jevans_synth_id_counter" opid_store = "jevans_synth_id_opid" -secret_key = "potsi" +secret_key = "trusted-server" # Possible values # - "client_ip" # - "user_agent"