Skip to content
This repository was archived by the owner on Jul 17, 2025. It is now read-only.

Commit 8216bfd

Browse files
authored
update user default token key to uuid (#436)
* update email * update email * update paginate query * update paginate query * update the random value * update all values need take from environment to config file
1 parent 87c7410 commit 8216bfd

File tree

9 files changed

+59
-54
lines changed

9 files changed

+59
-54
lines changed

BUILD.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ The project includes three components:
1010

1111
Building requires:
1212

13-
- [Node.js 16](https://nodejs.org/en/)
14-
- [mongodb 3.5](https://www.mongodb.com/download-center/community)
15-
- [Python >=3.6, Python<=3.9](https://www.python.org/downloads/)
13+
- [Node.js = 16 ](https://nodejs.org/en/)
14+
- [mongodb = 3.5](https://www.mongodb.com/download-center/community)
15+
- [Python = 3.7](https://www.python.org/downloads/)
1616

1717
## Installation
1818

active-learning-service/config/app_os.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424

2525
# optional token config
2626
"TOKEN_ALGORITHM": os.getenv("TOKEN_ALGORITHM", "HS256"),
27+
# !!! important 121ba6ff-64d6-4c1a-b6ef-dd6b95433064 just a random value get the value from environment or replace by yourslef
2728
# generate the key yourself. should keep the same with annotation-service TOKEN_SECRET_OR_PRIVATE_KEY
28-
"TOKEN_SECRET_OR_PRIVATE_KEY": os.getenv("TOKEN_SECRET_OR_PRIVATE_KEY", "OPEN SOURCE"),
29-
29+
"TOKEN_SECRET_OR_PRIVATE_KEY": os.getenv("TOKEN_SECRET_OR_PRIVATE_KEY", "121ba6ff-64d6-4c1a-b6ef-dd6b95433064"),
30+
# 01a406f3-e5f4-45b8-a722-cff17e9d8cf9 just a random value
3031
# generate the key yourself. django SECRET_KEY a random generated value https://docs.djangoproject.com/en/3.2/ref/settings/#std:setting-SECRET_KEY
31-
"DJANGO_SECRET_KEY": os.getenv("DJANGO_SECRET_KEY", "your_key"),
32+
"DJANGO_SECRET_KEY": os.getenv("DJANGO_SECRET_KEY", "01a406f3-e5f4-45b8-a722-cff17e9d8cf9"),
3233

3334
}

annotation-service/config/app-os.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,21 @@ module.exports = {
1515
//default admin users can see admin tab at ui
1616
adminDefault: ['[email protected]', '[email protected]'],
1717

18+
//-------------------- token configs --------------------//
19+
//TOKEN expire time
20+
TOKEN_EXPIRE_TIME: process.env.TOKEN_EXPIRE_TIME || 60*30,
21+
//TOKEN algorithm
22+
TOKEN_ALGORITHM: process.env.TOKEN_ALGORITHM || "HS256",
23+
//!!! important 121ba6ff-64d6-4c1a-b6ef-dd6b95433064 just a random value get the value from environment or replace by yourslef. should keep the same with active-learning-serviceTOKEN_SECRET_OR_PRIVATE_KEY
24+
TOKEN_SECRET_OR_PRIVATE_KEY: process.env.TOKEN_SECRET_OR_PRIVATE_KEY || "121ba6ff-64d6-4c1a-b6ef-dd6b95433064",
25+
1826
//-------------------- optional configs --------------------//
27+
//api base version
28+
API_VERSION: process.env.API_VERSION || 'v1.0',
29+
//project base path
30+
API_BASE_PATH: process.env.API_BASE_PATH || '',
31+
// default project role
32+
USER_ROLE: process.env.USER_ROLE || 'Project Owner',
1933
//Login with LDAP, need to provide the LDAP authorization service link, the response schema must have 'emailAddress' or 'email' field
2034
loginWithLDAP: process.env.LOGIN_WITH_LDAP || null,
2135
//server port [optional configs]
@@ -25,10 +39,10 @@ module.exports = {
2539
mongoDBAutoIndex: process.env.AUTO_INDEX || true,
2640
//Google Analytics tracking id [optional configs]
2741
trackingId: process.env.TRACKING_ID || null,
28-
29-
42+
3043
//IF true will save file to local, If set useAWS=true set it to false
3144
useLocalFileSys: process.env.USE_LOCAL_FILE_SYS || true,
45+
3246
//-------------------- aws config --------------------//
3347
//IF false below aws config can be skip, will not save files to aws-s3
3448
//IF true will save datasets to S3, should set useLocalFileSys=false
@@ -43,7 +57,6 @@ module.exports = {
4357
//if useAWS=true, SQS config must be set
4458
sqsRoleArn: process.env.SQS_ARN || null,
4559
sqsUrl: process.env.SQS_URL || null,
46-
//-------------------- aws config end--------------------//
4760

4861
//-------------------- send email config ----------------//
4962
//IF USE DEFAULT value false, will not sending email
@@ -65,16 +78,21 @@ module.exports = {
6578
annotationServiceUrl: process.env.ANNOTATION_SERVICE_URL || 'http://localhost:3000',
6679
//if enableEmail=true, can set teamTitle for sending email or use default value
6780
teamTitle: process.env.TEAM_TITILE || "Data-Annotator-For-Machine-Learning",
68-
//-------------------- send email config end-------------//
81+
//regular notification date and time
82+
REGULAR_NOTIFICATNO: process.env.REGULAR_NOTIFICATNO || "0 0 9 * * 1-5",
83+
//regular notification timezome
84+
CURRENT_TIME_ZONE: process.env.CURRENT_TIME_ZONE || "America/Los_Angeles",
85+
//regular notification not start annotate day
86+
NOT_START_DAY: process.env.NOT_START_DAY || 7,
87+
//regular notification not finish annotate day
88+
NOT_FINISH_DAY: process.env.NOT_FINISH_DAY || 14,
6989

70-
71-
//SLACK
90+
//-------------------- slack config ----------------//
7291
//If buildSlackApp=true, slackBotUserOAuthToken, slackSigningSecret and slackAppToken must be set. And please follow the path annotation-app/src/environments/environment.ts to set enableSlack=true at the same time.
7392
buildSlackApp: process.env.BUILD_SLACK_APP || false,
7493
slackAppName: process.env.SLACK_APP_NAME || null, //If buildSlackApp=true, here should be the slack app display name
7594
slackBotUserOAuthToken: process.env.SLACK_BOT_USER_OAUTH_TOKEN || null,
7695
slackSigningSecret: process.env.SLACK_SIGNING_SECRET || null,
77-
slackAppToken: process.env.SLACK_APP_TOKEN || null
78-
96+
slackAppToken: process.env.SLACK_APP_TOKEN || null,
7997

8098
};

annotation-service/config/constant.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
***/
77

88
module.exports = {
9-
API_VERSION: process.env.API_VERSION || 'v1.0',
10-
API_BASE_PATH: process.env.API_BASE_PATH || '',
11-
USER_ROLE: process.env.USER_ROLE || 'Project Owner',
129
ROLES:{
1310
ANNOTATOR: "Annotator",
1411
PROJECT_OWNER: "Project Owner",
@@ -36,12 +33,7 @@ module.exports = {
3633
FILESIZE: 1024*1024*50, //less than 50MB directly download
3734
ACCESS_TIME_60: 60*60, //in seconds
3835
ACCESS_TIME_30: 60*30, //in seconds
39-
ACCESS_TIME_15: 60*15, //in seconds
40-
//TOKEN
41-
TOKEN_EXPIRE_TIME: process.env.TOKEN_EXPIRE_TIME || 60*30,
42-
TOKEN_ALGORITHM: process.env.TOKEN_ALGORITHM || "HS256",
43-
//generate the key yourself. should keep the same with active-learning-serviceTOKEN_SECRET_OR_PRIVATE_KEY
44-
TOKEN_SECRET_OR_PRIVATE_KEY: process.env.TOKEN_SECRET_OR_PRIVATE_KEY || "OPEN SOURCE",
36+
ACCESS_TIME_15: 60*15, //in seconds
4537
TOKEN_EXPIRED_MESSAGE: 'SQS receive message failed: The security token included in the request is expired', //SQS Clinet
4638
ANNOTATION_QUESTION: "What label does this ticket belong to ?",
4739
TICKET_DESCRIPTION: "Passage",
@@ -113,10 +105,6 @@ module.exports = {
113105
SQS: "SQS",
114106
},
115107
MILLISECOND_DAY: 1000 * 60 * 60 * 24,
116-
REGULAR_NOTIFICATNO: process.env.REGULAR_NOTIFICATNO || "0 0 9 * * 1-5",
117-
CURRENT_TIME_ZONE: process.env.CURRENT_TIME_ZONE || "America/Los_Angeles",
118-
NOT_START_DAY: process.env.NOT_START_DAY || 7,
119-
NOT_FINISH_DAY: process.env.NOT_FINISH_DAY || 14,
120108
SOURCE: {
121109
MODEL_FEEDBACK: "MODEL_FEEDBACK",
122110
NIMBUS: "NIMBUS",

annotation-service/db/db-connect.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
***/
77

88
const config = require('../config/config');
9-
const { USER_ROLE, GENERATESTATUS, APPENDSR, QUERYORDER, ANNOTATION_QUESTION, TICKET_DESCRIPTION } = require('../config/constant');
9+
const { GENERATESTATUS, APPENDSR, QUERYORDER, ANNOTATION_QUESTION, TICKET_DESCRIPTION } = require('../config/constant');
1010
const mongoose = require("mongoose"),
1111
Schema = mongoose.Schema;
1212
const mongoosePaginate = require('mongoose-paginate-v2');
@@ -143,7 +143,7 @@ const userSchema = new mongoose.Schema({
143143
password: { type: String },
144144
fullName: { type: String },
145145
points: { type: Number, default: 0 },
146-
role: { type: String, default: USER_ROLE },
146+
role: { type: String, default: config.USER_ROLE },
147147
createdDate: { type: String },
148148
updateDate: { type: String },
149149
regularNotification: { type: Boolean, default: true },

annotation-service/middlewares/jwt.middleware.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
const jwt = require('express-jwt');
99
const config = require('../config/config');
1010
const JWTS = require('jsonwebtoken');
11-
const { API_VERSION, API_BASE_PATH, TOKEN_EXPIRE_TIME, TOKEN_ALGORITHM, TOKEN_SECRET_OR_PRIVATE_KEY} = require('../config/constant');
1211
const APIs = require('../resources/APIs');
1312

1413
jwtTokenAuthrization = (data) => {
@@ -21,20 +20,20 @@ jwtTokenAuthrization = (data) => {
2120
requestProperty: 'auth',
2221
}).unless({
2322
path: [
24-
`${API_BASE_PATH}/api/${API_VERSION}${APIs.EMAIL_REGULAR_NOTIFICATION}`,
23+
`${config.API_BASE_PATH}/api/${config.API_VERSION}${APIs.EMAIL_REGULAR_NOTIFICATION}`,
2524
],
2625
});
2726
} else {
2827
return jwt({
29-
secret: TOKEN_SECRET_OR_PRIVATE_KEY,
30-
algorithms: [TOKEN_ALGORITHM],
28+
secret: config.TOKEN_SECRET_OR_PRIVATE_KEY,
29+
algorithms: [config.TOKEN_ALGORITHM],
3130
getToken: fromHeaderOrQuerystring,
3231
requestProperty: 'auth',
3332
}).unless({
3433
path: [
35-
`${API_BASE_PATH}/api/${API_VERSION}${APIs.REGISTER}`,
36-
`${API_BASE_PATH}/api/${API_VERSION}${APIs.LOGIN}`,
37-
`${API_BASE_PATH}/api/${API_VERSION}${APIs.EMAIL_REGULAR_NOTIFICATION}`,
34+
`${config.API_BASE_PATH}/api/${config.API_VERSION}${APIs.REGISTER}`,
35+
`${config.API_BASE_PATH}/api/${config.API_VERSION}${APIs.LOGIN}`,
36+
`${config.API_BASE_PATH}/api/${config.API_VERSION}${APIs.EMAIL_REGULAR_NOTIFICATION}`,
3837
],
3938
});
4039
}
@@ -54,20 +53,20 @@ function fromHeaderOrQuerystring(req) {
5453

5554
async function generateBasicToken(user) {
5655

57-
const expires_time = Math.floor(Date.now() / 1000) + TOKEN_EXPIRE_TIME;
56+
const expires_time = Math.floor(Date.now() / 1000) + config.TOKEN_EXPIRE_TIME;
5857
const access_token = await JWTS.sign({
5958
exp: expires_time,
6059
email: user
6160
},
62-
TOKEN_SECRET_OR_PRIVATE_KEY,
61+
config.TOKEN_SECRET_OR_PRIVATE_KEY,
6362
{
64-
algorithm: TOKEN_ALGORITHM
63+
algorithm: config.TOKEN_ALGORITHM
6564
}
6665
);
6766
return {
6867
access_token: access_token,
6968
access_type: "Bearer",
70-
expires_in: TOKEN_EXPIRE_TIME,
69+
expires_in: config.TOKEN_EXPIRE_TIME,
7170
expires_time: expires_time
7271
}
7372
}

annotation-service/server.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const fs = require('fs')
1515
const { consumeSQSMessage } = require('./utils/sqs');
1616
const { regularNotification } = require('./utils/taskSchedule');
1717
const config = require('./config/config');
18-
const { API_VERSION, API_BASE_PATH } = require('./config/constant');
1918
const MESSAGE = require('./config/code_msg');
2019

2120
// Get our API routes
@@ -51,10 +50,10 @@ app.use(function (req, res, next) {
5150
});
5251

5352
// mannually set up swagger
54-
app.use(`${API_BASE_PATH}/api/api-docs`, swaggerUi.serve, swaggerUi.setup(swaggerDocument));
53+
app.use(`${config.API_BASE_PATH}/api/api-docs`, swaggerUi.serve, swaggerUi.setup(swaggerDocument));
5554

5655
// Server health check
57-
app.get(`${API_BASE_PATH}/api/health`, (req, res) => {
56+
app.get(`${config.API_BASE_PATH}/api/health`, (req, res) => {
5857
return res.status(200).json(MESSAGE.SUCCESS);
5958
});
6059

@@ -86,7 +85,7 @@ authService.authentication().then(data => {
8685
}).finally(() => {
8786
// Set our api routers
8887
routers.forEach(
89-
api => app.use(`${API_BASE_PATH}/api/${API_VERSION}`, require(`./routers/${api}`))
88+
api => app.use(`${config.API_BASE_PATH}/api/${config.API_VERSION}`, require(`./routers/${api}`))
9089
);
9190
consumeSQSMessage();
9291
regularNotification();

annotation-service/services/email-service.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const authForNoe = require("./authForNoe.service");
1313
const config = require("../config/config");
1414
const AWS = require('aws-sdk');
1515
const STS = require('../utils/sts');
16-
const { ACCESS_TIME_15, API_VERSION } = require('../config/constant')
16+
const { ACCESS_TIME_15 } = require('../config/constant')
1717
const nodemailer = require("nodemailer");
1818
const APIs = require('../resources/APIs');
1919

@@ -58,7 +58,7 @@ async function sendNotStartLabelingNotificationEmail(user, projectName, projectO
5858
const htmlTemplate = notStartTemp.replace(/\${user}/g, user)
5959
.replace(/\${projectName}/g, projectName)
6060
.replace(/\${serviceHost}/g, config.annotationServiceUrl)
61-
.replace(/\${apiVersion}/g, API_VERSION)
61+
.replace(/\${apiVersion}/g, config.API_VERSION)
6262
.replace(/\${notification}/g, APIs.EMAIL_REGULAR_NOTIFICATION)
6363
.replace("${projectOwner}", projectOwner)
6464
.replace("${assignedDate}", assignedDate)
@@ -73,7 +73,7 @@ async function sendNotFinishLabelingNotificationEmail(user, projectName, project
7373
const htmlTemplate = notFinishTemp.replace(/\${user}/g, user)
7474
.replace(/\${projectName}/g, projectName)
7575
.replace(/\${serviceHost}/g, config.annotationServiceUrl)
76-
.replace(/\${apiVersion}/g, API_VERSION)
76+
.replace(/\${apiVersion}/g, config.API_VERSION)
7777
.replace(/\${notification}/g, APIs.EMAIL_REGULAR_NOTIFICATION)
7878
.replace("${projectOwner}", projectOwner)
7979
.replace("${assignedDate}", assignedDate)

annotation-service/utils/taskSchedule.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
***/
77

8-
const { MILLISECOND_DAY, REGULAR_NOTIFICATNO, CURRENT_TIME_ZONE, NOT_START_DAY, NOT_FINISH_DAY } = require("../config/constant");
8+
const { MILLISECOND_DAY } = require("../config/constant");
99
const config = require("../config/config");
1010
const { ProjectModel, UserModel, InstanceModel } = require("../db/db-connect");
1111
const mongoDb = require("../db/mongo.db");
@@ -26,7 +26,7 @@ module.exports.regularNotification = async () => {
2626
}
2727

2828
var job = new CronJob(
29-
REGULAR_NOTIFICATNO,
29+
config.REGULAR_NOTIFICATNO,
3030
async () => {
3131
if (await checkingRunningInstance()) {
3232
return;
@@ -35,13 +35,13 @@ module.exports.regularNotification = async () => {
3535
},
3636
null,
3737
true,
38-
CURRENT_TIME_ZONE
38+
config.CURRENT_TIME_ZONE
3939
);
4040

4141
}
4242
async function checkingRunningInstance() {
4343

44-
const NODE_INSTANCE = {data: new Date(Date.now()).toLocaleDateString("en-US", {timeZone: CURRENT_TIME_ZONE})};
44+
const NODE_INSTANCE = {data: new Date(Date.now()).toLocaleDateString("en-US", {timeZone: config.CURRENT_TIME_ZONE})};
4545
const instance = await mongoDb.findByConditions(InstanceModel, NODE_INSTANCE);
4646
console.log('[ REGULAR-NOTIFICATION ]', NODE_INSTANCE);
4747
if (instance.length) {
@@ -69,7 +69,7 @@ async function findProjectAndSendRegularNotification() {
6969

7070
const createTime = (today - pro.createdDate) / MILLISECOND_DAY;
7171
const done = pro.totalCase <= pro.projectCompleteCase;
72-
const overStart = createTime < NOT_START_DAY;
72+
const overStart = createTime < config.NOT_START_DAY;
7373
//don't more than NOT_START_DAY
7474
if(overStart || done){
7575
continue;
@@ -102,7 +102,7 @@ async function findUserSendNotification(pro, today){
102102
//not start labeling
103103
uc.assignedDate = uc.assignedDate? uc.assignedDate: pro.createdDate;
104104
const assignedTime = (today - uc.assignedDate) / MILLISECOND_DAY;
105-
const overStartDay = assignedTime >= NOT_START_DAY;
105+
const overStartDay = assignedTime >= config.NOT_START_DAY;
106106
//send notification
107107
if(!uc.completeCase && overStartDay){
108108
const assignedDate = new Date(uc.assignedDate * 1).toLocaleDateString();
@@ -113,7 +113,7 @@ async function findUserSendNotification(pro, today){
113113
//not finish labeling
114114
uc.updateDate = uc.updateDate? uc.updateDate: uc.assignedDate;
115115
const updateTime = (today - uc.updateDate) / MILLISECOND_DAY;
116-
const overFinish = updateTime >= NOT_FINISH_DAY;
116+
const overFinish = updateTime >= config.NOT_FINISH_DAY;
117117
const userNotFinish = uc.assignedCase > uc.completeCase;
118118
//send notification
119119
if(uc.completeCase && overFinish && userNotFinish){

0 commit comments

Comments
 (0)