Skip to content

Commit

Permalink
fixed env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
holashchand committed Aug 4, 2023
1 parent 33931d9 commit dc42c74
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 27 deletions.
16 changes: 10 additions & 6 deletions backend/donor-service/configs/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ const NOTIFY_TEMPLATE_ID = process.env.NOTIFY_TEMPLATE_ID;
const UPDATE_TEMPLATE_ID = process.env.UPDATE_TEMPLATE_ID;
const UNPLEDGE_TEMPLATE_ID = process.env.UNPLEDGE_TEMPLATE_ID;
const API_KEY = process.env.API_KEY;
const ABDM_KAFKA = process.env.ABDM_KAFKA || 'localhost:5101';
const ESIGN_STATUS = Object.freeze({
'PENDING': 0,
'SUCCESS': 1,
'FAILED': 2,
'EXPIRED': 3,
});
const EXPIRE_ESIGN_VALID_STATUS = process.env.EXPIRE_ESIGN_VALID_STATUS || 2*60;
const PREVENT_3RD_PARTY_ESIGN_VALIDATION = process.env.PREVENT_3RD_PARTY_ESIGN_VALIDATION || true;
const ESIGN_VALIDATION_KAFKA_BROKERS = process.env.ESIGN_VALIDATION_KAFKA_BROKERS || 'localhost:5101';
const ESIGN_VALIDATION_EXPIRE_TIME = process.env.ESIGN_VALIDATION_EXPIRE_TIME || 2*60;
const ESIGN_VALIDATION_PREVENT_3RD_PARTY = process.env.ESIGN_VALIDATION_PREVENT_3RD_PARTY || false;
const ESIGN_VALIDATION_KAFKA_TOPIC = process.env.ESIGN_VALIDATION_TOPIC || 'esign_topic';
const ESIGN_VALIDATION_KAFKA_TOPIC_GROUP = process.env.ESIGN_VALIDATION_TOPIC || 'notto_esign_group_1';
module.exports = {
REDIS_URL,
BASE_URL,
Expand All @@ -58,8 +60,10 @@ module.exports = {
UPDATE_TEMPLATE_ID,
UNPLEDGE_TEMPLATE_ID,
API_KEY,
ABDM_KAFKA,
EXPIRE_ESIGN_VALID_STATUS,
ESIGN_VALIDATION_KAFKA_BROKERS,
ESIGN_VALIDATION_EXPIRE_TIME,
ESIGN_STATUS,
PREVENT_3RD_PARTY_ESIGN_VALIDATION
ESIGN_VALIDATION_PREVENT_3RD_PARTY,
ESIGN_VALIDATION_KAFKA_TOPIC,
ESIGN_VALIDATION_KAFKA_TOPIC_GROUP,
}
6 changes: 3 additions & 3 deletions backend/donor-service/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ app.post('/esign/init', async (req, res) => {
// const pledge = JSON.parse(req.query.data)
const pledge = req.body.data;
const esignData = await getEsignData(pledge);
if (config.PREVENT_3RD_PARTY_ESIGN_VALIDATION) {
if (config.ESIGN_VALIDATION_PREVENT_3RD_PARTY) {
const verificationData = {
"firstName": R.pathOr("", ["personalDetails", "firstName"], pledge),
"middleName": R.pathOr("", ["personalDetails", "middleName"], pledge),
Expand All @@ -359,7 +359,7 @@ app.post('/esign/init', async (req, res) => {
};
for(const[key, value] of Object.entries(verificationData)) {
console.log(key, value)
await redis.storeHashWithExpiry(getEsignVerificationKey(esignData.txnId), key, value, config.EXPIRE_ESIGN_VALID_STATUS)
await redis.storeHashWithExpiry(getEsignVerificationKey(esignData.txnId), key, value, config.ESIGN_VALIDATION_EXPIRE_TIME)
}
}
res.send({
Expand Down Expand Up @@ -560,7 +560,7 @@ async function getESingDoc(abha) {

app.get('/esign/:abha/status', async (req, res) => {
try {
if (config.PREVENT_3RD_PARTY_ESIGN_VALIDATION) {
if (config.ESIGN_VALIDATION_PREVENT_3RD_PARTY) {
const transactionID = await redis.getKey(getEsginKey(req.params.abha))
const storedTransaction = await redis.getHash(getEsignVerificationKey(transactionID));
if(!storedTransaction || storedTransaction?.esignStatus === config.ESIGN_STATUS.PENDING.toString()) {
Expand Down
31 changes: 16 additions & 15 deletions backend/donor-service/services/esign.consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ function getEsignVerificationKey(transactionId) {
return `${transactionId}-esign-verification`;
}
const initSubscription = async () => {
const kafka = new Kafka ({
brokers: config.ABDM_KAFKA.split(",")
// 100.65.159.43:5101
// pkc-lq8v7.eu-central-1.aws.confluent.cloud:9092
// brokers: ['localhost:9092']
});
consumer = kafka.consumer({groupId: 'notto_esign_group_1'});
await consumer.subscribe({topic: 'esign_topic', fromBeginning: false });
await consumer.run({
autoCommit: false,
eachMessage: processEachMessage
});
console.log("Initialised the kafka connection ");
try {
const kafka = new Kafka ({
brokers: config.ESIGN_VALIDATION_KAFKA_BROKERS?.split(",")
});
consumer = kafka.consumer({groupId: config.ESIGN_VALIDATION_KAFKA_TOPIC_GROUP});
await consumer.subscribe({topic: config.ESIGN_VALIDATION_KAFKA_TOPIC, fromBeginning: false });
await consumer.run({
autoCommit: true,
eachMessage: processEachMessage
});
console.log("Initialised the kafka connection ");
} catch (e) {
console.log("Failed to initialise Kafka consumer ", e);
}
}

const processEachMessage = async ({ message }) => {
Expand All @@ -31,10 +32,10 @@ const processEachMessage = async ({ message }) => {
if(Object.keys(enteredData).length !== 0) {
const status = getEsignDataMatchStatus(enteredData, esignData);
if(status.errors.length > 0 ) {
await redis.storeHashWithExpiry(esignVerificationKey, 'esignErrors', JSON.stringify(status.errors), config.EXPIRE_ESIGN_VALID_STATUS)
await redis.storeHashWithExpiry(esignVerificationKey, 'esignErrors', JSON.stringify(status.errors), config.ESIGN_VALIDATION_EXPIRE_TIME)
console.log("error validating esign data: ", status);
}
await redis.storeHashWithExpiry(esignVerificationKey, 'esignStatus', status?.esign, config.EXPIRE_ESIGN_VALID_STATUS)
await redis.storeHashWithExpiry(esignVerificationKey, 'esignStatus', status?.esign, config.ESIGN_VALIDATION_EXPIRE_TIME)
} else {
console.log("Entered Data is null");
}
Expand Down
8 changes: 5 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ services:
UPDATE_TEMPLATE_ID: ${UPDATE_TEMPLATE_ID}
UNPLEDGE_TEMPLATE_ID: ${UNPLEDGE_TEMPLATE_ID}
API_KEY: ${API_KEY}
PREVENT_3RD_PARTY_ESIGN_VALIDATION: ${PREVENT_3RD_PARTY_ESIGN_VALIDATION}
EXPIRE_ESIGN_VALID_STATUS: ${EXPIRE_ESIGN_VALID_STATUS}
ABDM_KAFKA: ${ABDM_KAFKA}
ESIGN_VALIDATION_PREVENT_3RD_PARTY: ${ESIGN_VALIDATION_PREVENT_3RD_PARTY}
ESIGN_VALIDATION_EXPIRE_TIME: ${ESIGN_VALIDATION_EXPIRE_TIME}
ESIGN_VALIDATION_KAFKA_BROKERS: ${ESIGN_VALIDATION_KAFKA_BROKERS}
ESIGN_VALIDATION_KAFKA_TOPIC: ${ESIGN_VALIDATION_KAFKA_TOPIC}
ESIGN_VALIDATION_KAFKA_TOPIC_GROUP: ${ESIGN_VALIDATION_KAFKA_TOPIC_GROUP}

0 comments on commit dc42c74

Please sign in to comment.