From b7566fded040eb054411fe8bf5898a0aa3851f68 Mon Sep 17 00:00:00 2001 From: Holash Chand Date: Wed, 2 Aug 2023 15:48:35 +0530 Subject: [PATCH] added timezone to certificate signer --- docker-compose.yml | 1 + services/certificate-signer/config/config.js | 5 +-- services/certificate-signer/package-lock.json | 33 +++++++++++++++++++ services/certificate-signer/package.json | 1 + .../src/services/signerService.js | 12 ++++++- services/certificate-signer/yarn.lock | 17 +++++++--- 6 files changed, 61 insertions(+), 8 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 8b49b3986..4c520d8cf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -145,6 +145,7 @@ services: image: dockerhub/sunbird-rc-certificate-signer:${RELEASE_VERSION} environment: - PORT=8079 + - TIME_ZONE=Asia/Kolkata ports: - "8079:8079" volumes: diff --git a/services/certificate-signer/config/config.js b/services/certificate-signer/config/config.js index 1a5695698..ed51f1d36 100644 --- a/services/certificate-signer/config/config.js +++ b/services/certificate-signer/config/config.js @@ -2,10 +2,11 @@ const CERTIFICATE_CONTROLLER_ID = process.env.CERTIFICATE_CONTROLLER_ID || 'http const CERTIFICATE_ISSUER = process.env.CERTIFICATE_ISSUER || "https://sunbird.org/"; const CUSTOM_TEMPLATE_DELIMITERS = process.env.CUSTOM_TEMPLATE_DELIMITERS?.split(',') || "{{,}}".split(","); const CACHE_CONTEXT_URLS = process.env.CACHE_CONTEXT_URLS || ""; - +const TIME_ZONE = process.env.TIME_ZONE; module.exports = { CERTIFICATE_CONTROLLER_ID, CERTIFICATE_ISSUER, CUSTOM_TEMPLATE_DELIMITERS, - CACHE_CONTEXT_URLS + CACHE_CONTEXT_URLS, + TIME_ZONE }; diff --git a/services/certificate-signer/package-lock.json b/services/certificate-signer/package-lock.json index a714d6d08..4d2e79455 100644 --- a/services/certificate-signer/package-lock.json +++ b/services/certificate-signer/package-lock.json @@ -14,6 +14,7 @@ "handlebars-delimiters": "^1.0.0", "jsonld-signatures": "^6.0.0", "kafkajs": "^1.15.0", + "moment-timezone": "^0.5.43", "mustache": "^4.2.0", "node-cache": "^5.1.2", "object-hash": "^3.0.0", @@ -4642,6 +4643,25 @@ "node": ">=0.10.0" } }, + "node_modules/moment": { + "version": "2.29.4", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", + "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==", + "engines": { + "node": "*" + } + }, + "node_modules/moment-timezone": { + "version": "0.5.43", + "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.43.tgz", + "integrity": "sha512-72j3aNyuIsDxdF1i7CEgV2FfxM1r6aaqJyLB2vwb33mXYyoyLly+F1zbWqhA3/bVIoJ4szlUoMbUnVdid32NUQ==", + "dependencies": { + "moment": "^2.29.4" + }, + "engines": { + "node": "*" + } + }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -11076,6 +11096,19 @@ "is-extendable": "^1.0.1" } }, + "moment": { + "version": "2.29.4", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", + "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==" + }, + "moment-timezone": { + "version": "0.5.43", + "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.43.tgz", + "integrity": "sha512-72j3aNyuIsDxdF1i7CEgV2FfxM1r6aaqJyLB2vwb33mXYyoyLly+F1zbWqhA3/bVIoJ4szlUoMbUnVdid32NUQ==", + "requires": { + "moment": "^2.29.4" + } + }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", diff --git a/services/certificate-signer/package.json b/services/certificate-signer/package.json index cd17ad0a2..120727cba 100644 --- a/services/certificate-signer/package.json +++ b/services/certificate-signer/package.json @@ -15,6 +15,7 @@ "handlebars-delimiters": "^1.0.0", "jsonld-signatures": "^6.0.0", "kafkajs": "^1.15.0", + "moment-timezone": "^0.5.43", "mustache": "^4.2.0", "node-cache": "^5.1.2", "object-hash": "^3.0.0", diff --git a/services/certificate-signer/src/services/signerService.js b/services/certificate-signer/src/services/signerService.js index 09a6fb3e8..5246ac51f 100644 --- a/services/certificate-signer/src/services/signerService.js +++ b/services/certificate-signer/src/services/signerService.js @@ -2,7 +2,7 @@ const jsigs = require('jsonld-signatures'); const {Ed25519KeyPair, RSAKeyPair} = require('crypto-ld'); const {Ed25519Signature2018, RsaSignature2018} = jsigs.suites; const {AssertionProofPurpose} = jsigs.purposes; -const {CERTIFICATE_CONTROLLER_ID, CUSTOM_TEMPLATE_DELIMITERS} = require('../../config/config'); +const {CERTIFICATE_CONTROLLER_ID, CUSTOM_TEMPLATE_DELIMITERS, TIME_ZONE} = require('../../config/config'); const vc = require('vc-js'); const Handlebars = require("handlebars"); const delimiters = require('handlebars-delimiters'); @@ -15,6 +15,16 @@ delimiters(Handlebars, CUSTOM_TEMPLATE_DELIMITERS); const {documentLoaders} = require('jsonld'); const {node: documentLoader} = documentLoaders; const DEFAULT = "default"; +const moment = require("moment-timezone"); + +Handlebars.registerHelper('formatTime', function (date) { + try { + if(!!TIME_ZONE) return moment.tz(date, TIME_ZONE).format(); + } catch (err) { + console.log("Failed converting to timezone ", TIME_ZONE); + } + return date; +}); const KeyType = { RSA: "RSA", ED25519: "ED25519" diff --git a/services/certificate-signer/yarn.lock b/services/certificate-signer/yarn.lock index 2dd4a3ceb..e5bf48106 100644 --- a/services/certificate-signer/yarn.lock +++ b/services/certificate-signer/yarn.lock @@ -1706,11 +1706,6 @@ "resolved" "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" "version" "1.0.0" -"fsevents@^2.1.2", "fsevents@~2.3.2": - "integrity" "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==" - "resolved" "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz" - "version" "2.3.2" - "function-bind@^1.1.1": "integrity" "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" "resolved" "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz" @@ -3018,6 +3013,18 @@ "for-in" "^1.0.2" "is-extendable" "^1.0.1" +"moment-timezone@^0.5.43": + "integrity" "sha512-72j3aNyuIsDxdF1i7CEgV2FfxM1r6aaqJyLB2vwb33mXYyoyLly+F1zbWqhA3/bVIoJ4szlUoMbUnVdid32NUQ==" + "resolved" "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.43.tgz" + "version" "0.5.43" + dependencies: + "moment" "^2.29.4" + +"moment@^2.29.4": + "integrity" "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==" + "resolved" "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz" + "version" "2.29.4" + "ms@^2.1.1", "ms@2.1.2": "integrity" "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" "resolved" "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz"