From ba0170ea15d6ebc1c9049f02adabd1ee4df6de64 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Fri, 17 Sep 2021 13:14:24 +0400 Subject: [PATCH] webhook base implementation --- Cargo.lock | 74 +++++++++- cargo/crates.bzl | 51 ++++++- cargo/remote/BUILD.chrono-0.4.19.bazel | 90 ++++++++++++ cargo/remote/BUILD.getrandom-0.2.3.bazel | 2 +- cargo/remote/BUILD.nats-0.15.2.bazel | 131 ++++++++++++++++++ cargo/remote/BUILD.num-integer-0.1.44.bazel | 95 +++++++++++++ cargo/remote/BUILD.time-0.1.44.bazel | 73 ++++++++++ ....wasi-0.10.0+wasi-snapshot-preview1.bazel} | 2 +- cargo/remote/BUILD.winapi-0.3.9.bazel | 2 + docker-compose.yaml | 7 +- webhook/Cargo.toml | 1 + webhook/cargo/BUILD.bazel | 9 ++ webhook/config/default.yaml | 2 +- webhook/src/handle.rs | 18 ++- webhook/src/main.rs | 2 + 15 files changed, 535 insertions(+), 24 deletions(-) create mode 100644 cargo/remote/BUILD.chrono-0.4.19.bazel create mode 100644 cargo/remote/BUILD.nats-0.15.2.bazel create mode 100644 cargo/remote/BUILD.num-integer-0.1.44.bazel create mode 100644 cargo/remote/BUILD.time-0.1.44.bazel rename cargo/remote/{BUILD.wasi-0.10.2+wasi-snapshot-preview1.bazel => BUILD.wasi-0.10.0+wasi-snapshot-preview1.bazel} (95%) diff --git a/Cargo.lock b/Cargo.lock index 4051470..24d7405 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -47,7 +47,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dae854440faecce70f0664f41f09a588de1e7a4366931ec3962ded3d8f903c5" dependencies = [ "blocking", - "nats", + "nats 0.10.1", ] [[package]] @@ -207,6 +207,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "libc", + "num-integer", + "num-traits 0.2.14", + "serde 1.0.130", + "time", + "winapi 0.3.9", +] + [[package]] name = "cloudabi" version = "0.0.3" @@ -678,7 +692,7 @@ checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ "cfg-if 1.0.0", "libc", - "wasi 0.10.2+wasi-snapshot-preview1", + "wasi 0.10.0+wasi-snapshot-preview1", ] [[package]] @@ -1091,6 +1105,36 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "nats" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a3097b182107db2cf690280d61f23f17ee31d49f3994ad152ee6a10261f77c3" +dependencies = [ + "base64", + "base64-url", + "blocking", + "chrono", + "crossbeam-channel", + "fastrand", + "itoa", + "json", + "libc", + "log", + "memchr", + "nkeys", + "nuid", + "once_cell", + "parking_lot 0.11.2", + "regex", + "rustls", + "rustls-native-certs", + "serde 1.0.130", + "serde_json", + "webpki", + "winapi 0.3.9", +] + [[package]] name = "net2" version = "0.2.37" @@ -1153,6 +1197,16 @@ dependencies = [ "rand 0.8.4", ] +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits 0.2.14", +] + [[package]] name = "num-traits" version = "0.1.43" @@ -1937,6 +1991,17 @@ dependencies = [ "syn", ] +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi 0.3.9", +] + [[package]] name = "tinyvec" version = "1.3.1" @@ -2491,9 +2556,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" +version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" [[package]] name = "wasm-bindgen" @@ -2569,6 +2634,7 @@ dependencies = [ "hyper", "libsodium-sys", "log", + "nats 0.15.2", "pretty_env_logger", "serde 1.0.130", "serde_json", diff --git a/cargo/crates.bzl b/cargo/crates.bzl index f473029..f51e66e 100644 --- a/cargo/crates.bzl +++ b/cargo/crates.bzl @@ -17,6 +17,7 @@ _DEPENDENCIES = { "hyper": "@raze__hyper__0_14_12//:hyper", "libsodium-sys": "@raze__libsodium_sys__0_2_7//:libsodium_sys", "log": "@raze__log__0_4_14//:log", + "nats": "@raze__nats__0_15_2//:nats", "pretty_env_logger": "@raze__pretty_env_logger__0_4_0//:pretty_env_logger", "serde": "@raze__serde__1_0_130//:serde", "serde_json": "@raze__serde_json__1_0_67//:serde_json", @@ -498,6 +499,16 @@ def raze_fetch_remote_crates(): build_file = Label("//cargo/remote:BUILD.cfg-if-1.0.0.bazel"), ) + maybe( + http_archive, + name = "raze__chrono__0_4_19", + url = "https://crates.io/api/v1/crates/chrono/0.4.19/download", + type = "tar.gz", + sha256 = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73", + strip_prefix = "chrono-0.4.19", + build_file = Label("//cargo/remote:BUILD.chrono-0.4.19.bazel"), + ) + maybe( http_archive, name = "raze__cloudabi__0_0_3", @@ -1348,6 +1359,16 @@ def raze_fetch_remote_crates(): build_file = Label("//cargo/remote:BUILD.nats-0.10.1.bazel"), ) + maybe( + http_archive, + name = "raze__nats__0_15_2", + url = "https://crates.io/api/v1/crates/nats/0.15.2/download", + type = "tar.gz", + sha256 = "2a3097b182107db2cf690280d61f23f17ee31d49f3994ad152ee6a10261f77c3", + strip_prefix = "nats-0.15.2", + build_file = Label("//cargo/remote:BUILD.nats-0.15.2.bazel"), + ) + maybe( http_archive, name = "raze__net2__0_2_37", @@ -1398,6 +1419,16 @@ def raze_fetch_remote_crates(): build_file = Label("//cargo/remote:BUILD.nuid-0.3.0.bazel"), ) + maybe( + http_archive, + name = "raze__num_integer__0_1_44", + url = "https://crates.io/api/v1/crates/num-integer/0.1.44/download", + type = "tar.gz", + sha256 = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db", + strip_prefix = "num-integer-0.1.44", + build_file = Label("//cargo/remote:BUILD.num-integer-0.1.44.bazel"), + ) + maybe( http_archive, name = "raze__num_traits__0_1_43", @@ -2228,6 +2259,16 @@ def raze_fetch_remote_crates(): build_file = Label("//cargo/remote:BUILD.thiserror-impl-1.0.29.bazel"), ) + maybe( + http_archive, + name = "raze__time__0_1_44", + url = "https://crates.io/api/v1/crates/time/0.1.44/download", + type = "tar.gz", + sha256 = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255", + strip_prefix = "time-0.1.44", + build_file = Label("//cargo/remote:BUILD.time-0.1.44.bazel"), + ) + maybe( http_archive, name = "raze__tinyvec__1_3_1", @@ -2700,12 +2741,12 @@ def raze_fetch_remote_crates(): maybe( http_archive, - name = "raze__wasi__0_10_2_wasi_snapshot_preview1", - url = "https://crates.io/api/v1/crates/wasi/0.10.2+wasi-snapshot-preview1/download", + name = "raze__wasi__0_10_0_wasi_snapshot_preview1", + url = "https://crates.io/api/v1/crates/wasi/0.10.0+wasi-snapshot-preview1/download", type = "tar.gz", - sha256 = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6", - strip_prefix = "wasi-0.10.2+wasi-snapshot-preview1", - build_file = Label("//cargo/remote:BUILD.wasi-0.10.2+wasi-snapshot-preview1.bazel"), + sha256 = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f", + strip_prefix = "wasi-0.10.0+wasi-snapshot-preview1", + build_file = Label("//cargo/remote:BUILD.wasi-0.10.0+wasi-snapshot-preview1.bazel"), ) maybe( diff --git a/cargo/remote/BUILD.chrono-0.4.19.bazel b/cargo/remote/BUILD.chrono-0.4.19.bazel new file mode 100644 index 0000000..487a0e6 --- /dev/null +++ b/cargo/remote/BUILD.chrono-0.4.19.bazel @@ -0,0 +1,90 @@ +""" +@generated +cargo-raze crate build file. + +DO NOT EDIT! Replaced on runs of cargo-raze +""" + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +package(default_visibility = [ + # Public for visibility by "@raze__crate__version//" targets. + # + # Prefer access through "//cargo", which limits external + # visibility to explicit Cargo.toml dependencies. + "//visibility:public", +]) + +licenses([ + "notice", # MIT from expression "MIT OR Apache-2.0" +]) + +# Generated Targets + +# Unsupported target "chrono" with type "bench" omitted + +# Unsupported target "serde" with type "bench" omitted + +rust_library( + name = "chrono", + srcs = glob(["**/*.rs"]), + aliases = { + }, + crate_features = [ + "clock", + "default", + "libc", + "oldtime", + "serde", + "std", + "time", + "winapi", + ], + crate_root = "src/lib.rs", + crate_type = "lib", + data = [], + edition = "2015", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-raze", + "manual", + ], + version = "0.4.19", + # buildifier: leave-alone + deps = [ + "@raze__libc__0_2_101//:libc", + "@raze__num_integer__0_1_44//:num_integer", + "@raze__num_traits__0_2_14//:num_traits", + "@raze__serde__1_0_130//:serde", + "@raze__time__0_1_44//:time", + ] + selects.with_or({ + # cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))) + ( + "@rules_rust//rust/platform:wasm32-unknown-unknown", + ): [ + ], + "//conditions:default": [], + }) + selects.with_or({ + # cfg(windows) + ( + "@rules_rust//rust/platform:i686-pc-windows-msvc", + "@rules_rust//rust/platform:x86_64-pc-windows-msvc", + ): [ + "@raze__winapi__0_3_9//:winapi", + ], + "//conditions:default": [], + }), +) + +# Unsupported target "wasm" with type "test" omitted diff --git a/cargo/remote/BUILD.getrandom-0.2.3.bazel b/cargo/remote/BUILD.getrandom-0.2.3.bazel index 2e8e74c..ac6f855 100644 --- a/cargo/remote/BUILD.getrandom-0.2.3.bazel +++ b/cargo/remote/BUILD.getrandom-0.2.3.bazel @@ -67,7 +67,7 @@ rust_library( ( "@rules_rust//rust/platform:wasm32-wasi", ): [ - "@raze__wasi__0_10_2_wasi_snapshot_preview1//:wasi", + "@raze__wasi__0_10_0_wasi_snapshot_preview1//:wasi", ], "//conditions:default": [], }) + selects.with_or({ diff --git a/cargo/remote/BUILD.nats-0.15.2.bazel b/cargo/remote/BUILD.nats-0.15.2.bazel new file mode 100644 index 0000000..2012fac --- /dev/null +++ b/cargo/remote/BUILD.nats-0.15.2.bazel @@ -0,0 +1,131 @@ +""" +@generated +cargo-raze crate build file. + +DO NOT EDIT! Replaced on runs of cargo-raze +""" + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +package(default_visibility = [ + # Public for visibility by "@raze__crate__version//" targets. + # + # Prefer access through "//cargo", which limits external + # visibility to explicit Cargo.toml dependencies. + "//visibility:public", +]) + +licenses([ + "notice", # Apache-2.0 from expression "Apache-2.0" +]) + +# Generated Targets + +# Unsupported target "nats_bench" with type "bench" omitted + +# Unsupported target "async_nats_bench" with type "example" omitted + +# Unsupported target "nats-box" with type "example" omitted + +# Unsupported target "nats_bench" with type "example" omitted + +# Unsupported target "serde-json" with type "example" omitted + +rust_library( + name = "nats", + srcs = glob(["**/*.rs"]), + aliases = { + }, + crate_features = [ + ], + crate_root = "src/lib.rs", + crate_type = "lib", + data = [], + edition = "2018", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-raze", + "manual", + ], + version = "0.15.2", + # buildifier: leave-alone + deps = [ + "@raze__base64__0_13_0//:base64", + "@raze__base64_url__1_4_10//:base64_url", + "@raze__blocking__1_0_2//:blocking", + "@raze__chrono__0_4_19//:chrono", + "@raze__crossbeam_channel__0_5_1//:crossbeam_channel", + "@raze__fastrand__1_5_0//:fastrand", + "@raze__itoa__0_4_8//:itoa", + "@raze__json__0_12_4//:json", + "@raze__log__0_4_14//:log", + "@raze__memchr__2_4_1//:memchr", + "@raze__nkeys__0_1_0//:nkeys", + "@raze__nuid__0_3_0//:nuid", + "@raze__once_cell__1_8_0//:once_cell", + "@raze__parking_lot__0_11_2//:parking_lot", + "@raze__regex__1_5_4//:regex", + "@raze__rustls__0_19_1//:rustls", + "@raze__rustls_native_certs__0_5_0//:rustls_native_certs", + "@raze__serde__1_0_130//:serde", + "@raze__serde_json__1_0_67//:serde_json", + "@raze__webpki__0_21_4//:webpki", + ] + selects.with_or({ + # cfg(unix) + ( + "@rules_rust//rust/platform:aarch64-apple-darwin", + "@rules_rust//rust/platform:aarch64-apple-ios", + "@rules_rust//rust/platform:aarch64-linux-android", + "@rules_rust//rust/platform:aarch64-unknown-linux-gnu", + "@rules_rust//rust/platform:arm-unknown-linux-gnueabi", + "@rules_rust//rust/platform:i686-apple-darwin", + "@rules_rust//rust/platform:i686-linux-android", + "@rules_rust//rust/platform:i686-unknown-freebsd", + "@rules_rust//rust/platform:i686-unknown-linux-gnu", + "@rules_rust//rust/platform:powerpc-unknown-linux-gnu", + "@rules_rust//rust/platform:s390x-unknown-linux-gnu", + "@rules_rust//rust/platform:x86_64-apple-darwin", + "@rules_rust//rust/platform:x86_64-apple-ios", + "@rules_rust//rust/platform:x86_64-linux-android", + "@rules_rust//rust/platform:x86_64-unknown-freebsd", + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu", + ): [ + "@raze__libc__0_2_101//:libc", + ], + "//conditions:default": [], + }) + selects.with_or({ + # cfg(windows) + ( + "@rules_rust//rust/platform:i686-pc-windows-msvc", + "@rules_rust//rust/platform:x86_64-pc-windows-msvc", + ): [ + "@raze__winapi__0_3_9//:winapi", + ], + "//conditions:default": [], + }), +) + +# Unsupported target "auth_nkey" with type "test" omitted + +# Unsupported target "auth_tls" with type "test" omitted + +# Unsupported target "auth_user_pass" with type "test" omitted + +# Unsupported target "connect" with type "test" omitted + +# Unsupported target "drop" with type "test" omitted + +# Unsupported target "jetstream" with type "test" omitted + +# Unsupported target "reconnection" with type "test" omitted diff --git a/cargo/remote/BUILD.num-integer-0.1.44.bazel b/cargo/remote/BUILD.num-integer-0.1.44.bazel new file mode 100644 index 0000000..51f2ad6 --- /dev/null +++ b/cargo/remote/BUILD.num-integer-0.1.44.bazel @@ -0,0 +1,95 @@ +""" +@generated +cargo-raze crate build file. + +DO NOT EDIT! Replaced on runs of cargo-raze +""" + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +package(default_visibility = [ + # Public for visibility by "@raze__crate__version//" targets. + # + # Prefer access through "//cargo", which limits external + # visibility to explicit Cargo.toml dependencies. + "//visibility:public", +]) + +licenses([ + "notice", # MIT from expression "MIT OR Apache-2.0" +]) + +# Generated Targets +# buildifier: disable=out-of-order-load +# buildifier: disable=load-on-top +load( + "@rules_rust//cargo:cargo_build_script.bzl", + "cargo_build_script", +) + +cargo_build_script( + name = "num_integer_build_script", + srcs = glob(["**/*.rs"]), + build_script_env = { + }, + crate_features = [ + ], + crate_root = "build.rs", + data = glob(["**"]), + edition = "2015", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-raze", + "manual", + ], + version = "0.1.44", + visibility = ["//visibility:private"], + deps = [ + "@raze__autocfg__1_0_1//:autocfg", + ], +) + +# Unsupported target "average" with type "bench" omitted + +# Unsupported target "gcd" with type "bench" omitted + +# Unsupported target "roots" with type "bench" omitted + +rust_library( + name = "num_integer", + srcs = glob(["**/*.rs"]), + crate_features = [ + ], + crate_root = "src/lib.rs", + crate_type = "lib", + data = [], + edition = "2015", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-raze", + "manual", + ], + version = "0.1.44", + # buildifier: leave-alone + deps = [ + ":num_integer_build_script", + "@raze__num_traits__0_2_14//:num_traits", + ], +) + +# Unsupported target "average" with type "test" omitted + +# Unsupported target "roots" with type "test" omitted diff --git a/cargo/remote/BUILD.time-0.1.44.bazel b/cargo/remote/BUILD.time-0.1.44.bazel new file mode 100644 index 0000000..980ab5f --- /dev/null +++ b/cargo/remote/BUILD.time-0.1.44.bazel @@ -0,0 +1,73 @@ +""" +@generated +cargo-raze crate build file. + +DO NOT EDIT! Replaced on runs of cargo-raze +""" + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +package(default_visibility = [ + # Public for visibility by "@raze__crate__version//" targets. + # + # Prefer access through "//cargo", which limits external + # visibility to explicit Cargo.toml dependencies. + "//visibility:public", +]) + +licenses([ + "notice", # MIT from expression "MIT OR Apache-2.0" +]) + +# Generated Targets + +rust_library( + name = "time", + srcs = glob(["**/*.rs"]), + aliases = { + }, + crate_features = [ + ], + crate_root = "src/lib.rs", + crate_type = "lib", + data = [], + edition = "2015", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-raze", + "manual", + ], + version = "0.1.44", + # buildifier: leave-alone + deps = [ + "@raze__libc__0_2_101//:libc", + ] + selects.with_or({ + # cfg(target_os = "wasi") + ( + "@rules_rust//rust/platform:wasm32-wasi", + ): [ + "@raze__wasi__0_10_0_wasi_snapshot_preview1//:wasi", + ], + "//conditions:default": [], + }) + selects.with_or({ + # cfg(windows) + ( + "@rules_rust//rust/platform:i686-pc-windows-msvc", + "@rules_rust//rust/platform:x86_64-pc-windows-msvc", + ): [ + "@raze__winapi__0_3_9//:winapi", + ], + "//conditions:default": [], + }), +) diff --git a/cargo/remote/BUILD.wasi-0.10.2+wasi-snapshot-preview1.bazel b/cargo/remote/BUILD.wasi-0.10.0+wasi-snapshot-preview1.bazel similarity index 95% rename from cargo/remote/BUILD.wasi-0.10.2+wasi-snapshot-preview1.bazel rename to cargo/remote/BUILD.wasi-0.10.0+wasi-snapshot-preview1.bazel index 49e605d..d1e5906 100644 --- a/cargo/remote/BUILD.wasi-0.10.2+wasi-snapshot-preview1.bazel +++ b/cargo/remote/BUILD.wasi-0.10.0+wasi-snapshot-preview1.bazel @@ -48,7 +48,7 @@ rust_library( "cargo-raze", "manual", ], - version = "0.10.2+wasi-snapshot-preview1", + version = "0.10.0+wasi-snapshot-preview1", # buildifier: leave-alone deps = [ ], diff --git a/cargo/remote/BUILD.winapi-0.3.9.bazel b/cargo/remote/BUILD.winapi-0.3.9.bazel index 675fd78..55afd20 100644 --- a/cargo/remote/BUILD.winapi-0.3.9.bazel +++ b/cargo/remote/BUILD.winapi-0.3.9.bazel @@ -62,6 +62,7 @@ cargo_build_script( "ntsecapi", "ntstatus", "processenv", + "profileapi", "schannel", "securitybaseapi", "sspi", @@ -123,6 +124,7 @@ rust_library( "ntsecapi", "ntstatus", "processenv", + "profileapi", "schannel", "securitybaseapi", "sspi", diff --git a/docker-compose.yaml b/docker-compose.yaml index a0bb20f..790c5b0 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -7,9 +7,4 @@ services: ports: - "8222:8222" - "4222:4222" - hostname: nats-server - registry: - restart: always - image: registry:2 - ports: - - 5000:5000 \ No newline at end of file + hostname: nats-server \ No newline at end of file diff --git a/webhook/Cargo.toml b/webhook/Cargo.toml index fb3da51..f2c278e 100644 --- a/webhook/Cargo.toml +++ b/webhook/Cargo.toml @@ -14,6 +14,7 @@ hex = "0.4.3" pretty_env_logger = "0.4" serde_json = { version = "1.0" } common = { path = "../common/rust" } +nats = "0.15.2" [[bin]] name = "webhook" diff --git a/webhook/cargo/BUILD.bazel b/webhook/cargo/BUILD.bazel index cb1c9cd..e698ae3 100644 --- a/webhook/cargo/BUILD.bazel +++ b/webhook/cargo/BUILD.bazel @@ -57,6 +57,15 @@ alias( ], ) +alias( + name = "nats", + actual = "@raze__nats__0_15_2//:nats", + tags = [ + "cargo-raze", + "manual", + ], +) + alias( name = "pretty_env_logger", actual = "@raze__pretty_env_logger__0_4_0//:pretty_env_logger", diff --git a/webhook/config/default.yaml b/webhook/config/default.yaml index 80cf77a..770d67f 100644 --- a/webhook/config/default.yaml +++ b/webhook/config/default.yaml @@ -10,5 +10,5 @@ webhook: port: 8000 discord: client_id: 738817757650485300 - public_key: "475bed67e20fb1e2d9b9007607f08d7b25b5a0aa936ef2d4ddaf7d592c993860" + public_key: "2dc5873bb9e603dbf70e6abc217768b9d7dfacef9e74ddaefcca6a9aed41f30d" diff --git a/webhook/src/handle.rs b/webhook/src/handle.rs index b60889e..b87d9a5 100644 --- a/webhook/src/handle.rs +++ b/webhook/src/handle.rs @@ -11,6 +11,7 @@ use std::str::from_utf8; use std::task::{Context, Poll}; use serde::{Deserialize, Serialize}; use crate::config::Config; +use nats::{Connection, connect}; pub fn validate_signature(b64_public_key: &str, data: &Vec, b64_signature: &str) -> bool { // First, we need to check if the signature & private key is valid base64. @@ -56,6 +57,7 @@ fn get_signature(headers: &HeaderMap) -> Option<(&str, &str)> { pub struct HandlerService { pub config: Config, + pub nats: Box } #[derive(Debug, Serialize, Deserialize)] @@ -76,6 +78,7 @@ impl Service> for HandlerService { fn call(&mut self, req: Request) -> Self::Future { if req.method() == Method::POST { let public_key = self.config.discord.public_key.clone(); + let nats = self.nats.clone(); return Box::pin(async move { let headers = req.headers().clone(); if let Some((signature, timestamp)) = get_signature(&headers) { @@ -83,18 +86,19 @@ impl Service> for HandlerService { let contatenated_data = [timestamp.as_bytes().to_vec(), data.to_vec()].concat(); if validate_signature(public_key.as_str(), &contatenated_data, signature) { - let data: Value = serde_json::from_str(from_utf8(&data).unwrap()).unwrap(); - let t = data.get("type").unwrap().as_i64().unwrap(); + let d: Value = serde_json::from_str(from_utf8(&data).unwrap()).unwrap(); + let t = d.get("type").unwrap().as_i64().unwrap(); if t == 1 { - info!("success!"); - return Ok(Response::builder().header("Content-Type", "application/json").body(serde_json::to_string(&Ping { t: 1 }).unwrap().into()).unwrap()); - } else { - Ok(Response::builder().status(StatusCode::UNAUTHORIZED).body("invalid operation".into()).unwrap()) + info!("Handled event"); + nats.publish(&format!("nova.dispatch.interaction_raw"), data).unwrap(); + return Ok(Response::builder().header("Content-Type", "application/json").body(serde_json::to_string(&Ping { + t: 5 + }).unwrap().into()).unwrap()); } } else { Ok(Response::builder().status(StatusCode::UNAUTHORIZED).body("signature verification failed".into()).unwrap()) @@ -116,6 +120,7 @@ impl Service> for HandlerService { pub struct MakeSvc { pub settings: Config, + pub nats: Box, } impl Service for MakeSvc { @@ -130,6 +135,7 @@ impl Service for MakeSvc { fn call(&mut self, _: T) -> Self::Future { future::ready(Ok(HandlerService { config: self.settings.clone(), + nats: self.nats.clone(), })) } } diff --git a/webhook/src/main.rs b/webhook/src/main.rs index 3125373..b9fefc5 100644 --- a/webhook/src/main.rs +++ b/webhook/src/main.rs @@ -22,8 +22,10 @@ async fn main() { "Starting server on {}:{}", settings.config.server.address, settings.config.server.port ); + let nats = Box::new(nats::connect("localhost").unwrap()); let server = Server::bind(&addr).serve(MakeSvc { settings: settings.config.clone(), + nats }); if let Err(e) = server.await { -- 2.39.5