From ba00afab41d546b5cc52898206fab6d723607606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Wo=C5=BAniak?= Date: Tue, 20 Dec 2022 15:34:20 +0100 Subject: [PATCH] Tokens manager --- .env | 1 + Cargo.lock | 689 +++++------------- Cargo.toml | 2 +- crates/account_manager/Cargo.toml | 32 +- .../account_manager/src/bin/account-client.rs | 1 - crates/account_manager/src/main.rs | 28 +- crates/api/Cargo.toml | 78 +- crates/api/src/main.rs | 2 +- crates/cart_manager/Cargo.toml | 29 +- crates/cart_manager/src/main.rs | 25 +- crates/channels/Cargo.toml | 21 +- crates/channels/src/carts.rs | 4 +- crates/channels/src/lib.rs | 2 + crates/channels/src/payments.rs | 20 +- crates/channels/src/tokens.rs | 97 +++ crates/config/Cargo.toml | 18 +- crates/config/src/lib.rs | 167 +++-- crates/database_manager/Cargo.toml | 30 +- crates/db-seed/Cargo.toml | 20 +- crates/db-utils/Cargo.toml | 4 +- crates/email_manager/Cargo.toml | 29 +- crates/email_manager/src/main.rs | 27 +- crates/fs_manager/Cargo.toml | 20 +- crates/lang_provider/Cargo.toml | 11 +- crates/model/Cargo.toml | 25 +- crates/order_manager/Cargo.toml | 24 +- crates/order_manager/src/main.rs | 1 + crates/payment_adapter/Cargo.toml | 10 +- crates/payment_adapter/src/lib.rs | 23 +- crates/payment_adapter_pay_u/Cargo.lock | 276 +++++++ crates/payment_adapter_pay_u/Cargo.toml | 18 +- crates/payment_manager/Cargo.toml | 43 +- crates/payment_manager/src/main.rs | 354 +++++---- crates/payment_manager/src/rpc.rs | 127 +++- crates/search_manager/Cargo.toml | 37 +- crates/search_manager/src/main.rs | 26 +- crates/stock_manager/Cargo.toml | 33 +- crates/stock_manager/src/main.rs | 2 + crates/token_manager/Cargo.toml | 49 +- .../migrations/202204131841_init.sql | 27 + crates/token_manager/src/context.rs | 0 crates/token_manager/src/db/mod.rs | 28 + crates/token_manager/src/lib.rs | 641 ---------------- crates/token_manager/src/main.rs | 570 +++++++++++++++ crates/web/Cargo.toml | 20 +- scripts/migrate.sh | 4 + 46 files changed, 1893 insertions(+), 1802 deletions(-) create mode 100644 crates/channels/src/tokens.rs create mode 100644 crates/token_manager/migrations/202204131841_init.sql create mode 100644 crates/token_manager/src/context.rs create mode 100644 crates/token_manager/src/db/mod.rs delete mode 100644 crates/token_manager/src/lib.rs create mode 100644 crates/token_manager/src/main.rs diff --git a/.env b/.env index f0a8719..f256875 100644 --- a/.env +++ b/.env @@ -4,6 +4,7 @@ ACCOUNT_DATABASE_URL=postgres://postgres@localhost/bazzar_accounts CART_DATABASE_URL=postgres://postgres@localhost/bazzar_carts STOCK_DATABASE_URL=postgres://postgres@localhost/bazzar_stocks ORDER_DATABASE_URL=postgres://postgres@localhost/bazzar_orders +TOKEN_DATABASE_URL=postgres://postgres@localhost/bazzar_tokens PASS_SALT=18CHwV7eGFAea16z+qMKZg RUST_LOG=debug diff --git a/Cargo.lock b/Cargo.lock index 0d97b49..47231ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12,12 +12,10 @@ dependencies = [ "config", "dotenv", "fake", - "futures 0.3.25", + "futures", "gumdrop", "json", "model", - "opentelemetry 0.17.0", - "opentelemetry-jaeger", "rumqttc", "serde", "sqlx", @@ -27,8 +25,6 @@ dependencies = [ "thiserror", "tokio 1.23.0", "tracing", - "tracing-opentelemetry", - "tracing-subscriber", ] [[package]] @@ -83,7 +79,7 @@ dependencies = [ "actix-service", "actix-utils", "ahash", - "base64", + "base64 0.13.1", "bitflags", "brotli", "bytes 1.3.0", @@ -96,7 +92,7 @@ dependencies = [ "http", "httparse", "httpdate 1.0.2", - "itoa 1.0.4", + "itoa 1.0.5", "language-tags", "local-channel", "mime", @@ -207,7 +203,7 @@ dependencies = [ "futures-core", "futures-util", "http", - "itoa 1.0.4", + "itoa 1.0.5", "language-tags", "log", "mime", @@ -322,9 +318,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.66" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" +checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61" [[package]] name = "argon2" @@ -346,9 +342,9 @@ checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" [[package]] name = "async-trait" -version = "0.1.59" +version = "0.1.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6e93155431f3931513b243d371981bb2770112b370c82745a1d19d2f99364" +checksum = "677d1d8ab452a3936018a687b20e6f7cf5363d713b732b8884001317b0e48aa3" dependencies = [ "proc-macro2", "quote", @@ -373,12 +369,6 @@ dependencies = [ "autocfg 1.1.0", ] -[[package]] -name = "atomic_immut" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b9fcea66a65a49890058406499cca8906e4e9cd1173bfeb272dcd2ac603e4fa" - [[package]] name = "atty" version = "0.2.14" @@ -411,6 +401,12 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "base64" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ea22880d78093b0cbe17c89f64a7d457941e65759157ec6cb31a31d652b05e5" + [[package]] name = "base64ct" version = "1.5.3" @@ -451,9 +447,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "blake2" -version = "0.10.5" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b12e5fd123190ce1c2e559308a94c9bacad77907d4c6005d9e58fe1a0689e55e" +checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" dependencies = [ "digest", ] @@ -569,16 +565,6 @@ dependencies = [ "syn", ] -[[package]] -name = "bytecodec" -version = "0.4.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adf4c9d0bbf32eea58d7c0f812058138ee8edaf0f2802b6d03561b504729a325" -dependencies = [ - "byteorder", - "trackable 0.2.24", -] - [[package]] name = "byteorder" version = "1.4.3" @@ -680,11 +666,8 @@ dependencies = [ "config", "dotenv", "fake", - "futures 0.3.25", + "futures", "model", - "opentelemetry 0.17.0", - "opentelemetry-jaeger", - "pretty_env_logger", "rumqttc", "serde", "sqlx", @@ -694,16 +677,14 @@ dependencies = [ "thiserror", "tokio 1.23.0", "tracing", - "tracing-opentelemetry", - "tracing-subscriber", "uuid 0.8.2", ] [[package]] name = "cc" -version = "1.0.77" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4" +checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" dependencies = [ "jobserver", ] @@ -727,7 +708,7 @@ dependencies = [ "bincode", "bytes 1.3.0", "config", - "futures 0.3.25", + "futures", "model", "payment_adapter", "rumqttc", @@ -802,6 +783,8 @@ dependencies = [ "serde_json", "thiserror", "toml", + "tracing-subscriber", + "tracing-timing", ] [[package]] @@ -836,11 +819,11 @@ checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" [[package]] name = "cookie" -version = "0.16.1" +version = "0.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "344adc371239ef32293cb1c4fe519592fcf21206c79c02854320afcdf3ab4917" +checksum = "e859cd57d0710d9e06c381b550c06e76992472a8c6d527aecd2fc673dcc231fb" dependencies = [ - "base64", + "base64 0.20.0", "hmac", "percent-encoding", "rand 0.8.5", @@ -1100,9 +1083,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.83" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdf07d07d6531bfcdbe9b8b739b104610c6508dcc4d63b410585faf338241daf" +checksum = "5add3fc1717409d029b20c5b6903fc0c0b02fa6741d820054f4a2efa5e5816fd" dependencies = [ "cc", "cxxbridge-flags", @@ -1112,9 +1095,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.83" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2eb5b96ecdc99f72657332953d4d9c50135af1bac34277801cc3937906ebd39" +checksum = "b4c87959ba14bc6fbc61df77c3fcfe180fc32b93538c4f1031dd802ccb5f2ff0" dependencies = [ "cc", "codespan-reporting", @@ -1127,15 +1110,15 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.83" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac040a39517fd1674e0f32177648334b0f4074625b5588a64519804ba0553b12" +checksum = "69a3e162fde4e594ed2b07d0f83c6c67b745e7f28ce58c6df5e6b6bef99dfb59" [[package]] name = "cxxbridge-macro" -version = "1.0.83" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1362b0ddcfc4eb0a1f57b68bd77dd99f0e826958a96abd0ae9bd092e114ffed6" +checksum = "3e7e2adeb6a0d4a282e581096b06e1791532b7d576dcde5ccd9382acf55db8e6" dependencies = [ "proc-macro2", "quote", @@ -1183,30 +1166,6 @@ version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23d8666cb01533c39dde32bcbab8e227b4ed6679b2c925eba05feabea39508fb" -[[package]] -name = "database_manager" -version = "0.1.0" -dependencies = [ - "actix", - "actix-rt", - "async-trait", - "chrono", - "config", - "fake", - "itertools 0.10.5", - "model", - "pretty_env_logger", - "rand 0.8.5", - "rumqttc", - "serde", - "sqlx", - "sqlx-core", - "testx", - "thiserror", - "tracing", - "uuid 1.2.2", -] - [[package]] name = "db-utils" version = "0.1.0" @@ -1234,7 +1193,7 @@ dependencies = [ "convert_case", "proc-macro2", "quote", - "rustc_version 0.4.0", + "rustc_version", "syn", ] @@ -1310,6 +1269,12 @@ dependencies = [ "syn", ] +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + [[package]] name = "dotenv" version = "0.15.0" @@ -1355,8 +1320,6 @@ checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" name = "email_manager" version = "0.1.0" dependencies = [ - "actix", - "actix-rt", "channels", "chrono", "config", @@ -1364,9 +1327,6 @@ dependencies = [ "fake", "handlebars", "model", - "opentelemetry 0.17.0", - "opentelemetry-jaeger", - "pretty_env_logger", "rumqttc", "sendgrid", "serde", @@ -1376,8 +1336,6 @@ dependencies = [ "thiserror", "tokio 1.23.0", "tracing", - "tracing-opentelemetry", - "tracing-subscriber", "uuid 0.8.2", ] @@ -1412,23 +1370,10 @@ dependencies = [ "num-traits", "proc-macro2", "quote", - "rustc_version 0.4.0", + "rustc_version", "syn", ] -[[package]] -name = "env_logger" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" -dependencies = [ - "atty", - "humantime 1.3.0", - "log", - "regex", - "termcolor", -] - [[package]] name = "env_logger" version = "0.9.3" @@ -1436,7 +1381,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" dependencies = [ "atty", - "humantime 2.1.0", + "humantime", "log", "regex", "termcolor", @@ -1469,12 +1414,6 @@ version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" -[[package]] -name = "factory" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73a3579e5ac964dd11bed8ba3932ee51b48ce652ee12e49c61a78a268bbc9b2c" - [[package]] name = "fake" version = "2.5.0" @@ -1516,56 +1455,13 @@ dependencies = [ "instant", ] -[[package]] -name = "fibers" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cce97d737d7eda3d2e8a907892b4c4fdd3857cb6f18b58047645011c5a0b46e7" -dependencies = [ - "futures 0.1.31", - "mio 0.6.23", - "nbchan", - "num_cpus", - "splay_tree", -] - -[[package]] -name = "fibers_rpc" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56413f3c95f2a93aaf579d1f549ac4043b8a2ed5f37e7fd5d3d32be58ef88691" -dependencies = [ - "atomic_immut", - "bytecodec", - "byteorder", - "factory", - "fibers", - "fibers_tasque", - "futures 0.1.31", - "prometrics", - "slog", - "trackable 0.2.24", -] - -[[package]] -name = "fibers_tasque" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "504278fcd15ae0c70acf6dcf85c8b4e16cb0c8e71f7d8a0ef8d560b116f21cac" -dependencies = [ - "fibers", - "futures 0.1.31", - "lazy_static", - "tasque", -] - [[package]] name = "file-per-thread-logger" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21e16290574b39ee41c71aeb90ae960c504ebaf1e2a1c87bd52aa56ed6e1a02f" dependencies = [ - "env_logger 0.9.3", + "env_logger", "log", ] @@ -1695,27 +1591,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" -[[package]] -name = "fs_manager" -version = "0.1.0" -dependencies = [ - "actix", - "actix-rt", - "actix-web", - "bytes 1.3.0", - "chrono", - "config", - "fibers_rpc", - "model", - "pretty_env_logger", - "rumqttc", - "serde", - "thiserror", - "tokio 1.23.0", - "tracing", - "uuid 1.2.2", -] - [[package]] name = "fuchsia-cprng" version = "0.1.1" @@ -1738,12 +1613,6 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -[[package]] -name = "futures" -version = "0.1.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678" - [[package]] name = "futures" version = "0.3.25" @@ -2054,6 +1923,20 @@ dependencies = [ "hashbrown 0.12.3", ] +[[package]] +name = "hdrhistogram" +version = "7.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f19b9f54f7c7f55e31401bb647626ce0cf0f67b0004982ce815b3ee72a02aa8" +dependencies = [ + "base64 0.13.1", + "byteorder", + "crossbeam-channel", + "flate2", + "nom", + "num-traits", +] + [[package]] name = "heck" version = "0.3.3" @@ -2122,7 +2005,7 @@ checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" dependencies = [ "bytes 1.3.0", "fnv", - "itoa 1.0.4", + "itoa 1.0.5", ] [[package]] @@ -2164,15 +2047,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" -[[package]] -name = "humantime" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" -dependencies = [ - "quick-error", -] - [[package]] name = "humantime" version = "2.1.0" @@ -2218,7 +2092,7 @@ dependencies = [ "http-body 0.4.5", "httparse", "httpdate 1.0.2", - "itoa 1.0.4", + "itoa 1.0.5", "pin-project-lite 0.2.9", "socket2 0.4.7", "tokio 1.23.0", @@ -2329,9 +2203,9 @@ dependencies = [ [[package]] name = "insta" -version = "1.22.0" +version = "1.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "197f4e300af8b23664d4077bf5c40e0afa9ba66a567bb5a51d3def3c7b287d1c" +checksum = "e48b08a091dfe5b09a6a9688c468fdd5b4396e92ce09e2eb932f0884b02788a4" dependencies = [ "console", "lazy_static", @@ -2349,12 +2223,6 @@ dependencies = [ "cfg-if 1.0.0", ] -[[package]] -name = "integer-encoding" -version = "3.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bb03732005da905c88227371639bf1ad885cc712789c011c31c5fb3ab3ccf02" - [[package]] name = "intl-memoizer" version = "0.5.1" @@ -2415,9 +2283,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec947b7a4ce12e3b87e353abae7ce124d025b6c7d6c5aea5cc0bcf92e9510ded" +checksum = "11b0d96e660696543b251e58030cf9787df56da39dab19ad60eae7353040917e" [[package]] name = "ipnetwork" @@ -2463,9 +2331,9 @@ checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" [[package]] name = "itoa" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" +checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" [[package]] name = "ittapi" @@ -2517,7 +2385,7 @@ version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6204285f77fe7d9784db3fdc449ecce1a0114927a51d5a41c4c7a292011c015f" dependencies = [ - "base64", + "base64 0.13.1", "crypto-common", "digest", "hmac", @@ -2540,12 +2408,9 @@ dependencies = [ name = "lang_provider" version = "0.1.0" dependencies = [ - "actix", - "actix-rt", "config", "fluent", "model", - "pretty_env_logger", "rumqttc", "thiserror", "tracing", @@ -2611,9 +2476,9 @@ dependencies = [ [[package]] name = "link-cplusplus" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369" +checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5" dependencies = [ "cc", ] @@ -2632,9 +2497,9 @@ checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d" [[package]] name = "linux-raw-sys" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f9f08d8963a6c613f4b1a78f4f4a4dbfadf8e6545b2d72861731e4858b8b47f" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" [[package]] name = "llvmenv" @@ -2645,7 +2510,7 @@ dependencies = [ "bytes 0.5.6", "dirs 3.0.2", "fs_extra", - "futures 0.3.25", + "futures", "glob", "indicatif", "itertools 0.9.0", @@ -2920,12 +2785,6 @@ dependencies = [ "tempfile", ] -[[package]] -name = "nbchan" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b1d61edb4e941c69f2a74782b3dc4a388adeab2d8cc1fe29e8ef8d2a7f9760" - [[package]] name = "net2" version = "0.2.38" @@ -2950,12 +2809,6 @@ dependencies = [ "memoffset 0.6.5", ] -[[package]] -name = "nom" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf51a729ecf40266a2368ad335a5fdde43471f545a967109cd62146ecf8b66ff" - [[package]] name = "nom" version = "7.1.1" @@ -3104,74 +2957,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "opentelemetry" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69d6c3d7288a106c0a363e4b0e8d308058d56902adefb16f4936f417ffef086e" -dependencies = [ - "opentelemetry_api", - "opentelemetry_sdk", -] - -[[package]] -name = "opentelemetry-jaeger" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e785d273968748578931e4dc3b4f5ec86b26e09d9e0d66b55adda7fce742f7a" -dependencies = [ - "async-trait", - "futures 0.3.25", - "futures-executor", - "once_cell", - "opentelemetry 0.18.0", - "opentelemetry-semantic-conventions", - "thiserror", - "thrift", -] - -[[package]] -name = "opentelemetry-semantic-conventions" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b02e0230abb0ab6636d18e2ba8fa02903ea63772281340ccac18e0af3ec9eeb" -dependencies = [ - "opentelemetry 0.18.0", -] - -[[package]] -name = "opentelemetry_api" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c24f96e21e7acc813c7a8394ee94978929db2bcc46cf6b5014fc612bf7760c22" -dependencies = [ - "futures-channel", - "futures-util", - "indexmap", - "js-sys", - "once_cell", - "pin-project-lite 0.2.9", - "thiserror", -] - -[[package]] -name = "opentelemetry_sdk" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ca41c4933371b61c2a2f214bf16931499af4ec90543604ec828f7a625c09113" -dependencies = [ - "async-trait", - "crossbeam-channel", - "futures-channel", - "futures-executor", - "futures-util", - "once_cell", - "opentelemetry_api", - "percent-encoding", - "rand 0.8.5", - "thiserror", -] - [[package]] name = "order_manager" version = "0.1.0" @@ -3182,8 +2967,6 @@ dependencies = [ "db-utils", "fake", "model", - "opentelemetry 0.17.0", - "opentelemetry-jaeger", "rumqttc", "serde", "sqlx", @@ -3193,20 +2976,9 @@ dependencies = [ "thiserror", "tokio 1.23.0", "tracing", - "tracing-opentelemetry", - "tracing-subscriber", "uuid 1.2.2", ] -[[package]] -name = "ordered-float" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3305af35278dd29f46fcdd139e0b1fbfae2153f0e5928b39b035542dd31e37b7" -dependencies = [ - "num-traits", -] - [[package]] name = "overload" version = "0.1.1" @@ -3221,7 +2993,7 @@ checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" dependencies = [ "instant", "lock_api", - "parking_lot_core 0.8.5", + "parking_lot_core 0.8.6", ] [[package]] @@ -3236,9 +3008,9 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" dependencies = [ "cfg-if 1.0.0", "instant", @@ -3274,16 +3046,16 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1" +checksum = "d01a5bd0424d00070b0098dd17ebca6f961a959dead1dbcbbbc1d1cd8d3deeba" [[package]] name = "payment_adapter" version = "0.1.0" dependencies = [ "config", - "futures 0.3.25", + "futures", "model", "serde", "thiserror", @@ -3304,8 +3076,6 @@ dependencies = [ "gumdrop", "llvmenv", "model", - "opentelemetry 0.17.0", - "opentelemetry-jaeger", "payment_adapter", "reqwest 0.11.13", "rumqttc", @@ -3317,8 +3087,6 @@ dependencies = [ "thiserror", "tokio 1.23.0", "tracing", - "tracing-opentelemetry", - "tracing-subscriber", "uuid 1.2.2", "wapc", "wapc-codec", @@ -3433,16 +3201,6 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" -[[package]] -name = "pretty_env_logger" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "926d36b9553851b8b0005f1275891b392ee4d2d833852c417ed025477350fb9d" -dependencies = [ - "env_logger 0.7.1", - "log", -] - [[package]] name = "proc-macro-crate" version = "0.1.5" @@ -3478,38 +3236,13 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.47" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" +checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" dependencies = [ "unicode-ident", ] -[[package]] -name = "procinfo" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ab1427f3d2635891f842892dda177883dca0639e05fe66796a62c9d2f23b49c" -dependencies = [ - "byteorder", - "libc", - "nom 2.2.1", - "rustc_version 0.2.3", -] - -[[package]] -name = "prometrics" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8794f06bb51baa428e62af268ccdda6f40254f742234cdfb80cf4ad84890b38f" -dependencies = [ - "atomic_immut", - "lazy_static", - "libc", - "procinfo", - "trackable 0.2.24", -] - [[package]] name = "psm" version = "0.1.21" @@ -3540,16 +3273,26 @@ dependencies = [ ] [[package]] -name = "quick-error" -version = "1.2.3" +name = "quanta" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" +checksum = "20afe714292d5e879d8b12740aa223c6a88f118af41870e8b6196e39a02238a8" +dependencies = [ + "crossbeam-utils", + "libc", + "mach", + "once_cell", + "raw-cpuid", + "wasi 0.10.0+wasi-snapshot-preview1", + "web-sys", + "winapi 0.3.9", +] [[package]] name = "quote" -version = "1.0.21" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" dependencies = [ "proc-macro2", ] @@ -3714,12 +3457,20 @@ dependencies = [ ] [[package]] -name = "rayon" -version = "1.6.0" +name = "raw-cpuid" +version = "10.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e060280438193c554f654141c9ea9417886713b7acd75974c85b18a69a88e0b" +checksum = "a6823ea29436221176fe662da99998ad3b4db2c7f31e7b6f5fe43adccd6320bb" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rayon" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db3a213adf02b3bcfd2d3846bb41cb22857d131789e01df434fb7e7bc0759b7" dependencies = [ - "crossbeam-deque", "either", "rayon-core", ] @@ -3827,7 +3578,7 @@ version = "0.10.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0718f81a8e14c4dbb3b34cf23dc6aaf9ab8a0dfec160c534b3dbca1aaa21f47c" dependencies = [ - "base64", + "base64 0.13.1", "bytes 0.5.6", "encoding_rs", "futures-core", @@ -3862,7 +3613,7 @@ version = "0.11.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68cc60575865c7831548863cc02356512e3f1dc2f3f82cb837d7fc4cc8f3c97c" dependencies = [ - "base64", + "base64 0.13.1", "bytes 1.3.0", "encoding_rs", "futures-core", @@ -3963,7 +3714,7 @@ checksum = "1514bbc994fc9f36ab7f7ae067b3e4758c717aff7a06c4818c6787cad8b086e1" dependencies = [ "bytes 1.3.0", "flume", - "futures 0.3.25", + "futures", "log", "pollster", "rustls-native-certs", @@ -4013,22 +3764,13 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver 0.9.0", -] - [[package]] name = "rustc_version" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.14", + "semver 1.0.16", ] [[package]] @@ -4040,7 +3782,7 @@ dependencies = [ "bitflags", "errno", "io-lifetimes 0.7.5", - "itoa 1.0.4", + "itoa 1.0.5", "libc", "linux-raw-sys 0.0.46", "once_cell", @@ -4057,7 +3799,7 @@ dependencies = [ "errno", "io-lifetimes 1.0.3", "libc", - "linux-raw-sys 0.1.3", + "linux-raw-sys 0.1.4", "windows-sys 0.42.0", ] @@ -4091,7 +3833,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ee86d63972a7c661d1536fefe8c3c8407321c3df668891286de28abcd087360" dependencies = [ - "base64", + "base64 0.13.1", ] [[package]] @@ -4100,14 +3842,14 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0864aeff53f8c05aa08d86e5ef839d3dfcf07aeba2db32f12db0ef716e87bd55" dependencies = [ - "base64", + "base64 0.13.1", ] [[package]] name = "rustversion" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8" +checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70" [[package]] name = "rusty-money" @@ -4126,7 +3868,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33a01b7876355018cbcc41204d38ff70227950dd3cd6fe3f4f52a10474b1a2de" dependencies = [ "crossbeam-channel", - "futures 0.3.25", + "futures", "futures-channel", "futures-executor", "num_cpus", @@ -4134,9 +3876,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" +checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" [[package]] name = "schannel" @@ -4156,9 +3898,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "scratch" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" +checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2" [[package]] name = "sct" @@ -4188,12 +3930,9 @@ dependencies = [ "derive_more", "dotenv", "fake", - "futures 0.3.25", + "futures", "model", - "opentelemetry 0.17.0", - "opentelemetry-jaeger", "parking_lot 0.12.1", - "pretty_env_logger", "rumqttc", "serde", "sonic-channel", @@ -4202,8 +3941,6 @@ dependencies = [ "thiserror", "tokio 1.23.0", "tracing", - "tracing-opentelemetry", - "tracing-subscriber", "uuid 1.2.2", "whatlang", ] @@ -4241,7 +3978,7 @@ dependencies = [ "cookie", "dbg", "enclose", - "futures 0.3.25", + "futures", "getrandom", "gloo-file", "gloo-timers", @@ -4264,35 +4001,20 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ef965a420fe14fdac7dd018862966a4c14094f900e1650bbc71ddd7d580c8af" -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser 0.7.0", -] - [[package]] name = "semver" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" dependencies = [ - "semver-parser 0.10.2", + "semver-parser", ] [[package]] name = "semver" -version = "1.0.14" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" - -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +checksum = "58bc9567378fc7690d6b2addae4e60ac2eeea07becb2c64b9f218b53865cba2a" [[package]] name = "semver-parser" @@ -4319,9 +4041,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.149" +version = "1.0.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "256b9932320c590e707b94576e3cc1f7c9024d0ee6612dfbcf1cb106cbe8e055" +checksum = "97fed41fc1a24994d044e6db6935e69511a1153b52c15eb42493b26fa87feba0" dependencies = [ "serde_derive", ] @@ -4339,9 +4061,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.149" +version = "1.0.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4eae9b04cbffdfd550eb462ed33bc6a1b68c935127d008b27444d08380f94e4" +checksum = "255abe9a125a985c05190d687b320c12f9b1f0b99445e608c21ba0782c719ad8" dependencies = [ "proc-macro2", "quote", @@ -4350,11 +4072,11 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.89" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db" +checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" dependencies = [ - "itoa 1.0.4", + "itoa 1.0.5", "ryu", "serde", ] @@ -4366,7 +4088,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" dependencies = [ "form_urlencoded", - "itoa 1.0.4", + "itoa 1.0.5", "ryu", "serde", ] @@ -4467,12 +4189,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03b634d87b960ab1a38c4fe143b508576f075e7c978bfad18217645ebfdfa2ec" -[[package]] -name = "slog" -version = "2.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8347046d4ebd943127157b94d63abb990fcf729dc4e9978927fdf4ac3c998d06" - [[package]] name = "smallvec" version = "1.10.0" @@ -4525,12 +4241,6 @@ dependencies = [ "lock_api", ] -[[package]] -name = "splay_tree" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "309dee0d93c0a8f7a852cbd9a86e01e1a94781b64d98d86a191f4af7f095ecc1" - [[package]] name = "sqlformat" version = "0.2.0" @@ -4538,7 +4248,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f87e292b4291f154971a43c3774364e2cbcaec599d3f5bf6fa9d122885dbc38a" dependencies = [ "itertools 0.10.5", - "nom 7.1.1", + "nom", "unicode_categories", ] @@ -4560,7 +4270,7 @@ checksum = "dcbc16ddba161afc99e14d1713a453747a2b07fc097d2009f4c300ec99286105" dependencies = [ "ahash", "atoi", - "base64", + "base64 0.13.1", "bigdecimal", "bit-vec", "bitflags", @@ -4585,7 +4295,7 @@ dependencies = [ "hmac", "indexmap", "ipnetwork", - "itoa 1.0.4", + "itoa 1.0.5", "libc", "log", "mac_address", @@ -4670,12 +4380,9 @@ dependencies = [ "derive_more", "dotenv", "fakeit", - "futures 0.3.25", + "futures", "insta", "model", - "opentelemetry 0.17.0", - "opentelemetry-jaeger", - "pretty_env_logger", "rumqttc", "serde", "sqlx", @@ -4685,8 +4392,6 @@ dependencies = [ "thiserror", "tokio 1.23.0", "tracing", - "tracing-opentelemetry", - "tracing-subscriber", "uuid 1.2.2", ] @@ -4766,9 +4471,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.105" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908" +checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" dependencies = [ "proc-macro2", "quote", @@ -4816,9 +4521,9 @@ checksum = "71a98cc1a0a9013e8df3900d09c597dd65cfc6ea4d42968629b1b9ea949acf8f" dependencies = [ "anyhow", "fnv", - "futures 0.3.25", - "humantime 2.1.0", - "opentelemetry 0.17.0", + "futures", + "humantime", + "opentelemetry", "pin-project", "rand 0.8.5", "serde", @@ -4843,16 +4548,6 @@ dependencies = [ "syn", ] -[[package]] -name = "tasque" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38095001d1ebb11e772cf2b61b09c3aa657722088ac31474695298d227755753" -dependencies = [ - "num_cpus", - "prometrics", -] - [[package]] name = "tempfile" version = "3.3.0" @@ -4901,18 +4596,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.37" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" +checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.37" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" +checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" dependencies = [ "proc-macro2", "quote", @@ -4928,28 +4623,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "threadpool" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" -dependencies = [ - "num_cpus", -] - -[[package]] -name = "thrift" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09678c4cdbb4eed72e18b7c2af1329c69825ed16fcbac62d083fc3e2b0590ff0" -dependencies = [ - "byteorder", - "integer-encoding", - "log", - "ordered-float", - "threadpool", -] - [[package]] name = "time" version = "0.1.45" @@ -4967,7 +4640,7 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376" dependencies = [ - "itoa 1.0.4", + "itoa 1.0.5", "serde", "time-core", "time-macros", @@ -5016,26 +4689,27 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" name = "token_manager" version = "0.1.0" dependencies = [ - "actix", - "actix-rt", "argon2", + "channels", "chrono", "config", - "database_manager", + "db-utils", "derive_more", + "dotenv", "fake", - "futures 0.3.25", + "futures", "futures-util", "hmac", "jwt", "model", - "parking_lot 0.12.1", "password-hash", - "pretty_env_logger", "rand_core 0.6.4", "rumqttc", "serde", "sha2", + "sqlx", + "sqlx-core", + "tarpc", "testx", "thiserror", "tokio 1.23.0", @@ -5181,9 +4855,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.9" +version = "0.5.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" +checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f" dependencies = [ "serde", ] @@ -5256,10 +4930,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbbe89715c1dbbb790059e2565353978564924ee85017b5fff365c872ff6721f" dependencies = [ "once_cell", - "opentelemetry 0.17.0", + "opentelemetry", "tracing", "tracing-core", - "tracing-log", "tracing-subscriber", ] @@ -5282,32 +4955,20 @@ dependencies = [ ] [[package]] -name = "trackable" -version = "0.2.24" +name = "tracing-timing" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b98abb9e7300b9ac902cc04920945a874c1973e08c310627cc4458c04b70dd32" +checksum = "fbe4966d7b6ae25201de6ff9fa822afb0c9e933809187d5b82ad846ec108771b" dependencies = [ - "trackable 1.2.0", - "trackable_derive", -] - -[[package]] -name = "trackable" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "017e2a1a93718e4e8386d037cfb8add78f1d690467f4350fb582f55af1203167" -dependencies = [ - "trackable_derive", -] - -[[package]] -name = "trackable_derive" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebeb235c5847e2f82cfe0f07eb971d1e5f6804b18dac2ae16349cc604380f82f" -dependencies = [ - "quote", - "syn", + "crossbeam", + "doc-comment", + "fxhash", + "hdrhistogram", + "indexmap", + "quanta", + "slab", + "tracing-core", + "tracing-subscriber", ] [[package]] @@ -5372,9 +5033,9 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-ident" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" [[package]] name = "unicode-normalization" @@ -5721,7 +5382,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f37efc6945b08fcb634cffafc438dd299bac55a27c836954656c634d3e63c31" dependencies = [ "anyhow", - "base64", + "base64 0.13.1", "bincode", "directories-next", "file-per-thread-logger", @@ -5976,9 +5637,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.22.5" +version = "0.22.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368bfe657969fb01238bb756d351dcade285e0f6fcbd36dcb23359a5169975be" +checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" dependencies = [ "webpki", ] diff --git a/Cargo.toml b/Cargo.toml index 604d253..6d4a307 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ members = [ "crates/search_manager", "crates/stock_manager", "crates/token_manager", - "crates/fs_manager", +# "crates/fs_manager", "crates/lang_provider", "crates/payment_adapter", # "crates/payment_adapter_pay_u", diff --git a/crates/account_manager/Cargo.toml b/crates/account_manager/Cargo.toml index 8dd7e59..5d02284 100644 --- a/crates/account_manager/Cargo.toml +++ b/crates/account_manager/Cargo.toml @@ -8,28 +8,24 @@ name = "account-manager" path = "src/main.rs" [dependencies] -bincode = { version = "1.3.3" } -bytes = { version = "1.2.1" } +bincode = { version = "1" } +bytes = { version = "1" } channels = { path = "../channels" } config = { path = "../config" } -dotenv = { version = "0.15.0" } -futures = { version = "0.3.25" } -gumdrop = { version = "0.8.1" } -json = { version = "0.12.4" } +dotenv = { version = "0" } +futures = { version = "0" } +gumdrop = { version = "0" } +json = { version = "0" } model = { path = "../model", features = ['db'] } -opentelemetry = { version = "0.17.0" } -opentelemetry-jaeger = { version = "0.17.0" } rumqttc = { version = "*" } -serde = { version = "1.0.137", features = ["derive"] } -sqlx = { version = "0.6.2", features = ["migrate", "runtime-actix-rustls", "all-types", "postgres"] } -sqlx-core = { version = "0.6.2", features = [] } -tarpc = { version = "0.31.0", features = ["tokio1", "serde-transport-bincode", "serde-transport", "serde", "serde-transport-json", "tcp"] } -thiserror = { version = "1.0.31" } -tokio = { version = "1.21.2", features = ['full'] } -tracing = { version = "0.1.6" } -tracing-opentelemetry = { version = "0.17.4" } -tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } +serde = { version = "1", features = ["derive"] } +sqlx = { version = "0", features = ["migrate", "runtime-actix-rustls", "all-types", "postgres"] } +sqlx-core = { version = "0", features = [] } +tarpc = { version = "0", features = ["tokio1", "serde-transport-bincode", "serde-transport", "serde", "serde-transport-json", "tcp"] } +thiserror = { version = "1" } +tokio = { version = "1", features = ['full'] } +tracing = { version = "0" } [dev-dependencies] -fake = { version = "2.5.0" } +fake = { version = "2" } testx = { path = "../testx" } diff --git a/crates/account_manager/src/bin/account-client.rs b/crates/account_manager/src/bin/account-client.rs index a774a54..264421f 100644 --- a/crates/account_manager/src/bin/account-client.rs +++ b/crates/account_manager/src/bin/account-client.rs @@ -34,7 +34,6 @@ async fn main() -> std::io::Result<()> { // Let the background span processor finish. sleep(Duration::from_micros(1)).await; - opentelemetry::global::shutdown_tracer_provider(); Ok(()) } diff --git a/crates/account_manager/src/main.rs b/crates/account_manager/src/main.rs index 2b15f1b..5ee656d 100644 --- a/crates/account_manager/src/main.rs +++ b/crates/account_manager/src/main.rs @@ -1,11 +1,6 @@ #![feature(structural_match)] -use std::env; - use config::UpdateConfig; -use tracing_subscriber::fmt::format::FmtSpan; -use tracing_subscriber::layer::SubscriberExt; -use tracing_subscriber::util::SubscriberInitExt; pub mod actions; pub mod db; @@ -35,7 +30,7 @@ impl UpdateConfig for Opts {} #[tokio::main] async fn main() { dotenv::dotenv().ok(); - init_tracing("account-manager"); + config::init_tracing("account-manager"); let opts = Opts {}; @@ -46,24 +41,3 @@ async fn main() { let mqtt_client = mqtt::start(config.clone(), db.clone()).await; rpc::start(config.clone(), db.clone(), mqtt_client.clone()).await; } - -pub fn init_tracing(_service_name: &str) { - env::set_var("OTEL_BSP_MAX_EXPORT_BATCH_SIZE", "12"); - - let tracer = { - use opentelemetry::sdk::export::trace::stdout::new_pipeline; - use opentelemetry::sdk::trace::Config; - - new_pipeline() - .with_trace_config(Config::default()) - .with_pretty_print(true) - .install_simple() - }; - - tracing_subscriber::registry() - .with(tracing_subscriber::EnvFilter::from_default_env()) - .with(tracing_subscriber::fmt::layer().with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)) - .with(tracing_opentelemetry::layer().with_tracer(tracer)) - .try_init() - .unwrap(); -} diff --git a/crates/api/Cargo.toml b/crates/api/Cargo.toml index 20549ca..9e83ddf 100644 --- a/crates/api/Cargo.toml +++ b/crates/api/Cargo.toml @@ -4,52 +4,50 @@ version = "0.1.0" edition = "2021" [dependencies] -actix = { version = "0.13", features = [] } -actix-broker = { version = "0.4", features = [] } -actix-cors = { version = "0.6", features = [] } -actix-files = { version = "0.6", features = [] } -actix-identity = { version = "0.4", features = [] } -actix-multipart = { version = "0.4", features = [] } -actix-redis = { version = "0.11", features = [] } -actix-rt = { version = "2.7", features = [] } -actix-session = { version = "0.6", features = ["actix-redis", "redis-actor-session"] } -actix-web = { version = "4.0", features = [] } -actix-web-httpauth = { version = "0.6", features = [] } -actix-web-opentelemetry = { version = "0.12", features = [] } -async-trait = { version = "0.1", features = [] } -bytes = { version = "1.1.0" } +actix = { version = "0", features = [] } +actix-broker = { version = "0", features = [] } +actix-cors = { version = "0", features = [] } +actix-files = { version = "0", features = [] } +actix-identity = { version = "0", features = [] } +actix-multipart = { version = "0", features = [] } +actix-redis = { version = "0", features = [] } +actix-rt = { version = "2", features = [] } +actix-session = { version = "0", features = ["actix-redis", "redis-actor-session"] } +actix-web = { version = "4", features = [] } +actix-web-httpauth = { version = "0", features = [] } +actix-web-opentelemetry = { version = "0", features = [] } +async-trait = { version = "0", features = [] } +bytes = { version = "1" } channels = { path = "../channels", features = ['accounts', 'carts', 'emails', 'search'] } -chrono = { version = "0.4", features = ["serde"] } +chrono = { version = "0", features = ["serde"] } config = { path = "../config", features = ['full'] } #database_manager = { path = "../database_manager" } -derive_more = { version = "0.99", features = [] } -dotenv = { version = "0.15", features = [] } +derive_more = { version = "0", features = [] } +dotenv = { version = "0", features = [] } fs_manager = { path = "../fs_manager" } -futures = { version = "0.3", features = [] } -futures-util = { version = "0.3", features = [] } -gumdrop = { version = "0.8", features = [] } -human-panic = { version = "1.0.3" } -include_dir = { version = "0.7.2", features = [] } -itertools = { version = "0.10.5" } -jemallocator = { version = "0.3", features = [] } +futures = { version = "0", features = [] } +futures-util = { version = "0", features = [] } +gumdrop = { version = "0", features = [] } +human-panic = { version = "1" } +include_dir = { version = "0", features = [] } +itertools = { version = "0" } +jemallocator = { version = "0", features = [] } model = { path = "../model", version = "0.1", features = ["db"] } -oauth2 = { version = "4.1", features = [] } +oauth2 = { version = "4", features = [] } order_manager = { path = "../order_manager" } -parking_lot = { version = "0.12", features = [] } +parking_lot = { version = "0", features = [] } payment_manager = { path = "../payment_manager" } -pretty_env_logger = { version = "0.4", features = [] } +pretty_env_logger = { version = "0", features = [] } rumqttc = { version = "*" } -serde = { version = "1.0", features = ["derive"] } -serde_json = { version = "1.0", features = [] } -sqlx = { version = "0.6.2", features = ["migrate", "runtime-actix-rustls", "all-types", "postgres"] } -sqlx-core = { version = "0.6.2", features = [] } -tarpc = { version = "0.31.0", features = ["tokio1", "serde-transport-bincode", "serde-transport", "serde", "serde-transport-json", "tcp"] } -tera = { version = "1.15", features = [] } -thiserror = { version = "1.0", features = [] } +serde = { version = "1", features = ["derive"] } +serde_json = { version = "1", features = [] } +sqlx = { version = "0", features = ["migrate", "runtime-actix-rustls", "all-types", "postgres"] } +sqlx-core = { version = "0", features = [] } +tarpc = { version = "0", features = ["tokio1", "serde-transport-bincode", "serde-transport", "serde", "serde-transport-json", "tcp"] } +tera = { version = "1", features = [] } +thiserror = { version = "1", features = [] } token_manager = { path = "../token_manager" } -tokio = { version = "1.17", features = ["full"] } -toml = { version = "0.5", features = [] } -tracing = { version = "0.1.34" } -tracing-subscriber = { version = "0.3.11" } -uuid = { version = "1.2.1", features = ["serde"] } -validator = { version = "0.14", features = [] } +tokio = { version = "1", features = ["full"] } +toml = { version = "0", features = [] } +uuid = { version = "1", features = ["serde"] } +validator = { version = "0", features = [] } diff --git a/crates/api/src/main.rs b/crates/api/src/main.rs index cc4f02a..dab8a6b 100644 --- a/crates/api/src/main.rs +++ b/crates/api/src/main.rs @@ -1,4 +1,4 @@ -#![feature(drain_filter)] ++#![feature(drain_filter)] use std::io::Write; use std::str::FromStr; diff --git a/crates/cart_manager/Cargo.toml b/crates/cart_manager/Cargo.toml index 6a257ae..2ca30b4 100644 --- a/crates/cart_manager/Cargo.toml +++ b/crates/cart_manager/Cargo.toml @@ -9,26 +9,21 @@ path = "src/main.rs" [dependencies] channels = { path = "../channels" } -chrono = { version = "0.4", features = ["serde"] } +chrono = { version = "0", features = ["serde"] } config = { path = "../config" } -dotenv = { version = "0.15.0" } -futures = { version = "0.3.25" } +dotenv = { version = "0" } +futures = { version = "0" } model = { path = "../model", features = ["db"] } -opentelemetry = { version = "0.17.0" } -opentelemetry-jaeger = { version = "0.17.0" } -pretty_env_logger = { version = "0.4", features = [] } rumqttc = { version = "*" } -serde = { version = "1.0.137", features = ["derive"] } -sqlx = { version = "0.6.2", features = ["migrate", "runtime-actix-rustls", "all-types", "postgres"] } -sqlx-core = { version = "0.6.2", features = [] } -tarpc = { version = "0.31.0", features = ["tokio1", "serde-transport-bincode", "serde-transport", "serde", "serde-transport-json", "tcp"] } -thiserror = { version = "1.0.31" } -tokio = { version = "1.21.2", features = ['full'] } -tracing = { version = "0.1.37" } -tracing-opentelemetry = { version = "0.17.4" } -tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } -uuid = { version = "0.8", features = ["serde", "v4"] } +serde = { version = "1", features = ["derive"] } +sqlx = { version = "0", features = ["migrate", "runtime-actix-rustls", "all-types", "postgres"] } +sqlx-core = { version = "0", features = [] } +tarpc = { version = "0", features = ["tokio1", "serde-transport-bincode", "serde-transport", "serde", "serde-transport-json", "tcp"] } +thiserror = { version = "1" } +tokio = { version = "1", features = ['full'] } +tracing = { version = "0" } +uuid = { version = "0", features = ["serde", "v4"] } [dev-dependencies] -fake = { version = "2.5.0" } +fake = { version = "2" } testx = { path = "../testx" } diff --git a/crates/cart_manager/src/main.rs b/crates/cart_manager/src/main.rs index 86c85e7..32f836e 100644 --- a/crates/cart_manager/src/main.rs +++ b/crates/cart_manager/src/main.rs @@ -1,7 +1,4 @@ use config::UpdateConfig; -use tracing_subscriber::fmt::format::FmtSpan; -use tracing_subscriber::layer::SubscriberExt; -use tracing_subscriber::util::SubscriberInitExt; use crate::db::Database; @@ -17,7 +14,7 @@ impl UpdateConfig for Opts {} #[tokio::main] async fn main() { dotenv::dotenv().ok(); - init_tracing("account-manager"); + config::init_tracing("account-manager"); let opts = Opts {}; @@ -28,23 +25,3 @@ async fn main() { let mqtt_client = mqtt::start(config.clone(), db.clone()).await; rpc::start(config.clone(), db.clone(), mqtt_client.clone()).await; } - -pub fn init_tracing(_service_name: &str) { - std::env::set_var("OTEL_BSP_MAX_EXPORT_BATCH_SIZE", "12"); - - let tracer = { - use opentelemetry::sdk::export::trace::stdout::new_pipeline; - use opentelemetry::sdk::trace::Config; - new_pipeline() - .with_trace_config(Config::default()) - .with_pretty_print(true) - .install_simple() - }; - - tracing_subscriber::registry() - .with(tracing_subscriber::EnvFilter::from_default_env()) - .with(tracing_subscriber::fmt::layer().with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)) - .with(tracing_opentelemetry::layer().with_tracer(tracer)) - .try_init() - .unwrap(); -} diff --git a/crates/channels/Cargo.toml b/crates/channels/Cargo.toml index d92c2b7..11dbd40 100644 --- a/crates/channels/Cargo.toml +++ b/crates/channels/Cargo.toml @@ -11,20 +11,21 @@ search = [] stocks = [] orders = [] payments = ['payment_adapter'] -default = ['accounts', 'carts', 'emails', 'search', 'stocks', 'orders', 'payments'] +tokens = [] +default = ['accounts', 'carts', 'emails', 'search', 'stocks', 'orders', 'payments', 'tokens'] [dependencies] bincode = { version = "*" } -bytes = { version = "1.2.1" } +bytes = { version = "1" } config = { path = "../config" } -futures = { version = "0.3.25" } +futures = { version = "0" } model = { path = "../model" } +payment_adapter = { path = "../payment_adapter", optional = true } rumqttc = { version = "*" } serde = { version = "*", features = ['derive'] } -strum = { version = "0.24.1", features = ['strum_macros', 'default', 'derive'] } -tarpc = { version = "0.31.0", features = ["tokio1", "serde-transport-bincode", "serde-transport", "serde", "serde-transport-json", "tcp"] } -thiserror = { version = "1.0.37" } -tokio = { version = "1.21.2", features = ['full'] } -tracing = { version = "0.1.37" } -whatlang = { version = "0.16.2" } -payment_adapter = { path = "../payment_adapter", optional = true } +strum = { version = "0", features = ['strum_macros', 'default', 'derive'] } +tarpc = { version = "0", features = ["tokio1", "serde-transport-bincode", "serde-transport", "serde", "serde-transport-json", "tcp"] } +thiserror = { version = "1" } +tokio = { version = "1", features = ['full'] } +tracing = { version = "0" } +whatlang = { version = "0" } diff --git a/crates/channels/src/carts.rs b/crates/channels/src/carts.rs index f1acee2..f3425a6 100644 --- a/crates/channels/src/carts.rs +++ b/crates/channels/src/carts.rs @@ -1,4 +1,4 @@ -pub static CLIENT_NAME: &str = "cart-manager"; +pub static CLIENT_NAME: &str = "carts"; pub enum Topic {} @@ -154,7 +154,7 @@ pub mod mqtt { use config::SharedAppConfig; use rumqttc::EventLoop; - use crate::carts::CLIENT_NAME; + use super::CLIENT_NAME; use crate::AsyncClient; pub fn create_client(config: SharedAppConfig) -> (AsyncClient, EventLoop) { diff --git a/crates/channels/src/lib.rs b/crates/channels/src/lib.rs index 458327a..c4fb6a8 100644 --- a/crates/channels/src/lib.rs +++ b/crates/channels/src/lib.rs @@ -18,6 +18,8 @@ pub mod rpc; pub mod search; #[cfg(feature = "stocks")] pub mod stocks; +#[cfg(feature = "tokens")] +pub mod tokens; pub trait DeserializePayload { fn deserialize_payload(self, bytes: bytes::Bytes) -> Option; diff --git a/crates/channels/src/payments.rs b/crates/channels/src/payments.rs index 54226f7..127f507 100644 --- a/crates/channels/src/payments.rs +++ b/crates/channels/src/payments.rs @@ -1,7 +1,4 @@ -// use rumqttc::QoS; - pub use payment_adapter::*; -// use crate::AsyncClient; pub static CLIENT_NAME: &str = "payments"; @@ -13,8 +10,21 @@ pub enum Error { UnknownAdapter(String), #[error("Payment failed")] PaymentFailed, - #[error("Payment adapter returned invalid response data")] + #[error("Cancel failed")] + CancelFailed, + #[error("Payment adapter returned invalid create order response data")] MalformedCreatePaymentResult, + #[error("Payment adapter returned invalid cancel response data")] + MalformedCancelResult, + #[error("Update payment state failed")] + UpdateStateFailed, + #[error("Payment adapter returned invalid update state response data")] + MalformedUpdateStateResult, + // + #[error("Unable to send msg to adapter")] + SendToWasmFailed, + #[error("Unable to receive response from adapter")] + RecvFromWasmFailed, } #[derive(Debug, Copy, Clone)] @@ -91,7 +101,7 @@ pub mod cancel { use super::Error; - #[derive(Debug, serde::Serialize, serde::Deserialize)] + #[derive(Debug, Copy, Clone, serde::Serialize, serde::Deserialize)] pub enum RefundType { /// Refund entire payment Full, diff --git a/crates/channels/src/tokens.rs b/crates/channels/src/tokens.rs new file mode 100644 index 0000000..ba82215 --- /dev/null +++ b/crates/channels/src/tokens.rs @@ -0,0 +1,97 @@ +pub static CLIENT_NAME: &str = "tokens"; + +pub enum Topic {} + +#[derive(Debug, Clone, thiserror::Error, serde::Serialize, serde::Deserialize)] +pub enum Error {} + +pub mod create_pair { + use super::Error; + + #[derive(Debug, serde::Serialize, serde::Deserialize)] + pub struct Input {} + + #[derive(Debug, serde::Serialize, serde::Deserialize)] + pub struct Details {} + + pub type Output = Result; +} + +pub mod validate { + use super::Error; + + #[derive(Debug, serde::Serialize, serde::Deserialize)] + pub struct Input {} + + #[derive(Debug, serde::Serialize, serde::Deserialize)] + pub struct Details {} + + pub type Output = Result; +} + +pub mod refresh { + use model::RefreshTokenString; + + use super::Error; + + #[derive(Debug, serde::Serialize, serde::Deserialize)] + pub struct Input { + pub refresh_token: RefreshTokenString, + } + + #[derive(Debug, serde::Serialize, serde::Deserialize)] + pub struct Details {} + + pub type Output = Result; +} + +pub mod rpc { + use config::SharedAppConfig; + + use crate::tokens::{create_pair, refresh, validate}; + + #[tarpc::service] + pub trait Tokens { + /// Create new access token and refresh token without any validations + async fn create_pair(input: create_pair::Input) -> create_pair::Output; + + /// Check if access token is valid + async fn validate(input: validate::Input) -> validate::Output; + + /// Validate with refresh token and create new access token and refresh + /// token + async fn refresh(input: refresh::Input) -> refresh::Output; + } + + pub async fn create_client(config: SharedAppConfig) -> TokensClient { + use tarpc::client; + use tarpc::tokio_serde::formats::Bincode; + + let addr = { + let l = config.lock(); + (l.tokens().rpc_bind.clone(), l.tokens().rpc_port) + }; + + let transport = tarpc::serde_transport::tcp::connect(addr, Bincode::default); + + let client = TokensClient::new( + client::Config::default(), + transport.await.expect("Failed to connect to server"), + ) + .spawn(); + + client + } +} + +pub mod mqtt { + use config::SharedAppConfig; + use rumqttc::EventLoop; + + use super::CLIENT_NAME; + use crate::AsyncClient; + + pub fn create_client(config: SharedAppConfig) -> (AsyncClient, EventLoop) { + crate::mqtt::create_client(CLIENT_NAME, config.lock().tokens().mqtt_addr()) + } +} diff --git a/crates/config/Cargo.toml b/crates/config/Cargo.toml index d04c8f2..f0c3fe3 100644 --- a/crates/config/Cargo.toml +++ b/crates/config/Cargo.toml @@ -8,11 +8,13 @@ full = ['actix-web', 'cookie'] default = [] [dependencies] -actix-web = { version = "4.0", features = [], optional = true } -cookie = { version = "0.16.1", features = ["signed"], optional = true } -parking_lot = { version = "0.12", features = [] } -password-hash = { version = "0.4", features = ["alloc"] } -serde = { version = "1.0", features = ["derive"] } -serde_json = { version = "1.0", features = [] } -thiserror = { version = "1.0" } -toml = { version = "0.5", features = [] } +actix-web = { version = "4", features = [], optional = true } +cookie = { version = "0", features = ["signed"], optional = true } +parking_lot = { version = "0", features = [] } +password-hash = { version = "0", features = ["alloc"] } +serde = { version = "1", features = ["derive"] } +serde_json = { version = "1", features = [] } +thiserror = { version = "1" } +toml = { version = "0", features = [] } +tracing-subscriber = { version = "0", features = ['env-filter'] } +tracing-timing = { version = "0", features = [] } diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs index e9b8e55..a7ba889 100644 --- a/crates/config/src/lib.rs +++ b/crates/config/src/lib.rs @@ -625,32 +625,67 @@ impl PaymentConfig { } } +#[derive(Serialize, Deserialize)] +pub struct TokensConfig { + pub rpc_port: u16, + pub rpc_bind: String, + pub mqtt_port: u16, + pub mqtt_bind: String, + pub database_url: String, +} + +impl Default for TokensConfig { + fn default() -> Self { + Self { + rpc_port: 19336, + rpc_bind: "0.0.0.0".into(), + mqtt_port: 1889, + mqtt_bind: "0.0.0.0".into(), + database_url: "postgres://postgres@localhost/bazzar_tokens".into(), + } + } +} + +impl Example for TokensConfig {} + +impl TokensConfig { + pub fn rpc_addr(&self) -> (&str, u16) { + (&self.rpc_bind, self.rpc_port) + } + + pub fn mqtt_addr(&self) -> (&str, u16) { + (&self.mqtt_bind, self.mqtt_port) + } +} + #[derive(Serialize, Deserialize)] pub struct AppConfig { - #[serde(default)] - payment: PaymentConfig, - #[serde(default)] - web: WebConfig, - #[serde(default)] - mail: MailConfig, - #[serde(default)] - database: DatabaseConfig, - #[serde(default)] - search: SearchConfig, - #[serde(default)] - files: FilesConfig, #[serde(default)] account_manager: AccountManagerConfig, #[serde(default)] cart_manager: CartManagerConfig, + #[serde(skip)] + config_path: String, + #[serde(default)] + database: DatabaseConfig, #[serde(default)] email_sender: EmailSenderConfig, #[serde(default)] - stocks: StocksConfig, + files: FilesConfig, + #[serde(default)] + mail: MailConfig, #[serde(default)] order_manager: OrderConfig, - #[serde(skip)] - config_path: String, + #[serde(default)] + payment: PaymentConfig, + #[serde(default)] + search: SearchConfig, + #[serde(default)] + stocks: StocksConfig, + #[serde(default)] + tokens: TokensConfig, + #[serde(default)] + web: WebConfig, } impl Example for AppConfig { @@ -668,51 +703,12 @@ impl Example for AppConfig { stocks: StocksConfig::example(), order_manager: OrderConfig::example(), config_path: "".to_string(), + tokens: TokensConfig::example(), } } } impl AppConfig { - pub fn payment(&self) -> &PaymentConfig { - &self.payment - } - - pub fn web(&self) -> &WebConfig { - &self.web - } - - pub fn mail(&self) -> &MailConfig { - &self.mail - } - - pub fn database(&self) -> &DatabaseConfig { - &self.database - } - - pub fn payment_mut(&mut self) -> &mut PaymentConfig { - &mut self.payment - } - - pub fn web_mut(&mut self) -> &mut WebConfig { - &mut self.web - } - - pub fn mail_mut(&mut self) -> &mut MailConfig { - &mut self.mail - } - - pub fn database_mut(&mut self) -> &mut DatabaseConfig { - &mut self.database - } - - pub fn search(&self) -> &SearchConfig { - &self.search - } - - pub fn files(&self) -> &FilesConfig { - &self.files - } - pub fn account_manager(&self) -> &AccountManagerConfig { &self.account_manager } @@ -721,16 +717,60 @@ impl AppConfig { &self.cart_manager } + pub fn database(&self) -> &DatabaseConfig { + &self.database + } + + pub fn database_mut(&mut self) -> &mut DatabaseConfig { + &mut self.database + } + pub fn email_sender(&self) -> &EmailSenderConfig { &self.email_sender } + pub fn files(&self) -> &FilesConfig { + &self.files + } + + pub fn mail(&self) -> &MailConfig { + &self.mail + } + + pub fn mail_mut(&mut self) -> &mut MailConfig { + &mut self.mail + } + + pub fn orders_manager(&self) -> &OrderConfig { + &self.order_manager + } + + pub fn payment(&self) -> &PaymentConfig { + &self.payment + } + + pub fn payment_mut(&mut self) -> &mut PaymentConfig { + &mut self.payment + } + + pub fn search(&self) -> &SearchConfig { + &self.search + } + pub fn stocks_manager(&self) -> &StocksConfig { &self.stocks } - pub fn orders_manager(&self) -> &OrderConfig { - &self.order_manager + pub fn tokens(&self) -> &TokensConfig { + &self.tokens + } + + pub fn web(&self) -> &WebConfig { + &self.web + } + + pub fn web_mut(&mut self) -> &mut WebConfig { + &mut self.web } } @@ -749,6 +789,7 @@ impl Default for AppConfig { stocks: StocksConfig::default(), order_manager: OrderConfig::default(), config_path: "".to_string(), + tokens: Default::default(), } } } @@ -822,3 +863,15 @@ pub fn save(config_path: &str, config: &mut AppConfig) { config.config_path = config_path.into(); std::fs::write(config_path, toml::to_string_pretty(&config).unwrap()).unwrap(); } + +pub fn init_tracing(_service_name: &str) { + use tracing_subscriber::fmt::format::FmtSpan; + use tracing_subscriber::layer::SubscriberExt; + use tracing_subscriber::util::SubscriberInitExt; + + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::from_default_env()) + .with(tracing_subscriber::fmt::layer().with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)) + .try_init() + .unwrap(); +} diff --git a/crates/database_manager/Cargo.toml b/crates/database_manager/Cargo.toml index d85f72c..26a9894 100644 --- a/crates/database_manager/Cargo.toml +++ b/crates/database_manager/Cargo.toml @@ -7,24 +7,24 @@ edition = "2021" dummy = ["fake", "rand"] [dependencies] -actix = { version = "0.13", features = [] } -actix-rt = { version = "2.7", features = [] } -async-trait = { version = "0.1.56" } -chrono = { version = "0.4", features = ["serde"] } +actix = { version = "0", features = [] } +actix-rt = { version = "2", features = [] } +async-trait = { version = "0" } +chrono = { version = "0", features = ["serde"] } config = { path = "../config" } -fake = { version = "2.4.3", features = ["derive", "chrono", "http", "uuid"], optional = true } -itertools = { version = "0.10.3" } +fake = { version = "2", features = ["derive", "chrono", "http", "uuid"], optional = true } +itertools = { version = "0" } model = { path = "../model", features = ['db', 'dummy', 'rand'] } -pretty_env_logger = { version = "0.4", features = [] } -rand = { version = "0.8.5", optional = true } +pretty_env_logger = { version = "0", features = [] } +rand = { version = "0", optional = true } rumqttc = { version = "*" } -serde = { version = "1.0", features = ["derive"] } -sqlx = { version = "0.6.2", features = ["migrate", "runtime-actix-rustls", "all-types", "postgres"] } -sqlx-core = { version = "0.6.2", features = [] } -thiserror = { version = "1.0.31" } -tracing = { version = "0.1.34" } -uuid = { version = "1.2.1", features = ["serde"] } +serde = { version = "1", features = ["derive"] } +sqlx = { version = "0", features = ["migrate", "runtime-actix-rustls", "all-types", "postgres"] } +sqlx-core = { version = "0", features = [] } +thiserror = { version = "1" } +tracing = { version = "0" } +uuid = { version = "1", features = ["serde"] } [dev-dependencies] -fake = { version = "2.5.0" } +fake = { version = "2" } testx = { path = "../testx" } diff --git a/crates/db-seed/Cargo.toml b/crates/db-seed/Cargo.toml index f1badfd..18ae8d6 100644 --- a/crates/db-seed/Cargo.toml +++ b/crates/db-seed/Cargo.toml @@ -5,18 +5,18 @@ edition = "2021" [dependencies] account-manager = { path = '../account_manager' } -bytes = { version = "1.1.0" } +bytes = { version = "1" } channels = { path = '../channels' } config = { path = "../config" } -dotenv = { version = "0.15", features = [] } -fakeit = { version = "1.1.1", features = [] } +dotenv = { version = "0", features = [] } +fakeit = { version = "1", features = [] } fs_manager = { path = "../fs_manager", features = [] } -human-panic = { version = "1.0.3" } +human-panic = { version = "1" } model = { path = "../model", version = "0.1", features = ["db", "dummy"] } -password-hash = { version = "0.4", features = ["alloc"] } -rand = { version = "0.8.5" } +password-hash = { version = "0", features = ["alloc"] } +rand = { version = "0" } stock-manager = { path = "../stock_manager" } -thiserror = { version = "1.0.31" } -tokio = { version = "1.18.1", features = ["full"] } -tracing = { version = "0.1.34" } -tracing-subscriber = { version = "0.3.11" } +thiserror = { version = "1" } +tokio = { version = "1", features = ["full"] } +tracing = { version = "0" } +tracing-subscriber = { version = "0" } diff --git a/crates/db-utils/Cargo.toml b/crates/db-utils/Cargo.toml index c8d654e..f805106 100644 --- a/crates/db-utils/Cargo.toml +++ b/crates/db-utils/Cargo.toml @@ -5,5 +5,5 @@ edition = "2021" [dependencies] model = { path = "../model", features = ["db"] } -sqlx = { version = "0.6.2", features = ["migrate", "runtime-actix-rustls", "all-types", "postgres"] } -sqlx-core = { version = "0.6.2", features = [] } +sqlx = { version = "0", features = ["migrate", "runtime-actix-rustls", "all-types", "postgres"] } +sqlx-core = { version = "0", features = [] } diff --git a/crates/email_manager/Cargo.toml b/crates/email_manager/Cargo.toml index 999fd0b..1c5600d 100644 --- a/crates/email_manager/Cargo.toml +++ b/crates/email_manager/Cargo.toml @@ -8,29 +8,22 @@ name = "email-sender" path = "./src/main.rs" [dependencies] -actix = { version = "0.13", features = [] } -actix-rt = { version = "2.7", features = [] } channels = { path = "../channels" } -chrono = { version = "0.4", features = ["serde"] } +chrono = { version = "0", features = ["serde"] } config = { path = "../config" } -dotenv = { version = "0.15.0" } +dotenv = { version = "0" } handlebars = { version = "*", features = [] } model = { path = "../model" } -opentelemetry = { version = "0.17.0" } -opentelemetry-jaeger = { version = "0.17.0" } -pretty_env_logger = { version = "0.4", features = [] } rumqttc = { version = "*" } -sendgrid = { version = "0.18.1", features = ["async"] } -serde = { version = "1.0", features = ["derive"] } -serde_json = { version = "1.0", features = [] } -tarpc = { version = "0.31.0", features = ["tokio1", "serde-transport-bincode", "serde-transport", "serde", "serde-transport-json", "tcp"] } -thiserror = { version = "1.0.31" } -tokio = { version = "1.21.2", features = ['full'] } -tracing = { version = "0.1.37" } -tracing-opentelemetry = { version = "0.17.4" } -tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } -uuid = { version = "0.8", features = ["serde"] } +sendgrid = { version = "0", features = ["async"] } +serde = { version = "1", features = ["derive"] } +serde_json = { version = "1", features = [] } +tarpc = { version = "0", features = ["tokio1", "serde-transport-bincode", "serde-transport", "serde", "serde-transport-json", "tcp"] } +thiserror = { version = "1" } +tokio = { version = "1", features = ['full'] } +tracing = { version = "0" } +uuid = { version = "0", features = ["serde"] } [dev-dependencies] -fake = { version = "2.5.0" } +fake = { version = "2" } testx = { path = "../testx" } diff --git a/crates/email_manager/src/main.rs b/crates/email_manager/src/main.rs index a356141..4b5abb5 100644 --- a/crates/email_manager/src/main.rs +++ b/crates/email_manager/src/main.rs @@ -1,9 +1,6 @@ use std::sync::Arc; use config::{SharedAppConfig, UpdateConfig}; -use tracing_subscriber::fmt::format::FmtSpan; -use tracing_subscriber::layer::SubscriberExt; -use tracing_subscriber::util::SubscriberInitExt; // use crate::db::Database; @@ -55,10 +52,10 @@ impl Context { pub type SharedContext = Arc; -#[actix::main] +#[tokio::main] async fn main() { dotenv::dotenv().ok(); - init_tracing("email-sender"); + config::init_tracing("email-sender"); let config = config::default_load(&Opts {}); @@ -67,23 +64,3 @@ async fn main() { let _mqtt_client = mqtt::start(config.clone(), context.clone()).await; // rpc::start(config.clone(), db.clone(), mqtt_client.clone()).await; } - -pub fn init_tracing(_service_name: &str) { - std::env::set_var("OTEL_BSP_MAX_EXPORT_BATCH_SIZE", "12"); - - let tracer = { - use opentelemetry::sdk::export::trace::stdout::new_pipeline; - use opentelemetry::sdk::trace::Config; - new_pipeline() - .with_trace_config(Config::default()) - .with_pretty_print(true) - .install_simple() - }; - - tracing_subscriber::registry() - .with(tracing_subscriber::EnvFilter::from_default_env()) - .with(tracing_subscriber::fmt::layer().with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)) - .with(tracing_opentelemetry::layer().with_tracer(tracer)) - .try_init() - .unwrap(); -} diff --git a/crates/fs_manager/Cargo.toml b/crates/fs_manager/Cargo.toml index c086c12..af93422 100644 --- a/crates/fs_manager/Cargo.toml +++ b/crates/fs_manager/Cargo.toml @@ -4,19 +4,13 @@ version = "0.1.0" edition = "2021" [dependencies] -actix = { version = "0.13", features = [] } -actix-rt = { version = "2.7", features = [] } -actix-web = { version = "4.0.1" } -bytes = { version = "1.1.0" } -chrono = { version = "0.4", features = ["serde"] } +bytes = { version = "1" } +chrono = { version = "0", features = ["serde"] } config = { path = "../config" } -fibers_rpc = { version = "0.3.4", features = [] } model = { path = "../model" } -pretty_env_logger = { version = "0.4", features = [] } rumqttc = { version = "*" } -serde = { version = "1.0", features = ["derive"] } -thiserror = { version = "1.0.31" } -tokio = { version = "1.18.1", features = ["full"] } -tracing = { version = "0.1.34" } -uuid = { version = "1.2.1", features = ["serde"] } - +serde = { version = "1", features = ["derive"] } +thiserror = { version = "1" } +tokio = { version = "1", features = ["full"] } +tracing = { version = "0" } +uuid = { version = "1", features = ["serde"] } diff --git a/crates/lang_provider/Cargo.toml b/crates/lang_provider/Cargo.toml index 542890d..3b1b091 100644 --- a/crates/lang_provider/Cargo.toml +++ b/crates/lang_provider/Cargo.toml @@ -4,13 +4,10 @@ version = "0.1.0" edition = "2021" [dependencies] -actix = { version = "0.13", features = [] } -actix-rt = { version = "2.7", features = [] } config = { path = "../config" } -fluent = { version = "0.16.0" } +fluent = { version = "0" } model = { path = "../model" } -pretty_env_logger = { version = "0.4", features = [] } rumqttc = { version = "*" } -thiserror = { version = "1.0.31" } -tracing = { version = "0.1.34" } -unic-langid = { version = "0.9.0" } +thiserror = { version = "1" } +tracing = { version = "0" } +unic-langid = { version = "0" } diff --git a/crates/model/Cargo.toml b/crates/model/Cargo.toml index 709747a..99d7c6d 100644 --- a/crates/model/Cargo.toml +++ b/crates/model/Cargo.toml @@ -17,17 +17,16 @@ payments = [] default = ['accounts', 'carts', 'emails', 'search', 'stocks', 'orders', 'payments'] [dependencies] -argon2 = { version = "0.4", features = ["parallel", "password-hash"] } -chrono = { version = "0.4", features = ["serde"] } -derive_more = { version = "0.99.17" } +argon2 = { version = "0", features = ["parallel", "password-hash"] } +chrono = { version = "0", features = ["serde"] } +derive_more = { version = "0" } fake = { version = "2", features = ["derive", "chrono", "http", "uuid", "dummy"], optional = true } -password-hash = { version = "0.4", features = ["alloc"] } -rand = { version = "0.8.5", optional = true } -rand_core = { version = "0.6", features = ["std"] } -serde = { version = "1.0.137" } -sqlx = { version = "0.6.2", features = ["migrate", "runtime-actix-rustls", "all-types", "postgres"], optional = true } -sqlx-core = { version = "0.6.2", features = [], optional = true } -thiserror = { version = "1.0.31" } -uuid = { version = "1.2.1", features = ["serde"] } -validator = { version = "0.16.0" } -#tracing = { version = "0.1.34" } +password-hash = { version = "0", features = ["alloc"] } +rand = { version = "0", optional = true } +rand_core = { version = "0", features = ["std"] } +serde = { version = "1" } +sqlx = { version = "0", features = ["migrate", "runtime-actix-rustls", "all-types", "postgres"], optional = true } +sqlx-core = { version = "0", features = [], optional = true } +thiserror = { version = "1" } +uuid = { version = "1", features = ["serde"] } +validator = { version = "0" } diff --git a/crates/order_manager/Cargo.toml b/crates/order_manager/Cargo.toml index 94a5e13..5395b6b 100644 --- a/crates/order_manager/Cargo.toml +++ b/crates/order_manager/Cargo.toml @@ -9,24 +9,20 @@ path = "./src/main.rs" [dependencies] channels = { path = "../channels" } -chrono = { version = "0.4", features = ["serde"] } +chrono = { version = "0", features = ["serde"] } config = { path = "../config" } db-utils = { path = "../db-utils" } model = { path = "../model", features = ["db"] } -opentelemetry = { version = "0.17.0" } -opentelemetry-jaeger = { version = "0.17.0" } rumqttc = { version = "*" } -serde = { version = "1.0.137", features = ["derive"] } -sqlx = { version = "0.6.2", features = ["migrate", "runtime-actix-rustls", "all-types", "postgres"] } -sqlx-core = { version = "0.6.2", features = [] } -tarpc = { version = "0.31.0", features = ["tokio1", "serde-transport-bincode", "serde-transport", "serde", "serde-transport-json", "tcp"] } -thiserror = { version = "1.0.31" } -tokio = { version = "1.21.2", features = ['full'] } -tracing = { version = "0.1.6" } -tracing-opentelemetry = { version = "0.17.4" } -tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } -uuid = { version = "1.2.1", features = ["serde"] } +serde = { version = "1", features = ["derive"] } +sqlx = { version = "0", features = ["migrate", "runtime-actix-rustls", "all-types", "postgres"] } +sqlx-core = { version = "0", features = [] } +tarpc = { version = "0", features = ["tokio1", "serde-transport-bincode", "serde-transport", "serde", "serde-transport-json", "tcp"] } +thiserror = { version = "1" } +tokio = { version = "1", features = ['full'] } +tracing = { version = "0" } +uuid = { version = "1", features = ["serde"] } [dev-dependencies] -fake = { version = "2.5.0" } +fake = { version = "2" } testx = { path = "../testx" } diff --git a/crates/order_manager/src/main.rs b/crates/order_manager/src/main.rs index edc341c..b221361 100644 --- a/crates/order_manager/src/main.rs +++ b/crates/order_manager/src/main.rs @@ -13,6 +13,7 @@ impl UpdateConfig for Opts {} #[tokio::main] async fn main() { let opts = Opts {}; + config::init_tracing("orders"); let config = config::default_load(&opts); diff --git a/crates/payment_adapter/Cargo.toml b/crates/payment_adapter/Cargo.toml index 6005a8d..2e13852 100644 --- a/crates/payment_adapter/Cargo.toml +++ b/crates/payment_adapter/Cargo.toml @@ -5,9 +5,9 @@ edition = "2021" [dependencies] config = { path = "../config", default-features = false, features = [] } +futures = { version = "0" } model = { path = "../model" } -serde = { version = "1.0.149", features = ['derive'] } -uuid = { version = "1.2.2", features = ['v4'] } -futures = { version = "0.3.25" } -tracing = { version = "0.1.37" } -thiserror = { version = "1.0.37" } +serde = { version = "1", features = ['derive'] } +thiserror = { version = "1" } +tracing = { version = "0" } +uuid = { version = "1", features = ['v4'] } diff --git a/crates/payment_adapter/src/lib.rs b/crates/payment_adapter/src/lib.rs index d80a003..dbe096e 100644 --- a/crates/payment_adapter/src/lib.rs +++ b/crates/payment_adapter/src/lib.rs @@ -66,7 +66,6 @@ pub struct Item { } #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] -#[repr(C)] pub struct CreatePayment { pub buyer: Buyer, pub customer_ip: String, @@ -80,24 +79,38 @@ pub struct CreatePayment { } #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] -#[repr(C)] pub struct OrderCreated { pub ext_order_id: Option, pub redirect_uri: Option, } +#[derive(Debug, Copy, Clone, serde::Serialize, serde::Deserialize)] +pub enum RefundType { + /// Refund entire payment + Full, + /// Refund only part given in enum + Partial(Price), +} + +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +pub struct Cancel { + pub refund: RefundType, + pub provider_order_id: String, + pub description: String, +} + +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +pub struct Cancelled {} + #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] -#[repr(C)] pub struct UpdateStatus { pub payload: Vec, } #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] -#[repr(C)] pub struct StatusUpdated {} #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] -#[repr(C)] pub enum HttpMethod { Get, Post, diff --git a/crates/payment_adapter_pay_u/Cargo.lock b/crates/payment_adapter_pay_u/Cargo.lock index 4cf9cf3..5acba71 100644 --- a/crates/payment_adapter_pay_u/Cargo.lock +++ b/crates/payment_adapter_pay_u/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "aho-corasick" version = "0.7.20" @@ -38,6 +44,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + [[package]] name = "base64ct" version = "1.5.3" @@ -143,6 +155,8 @@ dependencies = [ "serde_json", "thiserror", "toml", + "tracing-subscriber", + "tracing-timing", ] [[package]] @@ -157,6 +171,29 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2801af0d36612ae591caa9568261fddce32ce6e08a7275ea334a06a4ad021a2c" +dependencies = [ + "cfg-if", + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-epoch", + "crossbeam-queue", + "crossbeam-utils", +] + [[package]] name = "crossbeam-channel" version = "0.5.6" @@ -191,6 +228,16 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "crossbeam-queue" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1cfb3ea8a53f37c40dea2c7bedcbd88bdfae54f5e2175d6ecaff1c988353add" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.14" @@ -278,12 +325,28 @@ dependencies = [ "subtle", ] +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + [[package]] name = "either" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +[[package]] +name = "flate2" +version = "1.0.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + [[package]] name = "form_urlencoded" version = "1.1.0" @@ -382,6 +445,15 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + [[package]] name = "generic-array" version = "0.14.6" @@ -403,6 +475,26 @@ dependencies = [ "wasi 0.11.0+wasi-snapshot-preview1", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hdrhistogram" +version = "7.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f19b9f54f7c7f55e31401bb647626ce0cf0f67b0004982ce815b3ee72a02aa8" +dependencies = [ + "base64", + "byteorder", + "crossbeam-channel", + "flate2", + "nom", + "num-traits", +] + [[package]] name = "hermit-abi" version = "0.1.19" @@ -457,6 +549,16 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "indexmap" +version = "1.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +dependencies = [ + "autocfg", + "hashbrown", +] + [[package]] name = "instant" version = "0.1.12" @@ -521,6 +623,24 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "mach" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" +dependencies = [ + "libc", +] + +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata", +] + [[package]] name = "matches" version = "0.1.9" @@ -542,6 +662,21 @@ dependencies = [ "autocfg", ] +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "miniz_oxide" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" +dependencies = [ + "adler", +] + [[package]] name = "model" version = "0.1.0" @@ -557,6 +692,26 @@ dependencies = [ "validator", ] +[[package]] +name = "nom" +version = "7.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[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-integer" version = "0.1.45" @@ -592,6 +747,12 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "parking_lot" version = "0.11.2" @@ -712,6 +873,22 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quanta" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20afe714292d5e879d8b12740aa223c6a88f118af41870e8b6196e39a02238a8" +dependencies = [ + "crossbeam-utils", + "libc", + "mach", + "once_cell", + "raw-cpuid", + "wasi 0.10.0+wasi-snapshot-preview1", + "web-sys", + "winapi", +] + [[package]] name = "quote" version = "1.0.21" @@ -730,6 +907,15 @@ dependencies = [ "getrandom", ] +[[package]] +name = "raw-cpuid" +version = "10.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6823ea29436221176fe662da99998ad3b4db2c7f31e7b6f5fe43adccd6320bb" +dependencies = [ + "bitflags", +] + [[package]] name = "rayon" version = "1.6.0" @@ -773,6 +959,15 @@ dependencies = [ "regex-syntax", ] +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax", +] + [[package]] name = "regex-syntax" version = "0.6.28" @@ -865,6 +1060,15 @@ dependencies = [ "serde", ] +[[package]] +name = "sharded-slab" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +dependencies = [ + "lazy_static", +] + [[package]] name = "slab" version = "0.4.7" @@ -926,6 +1130,15 @@ dependencies = [ "syn", ] +[[package]] +name = "thread_local" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" +dependencies = [ + "once_cell", +] + [[package]] name = "time" version = "0.1.45" @@ -991,6 +1204,53 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" dependencies = [ "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" +dependencies = [ + "lazy_static", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "tracing-timing" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbe4966d7b6ae25201de6ff9fa822afb0c9e933809187d5b82ad846ec108771b" +dependencies = [ + "crossbeam", + "doc-comment", + "fxhash", + "hdrhistogram", + "indexmap", + "quanta", + "slab", + "tracing-core", + "tracing-subscriber", ] [[package]] @@ -1062,6 +1322,12 @@ dependencies = [ "url", ] +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "version_check" version = "0.9.4" @@ -1154,6 +1420,16 @@ version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" +[[package]] +name = "web-sys" +version = "0.3.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/crates/payment_adapter_pay_u/Cargo.toml b/crates/payment_adapter_pay_u/Cargo.toml index de1f4cc..f50da47 100644 --- a/crates/payment_adapter_pay_u/Cargo.toml +++ b/crates/payment_adapter_pay_u/Cargo.toml @@ -7,13 +7,13 @@ edition = "2021" crate-type = ['cdylib'] [dependencies] +bincode = { version = "1" } +#tracing = { version = "0" } +chrono = { version = "0", features = ['alloc', 'wasmbind'] } +common_macros = { version = "0" } payment_adapter = { path = "../payment_adapter" } -bincode = { version = "1.3.3" } -wapc-codec = { version = "1.0.0" } -wapc-guest = { version = "1.0.0" } -#tracing = { version = "0.1.37" } -chrono = { version = "0.4.23", features = ['alloc', 'wasmbind'] } -serde = { version = "1.0.149", features = ['derive'] } -thiserror = { version = "1.0.37" } -serde_json = { version = "1.0.89" } -common_macros = { version = "0.1.1" } +serde = { version = "1", features = ['derive'] } +serde_json = { version = "1" } +thiserror = { version = "1" } +wapc-codec = { version = "1" } +wapc-guest = { version = "1" } diff --git a/crates/payment_manager/Cargo.toml b/crates/payment_manager/Cargo.toml index 941ec7d..f948c73 100644 --- a/crates/payment_manager/Cargo.toml +++ b/crates/payment_manager/Cargo.toml @@ -8,36 +8,31 @@ name = "payment-manager" path = "./src/main.rs" [dependencies] +bincode = { version = "1" } channels = { path = "../channels" } -chrono = { version = "0.4", features = ["serde"] } +chrono = { version = "0", features = ["serde"] } config = { path = "../config" } db-utils = { path = "../db-utils" } -gumdrop = { version = "0.8.1", features = [] } -llvmenv = { version = "0.3.2" } +gumdrop = { version = "0", features = [] } +llvmenv = { version = "0" } model = { path = "../model", features = ["db"] } -opentelemetry = { version = "0.17.0" } -opentelemetry-jaeger = { version = "0.17.0" } payment_adapter = { path = "../payment_adapter" } +reqwest = { version = "0", features = ["default", "json", "blocking"] } rumqttc = { version = "*" } -serde = { version = "1.0.137", features = ["derive"] } -sqlx = { version = "0.6.2", features = ["migrate", "runtime-actix-rustls", "all-types", "postgres"] } -sqlx-core = { version = "0.6.2", features = [] } -tarpc = { version = "0.31.0", features = ["tokio1", "serde-transport-bincode", "serde-transport", "serde", "serde-transport-json", "tcp"] } -thiserror = { version = "1.0.31" } -tokio = { version = "1.21.2", features = ['full'] } -tracing = { version = "0.1.6" } -tracing-opentelemetry = { version = "0.17.4" } -tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } -uuid = { version = "1.2.1", features = ["serde", "v4"] } -bincode = { version = "1.3.3" } -wapc = { version = "1.0.0", features = [] } -wapc-codec = { version = "1.0.0", features = [] } -wapc-pool = { version = "1.0.0", features = [] } -wasmtime = { version = "3.0.1", features = ['parallel-compilation', 'async'] } -wasmtime-provider = { version = "1.3.2", features = ['wasmtime-wasi', 'wasi-common', 'wasi', 'cache'] } -reqwest = { version = "0.11.13", features = ["default", "json", "blocking"] } -#pay_u = { path = "../../vendor/pay_u" } +serde = { version = "1", features = ["derive"] } +sqlx = { version = "0", features = ["migrate", "runtime-actix-rustls", "all-types", "postgres"] } +sqlx-core = { version = "0", features = [] } +tarpc = { version = "0", features = ["tokio1", "serde-transport-bincode", "serde-transport", "serde", "serde-transport-json", "tcp"] } +thiserror = { version = "1" } +tokio = { version = "1", features = ['full'] } +tracing = { version = "0" } +uuid = { version = "1", features = ["serde", "v4"] } +wapc = { version = "1", features = [] } +wapc-codec = { version = "1", features = [] } +wapc-pool = { version = "1", features = [] } +wasmtime = { version = "3", features = ['parallel-compilation', 'async'] } +wasmtime-provider = { version = "1", features = ['wasmtime-wasi', 'wasi-common', 'wasi', 'cache'] } [dev-dependencies] -fake = { version = "2.5.0" } +fake = { version = "2" } testx = { path = "../testx" } diff --git a/crates/payment_manager/src/main.rs b/crates/payment_manager/src/main.rs index ad56688..0b7d3b5 100644 --- a/crates/payment_manager/src/main.rs +++ b/crates/payment_manager/src/main.rs @@ -3,14 +3,16 @@ use std::fs::read_dir; use std::path::PathBuf; use std::str::FromStr; use std::sync::mpsc::Sender; -use std::sync::{Arc, LockResult, MutexGuard, RwLock, RwLockReadGuard}; +use std::sync::{Arc, LockResult, MutexGuard}; -use config::{AppConfig, UpdateConfig}; -use payment_adapter::{HttpMethod, HttpRequest, Item, Product}; +use config::{AppConfig, SharedAppConfig, UpdateConfig}; +use payment_adapter::{HttpMethod, HttpRequest}; use reqwest::header::{HeaderMap, HeaderName, HeaderValue}; use wapc::WasiParams; use wapc_pool::{HostPool, HostPoolBuilder}; +use crate::rpc::ModuleSender; + // mod actions; // mod context; // mod db; @@ -23,14 +25,23 @@ mod rpc; pub enum WasmMsg { CreateOrder { create_payment: payment_adapter::CreatePayment, - callback: std::sync::mpsc::Sender, + tx: Sender, + }, + UpdateStatus { + update_status: payment_adapter::UpdateStatus, + tx: Sender, + }, + Cancel { + cancel: payment_adapter::Cancel, + tx: Sender, }, - UpdateStatus(Vec), } #[derive(Clone)] pub enum ResultMsg { OrderCreated(payment_adapter::OrderCreated), + StatusUpdated(payment_adapter::StatusUpdated), + Cancel(payment_adapter::Cancelled), } pub struct HostChannel { @@ -54,41 +65,84 @@ impl HostChannel { match msg { WasmMsg::CreateOrder { create_payment: msg, - callback, + tx, } => { - let msg = match wapc_codec::messagepack::serialize(msg) { - Ok(r) => r, - _ => continue, - }; - let call_result = match pool.call("create_payment", msg).await { - Ok(r) => r, - _ => continue, - }; - let result: payment_adapter::OrderCreated = - match wapc_codec::messagepack::deserialize(&call_result) { - Ok(r) => r, - _ => continue, - }; - if let Err(e) = callback.send(ResultMsg::OrderCreated(result)) { - tracing::error!("{e:?}"); - } + Self::send_and_rec( + "create_payment", + msg, + tx, + &pool, + ResultMsg::OrderCreated, + ) + .await + .ok(); + } + WasmMsg::UpdateStatus { + update_status: msg, + tx, + } => { + Self::send_and_rec( + "update_status", + msg, + tx, + &pool, + ResultMsg::StatusUpdated, + ) + .await + .ok(); + } + WasmMsg::Cancel { cancel: msg, tx } => { + Self::send_and_rec("cancel_order", msg, tx, &pool, ResultMsg::Cancel) + .await + .ok(); } - WasmMsg::UpdateStatus(_) => {} } } }); } + + async fn send_and_rec( + name: &str, + msg: R, + tx: Sender, + pool: &HostPool, + f: F, + ) -> Result<(), ()> + where + R: serde::Serialize, + T: serde::de::DeserializeOwned, + F: FnOnce(T) -> ResultMsg, + { + macro_rules! ok_or_bail { + ($run: expr) => { + match $run { + Ok(r) => r, + _ => return Err(()), + } + }; + } + + let msg = ok_or_bail!(wapc_codec::messagepack::serialize(msg)); + let call_result = ok_or_bail!(pool.call(name, msg).await); + let result: T = ok_or_bail!(wapc_codec::messagepack::deserialize(&call_result)); + if let Err(e) = tx.send(f(result)) { + tracing::error!("{e:?}"); + Err(()) + } else { + Ok(()) + } + } } #[derive(Clone)] -pub struct Modules(Arc>>>); +pub struct Modules(Arc>>); impl Modules { - pub fn new(h: HashMap>) -> Self { + pub fn new(h: HashMap) -> Self { Self(Arc::new(std::sync::Mutex::new(h))) } - pub fn lock(&self) -> LockResult>>> { + pub fn lock(&self) -> LockResult>> { self.0.lock() } } @@ -108,139 +162,145 @@ impl UpdateConfig for Opts { #[tokio::main] async fn main() { - std::env::set_var("RUST_LOG", "debug"); - - tracing_subscriber::fmt::init(); + config::init_tracing("payments"); let opts: Opts = gumdrop::parse_args_default_or_exit(); let config = config::default_load(&opts); - let mut modules; + let files = scan_adapters_dir(&config); + let mut modules = HashMap::with_capacity(files.len()); - { - let adapters_path = config.lock().payment().adapters_path.clone(); - let adapters = adapters_path.unwrap_or_else(|| panic!("No payment adapters path provided")); - let dir = read_dir(&adapters).unwrap_or_else(|e| { - panic!( - "Failed to load payment adapters at path {:?}. {}", - adapters, e - ) - }); - let files = dir - .filter_map(|r| r.map(|r| r.path()).ok()) - .filter(|file| file.extension().and_then(|s| s.to_str()) == Some("wasm")) - .collect::>(); + load_adapters(&config, &mut modules, files).await; - if files.is_empty() { - panic!("No payment adapters found in adapters directory"); - } - - modules = HashMap::with_capacity(files.len()); - - for file in files { - let module = std::fs::read(&file).unwrap(); - let engine = wasmtime_provider::WasmtimeEngineProviderBuilder::new() - .module_bytes(&module) - .wasi_params(WasiParams::default()) - .build() - .unwrap(); - - let pool = HostPoolBuilder::new() - .name("pool") - .factory(move || { - wapc::WapcHost::new( - Box::new(engine.clone()), - Some(Box::new( - move |_a, binding, _namespace, msg_name, payload| { - Ok(host_call(binding, msg_name, payload)?) - }, - )), - ) - .unwrap() - }) - .max_threads(5) - .build(); - let name = pool - .call("name", vec![]) - .await - .unwrap_or_else(|e| panic!("Failed to load adapter {file:?} `name`. {e}")); - let name: String = wapc_codec::messagepack::deserialize(&name) - .unwrap_or_else(|e| panic!("Adapter `name` ({name:?}) is not valid string. {e}")); - - let msg = config - .lock() - .payment() - .providers - .get(&name) - .cloned() - .unwrap_or_default(); - - tracing::info!("Start init"); - pool.call("init", wapc_codec::messagepack::serialize(msg).unwrap()) - .await - .unwrap(); - - let (tx, rx) = std::sync::mpsc::channel(); - HostChannel { - host: pool, - channel: rx, - } - .start(); - - modules.insert(name, tx); - } - - // for pool in modules.values() { - // let msg = payment_adapter::CreatePayment { - // buyer: payment_adapter::Buyer { - // email: "hello@example.com".to_string(), - // phone: "530698478".to_string(), - // first_name: "Joe".to_string(), - // last_name: "Doe".to_string(), - // language: "pl".to_string(), - // }, - // customer_ip: "12.22.34.54".to_string(), - // currency: "PLN".to_string(), - // description: "Nesciunt fugit libero quis dolorum quo. - // Tempore aut nisi voluptatem. Odio et aspernatur est. Sint vel - // molestias sunt cumque quibusdam reprehenderit est.".to_string(), - // cart_products: vec![Product { - // id: 23, - // name: "Socks".to_string(), - // unit_price: 1542, - // quantity_unit: "Unit".to_string(), - // quantity: 2, - // }], - // items: vec![Item { - // product_id: 23, - // quantity: 2, - // quantity_unit: "Unit".to_string(), - // }], - // order_ext_id: None, - // notify_uri: "https://localhost:3030/notify_uri".to_string(), - // continue_uri: "https://localhost:3030/continue_uri".to_string(), - // }; - // - // tracing::info!("Start create_payment"); - // let call_result = pool - // .call( - // "create_payment", - // wapc_codec::messagepack::serialize(msg).unwrap(), - // ) - // .await - // .unwrap(); - // let result: payment_adapter::OrderCreated = - // wapc_codec::messagepack::deserialize(&call_result).unwrap(); - // - // tracing::info!("create payment res {:?}", result) - // } - } + // for pool in modules.values() { + // let msg = payment_adapter::CreatePayment { + // buyer: payment_adapter::Buyer { + // email: "hello@example.com".to_string(), + // phone: "530698478".to_string(), + // first_name: "Joe".to_string(), + // last_name: "Doe".to_string(), + // language: "pl".to_string(), + // }, + // customer_ip: "12.22.34.54".to_string(), + // currency: "PLN".to_string(), + // description: "Nesciunt fugit libero quis dolorum quo. + // Tempore aut nisi voluptatem. Odio et aspernatur est. Sint vel + // molestias sunt cumque quibusdam reprehenderit est.".to_string(), + // cart_products: vec![Product { + // id: 23, + // name: "Socks".to_string(), + // unit_price: 1542, + // quantity_unit: "Unit".to_string(), + // quantity: 2, + // }], + // items: vec![Item { + // product_id: 23, + // quantity: 2, + // quantity_unit: "Unit".to_string(), + // }], + // order_ext_id: None, + // notify_uri: "https://localhost:3030/notify_uri".to_string(), + // continue_uri: "https://localhost:3030/continue_uri".to_string(), + // }; + // + // tracing::info!("Start create_payment"); + // let call_result = pool + // .call( + // "create_payment", + // wapc_codec::messagepack::serialize(msg).unwrap(), + // ) + // .await + // .unwrap(); + // let result: payment_adapter::OrderCreated = + // wapc_codec::messagepack::deserialize(&call_result).unwrap(); + // + // tracing::info!("create payment res {:?}", result) + // } let modules = Modules::new(modules); let mqtt_client = mqtt::start(config.clone(), modules.clone()).await; rpc::start(config, mqtt_client, modules.clone()).await; } +async fn load_adapters( + config: &SharedAppConfig, + modules: &mut HashMap, + files: Vec, +) { + for file in files { + let module = std::fs::read(&file).unwrap(); + let engine = wasmtime_provider::WasmtimeEngineProviderBuilder::new() + .module_bytes(&module) + .wasi_params(WasiParams::default()) + .build() + .unwrap(); + + let pool = HostPoolBuilder::new() + .name("pool") + .factory(move || { + wapc::WapcHost::new( + Box::new(engine.clone()), + Some(Box::new( + move |_a, binding, _namespace, msg_name, payload| { + Ok(host_call(binding, msg_name, payload)?) + }, + )), + ) + .unwrap() + }) + .max_threads(5) + .build(); + let name = pool + .call("name", vec![]) + .await + .unwrap_or_else(|e| panic!("Failed to load adapter {file:?} `name`. {e}")); + let name: String = wapc_codec::messagepack::deserialize(&name) + .unwrap_or_else(|e| panic!("Adapter `name` ({name:?}) is not valid string. {e}")); + + let msg = config + .lock() + .payment() + .providers + .get(&name) + .cloned() + .unwrap_or_default(); + + tracing::info!("Start init"); + pool.call("init", wapc_codec::messagepack::serialize(msg).unwrap()) + .await + .unwrap(); + + let (tx, rx) = std::sync::mpsc::channel(); + HostChannel { + host: pool, + channel: rx, + } + .start(); + + modules.insert(name, ModuleSender::new(tx)); + } +} + +fn scan_adapters_dir(config: &SharedAppConfig) -> Vec { + let adapters_path = config.lock().payment().adapters_path.clone(); + let adapters = adapters_path.unwrap_or_else(|| panic!("No payment adapters path provided")); + let dir = read_dir(&adapters).unwrap_or_else(|e| { + panic!( + "Failed to load payment adapters at path {:?}. {}", + adapters, e + ) + }); + let files = dir + .filter_map(|r| r.map(|r| r.path()).ok()) + .filter(|file| file.extension().and_then(|s| s.to_str()) == Some("wasm")) + .collect::>(); + + if files.is_empty() { + panic!("No payment adapters found in adapters directory"); + } + files +} + // #[tracing::instrument] fn host_call(binding: &str, name: &str, payload: &[u8]) -> Result, payment_adapter::Error> { match name { diff --git a/crates/payment_manager/src/rpc.rs b/crates/payment_manager/src/rpc.rs index 1ed0b36..f44e01a 100644 --- a/crates/payment_manager/src/rpc.rs +++ b/crates/payment_manager/src/rpc.rs @@ -1,13 +1,43 @@ -use std::sync::mpsc::RecvError; +use std::sync::mpsc::Sender; use channels::payments::rpc::Payments; use channels::payments::{adapters, cancel, notification, start_payment}; -use channels::AsyncClient; +use channels::{payments, AsyncClient}; use config::SharedAppConfig; +use payment_adapter::Cancel; use tarpc::context; use crate::{Modules, ResultMsg, WasmMsg}; +#[derive(Clone)] +pub struct ModuleSender { + tx: Sender, +} + +impl ModuleSender { + pub fn new(tx: Sender) -> Self { + Self { tx } + } + + pub fn send(&self, f: F) -> Result + where + F: FnOnce(Sender) -> WasmMsg, + { + use payments::Error; + + let (tx, rx) = std::sync::mpsc::channel(); + self.tx.send(f(tx)).map_err(|e| { + tracing::error!("{e}"); + Error::SendToWasmFailed + })?; + let res = rx.recv().map_err(|e| { + tracing::error!("{e}"); + Error::RecvFromWasmFailed + })?; + Ok(res) + } +} + #[derive(Clone)] pub struct PaymentsServer { pub config: SharedAppConfig, @@ -15,6 +45,21 @@ pub struct PaymentsServer { pub modules: Modules, } +impl PaymentsServer { + fn adapter_sender(&self, adapter_name: String) -> Result { + use channels::payments::Error; + let modules = self.modules.clone(); + let lock = modules.lock().map_err(|e| { + tracing::error!("{e}"); + Error::InternalServerError + })?; + Ok(lock + .get(&adapter_name) + .ok_or_else(|| Error::UnknownAdapter(adapter_name))? + .clone()) + } +} + #[tarpc::server] impl Payments for PaymentsServer { async fn start_payment( @@ -28,32 +73,8 @@ impl Payments for PaymentsServer { create_payment, } = input; - // let (tx, rx) = std::sync::mpsc::channel(); - - let modules = self.modules.clone(); - let lock = modules.lock().map_err(|e| { - tracing::error!("{e}"); - Error::InternalServerError - })?; - let module = lock - .get(&adapter_name) - .ok_or_else(|| Error::UnknownAdapter(adapter_name))? - .clone(); - - let (tx, rx) = std::sync::mpsc::channel(); - module - .send(WasmMsg::CreateOrder { - create_payment, - callback: tx, - }) - .map_err(|e| { - tracing::error!("{e}"); - Error::PaymentFailed - })?; - let res = rx.recv().map_err(|e| { - tracing::error!("{e}"); - Error::MalformedCreatePaymentResult - })?; + let module = self.adapter_sender(adapter_name)?; + let res = module.send(|tx| WasmMsg::CreateOrder { create_payment, tx })?; match res { ResultMsg::OrderCreated(res) => Ok(start_payment::Details { @@ -64,7 +85,31 @@ impl Payments for PaymentsServer { } async fn cancel(self, _: context::Context, input: cancel::Input) -> cancel::Output { - todo!() + use channels::payments::cancel::RefundType; + use channels::payments::Error; + + let cancel::Input { + adapter_name, + refund, + provider_order_id, + description, + } = input; + let module = self.adapter_sender(adapter_name)?; + let res = module.send(|tx| WasmMsg::Cancel { + cancel: Cancel { + refund: match refund { + RefundType::Full => payment_adapter::RefundType::Full, + RefundType::Partial(v) => payment_adapter::RefundType::Partial(v), + }, + provider_order_id, + description, + }, + tx, + })?; + match res { + ResultMsg::Cancel(_res) => Ok(cancel::Details {}), + _ => Err(Error::MalformedCancelResult), + } } async fn notification( @@ -72,11 +117,29 @@ impl Payments for PaymentsServer { _: context::Context, input: notification::Input, ) -> notification::Output { - todo!() + use channels::payments::{notification, Error}; + + let notification::Input { adapter_name, body } = input; + let module = self.adapter_sender(adapter_name)?; + let res = module.send(|tx| WasmMsg::UpdateStatus { + update_status: payment_adapter::UpdateStatus { payload: body }, + tx, + })?; + match res { + ResultMsg::StatusUpdated(_res) => Ok(notification::Details {}), + _ => Err(Error::MalformedUpdateStateResult), + } } - async fn adapters(self, _: context::Context, input: adapters::Input) -> adapters::Output { - todo!() + async fn adapters(self, _: context::Context, _input: adapters::Input) -> adapters::Output { + Ok(adapters::Details { + names: self + .modules + .0 + .lock() + .map(|r| r.keys().cloned().collect::>()) + .unwrap_or_default(), + }) } } diff --git a/crates/search_manager/Cargo.toml b/crates/search_manager/Cargo.toml index 09e86fe..653c492 100644 --- a/crates/search_manager/Cargo.toml +++ b/crates/search_manager/Cargo.toml @@ -8,31 +8,26 @@ name = "search-manager" path = "./src/main.rs" [dependencies] -actix = { version = "0.13", features = [] } -actix-rt = { version = "2.7", features = [] } +actix = { version = "0", features = [] } +actix-rt = { version = "2", features = [] } channels = { path = "../channels" } -chrono = { version = "0.4", features = ["serde"] } +chrono = { version = "0", features = ["serde"] } config = { path = "../config" } -derive_more = { version = "0.99", features = [] } -dotenv = { version = "0.15.0" } -futures = { version = "0.3.25" } +derive_more = { version = "0", features = [] } +dotenv = { version = "0" } +futures = { version = "0" } model = { path = "../model", features = ["db"] } -opentelemetry = { version = "0.17.0" } -opentelemetry-jaeger = { version = "0.17.0" } -parking_lot = { version = "0.12", features = [] } -pretty_env_logger = { version = "0.4", features = [] } +parking_lot = { version = "0", features = [] } rumqttc = { version = "*" } -serde = { version = "1.0", features = ["derive"] } -sonic-channel = { version = "1.1.0", features = ["ingest"] } -tarpc = { version = "0.31.0", features = ["tokio1", "serde-transport-bincode", "serde-transport", "serde", "serde-transport-json", "tcp"] } -thiserror = { version = "1.0.31" } -tokio = { version = "1.21.2", features = ['full'] } -tracing = { version = "0.1.6" } -tracing-opentelemetry = { version = "0.17.4" } -tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } -uuid = { version = "1.2.1", features = ["serde"] } -whatlang = { version = "0.16.2" } +serde = { version = "1", features = ["derive"] } +sonic-channel = { version = "1", features = ["ingest"] } +tarpc = { version = "0", features = ["tokio1", "serde-transport-bincode", "serde-transport", "serde", "serde-transport-json", "tcp"] } +thiserror = { version = "1" } +tokio = { version = "1", features = ['full'] } +tracing = { version = "0" } +uuid = { version = "1", features = ["serde"] } +whatlang = { version = "0" } [dev-dependencies] -fake = { version = "2.5.0" } +fake = { version = "2" } testx = { path = "../testx" } diff --git a/crates/search_manager/src/main.rs b/crates/search_manager/src/main.rs index 534c195..ef2b733 100644 --- a/crates/search_manager/src/main.rs +++ b/crates/search_manager/src/main.rs @@ -4,9 +4,6 @@ use std::env; use config::UpdateConfig; pub use context::*; -use tracing_subscriber::fmt::format::FmtSpan; -use tracing_subscriber::layer::SubscriberExt; -use tracing_subscriber::util::SubscriberInitExt; pub mod actions; pub mod context; @@ -35,7 +32,7 @@ impl UpdateConfig for Opts {} #[actix::main] async fn main() { dotenv::dotenv().ok(); - init_tracing("search-manager"); + config::init_tracing("search-manager"); let opts = Opts {}; @@ -47,24 +44,3 @@ async fn main() { rpc::start(config.clone(), ctx.clone()).await; } - -pub fn init_tracing(_service_name: &str) { - env::set_var("OTEL_BSP_MAX_EXPORT_BATCH_SIZE", "12"); - - let tracer = { - use opentelemetry::sdk::export::trace::stdout::new_pipeline; - use opentelemetry::sdk::trace::Config; - - new_pipeline() - .with_trace_config(Config::default()) - .with_pretty_print(true) - .install_simple() - }; - - tracing_subscriber::registry() - .with(tracing_subscriber::EnvFilter::from_default_env()) - .with(tracing_subscriber::fmt::layer().with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)) - .with(tracing_opentelemetry::layer().with_tracer(tracer)) - .try_init() - .unwrap(); -} diff --git a/crates/stock_manager/Cargo.toml b/crates/stock_manager/Cargo.toml index 5a6b8c8..16a9bae 100644 --- a/crates/stock_manager/Cargo.toml +++ b/crates/stock_manager/Cargo.toml @@ -9,29 +9,24 @@ path = "./src/main.rs" [dependencies] channels = { path = "../channels" } -chrono = { version = "0.4", features = ["serde"] } +chrono = { version = "0", features = ["serde"] } config = { path = "../config" } db-utils = { path = "../db-utils" } -derive_more = { version = "0.99", features = [] } -dotenv = { version = "0.15.0" } -futures = { version = "0.3.25" } +derive_more = { version = "0", features = [] } +dotenv = { version = "0" } +futures = { version = "0" } model = { path = "../model", features = ["db"] } -opentelemetry = { version = "0.17.0" } -opentelemetry-jaeger = { version = "0.17.0" } -pretty_env_logger = { version = "0.4", features = [] } rumqttc = { version = "*" } -serde = { version = "1.0", features = ["derive"] } -sqlx = { version = "0.6.2", features = ["migrate", "runtime-actix-rustls", "all-types", "postgres"] } -sqlx-core = { version = "0.6.2", features = [] } -tarpc = { version = "0.31.0", features = ["tokio1", "serde-transport-bincode", "serde-transport", "serde", "serde-transport-json", "tcp"] } -thiserror = { version = "1.0.31" } -tokio = { version = "1.21.2", features = ['full'] } -tracing = { version = "0.1.6" } -tracing-opentelemetry = { version = "0.17.4" } -tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } -uuid = { version = "1.2.1", features = ['v4'] } +serde = { version = "1", features = ["derive"] } +sqlx = { version = "0", features = ["migrate", "runtime-actix-rustls", "all-types", "postgres"] } +sqlx-core = { version = "0", features = [] } +tarpc = { version = "0", features = ["tokio1", "serde-transport-bincode", "serde-transport", "serde", "serde-transport-json", "tcp"] } +thiserror = { version = "1" } +tokio = { version = "1", features = ['full'] } +tracing = { version = "0" } +uuid = { version = "1", features = ['v4'] } [dev-dependencies] -fakeit = { version = "1.1.1" } -insta = { version = "1.21.0" } +fakeit = { version = "1" } +insta = { version = "1" } testx = { path = "../testx" } diff --git a/crates/stock_manager/src/main.rs b/crates/stock_manager/src/main.rs index edc341c..d0ca8a6 100644 --- a/crates/stock_manager/src/main.rs +++ b/crates/stock_manager/src/main.rs @@ -14,6 +14,8 @@ impl UpdateConfig for Opts {} async fn main() { let opts = Opts {}; + config::init_tracing("stocks"); + let config = config::default_load(&opts); let db = db::Database::build(config.clone()).await; diff --git a/crates/token_manager/Cargo.toml b/crates/token_manager/Cargo.toml index 6b7bf6f..6177d87 100644 --- a/crates/token_manager/Cargo.toml +++ b/crates/token_manager/Cargo.toml @@ -3,31 +3,36 @@ name = "token_manager" version = "0.1.0" edition = "2021" +[[bin]] +name = 'token-manager' +path = './src/main.rs' + [dependencies] -actix = { version = "0.13", features = [] } -actix-rt = { version = "2.7", features = [] } -argon2 = { version = "0.4", features = ["parallel", "password-hash"] } -chrono = { version = "0.4", features = ["serde"] } +argon2 = { version = "0", features = ["parallel", "password-hash"] } +channels = { path = "../channels" } +chrono = { version = "0", features = ["serde"] } config = { path = "../config" } -database_manager = { path = "../database_manager" } -derive_more = { version = "0.99", features = [] } -futures = { version = "0.3", features = [] } -futures-util = { version = "0.3", features = [] } -hmac = { version = "0.12", features = [] } -jwt = { version = "0.16", features = [] } -model = { path = "../model" } -parking_lot = { version = "0.12", features = [] } -password-hash = { version = "0.4", features = ["alloc"] } -pretty_env_logger = { version = "0.4", features = [] } -rand_core = { version = "0.6", features = ["std"] } +db-utils = { path = "../db-utils" } +derive_more = { version = "0", features = [] } +dotenv = { version = "0" } +futures = { version = "0" } +futures-util = { version = "0", features = [] } +hmac = { version = "0", features = [] } +jwt = { version = "0", features = [] } +model = { path = "../model", features = ["db"] } +password-hash = { version = "0", features = ["alloc"] } +rand_core = { version = "0", features = ["std"] } rumqttc = { version = "*" } -serde = { version = "1.0", features = ["derive"] } -sha2 = { version = "0.10", features = [] } -thiserror = { version = "1.0.31" } -tokio = { version = "1.17", features = ["full"] } -tracing = { version = "0.1.34" } -uuid = { version = "1.2.1", features = ["serde"] } +serde = { version = "1", features = ["derive"] } +sha2 = { version = "0", features = [] } +sqlx = { version = "0", features = ["migrate", "runtime-actix-rustls", "all-types", "postgres"] } +sqlx-core = { version = "0", features = [] } +tarpc = { version = "0", features = ["tokio1", "serde-transport-bincode", "serde-transport", "serde", "serde-transport-json", "tcp"] } +thiserror = { version = "1" } +tokio = { version = "1", features = ['full'] } +tracing = { version = "0" } +uuid = { version = "1", features = ['v4'] } [dev-dependencies] -fake = { version = "2.5.0" } +fake = { version = "2" } testx = { path = "../testx" } diff --git a/crates/token_manager/migrations/202204131841_init.sql b/crates/token_manager/migrations/202204131841_init.sql new file mode 100644 index 0000000..b510405 --- /dev/null +++ b/crates/token_manager/migrations/202204131841_init.sql @@ -0,0 +1,27 @@ +CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; + +CREATE TYPE "Audience" AS ENUM ( + 'web', + 'mobile', + 'feed', + 'admin_panel' + ); + +CREATE TYPE "Role" AS ENUM ( + 'admin', + 'user' + ); + +CREATE TABLE tokens +( + id integer NOT NULL, + customer_id uuid NOT NULL, + role "Role" NOT NULL, + issuer character varying DEFAULT 'bazzar'::character varying NOT NULL, + subject integer NOT NULL, + audience "Audience" DEFAULT 'web'::"Audience" NOT NULL, + expiration_time timestamp without time zone DEFAULT (now() + '14 days'::interval) NOT NULL, + not_before_time timestamp without time zone DEFAULT (now() - '00:01:00'::interval) NOT NULL, + issued_at_time timestamp without time zone DEFAULT now() NOT NULL, + jwt_id uuid DEFAULT gen_random_uuid() NOT NULL +); diff --git a/crates/token_manager/src/context.rs b/crates/token_manager/src/context.rs new file mode 100644 index 0000000..e69de29 diff --git a/crates/token_manager/src/db/mod.rs b/crates/token_manager/src/db/mod.rs new file mode 100644 index 0000000..036573c --- /dev/null +++ b/crates/token_manager/src/db/mod.rs @@ -0,0 +1,28 @@ +use config::SharedAppConfig; +use sqlx_core::pool::Pool; +use sqlx_core::postgres::Postgres; + +#[derive(Clone)] +pub struct Database { + pub pool: sqlx::PgPool, + _config: SharedAppConfig, +} + +impl Database { + pub async fn build(config: SharedAppConfig) -> Self { + let url = config.lock().tokens().database_url.clone(); + let pool = sqlx::PgPool::connect(&url).await.unwrap_or_else(|e| { + eprintln!("Failed to connect to database. {e:?}"); + tracing::error!("Failed to connect to database. {e:?}"); + std::process::exit(1); + }); + Self { + pool, + _config: config, + } + } + + pub fn pool(&self) -> Pool { + self.pool.clone() + } +} diff --git a/crates/token_manager/src/lib.rs b/crates/token_manager/src/lib.rs deleted file mode 100644 index df2246c..0000000 --- a/crates/token_manager/src/lib.rs +++ /dev/null @@ -1,641 +0,0 @@ -//! Tokens management system. -//! It's responsible for creating and validating all tokens. -//! -//! Application flow goes like this: -//! -//! ```ascii -//! Client API TokenManager Database -//! -//! │ │ │ │ -//! │ │ │ │ -//! │ │ │ ┌───────────────►│ -//! ├────────────────►├──────────────────►├──────►│ │ -//! │ Sign In │ CreatePair │ └───────────────►│ -//! │ │ │ Create │ -//! │ │ │ * AccessToken │ -//! │ │ │ * RefreshToken │ -//! │ │ │ │ -//! │ │ │ │ -//! -//! │ │ │ │ -//! ├────────────────►├──────────────────►├───────────────────────►│ -//! │ Validate token │ ValidateToken │ Load token │ -//! │ │ (string) │◄───────────────────────┤ -//! │ │ │ │ -//! │ │ Is Valid? │ -//! │ │ │ │ -//! │ │◄──────────────── YES │ -//! │ │ AccessToken │ │ -//! │ │ │ │ -//! │ │ │ │ -//! │ │◄──────────────── NO │ -//! │ │ Error │ │ -//! -//! │ │ │ │ -//! │ │ │ │ -//! │ │ │ ┌───────────────►│ -//! ├────────────────►├──────────────────►├──────►│ │ -//! │ Refresh token │ CreatePair │ └───────────────►│ -//! │ │ │ Create │ -//! │ │◄──────────────────┤ * AccessToken │ -//! │ │ Access Token │ * RefreshToken │ -//! │ │ Refresh Token │ │ -//! │ │ │ │ -//! ``` -//! -//! If you need to operate on tokens from API or any other actor you should -//! always use this actor and never touch database directly. -//! -//! # Examples -//! -//! ``` -//! use actix::{Actor, Addr}; -//! use config::SharedAppConfig; -//! use database_manager::Database; -//! use token_manager::*; -//! use model::*; -//! -//! async fn tokens(db: Addr, config: SharedAppConfig) { -//! let manager = TokenManager::new(config, db); -//! -//! let manager_addr = manager.start(); -//! -//! let AuthPair { access_token, access_token_string, refresh_token_string, .. } = manager_addr.send(CreatePair { -//! customer_id: uuid::Uuid::new_v4(), -//! account_id: AccountId::from(0), -//! role: Role::Admin -//! }).await.unwrap().unwrap(); -//! -//! manager_addr.send(Validate { token: access_token_string }).await.unwrap().unwrap(); -//! } -//! ``` - -use std::collections::BTreeMap; -use std::str::FromStr; - -use actix::{Addr, Message}; -use chrono::prelude::*; -use config::SharedAppConfig; -use database_manager::{query_db, Database}; -use hmac::digest::KeyInit; -use hmac::Hmac; -use model::{AccessTokenString, AccountId, Audience, Role, Token}; -use sha2::Sha256; - -#[macro_export] -macro_rules! token_async_handler { - ($msg: ty, $async: ident, $res: ty) => { - impl actix::Handler<$msg> for TokenManager { - type Result = actix::ResponseActFuture>; - - fn handle(&mut self, msg: $msg, _ctx: &mut Self::Context) -> Self::Result { - use actix::WrapFuture; - let db = self.db.clone(); - let config = self.config.clone(); - Box::pin(async { $async(msg, db, config).await }.into_actor(self)) - } - } - }; -} - -#[macro_export] -macro_rules! query_tm { - ($tm: expr, $msg: expr, default $fail: expr) => { - match $tm.send($msg).await { - Ok(Ok(r)) => r, - Ok(Err(e)) => { - tracing::error!("{e}"); - $fail - } - Err(e) => { - tracing::error!("{e:?}"); - $fail - } - } - }; - - (multi, $tm: expr, $fail: expr, $($msg: expr),*) => {{ - use futures_util::TryFutureExt; - tokio::join!( - $( - $tm.send($msg).map_ok_or_else( - |e| { - tracing::error!("{e:?}"); - Err($fail) - }, - |res| match res { - Ok(rec) => Ok(rec), - Err(e) => { - tracing::error!("{e}"); - Err($fail) - } - }, - ) - ),* - ) - }}; - - ($tm: expr, $msg: expr, $fail: expr) => { - $crate::query_tm!($tm, $msg, $fail, $fail) - }; - - ($tm: expr, $msg: expr, $db_fail: expr, $act_fail: expr) => { - match $tm.send($msg).await { - Ok(Ok(r)) => r, - Ok(Err(e)) => { - tracing::error!("{e}"); - return Err($db_fail); - } - Err(e) => { - tracing::error!("{e:?}"); - return Err($act_fail); - } - } - }; -} - -/*struct Jwt { - /// cti (customer id): Customer uuid identifier used by payment service - pub cti: uuid::Uuid, - /// arl (account role): account role - pub arl: Role, - /// iss (issuer): Issuer of the JWT - pub iss: String, - /// sub (subject): Subject of the JWT (the user) - pub sub: i32, - /// aud (audience): Recipient for which the JWT is intended - pub aud: Audience, - /// exp (expiration time): Time after which the JWT expires - pub exp: chrono::NaiveDateTime, - /// nbt (not before time): Time before which the JWT must not be accepted - /// for processing - pub nbt: chrono::NaiveDateTime, - /// iat (issued at time): Time at which the JWT was issued; can be used to - /// determine age of the JWT, - pub iat: chrono::NaiveDateTime, - /// jti (JWT ID): Unique identifier; can be used to prevent the JWT from - /// being replayed (allows a token to be used only once) - pub jti: uuid::Uuid, -}*/ - -#[derive(Debug, Copy, Clone, serde::Serialize, thiserror::Error)] -#[serde(rename_all = "kebab-case", tag = "token")] -pub enum Error { - #[error("Unable to save new token")] - Save, - #[error("Unable to save new token. Can't connect to database")] - SaveInternal, - #[error("Unable to validate token")] - Validate, - #[error("Unable to validate token. Can't connect to database")] - ValidateInternal, - #[error("Token does not exists or some fields are incorrect")] - Invalid, -} - -pub type Result = std::result::Result; - -pub struct TokenManager { - db: Addr, - config: SharedAppConfig, -} - -impl actix::Actor for TokenManager { - type Context = actix::Context; -} - -impl TokenManager { - pub fn new(config: SharedAppConfig, db: Addr) -> Self { - Self { db, config } - } -} - -/// Creates single token, it's mostly used by [CreatePair] -/// -/// # Examples -/// -/// ``` -/// use actix::Addr; -/// use model::{AccountId, Role}; -/// use token_manager::*; -/// async fn create_pair(token_manager: Addr) { -/// match token_manager.send(CreateToken { customer_id: uuid::Uuid::new_v4(), role: Role::Admin, subject: AccountId::from(1), audience: None, exp: None }).await { -/// Ok(Ok(pair)) => {} -/// Ok(Err(manager_error)) => {} -/// Err(actor_error) => {} -/// } -/// } -/// ``` -#[derive(Message)] -#[rtype(result = "Result<(Token, AccessTokenString)>")] -pub struct CreateToken { - pub customer_id: uuid::Uuid, - pub role: Role, - pub subject: AccountId, - pub audience: Option, - pub exp: Option, -} - -token_async_handler!(CreateToken, create_token, (Token, AccessTokenString)); - -pub(crate) async fn create_token( - msg: CreateToken, - db: Addr, - config: SharedAppConfig, -) -> Result<(Token, AccessTokenString)> { - let CreateToken { - customer_id, - role, - subject, - audience, - exp, - } = msg; - let audience = audience.unwrap_or_default(); - - let token: Token = match exp { - None => query_db!( - db, - database_manager::CreateToken { - customer_id, - role, - subject, - audience, - }, - Error::Save, - Error::SaveInternal - ), - Some(exp) => query_db!( - db, - database_manager::CreateExtendedToken { - customer_id, - role, - subject, - audience, - expiration_time: exp - }, - Error::Save, - Error::SaveInternal - ), - }; - - let token_string = { - use jwt::SignWithKey; - - let secret = config.lock().web().jwt_secret(); - let key: Hmac = build_key(secret)?; - let mut claims = BTreeMap::new(); - - // cti (customer id): Customer uuid identifier used by payment service - claims.insert("cti", format!("{}", token.customer_id)); - // arl (account role): account role - claims.insert("arl", String::from(token.role.as_str())); - // iss (issuer): Issuer of the JWT - claims.insert("iss", token.issuer.to_string()); - // sub (subject): Subject of the JWT (the user) - claims.insert("sub", format!("{}", token.subject)); - // aud (audience): Recipient for which the JWT is intended - claims.insert("aud", String::from(token.audience.as_str())); - // exp (expiration time): Time after which the JWT expires - claims.insert( - "exp", - format!( - "{}", - Utc.from_utc_datetime(&token.expiration_time).format("%+") - ), - ); - // nbt (not before time): Time before which the JWT must not be accepted - // for processing - claims.insert( - "nbt", - format!( - "{}", - Utc.from_utc_datetime(&token.not_before_time).format("%+") - ), - ); - // iat (issued at time): Time at which the JWT was issued; can be used - // to determine age of the JWT, - claims.insert( - "iat", - format!( - "{}", - Utc.from_utc_datetime(&token.issued_at_time).format("%+") - ), - ); - // jti (JWT ID): Unique identifier; can be used to prevent the JWT from - // being replayed (allows a token to be used only once) - claims.insert("jti", format!("{}", token.jwt_id)); - - let s = match claims.sign_with_key(&key) { - Ok(s) => s, - Err(e) => { - tracing::error!("{e:?}"); - return Err(Error::SaveInternal); - } - }; - AccessTokenString::new(s) - }; - Ok((token, token_string)) -} - -pub struct AuthPair { - pub access_token: Token, - pub access_token_string: AccessTokenString, - pub _refresh_token: Token, - pub refresh_token_string: model::RefreshTokenString, -} - -/// Creates access token and refresh token -/// -/// # Examples -/// -/// ``` -/// use actix::Addr; -/// use model::{AccountId, Role}; -/// use token_manager::CreatePair; -/// async fn create_pair(token_manager: Addr) { -/// match token_manager.send(CreatePair { customer_id: uuid::Uuid::new_v4(), account_id: AccountId::from(0), role: Role::Admin }).await { -/// Ok(Ok(pair)) => {} -/// Ok(Err(manager_error)) => {} -/// Err(actor_error) => {} -/// } -/// } -/// ``` -#[derive(Message)] -#[rtype(result = "Result")] -pub struct CreatePair { - pub customer_id: uuid::Uuid, - pub role: Role, - pub account_id: AccountId, -} - -token_async_handler!(CreatePair, create_pair, AuthPair); - -pub(crate) async fn create_pair( - msg: CreatePair, - db: Addr, - config: SharedAppConfig, -) -> Result { - let (access_token, refresh_token) = tokio::join!( - create_token( - CreateToken { - customer_id: msg.customer_id, - role: msg.role, - subject: msg.account_id, - audience: Some(model::Audience::Web), - exp: None - }, - db.clone(), - config.clone() - ), - create_token( - CreateToken { - customer_id: msg.customer_id, - role: msg.role, - subject: msg.account_id, - audience: Some(model::Audience::Web), - exp: Some((chrono::Utc::now() + chrono::Duration::days(31)).naive_utc()) - }, - db.clone(), - config.clone() - ) - ); - let (access_token, access_token_string): (Token, AccessTokenString) = access_token?; - let (refresh_token, refresh_token_string): (Token, AccessTokenString) = refresh_token?; - Ok(AuthPair { - access_token, - access_token_string, - _refresh_token: refresh_token, - refresh_token_string: refresh_token_string.into(), - }) -} - -/// Checks if token is still valid -/// -/// # Examples -/// -/// ``` -/// use actix::Addr; -/// use model::{AccessTokenString, AccountId, Role}; -/// use token_manager::{CreatePair, Validate}; -/// async fn create_pair(token_manager: Addr, token: AccessTokenString) { -/// match token_manager.send(Validate { token }).await { -/// Ok(Ok(pair)) => {} -/// Ok(Err(manager_error)) => {} -/// Err(actor_error) => {} -/// } -/// } -/// ``` -#[derive(Message)] -#[rtype(result = "Result")] -pub struct Validate { - pub token: AccessTokenString, -} - -token_async_handler!(Validate, validate, Token); - -pub(crate) async fn validate( - msg: Validate, - db: Addr, - config: SharedAppConfig, -) -> Result { - use jwt::VerifyWithKey; - - tracing::info!("Validating token {:?}", msg.token); - - let secret = config.lock().web().jwt_secret(); - let key: Hmac = build_key(secret)?; - let claims: BTreeMap = match msg.token.verify_with_key(&key) { - Ok(claims) => claims, - _ => return Err(Error::Validate), - }; - let jti = match claims.get("jti") { - Some(jti) => jti, - _ => return Err(Error::Validate), - }; - - let token: Token = query_db!( - db, - database_manager::TokenByJti { - jti: match uuid::Uuid::from_str(jti) { - Ok(uid) => uid, - _ => return Err(Error::Validate), - }, - }, - Error::Validate, - Error::ValidateInternal - ); - - if token.expiration_time < Utc::now().naive_utc() { - return Err(Error::Validate); - } - - validate_pair(&claims, "cti", token.customer_id, validate_uuid)?; - validate_pair(&claims, "arl", token.role, eq)?; - validate_pair(&claims, "iss", &token.issuer, eq)?; - validate_pair(&claims, "sub", token.subject, validate_num)?; - validate_pair(&claims, "aud", token.audience, eq)?; - validate_pair(&claims, "exp", &token.expiration_time, validate_time)?; - validate_pair(&claims, "nbt", &token.not_before_time, validate_time)?; - validate_pair(&claims, "iat", &token.issued_at_time, validate_time)?; - - tracing::info!("JWT token valid"); - Ok(token) -} - -fn build_key(secret: String) -> Result> { - match Hmac::new_from_slice(secret.as_bytes()) { - Ok(key) => Ok(key), - Err(e) => { - tracing::error!("{e:?}"); - dbg!(e); - Err(Error::ValidateInternal) - } - } -} - -#[inline(always)] -fn validate_pair( - claims: &BTreeMap, - key: &str, - v: V, - cmp: F, -) -> std::result::Result<(), Error> -where - F: for<'s> FnOnce(V, &'s str) -> bool, - V: PartialEq, -{ - claims - .get(key) - .map(|s| cmp(v, s.as_str())) - .unwrap_or_default() - .then_some(()) - .ok_or(Error::Invalid) -} - -#[inline(always)] -fn eq(value: V, text: &str) -> bool -where - V: for<'s> PartialEq<&'s str>, -{ - value == text -} - -#[inline(always)] -fn validate_time(left: &NaiveDateTime, right: &str) -> bool { - chrono::DateTime::parse_from_str(right, "%+") - .map(|t| t.naive_utc() == *left) - .unwrap_or_default() -} - -#[inline(always)] -fn validate_num(left: i32, right: &str) -> bool { - right.parse::().map(|n| left == n).unwrap_or_default() -} - -#[inline(always)] -fn validate_uuid(left: uuid::Uuid, right: &str) -> bool { - uuid::Uuid::from_str(right) - .map(|u| u == left) - .unwrap_or_default() -} - -#[cfg(test)] -mod tests { - use actix::Actor; - use config::UpdateConfig; - use database_manager::Database; - use model::*; - - use super::*; - - pub struct NoOpts; - - impl UpdateConfig for NoOpts {} - - #[actix::test] - async fn create_token() { - testx::db!(config, db); - let db = db.start(); - - let (token, _text) = super::create_token( - CreateToken { - customer_id: Default::default(), - role: Role::Admin, - subject: AccountId::from(1), - audience: None, - exp: None, - }, - db.clone(), - config, - ) - .await - .unwrap(); - - db.send(database_manager::DeleteToken { token_id: token.id }) - .await - .ok(); - } - - #[actix::test] - async fn create_pair() { - testx::db!(config, db); - let db = db.start(); - - let AuthPair { - access_token, - access_token_string: _, - refresh_token_string: _, - _refresh_token, - } = super::create_pair( - CreatePair { - customer_id: Default::default(), - role: Role::Admin, - account_id: AccountId::from(0), - }, - db.clone(), - config, - ) - .await - .unwrap(); - - db.send(database_manager::DeleteToken { - token_id: access_token.id, - }) - .await - .ok(); - - db.send(database_manager::DeleteToken { - token_id: _refresh_token.id, - }) - .await - .ok(); - } - - #[actix::test] - async fn validate() { - testx::db!(config, db); - let db = db.start(); - - let (token, text) = super::create_token( - CreateToken { - customer_id: Default::default(), - role: Role::Admin, - subject: AccountId::from(1), - audience: None, - exp: None, - }, - db.clone(), - config.clone(), - ) - .await - .unwrap(); - - super::validate(Validate { token: text }, db.clone(), config.clone()) - .await - .unwrap(); - - db.send(database_manager::DeleteToken { token_id: token.id }) - .await - .ok(); - } -} diff --git a/crates/token_manager/src/main.rs b/crates/token_manager/src/main.rs new file mode 100644 index 0000000..c2b573e --- /dev/null +++ b/crates/token_manager/src/main.rs @@ -0,0 +1,570 @@ +//! Tokens management system. +//! It's responsible for creating and validating all tokens. +//! +//! Application flow goes like this: +//! +//! ```ascii +//! Client API TokenManager Database +//! +//! │ │ │ │ +//! │ │ │ │ +//! │ │ │ ┌───────────────►│ +//! ├────────────────►├──────────────────►├──────►│ │ +//! │ Sign In │ CreatePair │ └───────────────►│ +//! │ │ │ Create │ +//! │ │ │ * AccessToken │ +//! │ │ │ * RefreshToken │ +//! │ │ │ │ +//! │ │ │ │ +//! +//! │ │ │ │ +//! ├────────────────►├──────────────────►├───────────────────────►│ +//! │ Validate token │ ValidateToken │ Load token │ +//! │ │ (string) │◄───────────────────────┤ +//! │ │ │ │ +//! │ │ Is Valid? │ +//! │ │ │ │ +//! │ │◄──────────────── YES │ +//! │ │ AccessToken │ │ +//! │ │ │ │ +//! │ │ │ │ +//! │ │◄──────────────── NO │ +//! │ │ Error │ │ +//! +//! │ │ │ │ +//! │ │ │ │ +//! │ │ │ ┌───────────────►│ +//! ├────────────────►├──────────────────►├──────►│ │ +//! │ Refresh token │ CreatePair │ └───────────────►│ +//! │ │ │ Create │ +//! │ │◄──────────────────┤ * AccessToken │ +//! │ │ Access Token │ * RefreshToken │ +//! │ │ Refresh Token │ │ +//! │ │ │ │ +//! ``` +//! +//! If you need to operate on tokens from API or any other actor you should +//! always use this actor and never touch database directly. +//! +//! # Examples +//! +//! ``` +//! use actix::{Actor, Addr}; +//! use config::SharedAppConfig; +//! use database_manager::Database; +//! use token_manager::*; +//! use model::*; +//! +//! async fn tokens(db: Addr, config: SharedAppConfig) { +//! let manager = TokenManager::new(config, db); +//! +//! let manager_addr = manager.start(); +//! +//! let AuthPair { access_token, access_token_string, refresh_token_string, .. } = manager_addr.send(CreatePair { +//! customer_id: uuid::Uuid::new_v4(), +//! account_id: AccountId::from(0), +//! role: Role::Admin +//! }).await.unwrap().unwrap(); +//! +//! manager_addr.send(Validate { token: access_token_string }).await.unwrap().unwrap(); +//! } +//! ``` + +mod db; + +use std::collections::BTreeMap; +use std::str::FromStr; + +use channels::payments::CreatePayment; +use chrono::prelude::*; +use config::SharedAppConfig; +use hmac::digest::KeyInit; +use hmac::Hmac; +use model::{AccessTokenString, AccountId, Audience, Role, Token}; +use sha2::Sha256; + +use crate::db::Database; + +/*struct Jwt { + /// cti (customer id): Customer uuid identifier used by payment service + pub cti: uuid::Uuid, + /// arl (account role): account role + pub arl: Role, + /// iss (issuer): Issuer of the JWT + pub iss: String, + /// sub (subject): Subject of the JWT (the user) + pub sub: i32, + /// aud (audience): Recipient for which the JWT is intended + pub aud: Audience, + /// exp (expiration time): Time after which the JWT expires + pub exp: chrono::NaiveDateTime, + /// nbt (not before time): Time before which the JWT must not be accepted + /// for processing + pub nbt: chrono::NaiveDateTime, + /// iat (issued at time): Time at which the JWT was issued; can be used to + /// determine age of the JWT, + pub iat: chrono::NaiveDateTime, + /// jti (JWT ID): Unique identifier; can be used to prevent the JWT from + /// being replayed (allows a token to be used only once) + pub jti: uuid::Uuid, +}*/ + +#[derive(Debug, Copy, Clone, serde::Serialize, thiserror::Error)] +#[serde(rename_all = "kebab-case", tag = "token")] +pub enum Error { + #[error("Unable to save new token")] + Save, + #[error("Unable to save new token. Can't connect to database")] + SaveInternal, + #[error("Unable to validate token")] + Validate, + #[error("Unable to validate token. Can't connect to database")] + ValidateInternal, + #[error("Token does not exists or some fields are incorrect")] + Invalid, +} + +pub type Result = std::result::Result; + +pub struct TokenManager { + db: Database, + config: SharedAppConfig, +} + +impl TokenManager { + pub fn new(config: SharedAppConfig, db: Database) -> Self { + Self { db, config } + } +} + +/// Creates single token, it's mostly used by [CreatePair] +/// +/// # Examples +/// +/// ``` +/// use actix::Addr; +/// use model::{AccountId, Role}; +/// use token_manager::*; +/// async fn create_pair(token_manager: Addr) { +/// match token_manager.send(CreateToken { customer_id: uuid::Uuid::new_v4(), role: Role::Admin, subject: AccountId::from(1), audience: None, exp: None }).await { +/// Ok(Ok(pair)) => {} +/// Ok(Err(manager_error)) => {} +/// Err(actor_error) => {} +/// } +/// } +/// ``` +#[derive(Debug, Clone)] +pub struct CreateToken { + pub customer_id: uuid::Uuid, + pub role: Role, + pub subject: AccountId, + pub audience: Option, + pub exp: Option, +} + +impl CreateToken { + pub async fn run( + self, + db: Addr, + config: SharedAppConfig, + ) -> Result<(Token, AccessTokenString)> { + let CreateToken { + customer_id, + role, + subject, + audience, + exp, + } = self; + + let audience = audience.unwrap_or_default(); + + let token: Token = match exp { + None => query_db!( + db, + database_manager::CreateToken { + customer_id, + role, + subject, + audience, + }, + Error::Save, + Error::SaveInternal + ), + Some(exp) => query_db!( + db, + database_manager::CreateExtendedToken { + customer_id, + role, + subject, + audience, + expiration_time: exp + }, + Error::Save, + Error::SaveInternal + ), + }; + + let token_string = { + use jwt::SignWithKey; + + let secret = config.lock().web().jwt_secret(); + let key: Hmac = build_key(secret)?; + let mut claims = BTreeMap::new(); + + // cti (customer id): Customer uuid identifier used by payment service + claims.insert("cti", format!("{}", token.customer_id)); + // arl (account role): account role + claims.insert("arl", String::from(token.role.as_str())); + // iss (issuer): Issuer of the JWT + claims.insert("iss", token.issuer.to_string()); + // sub (subject): Subject of the JWT (the user) + claims.insert("sub", format!("{}", token.subject)); + // aud (audience): Recipient for which the JWT is intended + claims.insert("aud", String::from(token.audience.as_str())); + // exp (expiration time): Time after which the JWT expires + claims.insert( + "exp", + format!( + "{}", + Utc.from_utc_datetime(&token.expiration_time).format("%+") + ), + ); + // nbt (not before time): Time before which the JWT must not be accepted + // for processing + claims.insert( + "nbt", + format!( + "{}", + Utc.from_utc_datetime(&token.not_before_time).format("%+") + ), + ); + // iat (issued at time): Time at which the JWT was issued; can be used + // to determine age of the JWT, + claims.insert( + "iat", + format!( + "{}", + Utc.from_utc_datetime(&token.issued_at_time).format("%+") + ), + ); + // jti (JWT ID): Unique identifier; can be used to prevent the JWT from + // being replayed (allows a token to be used only once) + claims.insert("jti", format!("{}", token.jwt_id)); + + let s = match claims.sign_with_key(&key) { + Ok(s) => s, + Err(e) => { + tracing::error!("{e:?}"); + return Err(Error::SaveInternal); + } + }; + AccessTokenString::new(s) + }; + Ok((token, token_string)) + } +} + +#[derive(Debug, Clone)] +pub struct AuthPair { + pub access_token: Token, + pub access_token_string: AccessTokenString, + pub _refresh_token: Token, + pub refresh_token_string: model::RefreshTokenString, +} + +/// Creates access token and refresh token +/// +/// # Examples +/// +/// ``` +/// use actix::Addr; +/// use model::{AccountId, Role}; +/// use token_manager::CreatePair; +/// async fn create_pair(token_manager: Addr) { +/// match token_manager.send(CreatePair { customer_id: uuid::Uuid::new_v4(), account_id: AccountId::from(0), role: Role::Admin }).await { +/// Ok(Ok(pair)) => {} +/// Ok(Err(manager_error)) => {} +/// Err(actor_error) => {} +/// } +/// } +/// ``` +#[derive(Debug, Clone)] +pub struct CreatePair { + pub customer_id: uuid::Uuid, + pub role: Role, + pub account_id: AccountId, +} + +impl CreatePair { + pub async fn run(self, db: Database, config: SharedAppConfig) -> Result { + let (access_token, refresh_token) = tokio::join!( + create_token( + CreateToken { + customer_id: self.customer_id, + role: self.role, + subject: self.account_id, + audience: Some(model::Audience::Web), + exp: None + }, + db.clone(), + config.clone() + ), + create_token( + CreateToken { + customer_id: self.customer_id, + role: self.role, + subject: self.account_id, + audience: Some(model::Audience::Web), + exp: Some((chrono::Utc::now() + chrono::Duration::days(31)).naive_utc()) + }, + db.clone(), + config.clone() + ) + ); + let (access_token, access_token_string): (Token, AccessTokenString) = access_token?; + let (refresh_token, refresh_token_string): (Token, AccessTokenString) = refresh_token?; + Ok(AuthPair { + access_token, + access_token_string, + _refresh_token: refresh_token, + refresh_token_string: refresh_token_string.into(), + }) + } +} + +/// Checks if token is still valid +/// +/// # Examples +/// +/// ``` +/// use actix::Addr; +/// use model::{AccessTokenString, AccountId, Role}; +/// use token_manager::{CreatePair, Validate}; +/// async fn create_pair(token_manager: Addr, token: AccessTokenString) { +/// match token_manager.send(Validate { token }).await { +/// Ok(Ok(pair)) => {} +/// Ok(Err(manager_error)) => {} +/// Err(actor_error) => {} +/// } +/// } +/// ``` +#[derive(Debug, Clone)] +pub struct Validate { + pub token: AccessTokenString, +} + +impl Validate { + pub async fn run(self, db: Database, config: SharedAppConfig) -> Result { + use jwt::VerifyWithKey; + + tracing::info!("Validating token {:?}", self.token); + + let secret = config.lock().web().jwt_secret(); + let key: Hmac = build_key(secret)?; + let claims: BTreeMap = match self.token.verify_with_key(&key) { + Ok(claims) => claims, + _ => return Err(Error::Validate), + }; + let jti = match claims.get("jti") { + Some(jti) => jti, + _ => return Err(Error::Validate), + }; + + let token: Token = query_db!( + db, + database_manager::TokenByJti { + jti: match uuid::Uuid::from_str(jti) { + Ok(uid) => uid, + _ => return Err(Error::Validate), + }, + }, + Error::Validate, + Error::ValidateInternal + ); + + if token.expiration_time < Utc::now().naive_utc() { + return Err(Error::Validate); + } + + validate_pair(&claims, "cti", token.customer_id, validate_uuid)?; + validate_pair(&claims, "arl", token.role, eq)?; + validate_pair(&claims, "iss", &token.issuer, eq)?; + validate_pair(&claims, "sub", token.subject, validate_num)?; + validate_pair(&claims, "aud", token.audience, eq)?; + validate_pair(&claims, "exp", &token.expiration_time, validate_time)?; + validate_pair(&claims, "nbt", &token.not_before_time, validate_time)?; + validate_pair(&claims, "iat", &token.issued_at_time, validate_time)?; + + tracing::info!("JWT token valid"); + Ok(token) + } +} + +pub struct Refresh {} + +impl Refresh { + pub async fn run(self, db: Database, config: SharedAppConfig) -> Result { + todo!() + } +} + +fn build_key(secret: String) -> Result> { + match Hmac::new_from_slice(secret.as_bytes()) { + Ok(key) => Ok(key), + Err(e) => { + tracing::error!("{e:?}"); + dbg!(e); + Err(Error::ValidateInternal) + } + } +} + +#[inline(always)] +fn validate_pair( + claims: &BTreeMap, + key: &str, + v: V, + cmp: F, +) -> std::result::Result<(), Error> +where + F: for<'s> FnOnce(V, &'s str) -> bool, + V: PartialEq, +{ + claims + .get(key) + .map(|s| cmp(v, s.as_str())) + .unwrap_or_default() + .then_some(()) + .ok_or(Error::Invalid) +} + +#[inline(always)] +fn eq(value: V, text: &str) -> bool +where + V: for<'s> PartialEq<&'s str>, +{ + value == text +} + +#[inline(always)] +fn validate_time(left: &NaiveDateTime, right: &str) -> bool { + chrono::DateTime::parse_from_str(right, "%+") + .map(|t| t.naive_utc() == *left) + .unwrap_or_default() +} + +#[inline(always)] +fn validate_num(left: i32, right: &str) -> bool { + right.parse::().map(|n| left == n).unwrap_or_default() +} + +#[inline(always)] +fn validate_uuid(left: uuid::Uuid, right: &str) -> bool { + uuid::Uuid::from_str(right) + .map(|u| u == left) + .unwrap_or_default() +} + +// #[cfg(test)] +// mod tests { +// use actix::Actor; +// use config::UpdateConfig; +// use database_manager::Database; +// use model::*; +// +// use super::*; +// +// pub struct NoOpts; +// +// impl UpdateConfig for NoOpts {} +// +// #[actix::test] +// async fn create_token() { +// testx::db!(config, db); +// let db = db.start(); +// +// let (token, _text) = super::create_token( +// CreateToken { +// customer_id: Default::default(), +// role: Role::Admin, +// subject: AccountId::from(1), +// audience: None, +// exp: None, +// }, +// db.clone(), +// config, +// ) +// .await +// .unwrap(); +// +// db.send(database_manager::DeleteToken { token_id: token.id }) +// .await +// .ok(); +// } +// +// #[actix::test] +// async fn create_pair() { +// testx::db!(config, db); +// let db = db.start(); +// +// let AuthPair { +// access_token, +// access_token_string: _, +// refresh_token_string: _, +// _refresh_token, +// } = super::create_pair( +// CreatePair { +// customer_id: Default::default(), +// role: Role::Admin, +// account_id: AccountId::from(0), +// }, +// db.clone(), +// config, +// ) +// .await +// .unwrap(); +// +// db.send(database_manager::DeleteToken { +// token_id: access_token.id, +// }) +// .await +// .ok(); +// +// db.send(database_manager::DeleteToken { +// token_id: _refresh_token.id, +// }) +// .await +// .ok(); +// } +// +// #[actix::test] +// async fn validate() { +// testx::db!(config, db); +// let db = db.start(); +// +// let (token, text) = super::create_token( +// CreateToken { +// customer_id: Default::default(), +// role: Role::Admin, +// subject: AccountId::from(1), +// audience: None, +// exp: None, +// }, +// db.clone(), +// config.clone(), +// ) +// .await +// .unwrap(); +// +// super::validate(Validate { token: text }, db.clone(), config.clone()) +// .await +// .unwrap(); +// +// db.send(database_manager::DeleteToken { token_id: token.id }) +// .await +// .ok(); +// } +// } + +#[tokio::main] +async fn main() {} diff --git a/crates/web/Cargo.toml b/crates/web/Cargo.toml index a65e68f..2ff26d4 100644 --- a/crates/web/Cargo.toml +++ b/crates/web/Cargo.toml @@ -10,14 +10,14 @@ crate-type = ["cdylib"] chrono = { version = "*", features = ["wasm-bindgen", "wasmbind"] } gloo-timers = { version = "*", features = ["futures"] } indexmap = { version = "1", default-features = false, features = ["serde-1", "std"] } -js-sys = { version = "0.3.57", features = [] } +js-sys = { version = "0", features = [] } model = { path = "../model", features = ["dummy"] } -rusty-money = { version = "0.4.1", features = ["iso"] } -seed = { version = "0.9.1", features = [] } -serde = { version = "1.0.137", features = ["derive"] } -serde-wasm-bindgen = { version = "0.4.2" } -serde_json = { version = "1.0.81" } -thiserror = { version = "1.0.31" } -uuid = { version = "1.0.0", features = ["v4"] } -wasm-bindgen = { version = "0.2.80", features = ["default"] } -web-sys = { version = "0.3.57", features = ["Navigator"] } +rusty-money = { version = "0", features = ["iso"] } +seed = { version = "0", features = [] } +serde = { version = "1", features = ["derive"] } +serde-wasm-bindgen = { version = "0" } +serde_json = { version = "1" } +thiserror = { version = "1" } +uuid = { version = "1", features = ["v4"] } +wasm-bindgen = { version = "0", features = ["default"] } +web-sys = { version = "0", features = ["Navigator"] } diff --git a/scripts/migrate.sh b/scripts/migrate.sh index 9eb3592..0d20c30 100755 --- a/scripts/migrate.sh +++ b/scripts/migrate.sh @@ -8,6 +8,7 @@ then psql postgres postgres -c "DROP DATABASE ${DATABASE_NAME}_carts" || echo 0 psql postgres postgres -c "DROP DATABASE ${DATABASE_NAME}_stocks" || echo 0 psql postgres postgres -c "DROP DATABASE ${DATABASE_NAME}_orders" || echo 0 + psql postgres postgres -c "DROP DATABASE ${DATABASE_NAME}_tokens" || echo 0 fi psql postgres postgres -c "CREATE DATABASE ${DATABASE_NAME}_accounts" || echo 0 @@ -21,3 +22,6 @@ sqlx migrate run -D "${STOCK_DATABASE_URL}" --source ./crates/stock_manager/migr psql postgres postgres -c "CREATE DATABASE ${DATABASE_NAME}_orders" || echo 0 sqlx migrate run -D "${ORDER_DATABASE_URL}" --source ./crates/order_manager/migrations + +psql postgres postgres -c "CREATE DATABASE ${DATABASE_NAME}_tokens" || echo 0 +sqlx migrate run -D "${TOKEN_DATABASE_URL}" --source ./crates/token_manager/migrations