-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
OKTA-417465 <<<Jenkins Check-In of Tested SHA: 195793c for [email protected]>>> Artifact: okta-react Files changed count: 164 PR Link: "#155"
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
generated/**/* linguist-generated=true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
dist | ||
build2 | ||
node_modules | ||
.DS_Store | ||
testenv | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"env": { | ||
"commonjs": true, | ||
"es6": true, | ||
"node": true | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/*! | ||
* Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved. | ||
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") | ||
* | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* | ||
* See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
|
||
const dotenv = require('dotenv'); | ||
const yaml = require('js-yaml'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const ROOT_DIR = path.resolve(__dirname, '..'); | ||
|
||
// Read environment variables from "testenv". Override environment vars if they are already set. | ||
const TESTENV = path.resolve(ROOT_DIR, 'testenv'); | ||
|
||
// Multiple sets of environment variables can be stored in a file called "testenv.yml" | ||
const TESTENV_YAML = path.resolve(ROOT_DIR, 'testenv.yml'); | ||
|
||
if (fs.existsSync(TESTENV)) { | ||
setEnvironmentVarsFromTestEnv(); | ||
} | ||
|
||
function setEnvironmentVars(envConfig) { | ||
Object.keys(envConfig).forEach((k) => { | ||
if (process.env[k] !== envConfig[k]) { | ||
console.log(`Setting a new value for environment variable "${k}"`); | ||
} | ||
process.env[k] = envConfig[k]; | ||
}); | ||
} | ||
|
||
function setEnvironmentVarsFromTestEnv() { | ||
if (!fs.existsSync(TESTENV)) { | ||
return; | ||
} | ||
const envConfig = dotenv.parse(fs.readFileSync(TESTENV)); | ||
setEnvironmentVars(envConfig); | ||
} | ||
|
||
function loadTestEnvYaml() { | ||
if (!fs.existsSync(TESTENV_YAML)) { | ||
return; | ||
} | ||
|
||
return yaml.load(fs.readFileSync(TESTENV_YAML)); | ||
} | ||
|
||
function getTestEnvironmentNames() { | ||
const doc = loadTestEnvYaml(); | ||
if (!doc) { | ||
return; | ||
} | ||
return Object.keys(doc); | ||
} | ||
|
||
function setEnvironmentVarsFromTestEnvYaml(name) { | ||
const doc = loadTestEnvYaml(); | ||
if (!doc) { | ||
return; | ||
} | ||
|
||
if (doc.default) { | ||
console.log(`Loading environment variables from testenv.yml: "default"`); | ||
setEnvironmentVars(doc.default); | ||
} | ||
|
||
if (doc[name]) { | ||
console.log(`Loading environment variables from testenv.yml: "${name}"`); | ||
setEnvironmentVars(doc[name]); | ||
} | ||
} | ||
|
||
module.exports = { | ||
setEnvironmentVars, | ||
setEnvironmentVarsFromTestEnv, | ||
setEnvironmentVarsFromTestEnvYaml, | ||
getTestEnvironmentNames, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "@okta/env", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"private": true, | ||
"dependencies": { | ||
"dotenv": "^8.2.0", | ||
"js-yaml": "^4.1.0" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.