Skip to content

Commit

Permalink
secret cache
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeTWC1984 committed Mar 15, 2024
1 parent 748c425 commit 33ba829
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module.exports = Class.create({
eventQueue: null,
kids: null,
state: null,
secretCache: {},

defaultWebHookTextTemplates: {
"job_start": "Job started on [hostname]: [event_title] [job_details_url]",
Expand Down Expand Up @@ -261,13 +262,25 @@ module.exports = Class.create({
},

decryptObject: function (encObj) {
if(this.server.config.get('cache_secrets')) {
let cached = this.secretCache[encObj.substring(0,40)]
if(cached) {
this.logDebug(9, 'Secret fetched from cache')
return cached;
}
}
const encParts = encObj.split(":");
const IV = Buffer.from(encParts[0], outputEncoding);
const encryptedText = Buffer.from(encParts[1], outputEncoding);
const decipher = crypto.createDecipheriv(algorithm, this.eKey, IV);
let decrypted = decipher.update(encryptedText, outputEncoding, inputEncoding);
decrypted += decipher.final(inputEncoding);
return JSON.parse(decrypted);
let plain = JSON.parse(decrypted);
if(this.server.config.get('cache_secrets')) {
this.secretCache[encObj.substring(0,40)] = plain; // put into cache
this.logDebug(9, 'Secret put to cache')
}
return plain;
},

safeJobLog: function(job) { // print less verbose, more readable job data on logging
Expand Down

0 comments on commit 33ba829

Please sign in to comment.