Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UI - Serveur] Ajoute des workers pour la classification #377

Merged
merged 6 commits into from
Dec 4, 2024

Conversation

yohanngab
Copy link
Collaborator

Cette PR permet de déclencher des jobs de classification depuis l'UI.

@yohanngab yohanngab self-assigned this Dec 4, 2024
export const jobs = () => {
const router = express.Router();

router.post("/api/jobs/:jobId/stop", verifyUser, isAdmin, (req, res, next) => {

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
authorization
, but is not rate-limited.

Copilot Autofix AI 21 days ago

To fix the problem, we should introduce rate limiting to the Express application using the express-rate-limit package. This will help prevent denial-of-service attacks by limiting the number of requests a client can make within a specified time window.

  1. Install the express-rate-limit package.
  2. Import the express-rate-limit package in the server/src/routes/jobs.routes.ts file.
  3. Set up a rate limiter with appropriate configuration (e.g., maximum of 100 requests per 15 minutes).
  4. Apply the rate limiter to the routes defined in the jobs function.
Suggested changeset 1
server/src/routes/jobs.routes.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/server/src/routes/jobs.routes.ts b/server/src/routes/jobs.routes.ts
--- a/server/src/routes/jobs.routes.ts
+++ b/server/src/routes/jobs.routes.ts
@@ -1,2 +1,3 @@
 import express from "express";
+import rateLimit from "express-rate-limit";
 
@@ -11,2 +12,9 @@
 
+  const limiter = rateLimit({
+    windowMs: 15 * 60 * 1000, // 15 minutes
+    max: 100, // limit each IP to 100 requests per windowMs
+  });
+
+  router.use(limiter);
+
   router.post("/api/jobs/:jobId/stop", verifyUser, isAdmin, (req, res, next) => {
EOF
@@ -1,2 +1,3 @@
import express from "express";
import rateLimit from "express-rate-limit";

@@ -11,2 +12,9 @@

const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // limit each IP to 100 requests per windowMs
});

router.use(limiter);

router.post("/api/jobs/:jobId/stop", verifyUser, isAdmin, (req, res, next) => {
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
stopJob(req, res, next);
});

router.post("/api/jobs/start", verifyUser, isAdmin, validator(startJobSchema), (req, res, next) => {

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
authorization
, but is not rate-limited.

Copilot Autofix AI 21 days ago

To fix the problem, we will introduce rate limiting middleware using the express-rate-limit package. This middleware will limit the number of requests that can be made to the endpoints within a specified time window. We will configure the rate limiter to allow a maximum of 100 requests per 15 minutes for each IP address. This will help protect the application from denial-of-service attacks.

We will need to:

  1. Install the express-rate-limit package.
  2. Import the express-rate-limit package in the server/src/routes/jobs.routes.ts file.
  3. Configure the rate limiter and apply it to the router.
Suggested changeset 1
server/src/routes/jobs.routes.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/server/src/routes/jobs.routes.ts b/server/src/routes/jobs.routes.ts
--- a/server/src/routes/jobs.routes.ts
+++ b/server/src/routes/jobs.routes.ts
@@ -1,3 +1,3 @@
 import express from "express";
-
+import rateLimit from "express-rate-limit";
 import { getAllJobs, getJob, startJob, stopJob } from "../controllers/jobs.controller";
@@ -11,2 +11,9 @@
 
+  const limiter = rateLimit({
+    windowMs: 15 * 60 * 1000, // 15 minutes
+    max: 100, // limit each IP to 100 requests per windowMs
+  });
+
+  router.use(limiter);
+
   router.post("/api/jobs/:jobId/stop", verifyUser, isAdmin, (req, res, next) => {
EOF
@@ -1,3 +1,3 @@
import express from "express";

import rateLimit from "express-rate-limit";
import { getAllJobs, getJob, startJob, stopJob } from "../controllers/jobs.controller";
@@ -11,2 +11,9 @@

const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // limit each IP to 100 requests per windowMs
});

router.use(limiter);

router.post("/api/jobs/:jobId/stop", verifyUser, isAdmin, (req, res, next) => {
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
startJob(req, res, next);
});

router.get("/api/jobs", verifyUser, isAdmin, (req, res, next) => {

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
authorization
, but is not rate-limited.

Copilot Autofix AI 21 days ago

To fix the problem, we need to introduce rate limiting to the routes handling job operations. The best way to do this is by using the express-rate-limit package, which allows us to easily set up and apply rate limiting middleware to our routes. We will configure a rate limiter to allow a maximum of 100 requests per 15 minutes and apply it to all the routes in the jobs router.

Suggested changeset 1
server/src/routes/jobs.routes.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/server/src/routes/jobs.routes.ts b/server/src/routes/jobs.routes.ts
--- a/server/src/routes/jobs.routes.ts
+++ b/server/src/routes/jobs.routes.ts
@@ -1,3 +1,3 @@
 import express from "express";
-
+import rateLimit from "express-rate-limit";
 import { getAllJobs, getJob, startJob, stopJob } from "../controllers/jobs.controller";
@@ -11,2 +11,9 @@
 
+  const limiter = rateLimit({
+    windowMs: 15 * 60 * 1000, // 15 minutes
+    max: 100, // max 100 requests per windowMs
+  });
+
+  router.use(limiter);
+
   router.post("/api/jobs/:jobId/stop", verifyUser, isAdmin, (req, res, next) => {
EOF
@@ -1,3 +1,3 @@
import express from "express";

import rateLimit from "express-rate-limit";
import { getAllJobs, getJob, startJob, stopJob } from "../controllers/jobs.controller";
@@ -11,2 +11,9 @@

const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // max 100 requests per windowMs
});

router.use(limiter);

router.post("/api/jobs/:jobId/stop", verifyUser, isAdmin, (req, res, next) => {
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
getAllJobs(req, res, next);
});

router.get("/api/jobs/:jobId", verifyUser, isAdmin, (req, res, next) => {

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
authorization
, but is not rate-limited.

Copilot Autofix AI 21 days ago

To fix the problem, we need to introduce rate limiting to the routes defined in the jobs function. The best way to do this is by using the express-rate-limit package, which allows us to easily set up rate limiting middleware. We will configure a rate limiter to allow a maximum of 100 requests per 15 minutes and apply it to all the routes in the jobs function.

We need to:

  1. Install the express-rate-limit package.
  2. Import the express-rate-limit package in the file.
  3. Set up the rate limiter with the desired configuration.
  4. Apply the rate limiter to the router.
Suggested changeset 1
server/src/routes/jobs.routes.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/server/src/routes/jobs.routes.ts b/server/src/routes/jobs.routes.ts
--- a/server/src/routes/jobs.routes.ts
+++ b/server/src/routes/jobs.routes.ts
@@ -1,3 +1,3 @@
 import express from "express";
-
+import RateLimit from "express-rate-limit";
 import { getAllJobs, getJob, startJob, stopJob } from "../controllers/jobs.controller";
@@ -11,2 +11,11 @@
 
+  // set up rate limiter: maximum of 100 requests per 15 minutes
+  const limiter = RateLimit({
+    windowMs: 15 * 60 * 1000, // 15 minutes
+    max: 100, // max 100 requests per windowMs
+  });
+
+  // apply rate limiter to all requests
+  router.use(limiter);
+
   router.post("/api/jobs/:jobId/stop", verifyUser, isAdmin, (req, res, next) => {
EOF
@@ -1,3 +1,3 @@
import express from "express";

import RateLimit from "express-rate-limit";
import { getAllJobs, getJob, startJob, stopJob } from "../controllers/jobs.controller";
@@ -11,2 +11,11 @@

// set up rate limiter: maximum of 100 requests per 15 minutes
const limiter = RateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // max 100 requests per windowMs
});

// apply rate limiter to all requests
router.use(limiter);

router.post("/api/jobs/:jobId/stop", verifyUser, isAdmin, (req, res, next) => {
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@yohanngab yohanngab merged commit 953663e into main Dec 4, 2024
2 of 3 checks passed
@yohanngab yohanngab deleted the ui-server/run-classification-as-job branch December 4, 2024 14:26
Copy link

github-actions bot commented Dec 4, 2024

🎉 This PR is included in version 0.18.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant