Skip to content

Commit

Permalink
fix: use new API to modify configuration (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
erezrokah committed Feb 28, 2022
1 parent ab08fcf commit 8e090bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ node_modules
/build
.vscode
.env

# Local Netlify folder
.netlify
15 changes: 6 additions & 9 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const SECRET_PREFIX = process.env.NETLIFY_AWS_SECRET_PREFIX || 'NETLIFY_AWS_SECR
const getPrefixedKey = (key) => `${SECRET_PREFIX}${key}`

module.exports = {
async onPreBuild({ utils }) {
async onPreBuild({ netlifyConfig, utils }) {
const {
NETLIFY_AWS_ACCESS_KEY_ID: accessKeyId,
NETLIFY_AWS_SECRET_ACCESS_KEY: secretAccessKey,
Expand All @@ -60,14 +60,11 @@ module.exports = {
const normalizedSecrets = await normalizeSecrets({ client, secrets })

const entries = Object.entries(normalizedSecrets)
entries.forEach(([key]) => {
console.log(
`${chalk.bold('Injecting AWS secret')} ${chalk.magenta(`${key}`)} as ${chalk.green(getPrefixedKey(key))}`,
)
entries.forEach(([key, value]) => {
const prefixedKey = getPrefixedKey(key)
console.log(`${chalk.bold('Injecting AWS secret')} ${chalk.magenta(`${key}`)} as ${chalk.green(prefixedKey)}`)
// eslint-disable-next-line no-param-reassign
netlifyConfig.build.environment[prefixedKey] = value
})

const prefixedSecrets = Object.fromEntries(entries.map(([key, value]) => [getPrefixedKey(key), value]))

Object.assign(process.env, prefixedSecrets)
},
}

0 comments on commit 8e090bb

Please sign in to comment.