Compare commits
22 Commits
Author | SHA1 | Date | |
---|---|---|---|
936a719682 | |||
56c4b43f3c | |||
5ed11a280f | |||
346809d5be | |||
90add506e3 | |||
adea8d1d69 | |||
1b2eb1d763 | |||
cbc974b3d1 | |||
76e72e2a28 | |||
697eb83390 | |||
00ec15ccf7 | |||
b54a5e2fef | |||
a1aa1543a2 | |||
0e48cb8f89 | |||
d76d1a263b | |||
5f6f434998 | |||
8e7909e367 | |||
ff9302f745 | |||
3577fa22e1 | |||
f5275adfbd | |||
31bf1b27a4 | |||
a77def5844 |
22
.gitignore
vendored
22
.gitignore
vendored
@ -1,4 +1,22 @@
|
|||||||
node_modules/
|
.nogit/
|
||||||
|
|
||||||
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
pages/
|
|
||||||
public/
|
public/
|
||||||
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_web/
|
||||||
|
dist_serve/
|
||||||
|
dist_ts_web/
|
||||||
|
|
||||||
|
# custom
|
@ -1,5 +1,5 @@
|
|||||||
# gitzone standard
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
@ -34,48 +34,11 @@ snyk:
|
|||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
sast:
|
|
||||||
stage: security
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
|
|
||||||
variables:
|
|
||||||
DOCKER_DRIVER: overlay2
|
|
||||||
allow_failure: true
|
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command npm run build
|
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
|
||||||
- docker run
|
|
||||||
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
|
|
||||||
--volume "$PWD:/code"
|
|
||||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
"registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code
|
|
||||||
artifacts:
|
|
||||||
reports:
|
|
||||||
sast: gl-sast-report.json
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- priv
|
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
# ====================
|
# ====================
|
||||||
|
|
||||||
testLTS:
|
testStable:
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install lts
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
@ -85,6 +48,18 @@ testSTABLE:
|
|||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
|
testBuild:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command npm run build
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
@ -103,19 +78,11 @@ release:
|
|||||||
# ====================
|
# ====================
|
||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
image: docker:stable
|
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
script:
|
script:
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
- npmci command npm install -g tslint typescript
|
||||||
- docker run
|
- npmci npm install
|
||||||
--env SOURCE_CODE="$PWD"
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
--volume "$PWD":/code
|
|
||||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
|
||||||
artifacts:
|
|
||||||
paths: [codeclimate.json]
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- priv
|
- priv
|
||||||
@ -131,13 +98,15 @@ trigger:
|
|||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: hosttoday/ht-docker-dbase:npmci
|
||||||
|
services:
|
||||||
|
- docker:stable-dind
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g typedoc typescript
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
39
README.md
39
README.md
@ -1,25 +1,20 @@
|
|||||||
# qenv
|
# @pushrocks/qenv
|
||||||
|
|
||||||
easy promised environments
|
easy promised environments
|
||||||
|
|
||||||
## Availabililty
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/qenv)
|
||||||
[](https://www.npmjs.com/package/qenv)
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/qenv)
|
||||||
[](https://GitLab.com/pushrocks/qenv)
|
* [github.com (source mirror)](https://github.com/pushrocks/qenv)
|
||||||
[](https://github.com/pushrocks/qenv)
|
* [docs (typedoc)](https://pushrocks.gitlab.io/qenv/)
|
||||||
[](https://pushrocks.gitlab.io/qenv/)
|
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
|
[](https://gitlab.com/pushrocks/qenv/commits/master)
|
||||||
[](https://GitLab.com/pushrocks/qenv/commits/master)
|
[](https://gitlab.com/pushrocks/qenv/commits/master)
|
||||||
[](https://GitLab.com/pushrocks/qenv/commits/master)
|
[](https://www.npmjs.com/package/@pushrocks/qenv)
|
||||||
[](https://www.npmjs.com/package/qenv)
|
[](https://snyk.io/test/npm/@pushrocks/qenv)
|
||||||
[](https://david-dm.org/pushrocks/qenv)
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
[](https://www.bithound.io/github/pushrocks/qenv/master/dependencies/npm)
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
[](https://www.bithound.io/github/pushrocks/qenv)
|
[](https://prettier.io/)
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](http://standardjs.com/)
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@ -40,7 +35,9 @@ import { Qenv } from 'qenv';
|
|||||||
const myQenv = new Qenv('path/to/dir/where/qenv.yml/is/', 'path/to/dir/where/env.yml/is(');
|
const myQenv = new Qenv('path/to/dir/where/qenv.yml/is/', 'path/to/dir/where/env.yml/is(');
|
||||||
```
|
```
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
For further information read the linked docs at the top of this readme.
|
||||||
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
|
||||||
|
|
||||||
[](https://push.rocks)
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
|
[](https://maintainedby.lossless.com)
|
||||||
|
@ -2,5 +2,15 @@
|
|||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [],
|
"npmGlobalTools": [],
|
||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "pushrocks",
|
||||||
|
"gitrepo": "qenv",
|
||||||
|
"shortDescription": "easy promised environments",
|
||||||
|
"npmPackagename": "@pushrocks/qenv",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
5148
package-lock.json
generated
5148
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
33
package.json
33
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/qenv",
|
"name": "@pushrocks/qenv",
|
||||||
"version": "3.0.6",
|
"version": "4.0.7",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "easy promised environments",
|
"description": "easy promised environments",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@ -25,16 +25,27 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/qenv#README",
|
"homepage": "https://gitlab.com/pushrocks/qenv#README",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.0.22",
|
"@gitzone/tsbuild": "^2.1.24",
|
||||||
"@gitzone/tsrun": "^1.1.12",
|
"@gitzone/tsrun": "^1.2.12",
|
||||||
"@gitzone/tstest": "^1.0.13",
|
"@gitzone/tstest": "^1.0.33",
|
||||||
"@pushrocks/tapbundle": "^3.0.5",
|
"@pushrocks/tapbundle": "^3.2.1",
|
||||||
"@types/node": "^10.5.8",
|
"@types/node": "^14.0.12",
|
||||||
"tslint": "^5.12.0",
|
"tslint": "^6.1.2",
|
||||||
"tslint-config-prettier": "^1.17.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartfile": "^6.0.6",
|
"@pushrocks/smartfile": "^7.0.12",
|
||||||
"@pushrocks/smartlog": "^2.0.9"
|
"@pushrocks/smartlog": "^2.0.26"
|
||||||
}
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/*",
|
||||||
|
"ts_web/*",
|
||||||
|
"dist/*",
|
||||||
|
"dist_web/*",
|
||||||
|
"dist_ts_web/*",
|
||||||
|
"assets/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
4
test/assets/env.json
Normal file
4
test/assets/env.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"key1": "fromJson",
|
||||||
|
"key2" :"fromJson"
|
||||||
|
}
|
@ -1,2 +0,0 @@
|
|||||||
key1: fromYml
|
|
||||||
key2: fromYml
|
|
20
test/test.ts
20
test/test.ts
@ -4,28 +4,26 @@ import * as qenv from '../ts/index';
|
|||||||
|
|
||||||
process.env['key1'] = 'original';
|
process.env['key1'] = 'original';
|
||||||
|
|
||||||
let qenvTestObject: qenv.Qenv;
|
let testQenv: qenv.Qenv;
|
||||||
|
|
||||||
tap.test('should create a new class', async () => {
|
tap.test('should create a new class', async () => {
|
||||||
qenvTestObject = new qenv.Qenv(
|
testQenv = new qenv.Qenv(path.join(__dirname, 'assets'), path.join(__dirname, 'assets'), false);
|
||||||
path.join(__dirname, 'assets'),
|
expect(testQenv).to.be.instanceof(qenv.Qenv);
|
||||||
path.join(__dirname, 'assets'),
|
|
||||||
false
|
|
||||||
);
|
|
||||||
expect(qenvTestObject).to.be.instanceof(qenv.Qenv);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('key1 should be not be overwritten since it is already present', async () => {
|
tap.test('key1 should be not be overwritten since it is already present', async () => {
|
||||||
expect(process.env.key1).to.equal('original');
|
expect(testQenv.getEnvVarRequired('key1')).to.equal('original');
|
||||||
|
expect(testQenv.getEnvVarOnDemand('key1')).to.equal('original');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('key2 should be read from Yml', async () => {
|
tap.test('key2 should be read from Yml', async () => {
|
||||||
expect(process.env.key2).to.equal('fromYml');
|
expect(testQenv.getEnvVarRequired('key2')).to.equal('fromJson');
|
||||||
|
expect(testQenv.getEnvVarOnDemand('key2')).to.equal('fromJson');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('keyValueObjectArray should hold all retrieved values', async () => {
|
tap.test('keyValueObjectArray should hold all retrieved values', async () => {
|
||||||
expect(qenvTestObject.keyValueObjectArray[0].value).to.equal('original');
|
expect(testQenv.keyValueObject.key1).to.equal('original');
|
||||||
expect(qenvTestObject.keyValueObjectArray[1].value).to.equal('fromYml');
|
expect(testQenv.keyValueObject.key2).to.equal('fromJson');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -1,10 +1,4 @@
|
|||||||
import * as plugins from './qenv.plugins';
|
import * as plugins from './qenv.plugins';
|
||||||
plugins.smartlog.defaultLogger.enableConsole();
|
|
||||||
|
|
||||||
export interface IKeyValueObject {
|
|
||||||
key: string;
|
|
||||||
value: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class Qenv
|
* class Qenv
|
||||||
@ -14,8 +8,8 @@ export class Qenv {
|
|||||||
public requiredEnvVars: string[] = [];
|
public requiredEnvVars: string[] = [];
|
||||||
public availableEnvVars: string[] = [];
|
public availableEnvVars: string[] = [];
|
||||||
public missingEnvVars: string[] = [];
|
public missingEnvVars: string[] = [];
|
||||||
public keyValueObjectArray: IKeyValueObject[] = [];
|
public keyValueObject: { [key: string]: any } = {};
|
||||||
public logger: plugins.smartlog.Smartlog;
|
public logger = new plugins.smartlog.ConsoleLog();
|
||||||
|
|
||||||
// filePaths
|
// filePaths
|
||||||
public qenvFilePathAbsolute: string;
|
public qenvFilePathAbsolute: string;
|
||||||
@ -24,10 +18,8 @@ export class Qenv {
|
|||||||
constructor(
|
constructor(
|
||||||
qenvFileBasePathArg = process.cwd(),
|
qenvFileBasePathArg = process.cwd(),
|
||||||
envFileBasePathArg,
|
envFileBasePathArg,
|
||||||
failOnMissing = true,
|
failOnMissing = true
|
||||||
loggerArg: plugins.smartlog.Smartlog = plugins.smartlog.defaultLogger
|
|
||||||
) {
|
) {
|
||||||
this.logger = loggerArg;
|
|
||||||
|
|
||||||
// lets make sure paths are absolute
|
// lets make sure paths are absolute
|
||||||
this.qenvFilePathAbsolute = plugins.path.join(
|
this.qenvFilePathAbsolute = plugins.path.join(
|
||||||
@ -36,7 +28,7 @@ export class Qenv {
|
|||||||
);
|
);
|
||||||
this.envFilePathAbsolute = plugins.path.join(
|
this.envFilePathAbsolute = plugins.path.join(
|
||||||
plugins.path.resolve(envFileBasePathArg),
|
plugins.path.resolve(envFileBasePathArg),
|
||||||
'env.yml'
|
'env.json'
|
||||||
);
|
);
|
||||||
|
|
||||||
this.getRequiredEnvVars();
|
this.getRequiredEnvVars();
|
||||||
@ -51,8 +43,10 @@ export class Qenv {
|
|||||||
console.error('However some Env variables could not be resolved:');
|
console.error('However some Env variables could not be resolved:');
|
||||||
console.log(this.missingEnvVars);
|
console.log(this.missingEnvVars);
|
||||||
if (failOnMissing) {
|
if (failOnMissing) {
|
||||||
console.error('Exiting!');
|
this.logger.log('error', 'Exiting!');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
} else {
|
||||||
|
this.logger.log('warn', 'qenv is not set to fail on missing environment variables');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,86 +56,100 @@ export class Qenv {
|
|||||||
* @param envVarName
|
* @param envVarName
|
||||||
*/
|
*/
|
||||||
public getEnvVarRequired(envVarName): string {
|
public getEnvVarRequired(envVarName): string {
|
||||||
return process.env[envVarName];
|
return this.keyValueObject[envVarName];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* tries to get any env var even if it is not required
|
* tries to get any env var even if it is not required
|
||||||
* @param requiredEnvVar
|
* @param wantedEnvVar
|
||||||
*/
|
*/
|
||||||
public getEnvVarOnDemand(requiredEnvVar: string): string {
|
public getEnvVarOnDemand(wantedEnvVar: string): string {
|
||||||
// lets determine the actual env yml
|
let envVarFromEnvironmentVariable: string;
|
||||||
let envYml;
|
let envVarFromEnvJsonFile: string;
|
||||||
try {
|
let envVarFromDockerSecret: string;
|
||||||
envYml = plugins.smartfile.fs.toObjectSync(this.envFilePathAbsolute);
|
|
||||||
} catch (err) {
|
|
||||||
envYml = {};
|
|
||||||
}
|
|
||||||
let envVar: string;
|
|
||||||
let envFileVar: string;
|
|
||||||
let dockerSecret: string;
|
|
||||||
let dockerSecretJson: string;
|
let dockerSecretJson: string;
|
||||||
|
|
||||||
// env var check
|
// env var check
|
||||||
if (process.env[requiredEnvVar]) {
|
if (process.env[wantedEnvVar]) {
|
||||||
this.availableEnvVars.push(requiredEnvVar);
|
this.availableEnvVars.push(wantedEnvVar);
|
||||||
envVar = process.env[requiredEnvVar];
|
envVarFromEnvironmentVariable = process.env[wantedEnvVar];
|
||||||
}
|
}
|
||||||
|
|
||||||
// env file check
|
// env file check
|
||||||
if (envYml.hasOwnProperty(requiredEnvVar)) {
|
// lets determine the actual env yml
|
||||||
envFileVar = envYml[requiredEnvVar];
|
let envJsonFileAsObject;
|
||||||
this.availableEnvVars.push(requiredEnvVar);
|
try {
|
||||||
|
envJsonFileAsObject = plugins.smartfile.fs.toObjectSync(this.envFilePathAbsolute);
|
||||||
|
} catch (err) {
|
||||||
|
envJsonFileAsObject = {};
|
||||||
|
}
|
||||||
|
if (envJsonFileAsObject.hasOwnProperty(wantedEnvVar)) {
|
||||||
|
envVarFromEnvJsonFile = envJsonFileAsObject[wantedEnvVar];
|
||||||
}
|
}
|
||||||
|
|
||||||
// docker secret check
|
// docker secret check
|
||||||
if (
|
if (
|
||||||
plugins.smartfile.fs.isDirectory('/run') &&
|
plugins.smartfile.fs.isDirectory('/run') &&
|
||||||
plugins.smartfile.fs.isDirectory('/run/secrets') &&
|
plugins.smartfile.fs.isDirectory('/run/secrets') &&
|
||||||
plugins.smartfile.fs.fileExistsSync(`/run/secrets/${requiredEnvVar}`)
|
plugins.smartfile.fs.fileExistsSync(`/run/secrets/${wantedEnvVar}`)
|
||||||
) {
|
) {
|
||||||
dockerSecret = plugins.smartfile.fs.toStringSync(`/run/secrets/${requiredEnvVar}`);
|
envVarFromDockerSecret = plugins.smartfile.fs.toStringSync(`/run/secrets/${wantedEnvVar}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// docker secret.json
|
// docker secret.json
|
||||||
if (
|
if (
|
||||||
plugins.smartfile.fs.isDirectory('/run') &&
|
plugins.smartfile.fs.isDirectory('/run') &&
|
||||||
plugins.smartfile.fs.isDirectory('/run/secrets') &&
|
plugins.smartfile.fs.isDirectory('/run/secrets')
|
||||||
plugins.smartfile.fs.fileExistsSync(`/run/secrets/secret.json`)
|
|
||||||
) {
|
) {
|
||||||
const secretObject = plugins.smartfile.fs.toObjectSync('/run/secrets/secret.json');
|
const availableSecrets = plugins.smartfile.fs.listAllItemsSync('/run/secrets');
|
||||||
dockerSecret = secretObject[requiredEnvVar];
|
for (const secret of availableSecrets) {
|
||||||
|
if (secret.includes('secret.json') && !envVarFromDockerSecret) {
|
||||||
|
const secretObject = plugins.smartfile.fs.toObjectSync(`/run/secrets/${secret}`);
|
||||||
|
envVarFromDockerSecret = secretObject[wantedEnvVar];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// warn if there is more than one candidate
|
// warn if there is more than one candidate
|
||||||
let candidatesCounter = 0;
|
const availableCcandidates: any[] = [];
|
||||||
[envVar, envFileVar, dockerSecret, dockerSecretJson].forEach(candidate => {
|
[
|
||||||
|
envVarFromEnvironmentVariable,
|
||||||
|
envVarFromEnvJsonFile,
|
||||||
|
envVarFromDockerSecret,
|
||||||
|
dockerSecretJson
|
||||||
|
].forEach(candidate => {
|
||||||
if (candidate) {
|
if (candidate) {
|
||||||
candidatesCounter++;
|
availableCcandidates.push(candidate);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (candidatesCounter > 1) {
|
if (availableCcandidates.length > 1) {
|
||||||
this.logger.log(
|
this.logger.log(
|
||||||
'warn',
|
'warn',
|
||||||
`found multiple candidates for ${requiredEnvVar} Choosing in the order of envVar, envFileVar, dockerSecret, dockerSecretJson`
|
`found multiple candidates for ${wantedEnvVar} Choosing in the order of envVar, envFileVar, dockerSecret, dockerSecretJson`
|
||||||
);
|
);
|
||||||
|
console.log(availableCcandidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
let chosenVar: string = null;
|
switch (true) {
|
||||||
if (envVar) {
|
case !!envVarFromEnvironmentVariable:
|
||||||
this.logger.log('ok', `found ${requiredEnvVar} as environment variable`);
|
this.logger.log('ok', `found ${wantedEnvVar} as environment variable`);
|
||||||
chosenVar = envVar;
|
return envVarFromEnvironmentVariable;
|
||||||
} else if (envFileVar) {
|
case !!envVarFromEnvJsonFile:
|
||||||
this.logger.log('ok', `found ${requiredEnvVar} as env.yml variable`);
|
this.logger.log('ok', `found ${wantedEnvVar} as env.json variable`);
|
||||||
chosenVar = envFileVar;
|
return envVarFromEnvJsonFile;
|
||||||
} else if (dockerSecret) {
|
case !!envVarFromDockerSecret:
|
||||||
this.logger.log('ok', `found ${requiredEnvVar} as docker secret`);
|
this.logger.log('ok', `found ${wantedEnvVar} as docker secret`);
|
||||||
chosenVar = dockerSecret;
|
return envVarFromDockerSecret;
|
||||||
} else if (dockerSecretJson) {
|
case !!dockerSecretJson:
|
||||||
this.logger.log('ok', `found ${requiredEnvVar} as docker secret.json`);
|
this.logger.log('ok', `found ${wantedEnvVar} as docker secret.json`);
|
||||||
chosenVar = dockerSecretJson;
|
return dockerSecretJson;
|
||||||
|
default:
|
||||||
|
this.logger.log(
|
||||||
|
'warn',
|
||||||
|
`could not find the wanted environment variable ${wantedEnvVar} anywhere`
|
||||||
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return chosenVar;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -153,7 +161,10 @@ export class Qenv {
|
|||||||
qenvFile = plugins.smartfile.fs.toObjectSync(this.qenvFilePathAbsolute);
|
qenvFile = plugins.smartfile.fs.toObjectSync(this.qenvFilePathAbsolute);
|
||||||
}
|
}
|
||||||
if (!qenvFile || !qenvFile.required || !Array.isArray(qenvFile.required)) {
|
if (!qenvFile || !qenvFile.required || !Array.isArray(qenvFile.required)) {
|
||||||
this.logger.log('warn', `env File does not contain a 'required' Array!`);
|
this.logger.log(
|
||||||
|
'warn',
|
||||||
|
`qenv (promised environment): ./qenv.yml File does not contain a 'required' Array! This might be ok though.`
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
for (const keyArg of Object.keys(qenvFile.required)) {
|
for (const keyArg of Object.keys(qenvFile.required)) {
|
||||||
this.requiredEnvVars.push(qenvFile.required[keyArg]);
|
this.requiredEnvVars.push(qenvFile.required[keyArg]);
|
||||||
@ -169,11 +180,7 @@ export class Qenv {
|
|||||||
const chosenVar = this.getEnvVarOnDemand(requiredEnvVar);
|
const chosenVar = this.getEnvVarOnDemand(requiredEnvVar);
|
||||||
if (chosenVar) {
|
if (chosenVar) {
|
||||||
this.availableEnvVars.push(requiredEnvVar);
|
this.availableEnvVars.push(requiredEnvVar);
|
||||||
process.env[requiredEnvVar] = chosenVar;
|
this.keyValueObject[requiredEnvVar] = chosenVar;
|
||||||
this.keyValueObjectArray.push({
|
|
||||||
key: requiredEnvVar,
|
|
||||||
value: chosenVar
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,16 +1,10 @@
|
|||||||
// native
|
// native
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
export {
|
export { path };
|
||||||
path
|
|
||||||
}
|
|
||||||
|
|
||||||
// @pushrocks scope
|
// @pushrocks scope
|
||||||
import * as smartfile from '@pushrocks/smartfile';
|
import * as smartfile from '@pushrocks/smartfile';
|
||||||
import * as smartlog from '@pushrocks/smartlog';
|
import * as smartlog from '@pushrocks/smartlog';
|
||||||
|
|
||||||
export {
|
export { smartfile, smartlog };
|
||||||
smartfile,
|
|
||||||
smartlog
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user