diff --git a/lib/utils.js b/lib/utils.js index 0c6ae55..6ab6117 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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] } } @@ -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`, '') diff --git a/test/__fixtures__/app-env/my-env.expected b/test/__fixtures__/app-env/my-env.expected index 6615e87..3a3c33f 100644 --- a/test/__fixtures__/app-env/my-env.expected +++ b/test/__fixtures__/app-env/my-env.expected @@ -1,3 +1,4 @@ +FOO=bar AIO_RUNTIME_NAMESPACE=local-namespace AIO_RUNTIME_AUTH=local-auth AIO_RUNTIME_APIHOST=local-apihost diff --git a/test/__fixtures__/app-env/my-env.original b/test/__fixtures__/app-env/my-env.original index b479b40..a857007 100644 --- a/test/__fixtures__/app-env/my-env.original +++ b/test/__fixtures__/app-env/my-env.original @@ -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