Skip to content

Commit

Permalink
Merge branch 'master' into ft_sonarproblems
Browse files Browse the repository at this point in the history
  • Loading branch information
augustocristian committed May 1, 2024
2 parents 06d7495 + 2085d5e commit 8f4eb44
Show file tree
Hide file tree
Showing 51 changed files with 48,943 additions and 17,866 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,6 @@ jobs:
ELASTIC_PASSWORD: ${{ secrets.ELASTIC_PASSWORD }}
LOGSTASH_INTERNAL_PASSWORD: ${{ secrets.LOGSTASH_INTERNAL_PASSWORD }}
KIBANA_SYSTEM_PASSWORD: ${{ secrets.KIBANA_SYSTEM_PASSWORD }}
CUSTOM_USER: ${{ secrets.CUSTOM_USER }}
CUSTOM_USER_PASSWORD: ${{ secrets.CUSTOM_USER_PASSWORD }}

docker-push-elasticsearch:
name: Push elasticsearch service Docker Image to GitHub Packages
Expand Down Expand Up @@ -391,7 +389,6 @@ jobs:
GF_SECURITY_ADMIN_PASSWORD: ${{ secrets.GF_SECURITY_ADMIN_PASSWORD }}
GF_SERVER_SERVE_FROM_SUB_PATH: false
GF_SERVER_DOMAIN: cyt.is-cool.dev
GF_SERVER_HTTP_PORT: 443
GF_SERVER_PROTOCOL: https

