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

move to production #3719

Merged
merged 13 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;

Check warning on line 5 in src/device-registry/middleware/common.js

View check run for this annotation

Codecov / codecov/patch

src/device-registry/middleware/common.js#L2-L5

Added lines #L2 - L5 were not covered by tests
}
if (limit > 2000) {
limit = 2000;

Check warning on line 8 in src/device-registry/middleware/common.js

View check run for this annotation

Codecov / codecov/patch

src/device-registry/middleware/common.js#L7-L8

Added lines #L7 - L8 were not covered by tests
}
if (isNaN(skip) || skip < 0) {
req.query.skip = 0;

Check warning on line 11 in src/device-registry/middleware/common.js

View check run for this annotation

Codecov / codecov/patch

src/device-registry/middleware/common.js#L10-L11

Added lines #L10 - L11 were not covered by tests
}
req.query.limit = limit;

Check warning on line 13 in src/device-registry/middleware/common.js

View check run for this annotation

Codecov / codecov/patch

src/device-registry/middleware/common.js#L13

Added line #L13 was not covered by tests

next();

Check warning on line 15 in src/device-registry/middleware/common.js

View check run for this annotation

Codecov / codecov/patch

src/device-registry/middleware/common.js#L15

Added line #L15 was not covered by tests
};

const headers = (req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.header(

Check warning on line 20 in src/device-registry/middleware/common.js

View check run for this annotation

Codecov / codecov/patch

src/device-registry/middleware/common.js#L19-L20

Added lines #L19 - L20 were not covered by tests
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Authorization"
);
res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
next();

Check warning on line 25 in src/device-registry/middleware/common.js

View check run for this annotation

Codecov / codecov/patch

src/device-registry/middleware/common.js#L24-L25

Added lines #L24 - L25 were not covered by tests
};

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
Loading