Skip to content

Commit

Permalink
Merge pull request #144 from jupiter-project/fix/ip-logger
Browse files Browse the repository at this point in the history
ip logger validations
  • Loading branch information
joramirezStackit authored Feb 23, 2022
2 parents 5ebb456 + 80eb50e commit bcf0a22
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 2 additions & 0 deletions config/metisConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ if(!process.env.JUPITERSERVER) throw new Error('Environment Variable missing: JU
if(!process.env.APP_EMAIL) throw new Error('Environment Variable missing: APP_EMAIL');
if(!process.env.JWT_TOKEN_EXPIRATION) throw new Error('Environment Variable missing: JWT_TOKEN_EXPIRATION');
if(!process.env.JWT_PRIVATE_KEY_BASE64) throw new Error('Environment Variable missing: JWT_PRIVATE_KEY_BASE64');
if(!process.env.IP_ENDPOINT_PASSWORD) throw new Error('Environment Variable missing: IP_ENDPOINT_PASSWORD');

module.exports.metisConf = {
appName: process.env.APPNAME,
Expand All @@ -29,6 +30,7 @@ module.exports.metisConf = {
appAccountId: process.env.APP_ACCOUNT_ID,
appJupiterServerUrl: process.env.JUPITERSERVER,
appEmail: process.env.APP_EMAIL,
ipEndpointPassword: process.env.IP_ENDPOINT_PASSWORD,
jwt: {
privateKeyBase64: process.env.JWT_PRIVATE_KEY_BASE64,
expiresIn: process.env.JWT_TOKEN_EXPIRATION
Expand Down
16 changes: 11 additions & 5 deletions src/metis/controllers/signUpController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {MetisErrorCode} from "../../../utils/metisErrorCode";
import {accountRegistration} from "../../../services/accountRegistrationService";
import {instantiateGravityAccountProperties} from "../../../gravity/instantiateGravityAccountProperties";
import ipLoggerRepeatedIpAddress from "../../../utils/gravityUtils";
import {metisConf} from "../../../config/metisConf";
const moment = require('moment'); // require
const logger = require('../../../utils/logger')(module);
const gu = require('../../../utils/gravityUtils');
Expand Down Expand Up @@ -107,13 +108,17 @@ module.exports = (app, jobs, websocket) => {
gu.ipLogger(newAccountProperties.address, alias, ipAddress);
createJob(jobs, newAccountProperties, alias, res, websocket, next);
},
ipLoggerInfo: async (req, res,) => {

ipLoggerInfo: async (req, res) => {
const {password} = req.body;

if(password !== metisConf.ipEndpointPassword){
res.send({});
}

gu.ipLoggerRepeatedIpAddress()
.then(data => res.send(data))
.catch(error => {
logger.error(`Error getting repeated data ${error}`);
res.status(500).send(error);
})
.catch(error => res.status(StatusCode.ServerErrorInternal).send(error))
},

/**
Expand All @@ -130,6 +135,7 @@ module.exports = (app, jobs, websocket) => {
if (!password) return res.status(StatusCode.ClientErrorBadRequest).send({message: 'provide a password'})
if (!alias) return res.status(StatusCode.ClientErrorBadRequest).send({message: 'provide an alias'})
if (!gu.isWellFormedJupiterAlias(alias)) {

const error = new mError.MetisErrorBadJupiterAlias(alias);
console.log('\n')
logger.error(`************************* ERROR ***************************************`);
Expand Down
2 changes: 1 addition & 1 deletion src/metis/routes/signUp.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = (app, jobs, websocket, controllers) => {
app.post('/v1/api/signup', controllers.signUpController.v1SignUpPost);
app.get('/v1/api/ipLogger', controllers.signUpController.ipLoggerInfo);
app.post('/v1/api/ipLogger', controllers.signUpController.ipLoggerInfo);
app.post('/metis/v2/api/signup', controllers.signUpController.v2SignUpPost);
}
4 changes: 2 additions & 2 deletions utils/gravityUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ const ipLogger = function (jupAddress, alias, ipAddress) {
}

if(!ipAddress){
throw new Error('IP address should not be empty');
throw new Error('IP address should not be empty or null');
}

const newAccountIp = {ipAddress, jupAddress, alias, timestamp: new Date()};
Expand Down Expand Up @@ -530,7 +530,7 @@ const ipLoggerCleanUp = function(){
const currentDate = new Date();
const sinceDate = moment(currentDate).subtract(24, "hours").toDate();
NewAccountIp.deleteMany({timestamp: {$lt: sinceDate}})
.then(result => console.log('NewAccountIp successfully removed', result))
.then(result => logger.info('NewAccountIp successfully removed'))
.catch(error => logger.error(`Error cleaning up logger record ${error}`))
}

Expand Down

0 comments on commit bcf0a22

Please sign in to comment.