docker-push-prometheus:
Expand Down Expand Up @@ -449,6 +446,14 @@ jobs:
rm -rf ./*
wget https://raw.githubusercontent.com/arquisoft/wiq_es05b/master/docker-compose.yml -O docker-compose.yml
wget https://raw.githubusercontent.com/arquisoft/wiq_es05b/master/.env -O .env
echo "GF_SECURITY_ADMIN_USER=${{ secrets.GF_SECURITY_ADMIN_USER }}" >> .env
echo "GF_SECURITY_ADMIN_PASSWORD=${{ secrets.GF_SECURITY_ADMIN_PASSWORD }}" >> .env
echo "GF_SERVER_SERVE_FROM_SUB_PATH=false" >> .env
echo "GF_SERVER_DOMAIN=cyt.is-cool.dev" >> .env
echo "GF_SERVER_PROTOCOL=http" >> .env
echo "ELASTIC_PASSWORD=${{ secrets.ELASTIC_PASSWORD }}" >> .env
echo "LOGSTASH_INTERNAL_PASSWORD=${{ secrets.LOGSTASH_INTERNAL_PASSWORD }}" >> .env
echo "KIBANA_SYSTEM_PASSWORD=${{ secrets.KIBANA_SYSTEM_PASSWORD }}" >> .env
docker logout ghcr.io
docker logout ghcr
docker image prune -f
Expand Down
2 changes: 1 addition & 1 deletion cyt-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cyt-utils",
"version": "6.0.0",
"version": "6.1.0",
"description": "A variety of utilities for the project",
"main": "index.js",
"scripts": {
Expand Down
7 changes: 4 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3'
services:

# Production services
Expand Down Expand Up @@ -209,6 +208,8 @@ services:
- "9090:9090"
depends_on:
- gatewayservice
restart:
always

grafana:
image: ghcr.io/arquisoft/wiq_es05b/grafana:latest
Expand All @@ -228,12 +229,12 @@ services:
- GF_SECURITY_ADMIN_PASSWORD=${GF_SECURITY_ADMIN_PASSWORD:-changeme}
- GF_SERVER_SERVE_FROM_SUB_PATH=${GF_SERVER_SERVE_FROM_SUB_PATH:-true}
- GF_SERVER_DOMAIN=${GF_SERVER_DOMAIN:-}
- GF_SERVER_HTTP_PORT=${GF_SERVER_HTTP_PORT:-}
- GF_SERVER_PROTOCOL=${GF_PROTOCOL:-}
- GF_SERVER_PROTOCOL=${GF_SERVER_PROTOCOL:-}
ports:
- "9091:9091"
depends_on:
- prometheus
restart: always

volumes:
mongo_data:
Expand Down
6 changes: 1 addition & 5 deletions jordi/WikidataGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@ class WikidataGenerator {

});

return questions;

} else {
throw new Error("No Data found")
}
return questions; } else { throw new Error("No Data found") }

}

Expand Down
18 changes: 10 additions & 8 deletions jordi/jordi-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ if (generateOnStartup) {
.catch(e => console.log("Oh no", e));
}

// Disabled because of bugs in the library
//
// * second * minute * hour * date * month * year
cron.schedule(schedule, () => {
console.log("Running script at : " + new Date());
script(groupsRepository, questionsRepository, WikidataGenerator)
.catch(e => console.log("Oh no", e));
}, {
scheduled: true,
timezone: "Europe/Madrid"
});
// cron.schedule(schedule, () => {
// console.log("Running script at : " + new Date());
// script(groupsRepository, questionsRepository, WikidataGenerator)
// .catch(e => console.log("Oh no", e));
// }, {
// scheduled: true,
// timezone: "Europe/Madrid"
// });
15 changes: 14 additions & 1 deletion jordi/jordi-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,26 @@ describe("[Jordi Service] - /categories", () => {
it("Should return 200 and an array of categories", async () => {

axios.get.mockImplementation(() => Promise.resolve(WikidataMock));

await request(app).post("/addGroups").send(groups);
await request(app).get("/gen");

const response = await request(app).get('/categories');
let response = await request(app).get('/categories');

expect(response.status).toBe(200);
expect(response).toHaveProperty("text");

expect(response.text).toEqual("[\"area\",\"capitals\",\"continent\",\"currency\",\"economy\",\"gdp\",\"geography\",\"languages\",\"politics\",\"population\",\"president\",\"religion\"]");

await request(app).get("/removeAllGroups");

response = await request(app).get('/categories');

expect(response.status).toBe(200);
expect(response).toHaveProperty("text");

expect(response.text).toBe("[]");

});

it("Should return 200 and an empty array of categories if the database is empty", async () => {
Expand All @@ -226,6 +236,7 @@ describe("[Jordi Service] - /categories", () => {
expect(response.text).toBe("[]");

});

});

describe("[Jordi Service] - /questions/:category/:n", () => {
Expand Down Expand Up @@ -289,6 +300,7 @@ app2.set("i18next", require("i18next"))
routes(app2, mockQuestionsRepository);

describe('Routes', () => {

it('fetches categories', async () => {
mockQuestionsRepository.getCategories.mockResolvedValue([]);
const res = await request(app2).get('/categories');
Expand Down Expand Up @@ -319,4 +331,5 @@ describe('Routes', () => {
const res = await request(app2).get('/questions/category/invalid');
expect(res.statusCode).toEqual(400);
});

});
2 changes: 1 addition & 1 deletion jordi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"scripts": {
"start": "node jordi-service.js",
"dev": "nodemon jordi-service.js",
"test": "jest"
"test": "jest --coverage"
},
"repository": {
"type": "git",
Expand Down
38 changes: 15 additions & 23 deletions jordi/repositories/questionRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ module.exports = {
await this.checkUp();
return await this.mongoose.connection
.collection(this.collectionName)
.distinct("categories");
} catch (error) {
throw error.message;
}
.distinct("categories"); } catch (error) { throw error.message; }
},

checkCategory: async function (category) {
Expand All @@ -35,10 +32,7 @@ module.exports = {
const result = await this.mongoose.connection
.collection(this.collectionName)
.distinct("categories");
return result.some((x) => x === category);
} catch (e) {
throw e.message;
}
return result.some((x) => x === category); } catch (error) { throw error.message; }
},

getQuestions: async function (category, n = 10) {
Expand All @@ -57,38 +51,36 @@ module.exports = {
question.options = await this.getDistinctOptions(question);
}

return result;
} catch (error) {
throw error.message;
}
return result; } catch (error) { throw error.message; }
},

insertQuestions: async function (questions) {
try {
await this.checkUp();
await this.mongoose.connection
.collection(this.collectionName)
.insertMany(questions);
} catch (error) {
throw error.message;
}
.insertMany(questions); } catch (error) { throw error.message; }
},

deleteQuestions: async function (groupId) {
try {
await this.checkUp();
await this.mongoose.connection
.collection(this.collectionName)
.deleteMany({ groupId });
} catch (error) {
throw error.message;
}
.deleteMany({ groupId }); } catch (error) { throw error.message; }
},

getDistinctOptions: async function (question) {
// FIXME: Make it distinct and exclude the answer
// also make sure there are always 4 options at the end
removeQuestions: async function (filter, options) {

console.log("XD")
try {
await this.checkUp();
await this.mongoose.connection
.collection(this.collectionName)
.deleteMany(filter, options); } catch (error) { throw error.message; }
},

getDistinctOptions: async function (question) {
try {
await this.checkUp();
let result = (
Expand Down
4 changes: 4 additions & 0 deletions jordi/routes/jordi-think.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ module.exports = function (app, questionsRepository, groupsRepository) {
try {
const { groupId } = req.params;
await groupsRepository.removeGroups({ groupId: groupId });
await questionsRepository.deleteQuestions({ groupId: groupId });
res.json({ message: i18next.t("group_removed") })
} catch (error) { next(error); }
});

app.get("/removeAllGroups", async (req, res, next) => {
try {

await groupsRepository.removeGroups();
await questionsRepository.removeQuestions();

res.json({ message: i18next.t("all_groups_removed") });
} catch (error) { next(error); }
});
Expand Down
1 change: 1 addition & 0 deletions logging/setup/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ declare -A users_passwords
users_passwords=(
[logstash_internal]="${LOGSTASH_INTERNAL_PASSWORD:-}"
[kibana_system]="${KIBANA_SYSTEM_PASSWORD:-}"
[elastic]="${ELASTIC_PASSWORD:-}"
# [metricbeat_internal]="${METRICBEAT_INTERNAL_PASSWORD:-}"
# [filebeat_internal]="${FILEBEAT_INTERNAL_PASSWORD:-}"
# [heartbeat_internal]="${HEARTBEAT_INTERNAL_PASSWORD:-}"
Expand Down
2 changes: 1 addition & 1 deletion monitoring/grafana/grafana.ini
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

# The full public facing url you use in browser, used for redirects and emails
# If you use reverse proxy and sub path specify full url (with sub path)
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/

# Serve Grafana from subpath specified in `root_url` setting. By default it is set to `false` for compatibility reasons.
serve_from_sub_path = true
Expand Down
2 changes: 2 additions & 0 deletions proxy/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ server {
proxy_pass http://grafana:9091/;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location /robots.txt {
Expand Down
4 changes: 2 additions & 2 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sonar.language=js

sonar.coverage.exclusions=**/*.test.js,**/*.draft.js
sonar.cpd.exclusions=**/*.test.js,**/*.draft.js
sonar.sources=.
sonar.sources=users/authservice,users/userservice,gatewayservice,webapp/src,userhistory,jordi
sonar.sourceEncoding=UTF-8
sonar.exclusions=node_modules/**
sonar.javascript.lcov.reportPaths=**/coverage/lcov.info
sonar.javascript.lcov.reportPaths=**/coverage/lcov.info
Loading

0 comments on commit 8f4eb44

Please sign in to comment.