fix(core): update
This commit is contained in:
parent
1b2eb1d763
commit
adea8d1d69
@ -38,23 +38,23 @@ snyk:
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testLTS:
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- priv
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
@ -65,7 +65,7 @@ testBuild:
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
@ -100,7 +100,7 @@ trigger:
|
||||
pages:
|
||||
image: hosttoday/ht-docker-dbase:npmci
|
||||
services:
|
||||
- docker:18-dind
|
||||
- docker:stable-dind
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
|
@ -38,6 +38,6 @@ const myQenv = new Qenv('path/to/dir/where/qenv.yml/is/', 'path/to/dir/where/env
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
|
||||
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com)
|
||||
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)
|
||||
|
22
package-lock.json
generated
22
package-lock.json
generated
@ -425,9 +425,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "12.7.2",
|
||||
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.7.2.tgz",
|
||||
"integrity": "sha512-dyYO+f6ihZEtNPDcWNR1fkoTDf3zAK3lAABDze3mz6POyIercH0lEUawUFXlG8xaQZmm1yEBON/4TsYv/laDYg=="
|
||||
"version": "12.7.5",
|
||||
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.7.5.tgz",
|
||||
"integrity": "sha512-9fq4jZVhPNW8r+UYKnxF1e2HkDWOWKM5bC2/7c9wPV835I0aOrVbS/Hw/pWPk2uKrNXQqg9Z959Kz+IYDd5p3w=="
|
||||
},
|
||||
"@types/vinyl": {
|
||||
"version": "2.0.2",
|
||||
@ -1456,16 +1456,16 @@
|
||||
"dev": true
|
||||
},
|
||||
"tslint": {
|
||||
"version": "5.19.0",
|
||||
"resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.19.0.tgz",
|
||||
"integrity": "sha512-1LwwtBxfRJZnUvoS9c0uj8XQtAnyhWr9KlNvDIdB+oXyT+VpsOAaEhEgKi1HrZ8rq0ki/AAnbGSv4KM6/AfVZw==",
|
||||
"version": "5.20.0",
|
||||
"resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.20.0.tgz",
|
||||
"integrity": "sha512-2vqIvkMHbnx8acMogAERQ/IuINOq6DFqgF8/VDvhEkBqQh/x6SP0Y+OHnKth9/ZcHQSroOZwUQSN18v8KKF0/g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/code-frame": "^7.0.0",
|
||||
"builtin-modules": "^1.1.1",
|
||||
"chalk": "^2.3.0",
|
||||
"commander": "^2.12.1",
|
||||
"diff": "^3.2.0",
|
||||
"diff": "^4.0.1",
|
||||
"glob": "^7.1.1",
|
||||
"js-yaml": "^3.13.1",
|
||||
"minimatch": "^3.0.4",
|
||||
@ -1474,14 +1474,6 @@
|
||||
"semver": "^5.3.0",
|
||||
"tslib": "^1.8.0",
|
||||
"tsutils": "^2.29.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"diff": {
|
||||
"version": "3.5.0",
|
||||
"resolved": "https://verdaccio.lossless.one/diff/-/diff-3.5.0.tgz",
|
||||
"integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"tslint-config-prettier": {
|
||||
|
@ -29,8 +29,8 @@
|
||||
"@gitzone/tsrun": "^1.2.8",
|
||||
"@gitzone/tstest": "^1.0.24",
|
||||
"@pushrocks/tapbundle": "^3.0.13",
|
||||
"@types/node": "^12.7.2",
|
||||
"tslint": "^5.19.0",
|
||||
"@types/node": "^12.7.5",
|
||||
"tslint": "^5.20.0",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
"dependencies": {
|
||||
@ -48,4 +48,4 @@
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
]
|
||||
}
|
||||
}
|
@ -64,40 +64,39 @@ export class Qenv {
|
||||
|
||||
/**
|
||||
* tries to get any env var even if it is not required
|
||||
* @param requiredEnvVar
|
||||
* @param wantedEnvVar
|
||||
*/
|
||||
public getEnvVarOnDemand(requiredEnvVar: string): string {
|
||||
// lets determine the actual env yml
|
||||
let envYml;
|
||||
try {
|
||||
envYml = plugins.smartfile.fs.toObjectSync(this.envFilePathAbsolute);
|
||||
} catch (err) {
|
||||
envYml = {};
|
||||
}
|
||||
let envVar: string;
|
||||
let envFileVar: string;
|
||||
let dockerSecret: string;
|
||||
public getEnvVarOnDemand(wantedEnvVar: string): string {
|
||||
let envVarFromEnvironmentVariable: string;
|
||||
let envVarFromEnvJsonFile: string;
|
||||
let envVarFromDockerSecret: string;
|
||||
let dockerSecretJson: string;
|
||||
|
||||
// env var check
|
||||
if (process.env[requiredEnvVar]) {
|
||||
this.availableEnvVars.push(requiredEnvVar);
|
||||
envVar = process.env[requiredEnvVar];
|
||||
if (process.env[wantedEnvVar]) {
|
||||
this.availableEnvVars.push(wantedEnvVar);
|
||||
envVarFromEnvironmentVariable = process.env[wantedEnvVar];
|
||||
}
|
||||
|
||||
// env file check
|
||||
if (envYml.hasOwnProperty(requiredEnvVar)) {
|
||||
envFileVar = envYml[requiredEnvVar];
|
||||
this.availableEnvVars.push(requiredEnvVar);
|
||||
// lets determine the actual env yml
|
||||
let envJsonFileAsObject;
|
||||
try {
|
||||
envJsonFileAsObject = plugins.smartfile.fs.toObjectSync(this.envFilePathAbsolute);
|
||||
} catch (err) {
|
||||
envJsonFileAsObject = {};
|
||||
}
|
||||
if (envJsonFileAsObject.hasOwnProperty(wantedEnvVar)) {
|
||||
envVarFromEnvJsonFile = envJsonFileAsObject[wantedEnvVar];
|
||||
}
|
||||
|
||||
// docker secret check
|
||||
if (
|
||||
plugins.smartfile.fs.isDirectory('/run') &&
|
||||
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
|
||||
@ -107,42 +106,53 @@ export class Qenv {
|
||||
) {
|
||||
const availableSecrets = plugins.smartfile.fs.listAllItemsSync('/run/secrets');
|
||||
for (const secret of availableSecrets) {
|
||||
if (secret.includes('secret.json') && !dockerSecret) {
|
||||
if (secret.includes('secret.json') && !envVarFromDockerSecret) {
|
||||
const secretObject = plugins.smartfile.fs.toObjectSync(`/run/secrets/${secret}`);
|
||||
dockerSecret = secretObject[requiredEnvVar];
|
||||
envVarFromDockerSecret = secretObject[wantedEnvVar];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// warn if there is more than one candidate
|
||||
let candidatesCounter = 0;
|
||||
[envVar, envFileVar, dockerSecret, dockerSecretJson].forEach(candidate => {
|
||||
const availableCcandidates: any[] = [];
|
||||
[
|
||||
envVarFromEnvironmentVariable,
|
||||
envVarFromEnvJsonFile,
|
||||
envVarFromDockerSecret,
|
||||
dockerSecretJson
|
||||
].forEach(candidate => {
|
||||
if (candidate) {
|
||||
candidatesCounter++;
|
||||
availableCcandidates.push(candidate);
|
||||
}
|
||||
});
|
||||
if (candidatesCounter > 1) {
|
||||
if (availableCcandidates.length > 1) {
|
||||
this.logger.log(
|
||||
'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;
|
||||
if (envVar) {
|
||||
this.logger.log('ok', `found ${requiredEnvVar} as environment variable`);
|
||||
chosenVar = envVar;
|
||||
} else if (envFileVar) {
|
||||
this.logger.log('ok', `found ${requiredEnvVar} as env.json variable`);
|
||||
chosenVar = envFileVar;
|
||||
} else if (dockerSecret) {
|
||||
this.logger.log('ok', `found ${requiredEnvVar} as docker secret`);
|
||||
chosenVar = dockerSecret;
|
||||
} else if (dockerSecretJson) {
|
||||
this.logger.log('ok', `found ${requiredEnvVar} as docker secret.json`);
|
||||
chosenVar = dockerSecretJson;
|
||||
switch (true) {
|
||||
case !!envVarFromEnvironmentVariable:
|
||||
this.logger.log('ok', `found ${wantedEnvVar} as environment variable`);
|
||||
return envVarFromEnvironmentVariable;
|
||||
case !!envVarFromEnvJsonFile:
|
||||
this.logger.log('ok', `found ${wantedEnvVar} as env.json variable`);
|
||||
return envVarFromEnvJsonFile;
|
||||
case !!envVarFromDockerSecret:
|
||||
this.logger.log('ok', `found ${wantedEnvVar} as docker secret`);
|
||||
return envVarFromDockerSecret;
|
||||
case !!dockerSecretJson:
|
||||
this.logger.log('ok', `found ${wantedEnvVar} as docker secret.json`);
|
||||
return dockerSecretJson;
|
||||
default:
|
||||
this.logger.log(
|
||||
'warn',
|
||||
`could not find the wanted environment variable ${wantedEnvVar} anywhere`
|
||||
);
|
||||
return;
|
||||
}
|
||||
return chosenVar;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,13 +164,16 @@ export class Qenv {
|
||||
qenvFile = plugins.smartfile.fs.toObjectSync(this.qenvFilePathAbsolute);
|
||||
}
|
||||
if (!qenvFile || !qenvFile.required || !Array.isArray(qenvFile.required)) {
|
||||
this.logger.log('warn', `qenv (promised environment): ./env.yml File does not contain a 'required' Array!`);
|
||||
this.logger.log(
|
||||
'warn',
|
||||
`qenv (promised environment): ./env.yml File does not contain a 'required' Array!`
|
||||
);
|
||||
} else {
|
||||
for (const keyArg of Object.keys(qenvFile.required)) {
|
||||
this.requiredEnvVars.push(qenvFile.required[keyArg]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* gets the available env vars
|
||||
|
Loading…
Reference in New Issue
Block a user