]> git.puffer.fish Git - matthieu/nova.git/commitdiff
fix circle ci
authorMatthieu <matthieu@developershouse.xyz>
Fri, 15 Oct 2021 10:20:59 +0000 (14:20 +0400)
committerMatthieu <matthieu@developershouse.xyz>
Fri, 15 Oct 2021 10:20:59 +0000 (14:20 +0400)
.circleci/config.yml
.devcontainer/devcontainer.json
common/rust/src/error.rs
rest/src/proxy/mod.rs
rest/src/ratelimit/mod.rs
webhook/src/main.rs

index 5ca796bc7968fe15eaa048adb600c84a69d8d869..11895635ae6f6abbca305714f6d32f7a153a045a 100644 (file)
@@ -36,6 +36,9 @@ jobs:
           name: "Test"
           command: "bazelisk test //:tests || true"
 
+      - store_artifacts:
+          path: ~/project/bazel-testlogs
+      
       - store_test_results:
           path: ~/project/bazel-testlogs/rest
       - store_test_results:
@@ -74,6 +77,9 @@ jobs:
       - store_test_results:
           path: ~/project/bazel-testlogs/webhook
 
+      - store_artifacts:
+          path: ~/project/bazel-testlogs
+      
       - run:
           name: "Build"
           command: "bazelisk build //:packages"
@@ -103,13 +109,14 @@ jobs:
       - run:
           name: "Test"
           command: |
-            $ErrorActionPreference = â€˜SilentlyContinue’
-            bazelisk test //:tests
+            bazelisk test //:tests | Out-Null
 
       - store_test_results:
           path: ~/project/bazel-testlogs/rest
       - store_test_results:
           path: ~/project/bazel-testlogs/webhook
+      - store_artifacts:
+          path: ~/project/bazel-testlogs
 
       - run:
           name: "Build"
index 03c3e4cb8cd43b703faa08f53a660f8299c6cf83..a962bc7ce89b18cb0ad4522d7d08d5b9356cbb3d 100644 (file)
@@ -36,5 +36,5 @@
     // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
     "remoteUser": "vscode",
     "overrideCommand": false,
-    "runArgs": ["--init"],
+    "runArgs": ["--init", "--network=host"]
 }
\ No newline at end of file
index be1607ae40dcfa2bfd85b062ffc3fcd761e45b36..1a24657f8fcf2b60e7d6dfab374d853524603873 100644 (file)
@@ -10,3 +10,9 @@ impl fmt::Display for NovaError {
         write!(f, "An error occurred within the nova system: {}", self.message) // user-facing output
     }
 }
+
+impl From<&str> for NovaError {
+    fn from(message: &str) -> Self {
+        NovaError { message: message.to_string() }
+    }
+}
\ No newline at end of file
index a68429020f79e973bc0fde946948f93c84ab5517..ad1abbae3167c4b364023f38035e346b2030a9d2 100644 (file)
@@ -14,6 +14,10 @@ pub struct ServiceProxy {
     config: Arc<Config>,
 }
 
+impl ServiceProxy {
+    async fn proxy_call() {}
+}
+
 impl Service<Request<Body>> for ServiceProxy {
     type Response = Response<Body>;
     type Error = hyper::Error;
@@ -51,18 +55,32 @@ impl Service<Request<Body>> for ServiceProxy {
         );
 
         *req.headers_mut() = headers;
-        let res = self.client
-            .request(req)
-            .map_ok(move |res| {
-                if let Some(bucket) = res.headers().get("x-ratelimit-bucket") {
-                    
-                    println!("bucket ratelimit! {:?} : {:?}", path, bucket);
-                }
+        let client = self.client.clone();
+        let ratelimiter = self.ratelimiter.clone();
 
-                res
-            });
-        
-        return Box::pin(res);
+        return Box::pin(async move {
+            match ratelimiter.check(&req).await {
+                Ok(allowed) => match allowed {
+                    true => {
+                        Ok(client
+                        .request(req)
+                        .map_ok(move |res| {
+                            if let Some(bucket) = res.headers().get("x-ratelimit-bucket") {
+                                
+                                println!("bucket ratelimit! {:?} : {:?}", path, bucket);
+                            }
+                            res
+                        }).await.unwrap())
+                    },
+                    false => {
+                        Ok(Response::builder().body("ratelimited".into()).unwrap())
+                    },
+                },
+                Err(_) => {
+                    Ok(Response::builder().body("server error".into()).unwrap())
+                },
+            }
+        });
     }
 }
 
index c9c76437218aa70cb6cd8eefd3eb1080ab09e9d1..07db64395f370aa0c4018f8b6490e5bf4324735e 100644 (file)
@@ -1,4 +1,4 @@
-use common::redis_crate::{AsyncCommands, RedisError, aio::Connection};
+use common::{error::NovaError, redis_crate::{AsyncCommands, RedisError, aio::Connection}};
 use hyper::{Body, Request};
 use tokio::sync::Mutex;
 use std::sync::Arc;
@@ -15,7 +15,7 @@ impl Ratelimiter {
         }
     }
 
-    pub async fn check(&mut self,request: Request<Body>) -> bool {
+    pub async fn check(&self,request: &Request<Body>) -> Result<bool, NovaError> {
         // we lookup if the route hash is stored in the redis table
         let path = request.uri().path();
         let hash = xxh32(path.as_bytes(), 32);
@@ -24,8 +24,10 @@ impl Ratelimiter {
         let value: Result<String, RedisError> = redis.get(key).await;
 
         match value {
-            Ok(_) => true,
-            Err(error) => false,
+            Ok(response) => {
+                Ok(false)
+            },
+            Err(error) => Err(NovaError::from("failed to issue redis request")),
         }
     }
 }
index eef47514f4d41b078da0c693760b5ed2d7a158bc..98e5f133a123551efa70709392e1f055e82bdf82 100644 (file)
@@ -15,7 +15,6 @@ async fn main() {
 }\r
 \r
 async fn start(settings: Settings<Config>) {\r
-    \r
     let addr = format!(\r
         "{}:{}",\r
         settings.config.server.address, settings.config.server.port\r