Skip to content

Commit

Permalink
Merge pull request #3719 from airqo-platform/staging
Browse files Browse the repository at this point in the history
move to production
  • Loading branch information
Baalmart authored Oct 21, 2024
2 parents ca3c0a1 + c56e52f commit 19e9002
Show file tree
Hide file tree
Showing 16 changed files with 1,373 additions and 1,926 deletions.
2 changes: 1 addition & 1 deletion k8s/analytics/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ images:
celeryWorker: eu.gcr.io/airqo-250220/airqo-analytics-celery-worker
reportJob: eu.gcr.io/airqo-250220/airqo-analytics-report-job
devicesSummaryJob: eu.gcr.io/airqo-250220/airqo-analytics-devices-summary-job
tag: prod-ce887f9a-1729440023
tag: prod-ca3c0a10-1729545000
api:
name: airqo-analytics-api
label: analytics-api
Expand Down
2 changes: 1 addition & 1 deletion k8s/auth-service/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ app:
replicaCount: 3
image:
repository: eu.gcr.io/airqo-250220/airqo-auth-api
tag: prod-ce887f9a-1729440023
tag: prod-ca3c0a10-1729545000
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
2 changes: 1 addition & 1 deletion k8s/device-registry/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ app:
replicaCount: 3
image:
repository: eu.gcr.io/airqo-250220/airqo-device-registry-api
tag: prod-ce887f9a-1729440023
tag: prod-ca3c0a10-1729545000
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
2 changes: 1 addition & 1 deletion k8s/device-registry/values-stage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ app:
replicaCount: 2
image:
repository: eu.gcr.io/airqo-250220/airqo-stage-device-registry-api
tag: stage-c9289e15-1729439973
tag: stage-275dcdcd-1729551603
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
2 changes: 1 addition & 1 deletion k8s/exceedance/values-prod-airqo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ app:
configmap: env-exceedance-production
image:
repository: eu.gcr.io/airqo-250220/airqo-exceedance-job
tag: prod-ce887f9a-1729440023
tag: prod-ca3c0a10-1729545000
nameOverride: ''
fullnameOverride: ''
2 changes: 1 addition & 1 deletion k8s/exceedance/values-prod-kcca.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ app:
configmap: env-exceedance-production
image:
repository: eu.gcr.io/airqo-250220/kcca-exceedance-job
tag: prod-ce887f9a-1729440023
tag: prod-ca3c0a10-1729545000
nameOverride: ''
fullnameOverride: ''
2 changes: 1 addition & 1 deletion k8s/predict/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ images:
predictJob: eu.gcr.io/airqo-250220/airqo-predict-job
trainJob: eu.gcr.io/airqo-250220/airqo-train-job
predictPlaces: eu.gcr.io/airqo-250220/airqo-predict-places-air-quality
tag: prod-ce887f9a-1729440023
tag: prod-ca3c0a10-1729545000
api:
name: airqo-prediction-api
label: prediction-api
Expand Down
2 changes: 1 addition & 1 deletion k8s/spatial/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ app:
replicaCount: 3
image:
repository: eu.gcr.io/airqo-250220/airqo-spatial-api
tag: prod-ce887f9a-1729440023
tag: prod-ca3c0a10-1729545000
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
2 changes: 1 addition & 1 deletion k8s/workflows/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ images:
initContainer: eu.gcr.io/airqo-250220/airqo-workflows-xcom
redisContainer: eu.gcr.io/airqo-250220/airqo-redis
containers: eu.gcr.io/airqo-250220/airqo-workflows
tag: prod-ce887f9a-1729440023
tag: prod-ca3c0a10-1729545000
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
31 changes: 31 additions & 0 deletions src/device-registry/middleware/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const validatePagination = (req, res, next) => {
let limit = parseInt(req.query.limit, 10);
const skip = parseInt(req.query.skip, 10);
if (isNaN(limit) || limit < 1) {
limit = 1000;
}
if (limit > 2000) {
limit = 2000;
}
if (isNaN(skip) || skip < 0) {
req.query.skip = 0;
}
req.query.limit = limit;

next();
};

const headers = (req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Authorization"
);
res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
next();
};

module.exports = {
validatePagination,
headers,
};
82 changes: 82 additions & 0 deletions src/device-registry/middleware/test/ut_common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
require("module-alias/register");
const { expect } = require("chai");
const sinon = require("sinon");
const middleware = require("@middleware/common");

describe("Middleware", () => {
describe("validatePagination", () => {
it("should set default limit if not provided", () => {
const req = { query: {} };
const res = {};
const next = sinon.spy();

middleware.validatePagination(req, res, next);

expect(req.query.limit).to.equal(1000);
expect(next.calledOnce).to.be.true;
});

it("should set limit to 2000 if provided limit is greater", () => {
const req = { query: { limit: "3000" } };
const res = {};
const next = sinon.spy();

middleware.validatePagination(req, res, next);

expect(req.query.limit).to.equal(2000);
expect(next.calledOnce).to.be.true;
});

it("should set skip to 0 if not provided or invalid", () => {
const req = { query: { skip: "invalid" } };
const res = {};
const next = sinon.spy();

middleware.validatePagination(req, res, next);

expect(req.query.skip).to.equal(0);
expect(next.calledOnce).to.be.true;
});

it("should not modify valid limit and skip values", () => {
const req = { query: { limit: "500", skip: "100" } };
const res = {};
const next = sinon.spy();

middleware.validatePagination(req, res, next);

expect(req.query.limit).to.equal(500);
expect(req.query.skip).to.equal(100);
expect(next.calledOnce).to.be.true;
});
});

describe("headers", () => {
it("should set the correct headers", () => {
const req = {};
const res = {
setHeader: sinon.spy(),
header: sinon.spy(),
};
const next = sinon.spy();

middleware.headers(req, res, next);

expect(res.setHeader.calledWith("Access-Control-Allow-Origin", "*")).to.be
.true;
expect(
res.header.calledWith(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Authorization"
)
).to.be.true;
expect(
res.header.calledWith(
"Access-Control-Allow-Methods",
"GET, POST, PUT, DELETE"
)
).to.be.true;
expect(next.calledOnce).to.be.true;
});
});
});
3 changes: 2 additions & 1 deletion src/device-registry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"@middleware": "middleware",
"@scripts": "scripts",
"@routes": "routes",
"@bin": "bin"
"@bin": "bin",
"@validators": "validators"
},
"dependencies": {
"@google-cloud/bigquery": "^5.5.0",
Expand Down
Loading

0 comments on commit 19e9002

Please sign in to comment.