Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
a9bdfe9373 | |||
2017d51f11 | |||
765011ad2a | |||
d807cc6de2 | |||
53721a41c2 | |||
c9f79e6ea4 | |||
3c7e3e2589 | |||
205d27f9a0 | |||
56ce78f794 | |||
9d33054f03 | |||
072ca59ab0 | |||
59e3759a3a | |||
bc95ba3f2d | |||
1e6b9779b8 | |||
3988887a37 | |||
5a26ba7771 |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
name: Default (not tags)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags-ignore:
|
||||||
|
- '**'
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||||
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
|
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install pnpm and npmci
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
|
||||||
|
- name: Run npm prepare
|
||||||
|
run: npmci npm prepare
|
||||||
|
|
||||||
|
- name: Audit production dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --prod
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Audit development dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --dev
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
if: ${{ always() }}
|
||||||
|
needs: security
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Test stable
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm test
|
||||||
|
|
||||||
|
- name: Test build
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm build
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
name: Default (tags)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||||
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
|
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Audit production dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --prod
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Audit development dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --dev
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
if: ${{ always() }}
|
||||||
|
needs: security
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Test stable
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm test
|
||||||
|
|
||||||
|
- name: Test build
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm build
|
||||||
|
|
||||||
|
release:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Release
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm publish
|
||||||
|
|
||||||
|
metadata:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Code quality
|
||||||
|
run: |
|
||||||
|
npmci command npm install -g typescript
|
||||||
|
npmci npm install
|
||||||
|
|
||||||
|
- name: Trigger
|
||||||
|
run: npmci trigger
|
||||||
|
|
||||||
|
- name: Build docs and upload artifacts
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
pnpm install -g @git.zone/tsdoc
|
||||||
|
npmci command tsdoc
|
||||||
|
continue-on-error: true
|
128
.gitlab-ci.yml
128
.gitlab-ci.yml
@ -1,128 +0,0 @@
|
|||||||
# gitzone ci_default
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
|
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- .npmci_cache/
|
|
||||||
key: '$CI_BUILD_STAGE'
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- security
|
|
||||||
- test
|
|
||||||
- release
|
|
||||||
- metadata
|
|
||||||
|
|
||||||
before_script:
|
|
||||||
- npm install -g @shipzone/npmci
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# security stage
|
|
||||||
# ====================
|
|
||||||
auditProductionDependencies:
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci command npm install --production --ignore-scripts
|
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
- npmci command npm audit --audit-level=high --only=prod --production
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
auditDevDependencies:
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci command npm install --ignore-scripts
|
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
- npmci command npm audit --audit-level=high --only=dev
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# test stage
|
|
||||||
# ====================
|
|
||||||
|
|
||||||
testStable:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
release:
|
|
||||||
stage: release
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm publish
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# metadata stage
|
|
||||||
# ====================
|
|
||||||
codequality:
|
|
||||||
stage: metadata
|
|
||||||
allow_failure: true
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
script:
|
|
||||||
- npmci command npm install -g typescript
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- priv
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci trigger
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
pages:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command npm run buildDocs
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
artifacts:
|
|
||||||
expire_in: 1 week
|
|
||||||
paths:
|
|
||||||
- public
|
|
||||||
allow_failure: true
|
|
@ -1,4 +0,0 @@
|
|||||||
node_modules/
|
|
||||||
coverage/
|
|
||||||
docs/
|
|
||||||
|
|
@ -7,10 +7,10 @@
|
|||||||
"projectType": "npm",
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "push.rocks",
|
||||||
"gitrepo": "qenv",
|
"gitrepo": "qenv",
|
||||||
"description": "easy promised environments",
|
"description": "easy promised environments",
|
||||||
"npmPackagename": "@pushrocks/qenv",
|
"npmPackagename": "@push.rocks/qenv",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14367
package-lock.json
generated
14367
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
22
package.json
22
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/qenv",
|
"name": "@push.rocks/qenv",
|
||||||
"version": "5.0.2",
|
"version": "6.0.3",
|
||||||
"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,18 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/qenv#README",
|
"homepage": "https://gitlab.com/pushrocks/qenv#README",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.63",
|
"@git.zone/tsbuild": "^2.1.66",
|
||||||
"@gitzone/tsrun": "^1.2.37",
|
"@git.zone/tsrun": "^1.2.44",
|
||||||
"@gitzone/tstest": "^1.0.72",
|
"@git.zone/tstest": "^1.0.77",
|
||||||
"@pushrocks/tapbundle": "^5.0.4",
|
"@push.rocks/tapbundle": "^5.0.15",
|
||||||
"@types/node": "^18.6.3"
|
"@types/node": "^20.8.7"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartfile": "^10.0.4",
|
"@api.global/typedrequest": "^3.0.1",
|
||||||
"@pushrocks/smartlog": "^3.0.1",
|
"@configvault.io/interfaces": "^1.0.13",
|
||||||
"@pushrocks/smartpath": "^5.0.5"
|
"@push.rocks/smartfile": "^10.0.33",
|
||||||
|
"@push.rocks/smartlog": "^3.0.3",
|
||||||
|
"@push.rocks/smartpath": "^5.0.11"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
|
5979
pnpm-lock.yaml
generated
Normal file
5979
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
30
readme.md
30
readme.md
@ -1,27 +1,26 @@
|
|||||||
# @pushrocks/qenv
|
# @push.rocks/qenv
|
||||||
easy promised environments
|
easy promised environments
|
||||||
|
|
||||||
## Availabililty and Links
|
## Availabililty and Links
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/qenv)
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/qenv)
|
||||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/qenv)
|
* [gitlab.com (source)](https://gitlab.com/push.rocks/qenv)
|
||||||
* [github.com (source mirror)](https://github.com/pushrocks/qenv)
|
* [github.com (source mirror)](https://github.com/push.rocks/qenv)
|
||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/qenv/)
|
* [docs (typedoc)](https://push.rocks.gitlab.io/qenv/)
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
|
|
||||||
Status Category | Status Badge
|
Status Category | Status Badge
|
||||||
-- | --
|
-- | --
|
||||||
GitLab Pipelines | [](https://lossless.cloud)
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
npm | [](https://lossless.cloud)
|
npm | [](https://lossless.cloud)
|
||||||
Snyk | [](https://lossless.cloud)
|
Snyk | [](https://lossless.cloud)
|
||||||
TypeScript Support | [](https://lossless.cloud)
|
TypeScript Support | [](https://lossless.cloud)
|
||||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
Code Style | [](https://lossless.cloud)
|
Code Style | [](https://lossless.cloud)
|
||||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@ -48,7 +47,6 @@ We are always happy for code contributions. If you are not the code contributing
|
|||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
## Legal
|
||||||
|
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
|
||||||
|
16
test/test.ts
16
test/test.ts
@ -1,8 +1,8 @@
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
import { tap, expect } from '@push.rocks/tapbundle';
|
||||||
import * as qenv from '../ts/index.js';
|
import * as qenv from '../ts/index.js';
|
||||||
|
|
||||||
import * as smartpath from '@pushrocks/smartpath';
|
import * as smartpath from '@push.rocks/smartpath';
|
||||||
|
|
||||||
export { smartpath };
|
export { smartpath };
|
||||||
|
|
||||||
@ -18,18 +18,18 @@ tap.test('should create a new class', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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(testQenv.getEnvVarRequired('key1')).toEqual('original');
|
expect(await testQenv.getEnvVarOnDemand('key1')).toEqual('original');
|
||||||
expect(testQenv.getEnvVarOnDemand('key1')).toEqual('original');
|
expect(await testQenv.getEnvVarOnDemand('key1')).toEqual('original');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('key2 should be read from Yml', async () => {
|
tap.test('key2 should be read from Yml', async () => {
|
||||||
expect(testQenv.getEnvVarRequired('key2')).toEqual('fromJson');
|
expect(await testQenv.getEnvVarOnDemand('key2')).toEqual('fromJson');
|
||||||
expect(testQenv.getEnvVarOnDemand('key2')).toEqual('fromJson');
|
expect(await testQenv.getEnvVarOnDemand('key2')).toEqual('fromJson');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('keyValueObjectArray should hold all retrieved values', async () => {
|
tap.test('keyValueObjectArray should hold all retrieved values', async () => {
|
||||||
expect(testQenv.keyValueObject.key1).toEqual('original');
|
expect(await testQenv.keyValueObject.key1).toEqual('original');
|
||||||
expect(testQenv.keyValueObject.key2).toEqual('fromJson');
|
expect(await testQenv.keyValueObject.key2).toEqual('fromJson');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* autocreated commitinfo by @pushrocks/commitinfo
|
* autocreated commitinfo by @pushrocks/commitinfo
|
||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@pushrocks/qenv',
|
name: '@push.rocks/qenv',
|
||||||
version: '5.0.2',
|
version: '6.0.3',
|
||||||
description: 'easy promised environments'
|
description: 'easy promised environments'
|
||||||
}
|
}
|
||||||
|
30
ts/qenv.classes.configvaultadapter.ts
Normal file
30
ts/qenv.classes.configvaultadapter.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import * as plugins from './qenv.plugins.js';
|
||||||
|
|
||||||
|
export class ConfigVaultAdapter {
|
||||||
|
public configVaultUrl: string;
|
||||||
|
|
||||||
|
constructor(configVaultUrl?: string) {
|
||||||
|
this.configVaultUrl = configVaultUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getConfigBundle(): Promise<plugins.configvaultInterfaces.data.IConfigBundle> {
|
||||||
|
if (this.configVaultUrl) {
|
||||||
|
console.log(`ConfigVault specified through constructor`)
|
||||||
|
} else if (process.env['CONFIGVAULT_URL']) {
|
||||||
|
this.configVaultUrl = process.env['CONFIGVAULT_URL'];
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsedUrl = new URL(this.configVaultUrl);
|
||||||
|
|
||||||
|
const tr =
|
||||||
|
new plugins.typedrequest.TypedRequest<plugins.configvaultInterfaces.requests.IReq_GetEnvBundle>(
|
||||||
|
`${parsedUrl.host}/typedrequest`,
|
||||||
|
'getEnvBundle'
|
||||||
|
);
|
||||||
|
const response = await tr.fire({
|
||||||
|
authorization: parsedUrl.pathname.replace('/', ''),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,8 @@
|
|||||||
|
import { ConfigVaultAdapter } 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>);
|
||||||
* class Qenv
|
|
||||||
* allows to make assertions about the environments while being more flexibel in how to meet them
|
|
||||||
*/
|
|
||||||
export class Qenv {
|
export class Qenv {
|
||||||
public requiredEnvVars: string[] = [];
|
public requiredEnvVars: string[] = [];
|
||||||
public availableEnvVars: string[] = [];
|
public availableEnvVars: string[] = [];
|
||||||
@ -11,12 +10,24 @@ 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();
|
||||||
|
|
||||||
// filePaths
|
public configVaultAdapter: ConfigVaultAdapter;
|
||||||
|
|
||||||
public qenvFilePathAbsolute: string;
|
public qenvFilePathAbsolute: string;
|
||||||
public envFilePathAbsolute: string;
|
public envFilePathAbsolute: string;
|
||||||
|
|
||||||
constructor(qenvFileBasePathArg = process.cwd(), envFileBasePathArg, failOnMissing = true) {
|
constructor(
|
||||||
// lets make sure paths are absolute
|
qenvFileBasePathArg: string = process.cwd(),
|
||||||
|
envFileBasePathArg: string,
|
||||||
|
failOnMissing: boolean = true
|
||||||
|
) {
|
||||||
|
this.configVaultAdapter = new ConfigVaultAdapter();
|
||||||
|
this.initializeFilePaths(qenvFileBasePathArg, envFileBasePathArg);
|
||||||
|
this.loadRequiredEnvVars();
|
||||||
|
this.loadAvailableEnvVars();
|
||||||
|
this.checkForMissingEnvVars(failOnMissing);
|
||||||
|
}
|
||||||
|
|
||||||
|
private initializeFilePaths(qenvFileBasePathArg: string, envFileBasePathArg: string) {
|
||||||
this.qenvFilePathAbsolute = plugins.path.join(
|
this.qenvFilePathAbsolute = plugins.path.join(
|
||||||
plugins.path.resolve(qenvFileBasePathArg),
|
plugins.path.resolve(qenvFileBasePathArg),
|
||||||
'qenv.yml'
|
'qenv.yml'
|
||||||
@ -25,20 +36,39 @@ export class Qenv {
|
|||||||
plugins.path.resolve(envFileBasePathArg),
|
plugins.path.resolve(envFileBasePathArg),
|
||||||
'env.json'
|
'env.json'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.getRequiredEnvVars();
|
private loadRequiredEnvVars() {
|
||||||
this.getAvailableEnvVars();
|
if (plugins.smartfile.fs.fileExistsSync(this.qenvFilePathAbsolute)) {
|
||||||
|
const qenvFile = plugins.smartfile.fs.toObjectSync(this.qenvFilePathAbsolute);
|
||||||
|
if (qenvFile?.required && Array.isArray(qenvFile.required)) {
|
||||||
|
this.requiredEnvVars.push(...qenvFile.required);
|
||||||
|
} else {
|
||||||
|
this.logger.log('warn', 'qenv.yml does not contain a "required" Array!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.missingEnvVars = this.getMissingEnvVars();
|
private loadAvailableEnvVars() {
|
||||||
|
for (const envVar of this.requiredEnvVars) {
|
||||||
|
const value = this.getEnvVarOnDemand(envVar);
|
||||||
|
if (value) {
|
||||||
|
this.availableEnvVars.push(envVar);
|
||||||
|
this.keyValueObject[envVar] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private checkForMissingEnvVars(failOnMissing: boolean) {
|
||||||
|
this.missingEnvVars = this.requiredEnvVars.filter(
|
||||||
|
(envVar) => !this.availableEnvVars.includes(envVar)
|
||||||
|
);
|
||||||
|
|
||||||
// handle missing variables
|
|
||||||
if (this.missingEnvVars.length > 0) {
|
if (this.missingEnvVars.length > 0) {
|
||||||
console.info('Required Env Vars are:');
|
console.info('Required Env Vars are:', this.requiredEnvVars);
|
||||||
console.log(this.requiredEnvVars);
|
console.error('Missing Env Vars:', this.missingEnvVars);
|
||||||
console.error('However some Env variables could not be resolved:');
|
|
||||||
console.log(this.missingEnvVars);
|
|
||||||
if (failOnMissing) {
|
if (failOnMissing) {
|
||||||
this.logger.log('error', 'Exiting!');
|
this.logger.log('error', 'Exiting due to missing env vars!');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
} else {
|
} else {
|
||||||
this.logger.log('warn', 'qenv is not set to fail on missing environment variables');
|
this.logger.log('warn', 'qenv is not set to fail on missing environment variables');
|
||||||
@ -46,150 +76,118 @@ export class Qenv {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public async getEnvVarOnDemand(
|
||||||
* only gets an environment variable if it is required within a read qenv.yml file
|
envVarNameOrNames: TEnvVarRef | TEnvVarRef[]
|
||||||
* @param envVarName
|
): Promise<string | undefined> {
|
||||||
*/
|
if (Array.isArray(envVarNameOrNames)) {
|
||||||
public getEnvVarRequired(envVarName): string {
|
for (const envVarName of envVarNameOrNames) {
|
||||||
return this.keyValueObject[envVarName];
|
const value = await this.tryGetEnvVar(envVarName);
|
||||||
|
if (value) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
} else {
|
||||||
|
return await this.tryGetEnvVar(envVarNameOrNames);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public getEnvVarOnDemandSync(envVarNameOrNames: string | string[]): string | undefined {
|
||||||
* tries to get any env var even if it is not required
|
console.warn('requesting env var sync leaves out potentially important async env sources.');
|
||||||
* @param wantedEnvVar
|
|
||||||
*/
|
|
||||||
public getEnvVarOnDemand(wantedEnvVar: string): string {
|
|
||||||
let envVarFromEnvironmentVariable: string;
|
|
||||||
let envVarFromEnvJsonFile: string;
|
|
||||||
let envVarFromDockerSecret: string;
|
|
||||||
let dockerSecretJson: string;
|
|
||||||
|
|
||||||
// env var check
|
if (Array.isArray(envVarNameOrNames)) {
|
||||||
if (process.env[wantedEnvVar]) {
|
for (const envVarName of envVarNameOrNames) {
|
||||||
this.availableEnvVars.push(wantedEnvVar);
|
const value = this.tryGetEnvVarSync(envVarName);
|
||||||
envVarFromEnvironmentVariable = process.env[wantedEnvVar];
|
if (value) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
} else {
|
||||||
|
return this.tryGetEnvVarSync(envVarNameOrNames);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// env file check
|
public async getEnvVarOnDemandAsObject(envVarNameOrNames: string | string[]): Promise<any> {
|
||||||
// lets determine the actual env yml
|
const rawValue = await this.getEnvVarOnDemand(envVarNameOrNames);
|
||||||
let envJsonFileAsObject;
|
if (rawValue && rawValue.startsWith('base64Object:')) {
|
||||||
|
const base64Part = rawValue.split('base64Object:')[1];
|
||||||
|
return this.decodeBase64(base64Part);
|
||||||
|
}
|
||||||
|
return rawValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async tryGetEnvVar(envVarRefArg: TEnvVarRef): Promise<string | undefined> {
|
||||||
|
if (typeof envVarRefArg === 'function') {
|
||||||
|
return await envVarRefArg();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
this.getFromEnvironmentVariable(envVarRefArg) ||
|
||||||
|
this.getFromEnvJsonFile(envVarRefArg) ||
|
||||||
|
this.getFromDockerSecret(envVarRefArg) ||
|
||||||
|
this.getFromDockerSecretJson(envVarRefArg)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
return process.env[envVarName];
|
||||||
|
}
|
||||||
|
|
||||||
|
private getFromEnvJsonFile(envVarName: string): string | undefined {
|
||||||
try {
|
try {
|
||||||
envJsonFileAsObject = plugins.smartfile.fs.toObjectSync(this.envFilePathAbsolute);
|
const envJson = plugins.smartfile.fs.toObjectSync(this.envFilePathAbsolute);
|
||||||
} catch (err) {
|
const value = envJson[envVarName];
|
||||||
envJsonFileAsObject = {};
|
if (typeof value === 'object') {
|
||||||
|
return 'base64Object:' + this.encodeBase64(value);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
} catch (error) {
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
if (envJsonFileAsObject.hasOwnProperty(wantedEnvVar)) {
|
|
||||||
envVarFromEnvJsonFile = envJsonFileAsObject[wantedEnvVar];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// docker secret check
|
private getFromDockerSecret(envVarName: string): string | undefined {
|
||||||
if (
|
const secretPath = `/run/secrets/${envVarName}`;
|
||||||
plugins.smartfile.fs.isDirectory('/run') &&
|
if (plugins.smartfile.fs.fileExistsSync(secretPath)) {
|
||||||
plugins.smartfile.fs.isDirectory('/run/secrets') &&
|
return plugins.smartfile.fs.toStringSync(secretPath);
|
||||||
plugins.smartfile.fs.fileExistsSync(`/run/secrets/${wantedEnvVar}`)
|
}
|
||||||
) {
|
return undefined;
|
||||||
envVarFromDockerSecret = plugins.smartfile.fs.toStringSync(`/run/secrets/${wantedEnvVar}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// docker secret.json
|
private getFromDockerSecretJson(envVarName: string): string | undefined {
|
||||||
if (
|
if (plugins.smartfile.fs.isDirectory('/run/secrets')) {
|
||||||
plugins.smartfile.fs.isDirectory('/run') &&
|
|
||||||
plugins.smartfile.fs.isDirectory('/run/secrets')
|
|
||||||
) {
|
|
||||||
const availableSecrets = plugins.smartfile.fs.listAllItemsSync('/run/secrets');
|
const availableSecrets = plugins.smartfile.fs.listAllItemsSync('/run/secrets');
|
||||||
for (const secret of availableSecrets) {
|
for (const secret of availableSecrets) {
|
||||||
if (secret.includes('secret.json') && !envVarFromDockerSecret) {
|
if (secret.includes('secret.json')) {
|
||||||
const secretObject = plugins.smartfile.fs.toObjectSync(`/run/secrets/${secret}`);
|
const secretObject = plugins.smartfile.fs.toObjectSync(`/run/secrets/${secret}`);
|
||||||
envVarFromDockerSecret = secretObject[wantedEnvVar];
|
const value = secretObject[envVarName];
|
||||||
|
if (typeof value === 'object') {
|
||||||
|
return 'base64Object:' + this.encodeBase64(value);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
// warn if there is more than one candidate
|
private encodeBase64(data: any): string {
|
||||||
const availableCcandidates: any[] = [];
|
const jsonString = JSON.stringify(data);
|
||||||
[
|
return Buffer.from(jsonString).toString('base64');
|
||||||
envVarFromEnvironmentVariable,
|
|
||||||
envVarFromEnvJsonFile,
|
|
||||||
envVarFromDockerSecret,
|
|
||||||
dockerSecretJson,
|
|
||||||
].forEach((candidate) => {
|
|
||||||
if (candidate) {
|
|
||||||
availableCcandidates.push(candidate);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (availableCcandidates.length > 1) {
|
|
||||||
this.logger.log(
|
|
||||||
'warn',
|
|
||||||
`found multiple candidates for ${wantedEnvVar} Choosing in the order of envVar, envFileVar, dockerSecret, dockerSecretJson`
|
|
||||||
);
|
|
||||||
console.log(availableCcandidates);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (true) {
|
private decodeBase64(encodedString: string): any {
|
||||||
case !!envVarFromEnvironmentVariable:
|
const decodedString = Buffer.from(encodedString, 'base64').toString('utf-8');
|
||||||
this.logger.log('ok', `found ${wantedEnvVar} as environment variable`);
|
return JSON.parse(decodedString);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* gets the required env values
|
|
||||||
*/
|
|
||||||
private getRequiredEnvVars = () => {
|
|
||||||
let qenvFile: any = {};
|
|
||||||
if (plugins.smartfile.fs.fileExistsSync(this.qenvFilePathAbsolute)) {
|
|
||||||
qenvFile = plugins.smartfile.fs.toObjectSync(this.qenvFilePathAbsolute);
|
|
||||||
}
|
|
||||||
if (!qenvFile || !qenvFile.required || !Array.isArray(qenvFile.required)) {
|
|
||||||
this.logger.log(
|
|
||||||
'warn',
|
|
||||||
`qenv (promised environment): ./qenv.yml File does not contain a 'required' Array! This might be ok though.`
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
for (const keyArg of Object.keys(qenvFile.required)) {
|
|
||||||
this.requiredEnvVars.push(qenvFile.required[keyArg]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gets the available env vars
|
|
||||||
*/
|
|
||||||
private getAvailableEnvVars = () => {
|
|
||||||
for (const requiredEnvVar of this.requiredEnvVars) {
|
|
||||||
const chosenVar = this.getEnvVarOnDemand(requiredEnvVar);
|
|
||||||
if (chosenVar) {
|
|
||||||
this.availableEnvVars.push(requiredEnvVar);
|
|
||||||
this.keyValueObject[requiredEnvVar] = chosenVar;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gets missing env vars
|
|
||||||
*/
|
|
||||||
private getMissingEnvVars = (): string[] => {
|
|
||||||
const missingEnvVars: string[] = [];
|
|
||||||
for (const envVar of this.requiredEnvVars) {
|
|
||||||
if (!this.availableEnvVars.includes(envVar)) {
|
|
||||||
missingEnvVars.push(envVar);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return missingEnvVars;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
@ -3,8 +3,20 @@ import * as path from 'path';
|
|||||||
|
|
||||||
export { path };
|
export { path };
|
||||||
|
|
||||||
|
// @api.global scope
|
||||||
|
import * as typedrequest from '@api.global/typedrequest';
|
||||||
|
|
||||||
|
export {
|
||||||
|
typedrequest,
|
||||||
|
}
|
||||||
|
|
||||||
// @pushrocks scope
|
// @pushrocks scope
|
||||||
import * as smartfile from '@pushrocks/smartfile';
|
import * as smartfile from '@push.rocks/smartfile';
|
||||||
import * as smartlog from '@pushrocks/smartlog';
|
import * as smartlog from '@push.rocks/smartlog';
|
||||||
|
|
||||||
export { smartfile, smartlog };
|
export { smartfile, smartlog };
|
||||||
|
|
||||||
|
// @configvault.io scope
|
||||||
|
import * as configvaultInterfaces from '@configvault.io/interfaces';
|
||||||
|
|
||||||
|
export { configvaultInterfaces };
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
"target": "ES2022",
|
"target": "ES2022",
|
||||||
"module": "ES2022",
|
"module": "ES2022",
|
||||||
"moduleResolution": "nodenext",
|
"moduleResolution": "nodenext",
|
||||||
"esModuleInterop": true
|
"esModuleInterop": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user