Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
7655318629 | |||
754ffa6cac | |||
b644ca0c1a | |||
9f638d687b | |||
a9bdfe9373 | |||
2017d51f11 |
@ -119,6 +119,6 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
npmci node install stable
|
npmci node install stable
|
||||||
npmci npm install
|
npmci npm install
|
||||||
pnpm install -g @gitzone/tsdoc
|
pnpm install -g @git.zone/tsdoc
|
||||||
npmci command tsdoc
|
npmci command tsdoc
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
18
package.json
18
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/qenv",
|
"name": "@push.rocks/qenv",
|
||||||
"version": "6.0.2",
|
"version": "6.0.5",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "easy promised environments",
|
"description": "easy promised environments",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -27,16 +27,16 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/qenv#README",
|
"homepage": "https://gitlab.com/pushrocks/qenv#README",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.66",
|
"@git.zone/tsbuild": "^2.1.72",
|
||||||
"@gitzone/tsrun": "^1.2.44",
|
"@git.zone/tsrun": "^1.2.44",
|
||||||
"@gitzone/tstest": "^1.0.77",
|
"@git.zone/tstest": "^1.0.86",
|
||||||
"@push.rocks/tapbundle": "^5.0.12",
|
"@push.rocks/tapbundle": "^5.0.15",
|
||||||
"@types/node": "^20.4.6"
|
"@types/node": "^20.11.17"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@api.global/typedrequest": "^3.0.1",
|
"@api.global/typedrequest": "^3.0.4",
|
||||||
"@configvault.io/interfaces": "^1.0.2",
|
"@configvault.io/interfaces": "^1.0.17",
|
||||||
"@push.rocks/smartfile": "^10.0.28",
|
"@push.rocks/smartfile": "^11.0.4",
|
||||||
"@push.rocks/smartlog": "^3.0.3",
|
"@push.rocks/smartlog": "^3.0.3",
|
||||||
"@push.rocks/smartpath": "^5.0.11"
|
"@push.rocks/smartpath": "^5.0.11"
|
||||||
},
|
},
|
||||||
|
3260
pnpm-lock.yaml
generated
3260
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/qenv',
|
name: '@push.rocks/qenv',
|
||||||
version: '6.0.2',
|
version: '6.0.5',
|
||||||
description: 'easy promised environments'
|
description: 'easy promised environments'
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import * as plugins from './qenv.plugins.js';
|
import * as plugins from './qenv.plugins.js';
|
||||||
|
|
||||||
export class ConfigVaultAdapter {
|
export class CloudlyAdapter {
|
||||||
public configVaultUrl: string;
|
public configVaultUrl: string;
|
||||||
|
|
||||||
constructor(configVaultUrl?: string) {
|
constructor(configVaultUrl?: string) {
|
||||||
@ -19,9 +19,9 @@ export class ConfigVaultAdapter {
|
|||||||
const parsedUrl = new URL(this.configVaultUrl);
|
const parsedUrl = new URL(this.configVaultUrl);
|
||||||
|
|
||||||
const tr =
|
const tr =
|
||||||
new plugins.typedrequest.TypedRequest<plugins.configvaultInterfaces.requests.IReq_GetConfigBundle>(
|
new plugins.typedrequest.TypedRequest<plugins.configvaultInterfaces.requests.IReq_GetEnvBundle>(
|
||||||
`${parsedUrl.host}/typedrequest`,
|
`${parsedUrl.host}/typedrequest`,
|
||||||
'getConfigBundle'
|
'getEnvBundle'
|
||||||
);
|
);
|
||||||
const response = await tr.fire({
|
const response = await tr.fire({
|
||||||
authorization: parsedUrl.pathname.replace('/', ''),
|
authorization: parsedUrl.pathname.replace('/', ''),
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import { ConfigVaultAdapter } from './qenv.classes.configvaultadapter.js';
|
import { CloudlyAdapter } from './qenv.classes.configvaultadapter.js';
|
||||||
import * as plugins from './qenv.plugins.js';
|
import * as plugins from './qenv.plugins.js';
|
||||||
|
|
||||||
|
export type TEnvVarRef = string | (() => Promise<string>);
|
||||||
|
|
||||||
export class Qenv {
|
export class Qenv {
|
||||||
public requiredEnvVars: string[] = [];
|
public requiredEnvVars: string[] = [];
|
||||||
public availableEnvVars: string[] = [];
|
public availableEnvVars: string[] = [];
|
||||||
@ -8,17 +10,17 @@ export class Qenv {
|
|||||||
public keyValueObject: { [key: string]: any } = {};
|
public keyValueObject: { [key: string]: any } = {};
|
||||||
public logger = new plugins.smartlog.ConsoleLog();
|
public logger = new plugins.smartlog.ConsoleLog();
|
||||||
|
|
||||||
public configVaultAdapter: ConfigVaultAdapter;
|
public cloudlyAdapter: CloudlyAdapter;
|
||||||
|
|
||||||
public qenvFilePathAbsolute: string;
|
public qenvFilePathAbsolute: string;
|
||||||
public envFilePathAbsolute: string;
|
public envFilePathAbsolute: string;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
qenvFileBasePathArg: string = process.cwd(),
|
qenvFileBasePathArg: string = process.cwd(),
|
||||||
envFileBasePathArg: string,
|
envFileBasePathArg?: string,
|
||||||
failOnMissing: boolean = true
|
failOnMissing: boolean = true
|
||||||
) {
|
) {
|
||||||
this.configVaultAdapter = new ConfigVaultAdapter();
|
this.cloudlyAdapter = new CloudlyAdapter();
|
||||||
this.initializeFilePaths(qenvFileBasePathArg, envFileBasePathArg);
|
this.initializeFilePaths(qenvFileBasePathArg, envFileBasePathArg);
|
||||||
this.loadRequiredEnvVars();
|
this.loadRequiredEnvVars();
|
||||||
this.loadAvailableEnvVars();
|
this.loadAvailableEnvVars();
|
||||||
@ -30,10 +32,12 @@ export class Qenv {
|
|||||||
plugins.path.resolve(qenvFileBasePathArg),
|
plugins.path.resolve(qenvFileBasePathArg),
|
||||||
'qenv.yml'
|
'qenv.yml'
|
||||||
);
|
);
|
||||||
this.envFilePathAbsolute = plugins.path.join(
|
if (envFileBasePathArg) {
|
||||||
plugins.path.resolve(envFileBasePathArg),
|
this.envFilePathAbsolute = plugins.path.join(
|
||||||
'env.json'
|
plugins.path.resolve(envFileBasePathArg),
|
||||||
);
|
'env.json'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private loadRequiredEnvVars() {
|
private loadRequiredEnvVars() {
|
||||||
@ -75,7 +79,7 @@ export class Qenv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async getEnvVarOnDemand(
|
public async getEnvVarOnDemand(
|
||||||
envVarNameOrNames: string | string[]
|
envVarNameOrNames: TEnvVarRef | TEnvVarRef[]
|
||||||
): Promise<string | undefined> {
|
): Promise<string | undefined> {
|
||||||
if (Array.isArray(envVarNameOrNames)) {
|
if (Array.isArray(envVarNameOrNames)) {
|
||||||
for (const envVarName of envVarNameOrNames) {
|
for (const envVarName of envVarNameOrNames) {
|
||||||
@ -115,12 +119,16 @@ export class Qenv {
|
|||||||
return rawValue;
|
return rawValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async tryGetEnvVar(envVarName: string): Promise<string | undefined> {
|
private async tryGetEnvVar(envVarRefArg: TEnvVarRef): Promise<string | undefined> {
|
||||||
|
if (typeof envVarRefArg === 'function') {
|
||||||
|
return await envVarRefArg();
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
this.getFromEnvironmentVariable(envVarName) ||
|
this.getFromEnvironmentVariable(envVarRefArg) ||
|
||||||
this.getFromEnvJsonFile(envVarName) ||
|
this.getFromEnvJsonFile(envVarRefArg) ||
|
||||||
this.getFromDockerSecret(envVarName) ||
|
this.getFromDockerSecret(envVarRefArg) ||
|
||||||
this.getFromDockerSecretJson(envVarName)
|
this.getFromDockerSecretJson(envVarRefArg)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,6 +146,9 @@ export class Qenv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private getFromEnvJsonFile(envVarName: string): string | undefined {
|
private getFromEnvJsonFile(envVarName: string): string | undefined {
|
||||||
|
if (!plugins.smartfile.fs.fileExistsSync(this.envFilePathAbsolute)) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const envJson = plugins.smartfile.fs.toObjectSync(this.envFilePathAbsolute);
|
const envJson = plugins.smartfile.fs.toObjectSync(this.envFilePathAbsolute);
|
||||||
const value = envJson[envVarName];
|
const value = envJson[envVarName];
|
||||||
|
@ -3,9 +3,12 @@
|
|||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"useDefineForClassFields": false,
|
"useDefineForClassFields": false,
|
||||||
"target": "ES2022",
|
"target": "ES2022",
|
||||||
"module": "ES2022",
|
"module": "NodeNext",
|
||||||
"moduleResolution": "nodenext",
|
"moduleResolution": "NodeNext",
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"verbatimModuleSyntax": true,
|
"verbatimModuleSyntax": true
|
||||||
}
|
},
|
||||||
|
"exclude": [
|
||||||
|
"dist_*/**/*.d.ts"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user