From fc9a0abe7ec8bad2e98067ecb3cb097807b7d9c2 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Tue, 13 Feb 2024 22:13:03 +0100 Subject: [PATCH] Add nats --- .env | 4 + Cargo.lock | 530 +++++++++++++++++- crates/flux-releaser/Cargo.toml | 1 + crates/flux-releaser/src/app.rs | 38 +- crates/flux-releaser/src/app/infra.rs | 2 + crates/flux-releaser/src/app/infra/aws_s3.rs | 31 + crates/flux-releaser/src/app/infra/nats.rs | 32 ++ .../src/services/domain_events.rs | 18 +- .../src/services/domain_events/extensions.rs | 2 +- templates/docker-compose.yaml | 9 + 10 files changed, 599 insertions(+), 68 deletions(-) create mode 100644 crates/flux-releaser/src/app/infra.rs create mode 100644 crates/flux-releaser/src/app/infra/aws_s3.rs create mode 100644 crates/flux-releaser/src/app/infra/nats.rs diff --git a/.env b/.env index 6f56217..bb68347 100644 --- a/.env +++ b/.env @@ -1,3 +1,7 @@ AWS_ENDPOINT_URL=http://127.0.0.1:10000 AWS_ACCESS_KEY_ID=minioadmin AWS_SECRET_ACCESS_KEY=minioadminpassword + +NATS_URL=127.0.0.1:4222 +NATS_USERNAME=user +NATS_PASSWORD=secret diff --git a/Cargo.lock b/Cargo.lock index c9864f3..d451203 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -66,6 +66,26 @@ version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" +[[package]] +name = "async-channel" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" +dependencies = [ + "concurrent-queue", + "event-listener", + "futures-core", +] + +[[package]] +name = "async-lock" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" +dependencies = [ + "event-listener", +] + [[package]] name = "async-stream" version = "0.3.5" @@ -88,6 +108,12 @@ dependencies = [ "syn", ] +[[package]] +name = "async-task" +version = "4.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbb36e985947064623dbd357f727af08ffd077f93d696782f3c56365fa2e2799" + [[package]] name = "async-trait" version = "0.1.77" @@ -105,6 +131,12 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c59bdb34bc650a32731b31bd8f0829cc15d24a708ee31559e0bb34f2bc320cba" +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.1.0" @@ -130,11 +162,11 @@ dependencies = [ "aws-smithy-types", "aws-types", "bytes", - "fastrand", + "fastrand 2.0.1", "hex", "http 0.2.11", "hyper 0.14.28", - "ring", + "ring 0.17.7", "time", "tokio", "tracing", @@ -168,7 +200,7 @@ dependencies = [ "aws-smithy-types", "aws-types", "bytes", - "fastrand", + "fastrand 2.0.1", "http 0.2.11", "http-body 0.4.6", "percent-encoding", @@ -294,7 +326,7 @@ dependencies = [ "once_cell", "p256", "percent-encoding", - "ring", + "ring 0.17.7", "sha2", "subtle", "time", @@ -396,7 +428,7 @@ dependencies = [ "aws-smithy-runtime-api", "aws-smithy-types", "bytes", - "fastrand", + "fastrand 2.0.1", "h2 0.3.24", "http 0.2.11", "http-body 0.4.6", @@ -579,6 +611,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + [[package]] name = "base64" version = "0.21.7" @@ -595,6 +633,15 @@ dependencies = [ "vsimd", ] +[[package]] +name = "base64-url" +version = "1.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67a99c239d0c7e77c85dddfa9cebce48704b3c49550fcd3b84dd637e4484899f" +dependencies = [ + "base64 0.13.1", +] + [[package]] name = "base64ct" version = "1.6.0" @@ -622,6 +669,34 @@ dependencies = [ "generic-array", ] +[[package]] +name = "blocking" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c36a4d0d48574b3dd360b4b7d95cc651d2b6557b6402848a27d4b228a473e2a" +dependencies = [ + "async-channel", + "async-lock", + "async-task", + "fastrand 2.0.1", + "futures-io", + "futures-lite", + "piper", + "tracing", +] + +[[package]] +name = "bumpalo" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "bytes" version = "1.5.0" @@ -701,6 +776,15 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +[[package]] +name = "concurrent-queue" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d16048cd947b08fa32c24458a22f5dc5e835264f689f4f5653210c69fd107363" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "const-oid" version = "0.9.6" @@ -750,6 +834,21 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "176dc175b78f56c0f321911d9c8eb2b77a78a4860b9c19db83835fea1a46649b" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" + [[package]] name = "crypto-bigint" version = "0.4.9" @@ -782,6 +881,39 @@ dependencies = [ "typenum", ] +[[package]] +name = "curve25519-dalek" +version = "4.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a677b8922c94e01bdbb12126b0bc852f00447528dee1782229af9c720c3f348" +dependencies = [ + "cfg-if", + "cpufeatures", + "curve25519-dalek-derive", + "digest", + "fiat-crypto", + "platforms", + "rustc_version", + "subtle", +] + +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "data-encoding" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" + [[package]] name = "der" version = "0.6.1" @@ -792,6 +924,17 @@ dependencies = [ "zeroize", ] +[[package]] +name = "der" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" +dependencies = [ + "const-oid", + "pem-rfc7468", + "zeroize", +] + [[package]] name = "deranged" version = "0.3.11" @@ -799,6 +942,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" dependencies = [ "powerfmt", + "serde", ] [[package]] @@ -830,10 +974,32 @@ version = "0.14.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "413301934810f597c1d19ca71c8710e99a3f1ba28a0d2ebc01551a2daeea3c5c" dependencies = [ - "der", + "der 0.6.1", "elliptic-curve", "rfc6979", - "signature", + "signature 1.6.4", +] + +[[package]] +name = "ed25519" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" +dependencies = [ + "signature 2.2.0", +] + +[[package]] +name = "ed25519-dalek" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" +dependencies = [ + "curve25519-dalek", + "ed25519", + "sha2", + "signature 2.2.0", + "subtle", ] [[package]] @@ -850,12 +1016,12 @@ checksum = "e7bb888ab5300a19b8e5bceef25ac745ad065f3c9f7efc6de1b91958110891d3" dependencies = [ "base16ct", "crypto-bigint 0.4.9", - "der", + "der 0.6.1", "digest", "ff", "generic-array", "group", - "pkcs8", + "pkcs8 0.9.0", "rand_core", "sec1", "subtle", @@ -878,6 +1044,21 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + +[[package]] +name = "fastrand" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" +dependencies = [ + "instant", +] + [[package]] name = "fastrand" version = "2.0.1" @@ -894,6 +1075,12 @@ dependencies = [ "subtle", ] +[[package]] +name = "fiat-crypto" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1676f435fc1dadde4d03e43f5d62b259e1ce5f40bd4ffb21db2b42ebe59c1382" + [[package]] name = "fixedbitset" version = "0.4.2" @@ -913,6 +1100,7 @@ dependencies = [ "dotenv", "mockall", "mockall_double", + "nats", "prost", "serde", "serde_json", @@ -960,6 +1148,22 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-lite" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" +dependencies = [ + "futures-core", + "pin-project-lite", +] + [[package]] name = "futures-sink" version = "0.3.30" @@ -1296,6 +1500,15 @@ dependencies = [ "hashbrown 0.14.3", ] +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + [[package]] name = "io-lifetimes" version = "1.0.11" @@ -1334,6 +1547,21 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" +[[package]] +name = "js-sys" +version = "0.3.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "json" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd" + [[package]] name = "lazy_static" version = "1.4.0" @@ -1458,6 +1686,58 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" +[[package]] +name = "nats" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e008b4960823570e06c8804a5c2c91458b91cc1708d5e21095c5e6de3fb92f5" +dependencies = [ + "base64 0.13.1", + "base64-url", + "blocking", + "crossbeam-channel", + "fastrand 1.9.0", + "itoa", + "json", + "lazy_static", + "libc", + "log", + "memchr", + "nkeys", + "nuid", + "once_cell", + "parking_lot", + "regex", + "ring 0.16.20", + "rustls", + "rustls-native-certs", + "rustls-pemfile", + "rustls-webpki 0.100.3", + "serde", + "serde_json", + "serde_nanos", + "serde_repr", + "time", + "url", + "winapi", +] + +[[package]] +name = "nkeys" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aad178aad32087b19042ee36dfd450b73f5f934fbfb058b59b198684dfec4c47" +dependencies = [ + "byteorder", + "data-encoding", + "ed25519", + "ed25519-dalek", + "getrandom", + "log", + "rand", + "signatory", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -1468,6 +1748,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "nuid" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20c1bb65186718d348306bf1afdeb20d9ab45b2ab80fb793c0fdcf59ffbb4f38" +dependencies = [ + "lazy_static", + "rand", +] + [[package]] name = "num-conv" version = "0.1.0" @@ -1560,6 +1850,15 @@ dependencies = [ "windows-targets 0.48.0", ] +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + [[package]] name = "percent-encoding" version = "2.3.1" @@ -1608,16 +1907,43 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "piper" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "668d31b1c4eba19242f2088b2bf3316b82ca31082a8335764db4e083db7485d4" +dependencies = [ + "atomic-waker", + "fastrand 2.0.1", + "futures-io", +] + [[package]] name = "pkcs8" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9eca2c590a5f85da82668fa685c09ce2888b9430e83299debf1f34b65fd4a4ba" dependencies = [ - "der", - "spki", + "der 0.6.1", + "spki 0.6.0", ] +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der 0.7.8", + "spki 0.7.3", +] + +[[package]] +name = "platforms" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "626dec3cac7cc0e1577a2ec3fc496277ec2baa084bebad95bb6fdbfae235f84c" + [[package]] name = "powerfmt" version = "0.2.0" @@ -1823,6 +2149,21 @@ dependencies = [ "zeroize", ] +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin 0.5.2", + "untrusted 0.7.1", + "web-sys", + "winapi", +] + [[package]] name = "ring" version = "0.17.7" @@ -1832,8 +2173,8 @@ dependencies = [ "cc", "getrandom", "libc", - "spin", - "untrusted", + "spin 0.9.8", + "untrusted 0.9.0", "windows-sys 0.48.0", ] @@ -1880,8 +2221,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" dependencies = [ "log", - "ring", - "rustls-webpki", + "ring 0.17.7", + "rustls-webpki 0.101.7", "sct", ] @@ -1903,7 +2244,17 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ - "base64", + "base64 0.21.7", +] + +[[package]] +name = "rustls-webpki" +version = "0.100.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6a5fc258f1c1276dfe3016516945546e2d5383911efc0fc4f1cdc5df3a4ae3" +dependencies = [ + "ring 0.16.20", + "untrusted 0.7.1", ] [[package]] @@ -1912,8 +2263,8 @@ version = "0.101.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" dependencies = [ - "ring", - "untrusted", + "ring 0.17.7", + "untrusted 0.9.0", ] [[package]] @@ -1949,8 +2300,8 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ - "ring", - "untrusted", + "ring 0.17.7", + "untrusted 0.9.0", ] [[package]] @@ -1960,9 +2311,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3be24c1842290c45df0a7bf069e0c268a747ad05a192f2fd7dcfdbc1cba40928" dependencies = [ "base16ct", - "der", + "der 0.6.1", "generic-array", - "pkcs8", + "pkcs8 0.9.0", "subtle", "zeroize", ] @@ -2027,6 +2378,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_nanos" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ae801b7733ca8d6a2b580debe99f67f36826a0f5b8a36055dc6bc40f8d6bc71" +dependencies = [ + "serde", +] + [[package]] name = "serde_path_to_error" version = "0.1.11" @@ -2036,6 +2396,17 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_repr" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -2088,6 +2459,18 @@ dependencies = [ "libc", ] +[[package]] +name = "signatory" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1e303f8205714074f6068773f0e29527e0453937fe837c9717d066635b65f31" +dependencies = [ + "pkcs8 0.10.2", + "rand_core", + "signature 2.2.0", + "zeroize", +] + [[package]] name = "signature" version = "1.6.4" @@ -2098,6 +2481,16 @@ dependencies = [ "rand_core", ] +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core", +] + [[package]] name = "slab" version = "0.4.9" @@ -2133,6 +2526,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "spin" version = "0.9.8" @@ -2146,7 +2545,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67cf02bbac7a337dc36e4f5a693db6c21e7863f45070f7064577eb4367a3212b" dependencies = [ "base64ct", - "der", + "der 0.6.1", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der 0.7.8", ] [[package]] @@ -2185,7 +2594,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a365e8cd18e44762ef95d87f284f4b5cd04107fec2ff3052bd6a3e6069669e67" dependencies = [ "cfg-if", - "fastrand", + "fastrand 2.0.1", "rustix 0.38.31", "windows-sys 0.52.0", ] @@ -2213,6 +2622,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" dependencies = [ "deranged", + "itoa", "num-conv", "powerfmt", "serde", @@ -2335,7 +2745,7 @@ dependencies = [ "async-stream", "async-trait", "axum 0.6.20", - "base64", + "base64 0.21.7", "bytes", "h2 0.3.24", "http 0.2.11", @@ -2490,6 +2900,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + [[package]] name = "untrusted" version = "0.9.0" @@ -2562,6 +2978,70 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" + +[[package]] +name = "web-sys" +version = "0.3.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96565907687f7aceb35bc5fc03770a8a0471d82e479f25832f54a0e3f4b28446" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "which" version = "4.4.2" diff --git a/crates/flux-releaser/Cargo.toml b/crates/flux-releaser/Cargo.toml index 2f3303d..d471367 100644 --- a/crates/flux-releaser/Cargo.toml +++ b/crates/flux-releaser/Cargo.toml @@ -20,6 +20,7 @@ aws-config = { version = "1.1.5", features = ["behavior-version-latest"] } aws-sdk-s3 = { version = "1.15.0", features = ["behavior-version-latest"] } serde = { version = "1.0.196", features = ["derive"] } serde_json = "1.0.113" +nats = "0.24.1" [build-dependencies] tonic-build = "0.11.0" diff --git a/crates/flux-releaser/src/app.rs b/crates/flux-releaser/src/app.rs index 40a5e01..fd62f1c 100644 --- a/crates/flux-releaser/src/app.rs +++ b/crates/flux-releaser/src/app.rs @@ -24,48 +24,16 @@ impl SharedApp { pub struct App { pub s3_client: aws_sdk_s3::Client, + pub nats: infra::nats::Nats, } impl App { pub async fn new() -> anyhow::Result { Ok(Self { s3_client: s3_client().await?, + nats: infra::nats::Nats::new().await?, }) } } -mod infra { - pub mod aws_s3 { - use aws_config::{BehaviorVersion, Region}; - use aws_sdk_s3::config::Credentials; - - pub async fn s3_client() -> anyhow::Result { - let shared_config = aws_config::defaults(BehaviorVersion::latest()) - .region(Region::new("eu-west-1")) - .credentials_provider(Credentials::new( - std::env::var("AWS_ACCESS_KEY_ID")?, - std::env::var("AWS_SECRET_ACCESS_KEY")?, - None, - None, - "flux_releaser", - )); - - let config = aws_sdk_s3::config::Builder::from(&shared_config.load().await) - .endpoint_url(std::env::var("AWS_ENDPOINT_URL")?) - .build(); - - let client = aws_sdk_s3::Client::from_conf(config); - - let buckets = client.list_buckets().send().await?; - - buckets - .buckets - .iter() - .flatten() - .flat_map(|b| &b.name) - .for_each(|n| tracing::debug!("test: found aws bucket: {}", n)); - - Ok(client) - } - } -} +pub mod infra; diff --git a/crates/flux-releaser/src/app/infra.rs b/crates/flux-releaser/src/app/infra.rs new file mode 100644 index 0000000..d8acfad --- /dev/null +++ b/crates/flux-releaser/src/app/infra.rs @@ -0,0 +1,2 @@ +pub mod aws_s3; +pub mod nats; diff --git a/crates/flux-releaser/src/app/infra/aws_s3.rs b/crates/flux-releaser/src/app/infra/aws_s3.rs new file mode 100644 index 0000000..2a865a1 --- /dev/null +++ b/crates/flux-releaser/src/app/infra/aws_s3.rs @@ -0,0 +1,31 @@ +use aws_config::{BehaviorVersion, Region}; +use aws_sdk_s3::config::Credentials; + +pub async fn s3_client() -> anyhow::Result { + let shared_config = aws_config::defaults(BehaviorVersion::latest()) + .region(Region::new("eu-west-1")) + .credentials_provider(Credentials::new( + std::env::var("AWS_ACCESS_KEY_ID")?, + std::env::var("AWS_SECRET_ACCESS_KEY")?, + None, + None, + "flux_releaser", + )); + + let config = aws_sdk_s3::config::Builder::from(&shared_config.load().await) + .endpoint_url(std::env::var("AWS_ENDPOINT_URL")?) + .build(); + + let client = aws_sdk_s3::Client::from_conf(config); + + let buckets = client.list_buckets().send().await?; + + buckets + .buckets + .iter() + .flatten() + .flat_map(|b| &b.name) + .for_each(|n| tracing::debug!("test: found aws bucket: {}", n)); + + Ok(client) +} diff --git a/crates/flux-releaser/src/app/infra/nats.rs b/crates/flux-releaser/src/app/infra/nats.rs new file mode 100644 index 0000000..6b8f082 --- /dev/null +++ b/crates/flux-releaser/src/app/infra/nats.rs @@ -0,0 +1,32 @@ +use std::sync::Arc; + +use anyhow::Context; + +#[derive(Clone)] +pub struct Nats { + nats: Arc, +} + +impl Nats { + pub async fn new() -> anyhow::Result { + let nats = nats::asynk::Options::with_user_pass( + &std::env::var("NATS_USERNAME").context("NATS_USERNAME was not found")?, + &std::env::var("NATS_PASSWORD").context("NATS_PASSWORD was not found")?, + ) + .with_name(std::env!("CARGO_PKG_NAME")) + .connect(std::env::var("NATS_URL").context("NATS_URL was not found")?) + .await?; + + Ok(Self { + nats: Arc::new(nats), + }) + } +} + +impl std::ops::Deref for Nats { + type Target = nats::asynk::Connection; + + fn deref(&self) -> &Self::Target { + &self.nats + } +} diff --git a/crates/flux-releaser/src/services/domain_events.rs b/crates/flux-releaser/src/services/domain_events.rs index c53ea93..a2e2094 100644 --- a/crates/flux-releaser/src/services/domain_events.rs +++ b/crates/flux-releaser/src/services/domain_events.rs @@ -1,24 +1,28 @@ -use std::{path::PathBuf, sync::Arc}; - -use super::release_manager::models::ArtifactID; - pub mod extensions; #[derive(Clone)] -pub struct DomainEvents {} +pub struct DomainEvents { + nats: Nats, +} #[cfg(test)] use mockall::{automock, mock, predicate::*}; +use crate::app::infra::{self, nats::Nats}; + #[cfg_attr(test, automock)] impl DomainEvents { - pub fn new() -> Self { - Self {} + pub fn new(nats: Nats) -> Self { + Self { nats } } pub async fn publish_event(&self, event: &str) -> anyhow::Result<()> { tracing::trace!("publish events: {}", event); + self.nats + .publish("flux_releaser.domain_events", event) + .await?; + Ok(()) } } diff --git a/crates/flux-releaser/src/services/domain_events/extensions.rs b/crates/flux-releaser/src/services/domain_events/extensions.rs index 164f3ad..4041a03 100644 --- a/crates/flux-releaser/src/services/domain_events/extensions.rs +++ b/crates/flux-releaser/src/services/domain_events/extensions.rs @@ -9,6 +9,6 @@ pub trait DomainEventsExt { impl DomainEventsExt for SharedApp { fn domain_events(&self) -> DomainEvents { - DomainEvents::new() + DomainEvents::new(self.nats.clone()) } } diff --git a/templates/docker-compose.yaml b/templates/docker-compose.yaml index bd6bb40..ba6e0f2 100644 --- a/templates/docker-compose.yaml +++ b/templates/docker-compose.yaml @@ -25,3 +25,12 @@ services: /usr/bin/mc policy set public myminio/mybucket; exit 0; " + + nats: + image: bitnami/nats:2.10.10 + ports: + - "4222:4222" + environment: + - NATS_ENABLE_AUTH=yes + - NATS_USERNAME=user + - NATS_PASSWORD=secret