Skip to content

Commit 6eb28c6

Browse files
authored
Merge pull request #5898 from FlowFuse/encrypt-npmrc-gitops
Ensure npmrc is encrypted before pushing to github
2 parents e4dba78 + 95e18ac commit 6eb28c6

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

forge/ee/lib/gitops/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const execPromised = promisify(exec)
88

99
const axios = require('axios')
1010

11-
const { decryptValue } = require('../../../db/utils')
11+
const { encryptValue, decryptValue } = require('../../../db/utils')
1212

1313
async function cloneRepository (url, branch, workingDir) {
1414
try {
@@ -119,6 +119,10 @@ module.exports.init = async function (app) {
119119
}
120120
const result = await app.db.controllers.Snapshot.exportSnapshot(snapshot, exportOptions)
121121
const snapshotExport = app.db.views.ProjectSnapshot.snapshotExport(result)
122+
if (snapshotExport.settings?.settings?.palette?.npmrc) {
123+
const enc = encryptValue(repoOptions.credentialSecret, snapshotExport.settings.settings?.palette?.npmrc)
124+
snapshotExport.settings.settings.palette.npmrc = { $: enc }
125+
}
122126
const snapshotFile = path.join(workingDir, repoOptions.path || 'snapshot.json').replace(/"/g, '')
123127
await fs.writeFile(snapshotFile, JSON.stringify(snapshotExport, null, 4))
124128

@@ -202,6 +206,12 @@ module.exports.init = async function (app) {
202206
}
203207
})
204208
}
209+
if (snapshot.settings?.settings?.palette?.npmrc) {
210+
const npmrc = snapshot.settings.settings.palette.npmrc
211+
if (typeof npmrc === 'object' && npmrc.$) {
212+
snapshot.settings.settings.palette.npmrc = decryptValue(repoOptions.credentialSecret, npmrc.$)
213+
}
214+
}
205215
return snapshot
206216
} catch (err) {
207217
throw new Error('Failed to read snapshot file: ' + err.message)

0 commit comments

Comments
 (0)