fix(core): update
This commit is contained in:
parent
3c7e3e2589
commit
c9f79e6ea4
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/qenv',
|
name: '@push.rocks/qenv',
|
||||||
version: '6.0.0',
|
version: '6.0.1',
|
||||||
description: 'easy promised environments'
|
description: 'easy promised environments'
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,14 @@ export class Qenv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private initializeFilePaths(qenvFileBasePathArg: string, envFileBasePathArg: string) {
|
private initializeFilePaths(qenvFileBasePathArg: string, envFileBasePathArg: string) {
|
||||||
this.qenvFilePathAbsolute = plugins.path.join(plugins.path.resolve(qenvFileBasePathArg), 'qenv.yml');
|
this.qenvFilePathAbsolute = plugins.path.join(
|
||||||
this.envFilePathAbsolute = plugins.path.join(plugins.path.resolve(envFileBasePathArg), 'env.json');
|
plugins.path.resolve(qenvFileBasePathArg),
|
||||||
|
'qenv.yml'
|
||||||
|
);
|
||||||
|
this.envFilePathAbsolute = plugins.path.join(
|
||||||
|
plugins.path.resolve(envFileBasePathArg),
|
||||||
|
'env.json'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private loadRequiredEnvVars() {
|
private loadRequiredEnvVars() {
|
||||||
@ -48,7 +54,9 @@ export class Qenv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private checkForMissingEnvVars(failOnMissing: boolean) {
|
private checkForMissingEnvVars(failOnMissing: boolean) {
|
||||||
this.missingEnvVars = this.requiredEnvVars.filter((envVar) => !this.availableEnvVars.includes(envVar));
|
this.missingEnvVars = this.requiredEnvVars.filter(
|
||||||
|
(envVar) => !this.availableEnvVars.includes(envVar)
|
||||||
|
);
|
||||||
|
|
||||||
if (this.missingEnvVars.length > 0) {
|
if (this.missingEnvVars.length > 0) {
|
||||||
console.info('Required Env Vars are:', this.requiredEnvVars);
|
console.info('Required Env Vars are:', this.requiredEnvVars);
|
||||||
@ -62,27 +70,40 @@ export class Qenv {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getEnvVarOnDemand(envVarName: string): Promise<string | undefined> {
|
public async getEnvVarOnDemand(
|
||||||
return (
|
envVarNameOrNames: string | string[]
|
||||||
this.getFromEnvironmentVariable(envVarName) ||
|
): Promise<string | undefined> {
|
||||||
this.getFromEnvJsonFile(envVarName) ||
|
if (Array.isArray(envVarNameOrNames)) {
|
||||||
this.getFromDockerSecret(envVarName) ||
|
for (const envVarName of envVarNameOrNames) {
|
||||||
this.getFromDockerSecretJson(envVarName)
|
const value = await this.tryGetEnvVar(envVarName);
|
||||||
);
|
if (value) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
} else {
|
||||||
|
return await this.tryGetEnvVar(envVarNameOrNames);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getEnvVarOnDemandSync(envVarName: string): Promise<string | undefined> {
|
public getEnvVarOnDemandSync(envVarNameOrNames: string | string[]): string | undefined {
|
||||||
console.warn('requesting env var sync leaves out potentially important async env sources.');
|
console.warn('requesting env var sync leaves out potentially important async env sources.');
|
||||||
return (
|
|
||||||
this.getFromEnvironmentVariable(envVarName) ||
|
if (Array.isArray(envVarNameOrNames)) {
|
||||||
this.getFromEnvJsonFile(envVarName) ||
|
for (const envVarName of envVarNameOrNames) {
|
||||||
this.getFromDockerSecret(envVarName) ||
|
const value = this.tryGetEnvVarSync(envVarName);
|
||||||
this.getFromDockerSecretJson(envVarName)
|
if (value) {
|
||||||
);
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
} else {
|
||||||
|
return this.tryGetEnvVarSync(envVarNameOrNames);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getEnvVarOnDemandAsObject(envVarName: string): Promise<any> {
|
public async getEnvVarOnDemandAsObject(envVarNameOrNames: string | string[]): Promise<any> {
|
||||||
const rawValue = await this.getEnvVarOnDemand(envVarName);
|
const rawValue = await this.getEnvVarOnDemand(envVarNameOrNames);
|
||||||
if (rawValue && rawValue.startsWith('base64Object:')) {
|
if (rawValue && rawValue.startsWith('base64Object:')) {
|
||||||
const base64Part = rawValue.split('base64Object:')[1];
|
const base64Part = rawValue.split('base64Object:')[1];
|
||||||
return this.decodeBase64(base64Part);
|
return this.decodeBase64(base64Part);
|
||||||
@ -90,6 +111,24 @@ export class Qenv {
|
|||||||
return rawValue;
|
return rawValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async tryGetEnvVar(envVarName: string): Promise<string | undefined> {
|
||||||
|
return (
|
||||||
|
this.getFromEnvironmentVariable(envVarName) ||
|
||||||
|
this.getFromEnvJsonFile(envVarName) ||
|
||||||
|
this.getFromDockerSecret(envVarName) ||
|
||||||
|
this.getFromDockerSecretJson(envVarName)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private tryGetEnvVarSync(envVarName: string): string | undefined {
|
||||||
|
return (
|
||||||
|
this.getFromEnvironmentVariable(envVarName) ||
|
||||||
|
this.getFromEnvJsonFile(envVarName) ||
|
||||||
|
this.getFromDockerSecret(envVarName) ||
|
||||||
|
this.getFromDockerSecretJson(envVarName)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private getFromEnvironmentVariable(envVarName: string): string | undefined {
|
private getFromEnvironmentVariable(envVarName: string): string | undefined {
|
||||||
return process.env[envVarName];
|
return process.env[envVarName];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user