Skip to content

Commit

Permalink
fix: remove AIO__ prefixed env vars as well
Browse files Browse the repository at this point in the history
  • Loading branch information
shazron committed Aug 24, 2020
1 parent e45a6a3 commit 81641aa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,17 +372,19 @@ function saveAndReplaceDotEnvCredentials (dotenvFile, saveFile, apihost, namespa
// Only override needed env vars and preserve other vars in .env
const env = dotenv.parse(fs.readFileSync(saveFile))
const newCredentials = {
AIO_RUNTIME_NAMESPACE: namespace,
AIO_RUNTIME_AUTH: auth,
AIO_RUNTIME_APIHOST: apihost
RUNTIME_NAMESPACE: namespace,
RUNTIME_AUTH: auth,
RUNTIME_APIHOST: apihost
}

// remove old keys (match by normalized key name)
for (const key in env) {
const match = key.match(/^AIO_(.+)/i)
// match AIO_ or AIO__ since they map to the same key
// see https://github.com/adobe/aio-lib-core-config/issues/49
const match = key.match(/^AIO__(.+)/i) || key.match(/^AIO_(.+)/i)
if (match) {
for (const newCredential in newCredentials) {
if (newCredential.toLowerCase() === key.toLowerCase()) {
if (newCredential.toLowerCase() === match[1].toLowerCase()) {
delete env[key]
}
}
Expand All @@ -391,7 +393,7 @@ function saveAndReplaceDotEnvCredentials (dotenvFile, saveFile, apihost, namespa

// set the new keys
for (const key in newCredentials) {
env[key] = newCredentials[key]
env[`AIO_${key}`] = newCredentials[key]
}

const envContent = Object.keys(env).reduce((content, k) => content + `${k}=${env[k]}\n`, '')
Expand Down
1 change: 1 addition & 0 deletions test/__fixtures__/app-env/my-env.expected
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FOO=bar
AIO_RUNTIME_NAMESPACE=local-namespace
AIO_RUNTIME_AUTH=local-auth
AIO_RUNTIME_APIHOST=local-apihost
4 changes: 4 additions & 0 deletions test/__fixtures__/app-env/my-env.original
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
FOO=bar
AIO_runtime_namespace=my-remote-namespace
AIO_runtime_auth=my-remote-auth
AIO_runtime_apihost=my-remote-apihost
AIO__runtime_namespace=my-remote-namespace2
AIO__runtime_auth=my-remote-auth2
AIO__runtime_apihost=my-remote-apihost2

0 comments on commit 81641aa

Please sign in to comment.