]> git.puffer.fish Git - matthieu/nova.git/commitdiff
Basic structure for the project
authorMatthieu Pignolet <20992787+MatthieuCoder@users.noreply.github.com>
Wed, 4 Aug 2021 16:59:35 +0000 (20:59 +0400)
committerMatthieu Pignolet <20992787+MatthieuCoder@users.noreply.github.com>
Wed, 4 Aug 2021 16:59:35 +0000 (20:59 +0400)
17 files changed:
.gitignore [new file with mode: 0644]
.vscode/settings.json [new file with mode: 0644]
.vscode/tasks.json [new file with mode: 0644]
BUILD [new file with mode: 0644]
WORKSPACE [new file with mode: 0644]
deps.bzl [new file with mode: 0644]
gateway/BUILD.bazel [new file with mode: 0644]
gateway/go.mod [new file with mode: 0644]
gateway/main.go [new file with mode: 0644]
novactl/BUILD.bazel [new file with mode: 0644]
novactl/go.mod [new file with mode: 0644]
novactl/go.sum [new file with mode: 0644]
novactl/main.go [new file with mode: 0644]
rest-ratelimiter/Cargo.toml [new file with mode: 0644]
rest-ratelimiter/protos/BUILD.bazel [new file with mode: 0644]
rest-ratelimiter/protos/nova.ratelimit.v1.proto [new file with mode: 0644]
rest-ratelimiter/src/main.rs [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..1004d8f
--- /dev/null
@@ -0,0 +1,2 @@
+bazel-*
+.bazelrc
\ No newline at end of file
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644 (file)
index 0000000..f5b75bd
--- /dev/null
@@ -0,0 +1,10 @@
+{
+    "files.exclude": {
+        "**/.git": true,
+        "**/.svn": true,
+        "**/.hg": true,
+        "**/CVS": true,
+        "**/.DS_Store": true,
+        "**/bazel-*": true
+    }
+}
\ No newline at end of file
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
new file mode 100644 (file)
index 0000000..a846732
--- /dev/null
@@ -0,0 +1,28 @@
+{
+    "version": "2.0.0",
+    "tasks": [
+        {
+            "label": "Build",
+            "isBackground": true,
+            "command": [
+                "bash"
+            ],
+            "args": [
+                "-c",
+                "bazel build ..."
+            ]
+        },
+        {
+            "label": "Test",
+            "isBackground": true,
+            "command": [
+                "bash"
+            ],
+            "args": [
+                "-c",
+                "bazel -- test ..."
+            ],
+            "problemMatcher": []
+        }
+    ]
+}
\ No newline at end of file
diff --git a/BUILD b/BUILD
new file mode 100644 (file)
index 0000000..1d0f4ed
--- /dev/null
+++ b/BUILD
@@ -0,0 +1,4 @@
+load("@bazel_gazelle//:def.bzl", "gazelle")
+
+# gazelle:prefix github.com/discordnova/nova
+gazelle(name = "gazelle")
diff --git a/WORKSPACE b/WORKSPACE
new file mode 100644 (file)
index 0000000..280db03
--- /dev/null
+++ b/WORKSPACE
@@ -0,0 +1,54 @@
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+
+http_archive(
+    name = "io_bazel_rules_go",
+    sha256 = "8e968b5fcea1d2d64071872b12737bbb5514524ee5f0a4f54f5920266c261acb",
+    urls = [
+        "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.28.0/rules_go-v0.28.0.zip",
+        "https://github.com/bazelbuild/rules_go/releases/download/v0.28.0/rules_go-v0.28.0.zip",
+    ],
+)
+
+http_archive(
+    name = "bazel_gazelle",
+    sha256 = "62ca106be173579c0a167deb23358fdfe71ffa1e4cfdddf5582af26520f1c66f",
+    urls = [
+        "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.23.0/bazel-gazelle-v0.23.0.tar.gz",
+        "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.23.0/bazel-gazelle-v0.23.0.tar.gz",
+    ],
+)
+
+http_archive(
+    name = "rules_rust",
+    sha256 = "224ebaf1156b6f2d3680e5b8c25191e71483214957dfecd25d0f29b2f283283b",
+    strip_prefix = "rules_rust-a814d859845c420fd105c629134c4a4cb47ba3f8",
+    urls = [
+        # `main` branch as of 2021-06-15
+        "https://github.com/bazelbuild/rules_rust/archive/a814d859845c420fd105c629134c4a4cb47ba3f8.tar.gz",
+    ],
+)
+
+http_archive(
+    name = "cargo_raze",
+    sha256 = "c664e258ea79e7e4ec2f2b57bca8b1c37f11c8d5748e02b8224810da969eb681",
+    strip_prefix = "cargo-raze-0.11.0",
+    url = "https://github.com/google/cargo-raze/archive/v0.11.0.tar.gz",
+)
+
+load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
+go_register_toolchains(version = "1.16.5")
+go_rules_dependencies()
+
+load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
+gazelle_dependencies()
+load("//:deps.bzl", "go_dependencies")
+# gazelle:repository_macro deps.bzl%go_dependencies
+go_dependencies()
+
+load("@rules_rust//rust:repositories.bzl", "rust_repositories")
+rust_repositories()
+
+load("@cargo_raze//:repositories.bzl", "cargo_raze_repositories")
+cargo_raze_repositories()
+load("@cargo_raze//:transitive_deps.bzl", "cargo_raze_transitive_deps")
+cargo_raze_transitive_deps()
\ No newline at end of file
diff --git a/deps.bzl b/deps.bzl
new file mode 100644 (file)
index 0000000..c0a972c
--- /dev/null
+++ b/deps.bzl
@@ -0,0 +1,81 @@
+load("@bazel_gazelle//:deps.bzl", "go_repository")
+
+def go_dependencies():
+    go_repository(
+        name = "com_github_andybalholm_brotli",
+        importpath = "github.com/andybalholm/brotli",
+        sum = "h1:JKnhI/XQ75uFBTiuzXpzFrUriDPiZjlOSzh6wXogP0E=",
+        version = "v1.0.2",
+    )
+    go_repository(
+        name = "com_github_gofiber_fiber_v2",
+        importpath = "github.com/gofiber/fiber/v2",
+        sum = "h1:Bly40vAh4qofpCoVYGLYC0TS9lNGNA1OVSPuzhIK7Q8=",
+        version = "v2.16.0",
+    )
+    go_repository(
+        name = "com_github_golang_snappy",
+        importpath = "github.com/golang/snappy",
+        sum = "h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA=",
+        version = "v0.0.3",
+    )
+    go_repository(
+        name = "com_github_klauspost_compress",
+        importpath = "github.com/klauspost/compress",
+        sum = "h1:2KCfW3I9M7nSc5wOqXAlW2v2U6v+w6cbjvbfp+OykW8=",
+        version = "v1.12.2",
+    )
+    go_repository(
+        name = "com_github_valyala_bytebufferpool",
+        importpath = "github.com/valyala/bytebufferpool",
+        sum = "h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=",
+        version = "v1.0.0",
+    )
+    go_repository(
+        name = "com_github_valyala_fasthttp",
+        importpath = "github.com/valyala/fasthttp",
+        sum = "h1:k5Tooi31zPG/g8yS6o2RffRO2C9B9Kah9SY8j/S7058=",
+        version = "v1.26.0",
+    )
+    go_repository(
+        name = "com_github_valyala_tcplisten",
+        importpath = "github.com/valyala/tcplisten",
+        sum = "h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=",
+        version = "v1.0.0",
+    )
+    go_repository(
+        name = "org_golang_x_crypto",
+        importpath = "golang.org/x/crypto",
+        sum = "h1:kr2P4QFmQr29mSLA43kwrOcgcReGTfbE9N577tCTuBc=",
+        version = "v0.0.0-20210513164829-c07d793c2f9a",
+    )
+    go_repository(
+        name = "org_golang_x_net",
+        importpath = "golang.org/x/net",
+        sum = "h1:p9UgmWI9wKpfYmgaV/IZKGdXc5qEK45tDwwwDyjS26I=",
+        version = "v0.0.0-20210510120150-4163338589ed",
+    )
+    go_repository(
+        name = "org_golang_x_sys",
+        importpath = "golang.org/x/sys",
+        sum = "h1:hZR0X1kPW+nwyJ9xRxqZk1vx5RUObAPBdKVvXPDUH/E=",
+        version = "v0.0.0-20210514084401-e8d321eab015",
+    )
+    go_repository(
+        name = "org_golang_x_term",
+        importpath = "golang.org/x/term",
+        sum = "h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=",
+        version = "v0.0.0-20201126162022-7de9c90e9dd1",
+    )
+    go_repository(
+        name = "org_golang_x_text",
+        importpath = "golang.org/x/text",
+        sum = "h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=",
+        version = "v0.3.6",
+    )
+    go_repository(
+        name = "org_golang_x_tools",
+        importpath = "golang.org/x/tools",
+        sum = "h1:FDhOuMEY4JVRztM/gsbk+IKUQ8kj74bxZrgw87eMMVc=",
+        version = "v0.0.0-20180917221912-90fa682c2a6e",
+    )
diff --git a/gateway/BUILD.bazel b/gateway/BUILD.bazel
new file mode 100644 (file)
index 0000000..c7b6aa5
--- /dev/null
@@ -0,0 +1,14 @@
+load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
+
+go_library(
+    name = "gateway_lib",
+    srcs = ["main.go"],
+    importpath = "github.com/discordnova/nova/gateway",
+    visibility = ["//visibility:private"],
+)
+
+go_binary(
+    name = "gateway",
+    embed = [":gateway_lib"],
+    visibility = ["//visibility:public"],
+)
diff --git a/gateway/go.mod b/gateway/go.mod
new file mode 100644 (file)
index 0000000..8199032
--- /dev/null
@@ -0,0 +1,7 @@
+module github.com/discordnova/nova/gateway
+
+go 1.16
+
+require (
+       github.com/gofiber/fiber/v2 v2.16.0
+)
\ No newline at end of file
diff --git a/gateway/main.go b/gateway/main.go
new file mode 100644 (file)
index 0000000..39d1e52
--- /dev/null
@@ -0,0 +1,7 @@
+package main
+
+import "fmt"
+
+func main()  {
+       fmt.Println("Salut!")
+}
\ No newline at end of file
diff --git a/novactl/BUILD.bazel b/novactl/BUILD.bazel
new file mode 100644 (file)
index 0000000..a97deea
--- /dev/null
@@ -0,0 +1,15 @@
+load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
+
+go_library(
+    name = "novactl_lib",
+    srcs = ["main.go"],
+    importpath = "github.com/discordnova/nova/novactl",
+    visibility = ["//visibility:private"],
+    deps = ["@com_github_gofiber_fiber_v2//:go_default_library"],
+)
+
+go_binary(
+    name = "novactl",
+    embed = [":novactl_lib"],
+    visibility = ["//visibility:public"],
+)
diff --git a/novactl/go.mod b/novactl/go.mod
new file mode 100644 (file)
index 0000000..e09a041
--- /dev/null
@@ -0,0 +1,7 @@
+module github.com/discordnova/nova/novactl
+
+go 1.16
+
+require (
+       github.com/gofiber/fiber/v2 v2.16.0
+)
\ No newline at end of file
diff --git a/novactl/go.sum b/novactl/go.sum
new file mode 100644 (file)
index 0000000..abd2c10
--- /dev/null
@@ -0,0 +1,30 @@
+github.com/andybalholm/brotli v1.0.2 h1:JKnhI/XQ75uFBTiuzXpzFrUriDPiZjlOSzh6wXogP0E=
+github.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
+github.com/gofiber/fiber/v2 v2.16.0 h1:Bly40vAh4qofpCoVYGLYC0TS9lNGNA1OVSPuzhIK7Q8=
+github.com/gofiber/fiber/v2 v2.16.0/go.mod h1:iftruuHGkRYGEXVISmdD7HTYWyfS2Bh+Dkfq4n/1Owg=
+github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA=
+github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
+github.com/klauspost/compress v1.12.2 h1:2KCfW3I9M7nSc5wOqXAlW2v2U6v+w6cbjvbfp+OykW8=
+github.com/klauspost/compress v1.12.2/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
+github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
+github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
+github.com/valyala/fasthttp v1.26.0 h1:k5Tooi31zPG/g8yS6o2RffRO2C9B9Kah9SY8j/S7058=
+github.com/valyala/fasthttp v1.26.0/go.mod h1:cmWIqlu99AO/RKcp1HWaViTqc57FswJOfYYdPJBl8BA=
+github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
+github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
+golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a h1:kr2P4QFmQr29mSLA43kwrOcgcReGTfbE9N577tCTuBc=
+golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
+golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
+golang.org/x/net v0.0.0-20210510120150-4163338589ed h1:p9UgmWI9wKpfYmgaV/IZKGdXc5qEK45tDwwwDyjS26I=
+golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
+golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210514084401-e8d321eab015 h1:hZR0X1kPW+nwyJ9xRxqZk1vx5RUObAPBdKVvXPDUH/E=
+golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
+golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
+golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
+golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e h1:FDhOuMEY4JVRztM/gsbk+IKUQ8kj74bxZrgw87eMMVc=
+golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
diff --git a/novactl/main.go b/novactl/main.go
new file mode 100644 (file)
index 0000000..2f2f49d
--- /dev/null
@@ -0,0 +1,13 @@
+package main
+
+import "github.com/gofiber/fiber/v2"
+
+func main() {
+    app := fiber.New()
+
+    app.Get("/", func(c *fiber.Ctx) error {
+        return c.SendString("Hello, World ðŸ‘‹!")
+    })
+
+    app.Listen(":3000")
+}
\ No newline at end of file
diff --git a/rest-ratelimiter/Cargo.toml b/rest-ratelimiter/Cargo.toml
new file mode 100644 (file)
index 0000000..c1bfeb8
--- /dev/null
@@ -0,0 +1,22 @@
+[package]
+name = "rest-ratelimiter"
+version = "0.1.0"
+edition = "2018"
+
+[dependencies]
+tonic = "0.5"
+prost = "0.8"
+tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
+
+[build-dependencies]
+tonic-build = "0.5"
+
+[package.metadata.raze]
+# The path at which to write output files.
+#
+# `cargo raze` will generate Bazel-compatible BUILD files into this path.
+# This can either be a relative path (e.g. "foo/bar"), relative to this
+# Cargo.toml file; or relative to the Bazel workspace root (e.g. "//foo/bar").
+workspace_path = "//rest-ratelimiter"
+genmode = "Remote"
+default_gen_buildrs = true
\ No newline at end of file
diff --git a/rest-ratelimiter/protos/BUILD.bazel b/rest-ratelimiter/protos/BUILD.bazel
new file mode 100644 (file)
index 0000000..6cd212a
--- /dev/null
@@ -0,0 +1,24 @@
+load("@rules_proto//proto:defs.bzl", "proto_library")
+load("@io_bazel_rules_go//go:def.bzl", "go_library")
+load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
+
+proto_library(
+    name = "nova_ratelimit_v1_proto",
+    srcs = ["nova.ratelimit.v1.proto"],
+    visibility = ["//visibility:public"],
+)
+
+go_proto_library(
+    name = "nova_ratelimit_v1_go_proto",
+    compilers = ["@io_bazel_rules_go//proto:go_grpc"],
+    importpath = "github.com/discordnova/nova/rest-ratelimiter/protos",
+    proto = ":nova_ratelimit_v1_proto",
+    visibility = ["//visibility:public"],
+)
+
+go_library(
+    name = "protos",
+    embed = [":nova_ratelimit_v1_go_proto"],
+    importpath = "github.com/discordnova/nova/rest-ratelimiter/protos",
+    visibility = ["//visibility:public"],
+)
diff --git a/rest-ratelimiter/protos/nova.ratelimit.v1.proto b/rest-ratelimiter/protos/nova.ratelimit.v1.proto
new file mode 100644 (file)
index 0000000..5f06392
--- /dev/null
@@ -0,0 +1,39 @@
+// How does this works ?
+// Every request, the proxy (envoy) requests the rate-limiting service if
+// the requested route bucket or global rate-limit is hit.
+
+syntax = "proto3";
+package nova.ratelimit.v1;
+
+// The reponse of a RatelimitRequest, it includes the status of the reponse and
+// the bucket informations.
+message RatelimitResponse {
+    enum Status {
+        OK                  = 0;
+        RATELIMITED         = 1;
+        GLOBAL_RATELIMITED  = 2;
+    }
+    Status status = 1;
+    bool   updateAsked = 2;
+}
+
+// Requests the ratelimit status of a route request, it also takes the 
+// indentifiables of the request in question.
+message RatelimitRequest {
+    string          routeName       = 1;
+    repeated string indentifiables  = 2;
+}
+
+// Used when "updateAsked" is sed to true
+// this means the bucket is unknown to the ratelimit server.
+message CreateBucketData {
+    RatelimitRequest request    = 1;
+    int32 limit                 = 2;
+    int32 remaining             = 3;
+    int32 reset                 = 4;
+}
+
+service RatelimitService {
+    rpc GetRatelimitStatus (RatelimitRequest)   returns (RatelimitResponse);
+    rpc CreateBucket       (CreateBucketData)   returns (CreateBucketData);
+}
\ No newline at end of file
diff --git a/rest-ratelimiter/src/main.rs b/rest-ratelimiter/src/main.rs
new file mode 100644 (file)
index 0000000..e69de29