@floracodex/nestjs-secrets 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +96 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/secrets-loader-options.interface.d.ts +12 -0
- package/dist/interfaces/secrets-loader-options.interface.js +3 -0
- package/dist/interfaces/secrets-loader-options.interface.js.map +1 -0
- package/dist/interfaces/secrets-module-options.interface.d.ts +4 -0
- package/dist/interfaces/secrets-module-options.interface.js +3 -0
- package/dist/interfaces/secrets-module-options.interface.js.map +1 -0
- package/dist/interfaces/secrets-provider.interface.d.ts +26 -0
- package/dist/interfaces/secrets-provider.interface.js +10 -0
- package/dist/interfaces/secrets-provider.interface.js.map +1 -0
- package/dist/modules/secrets.module.d.ts +5 -0
- package/dist/modules/secrets.module.js +37 -0
- package/dist/modules/secrets.module.js.map +1 -0
- package/dist/providers/aws-parameter-store.provider.d.ts +39 -0
- package/dist/providers/aws-parameter-store.provider.js +98 -0
- package/dist/providers/aws-parameter-store.provider.js.map +1 -0
- package/dist/providers/aws-secrets-manager.provider.d.ts +30 -0
- package/dist/providers/aws-secrets-manager.provider.js +65 -0
- package/dist/providers/aws-secrets-manager.provider.js.map +1 -0
- package/dist/providers/azure-key-vault.provider.d.ts +34 -0
- package/dist/providers/azure-key-vault.provider.js +74 -0
- package/dist/providers/azure-key-vault.provider.js.map +1 -0
- package/dist/providers/google-secret-manager.provider.d.ts +25 -0
- package/dist/providers/google-secret-manager.provider.js +63 -0
- package/dist/providers/google-secret-manager.provider.js.map +1 -0
- package/dist/services/secrets-loader.service.d.ts +58 -0
- package/dist/services/secrets-loader.service.js +212 -0
- package/dist/services/secrets-loader.service.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +105 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SecretManagerServiceClient } from '@google-cloud/secret-manager';
|
|
2
|
+
import { SecretsProvider } from '../interfaces/secrets-provider.interface';
|
|
3
|
+
export declare class GoogleSecretManagerProvider implements SecretsProvider {
|
|
4
|
+
private readonly client;
|
|
5
|
+
private readonly logger;
|
|
6
|
+
/**
|
|
7
|
+
* Regular expression pattern for Google Secret Manager paths
|
|
8
|
+
* Format: projects/{project-id}/secrets/{secret-id}/versions/{version}
|
|
9
|
+
*/
|
|
10
|
+
private readonly secretPathPattern;
|
|
11
|
+
constructor(client: SecretManagerServiceClient);
|
|
12
|
+
/**
|
|
13
|
+
* Checks if a string is a valid Google Secret Manager reference.
|
|
14
|
+
* @param value The string to check
|
|
15
|
+
* @returns True if the string is a valid Google Secret Manager reference
|
|
16
|
+
*/
|
|
17
|
+
isSecretReference(value: string): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Resolves a Google Secret Manager reference to its actual value.
|
|
20
|
+
* @param secretRef The full path to the secret in format projects/{project}/secrets/{secret}/versions/{version}
|
|
21
|
+
* @returns The resolved secret value as a string
|
|
22
|
+
* @throws Error when the secret cannot be retrieved or has an invalid format
|
|
23
|
+
*/
|
|
24
|
+
resolveSecret(secretRef: string): Promise<string>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var GoogleSecretManagerProvider_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.GoogleSecretManagerProvider = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const secret_manager_1 = require("@google-cloud/secret-manager");
|
|
16
|
+
let GoogleSecretManagerProvider = GoogleSecretManagerProvider_1 = class GoogleSecretManagerProvider {
|
|
17
|
+
client;
|
|
18
|
+
logger = new common_1.Logger(GoogleSecretManagerProvider_1.name);
|
|
19
|
+
/**
|
|
20
|
+
* Regular expression pattern for Google Secret Manager paths
|
|
21
|
+
* Format: projects/{project-id}/secrets/{secret-id}/versions/{version}
|
|
22
|
+
*/
|
|
23
|
+
secretPathPattern = /^projects\/[^/]+\/secrets\/[^/]+\/versions\/[^/]+$/;
|
|
24
|
+
constructor(client) {
|
|
25
|
+
this.client = client;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Checks if a string is a valid Google Secret Manager reference.
|
|
29
|
+
* @param value The string to check
|
|
30
|
+
* @returns True if the string is a valid Google Secret Manager reference
|
|
31
|
+
*/
|
|
32
|
+
isSecretReference(value) {
|
|
33
|
+
return this.secretPathPattern.test(value);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Resolves a Google Secret Manager reference to its actual value.
|
|
37
|
+
* @param secretRef The full path to the secret in format projects/{project}/secrets/{secret}/versions/{version}
|
|
38
|
+
* @returns The resolved secret value as a string
|
|
39
|
+
* @throws Error when the secret cannot be retrieved or has an invalid format
|
|
40
|
+
*/
|
|
41
|
+
async resolveSecret(secretRef) {
|
|
42
|
+
// The Google client returns an array where the first element contains the response
|
|
43
|
+
const [response] = await this.client.accessSecretVersion({
|
|
44
|
+
name: secretRef
|
|
45
|
+
});
|
|
46
|
+
if (!response || !response.payload) {
|
|
47
|
+
throw new Error('Secret payload is missing');
|
|
48
|
+
}
|
|
49
|
+
if (!response.payload.data) {
|
|
50
|
+
throw new Error('Secret payload data is missing');
|
|
51
|
+
}
|
|
52
|
+
// Return the secret data as a string, handling both Buffer and string formats
|
|
53
|
+
return Buffer.isBuffer(response.payload.data)
|
|
54
|
+
? response.payload.data.toString('utf8')
|
|
55
|
+
: response.payload.data.toString();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
exports.GoogleSecretManagerProvider = GoogleSecretManagerProvider;
|
|
59
|
+
exports.GoogleSecretManagerProvider = GoogleSecretManagerProvider = GoogleSecretManagerProvider_1 = __decorate([
|
|
60
|
+
(0, common_1.Injectable)(),
|
|
61
|
+
__metadata("design:paramtypes", [secret_manager_1.SecretManagerServiceClient])
|
|
62
|
+
], GoogleSecretManagerProvider);
|
|
63
|
+
//# sourceMappingURL=google-secret-manager.provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-secret-manager.provider.js","sourceRoot":"","sources":["../../src/providers/google-secret-manager.provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAkD;AAClD,iEAAwE;AAIjE,IAAM,2BAA2B,mCAAjC,MAAM,2BAA2B;IASP;IARZ,MAAM,GAAG,IAAI,eAAM,CAAC,6BAA2B,CAAC,IAAI,CAAC,CAAC;IAEvE;;;OAGG;IACc,iBAAiB,GAAG,oDAAoD,CAAC;IAE1F,YAA6B,MAAkC;QAAlC,WAAM,GAAN,MAAM,CAA4B;IAC/D,CAAC;IAED;;;;OAIG;IACH,iBAAiB,CAAC,KAAa;QAC3B,OAAO,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,aAAa,CAAC,SAAiB;QACjC,mFAAmF;QACnF,MAAM,CAAC,QAAQ,CAAC,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC;YACrD,IAAI,EAAE,SAAS;SAClB,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QACjD,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACtD,CAAC;QAED,8EAA8E;QAC9E,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC;YACzC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;YACxC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC3C,CAAC;CACJ,CAAA;AA9CY,kEAA2B;sCAA3B,2BAA2B;IADvC,IAAA,mBAAU,GAAE;qCAU4B,2CAA0B;GATtD,2BAA2B,CA8CvC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ConfigFactory, ConfigService } from '@nestjs/config';
|
|
2
|
+
import { SecretsLoaderOptions } from '../interfaces/secrets-loader-options.interface';
|
|
3
|
+
import { SecretsProvider } from '../interfaces/secrets-provider.interface';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration loader with support for secret resolution
|
|
6
|
+
*/
|
|
7
|
+
export declare class SecretsLoaderService {
|
|
8
|
+
private readonly logger;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a config factory for use with ConfigModule.forRoot()
|
|
11
|
+
* @param options Configuration options
|
|
12
|
+
* @returns A config factory function
|
|
13
|
+
*/
|
|
14
|
+
createConfigFactory(options: SecretsLoaderOptions): ConfigFactory;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a secrets provider based on the provided key and client.
|
|
17
|
+
* @param key The provider type identifier
|
|
18
|
+
* @param client The client instance to be used by the provider
|
|
19
|
+
* @returns A promise that resolves to the created SecretsProvider or undefined if not supported
|
|
20
|
+
*/
|
|
21
|
+
createSecretProvider(key: string, client: any): Promise<SecretsProvider | undefined>;
|
|
22
|
+
/**
|
|
23
|
+
* Finds the application root directory
|
|
24
|
+
* (Usually one level up from where this code is running in a typical NestJS app)
|
|
25
|
+
*/
|
|
26
|
+
private findAppRootDirectory;
|
|
27
|
+
/**
|
|
28
|
+
* Determines if the path is specified relative to the current working directory
|
|
29
|
+
*/
|
|
30
|
+
private isRelativePathFromCwd;
|
|
31
|
+
/**
|
|
32
|
+
* Loads configuration and resolves secrets
|
|
33
|
+
* @param options Configuration options
|
|
34
|
+
* @returns ConfigService instance
|
|
35
|
+
*/
|
|
36
|
+
load(options: SecretsLoaderOptions): Promise<ConfigService>;
|
|
37
|
+
/**
|
|
38
|
+
* Loads and merges configuration files, resolving secrets if a provider is available
|
|
39
|
+
* @param provider The instantiated secret provider
|
|
40
|
+
* @param options Configuration options
|
|
41
|
+
* @returns Merged configuration object
|
|
42
|
+
*/
|
|
43
|
+
private loadConfigFiles;
|
|
44
|
+
loadProvider(options: SecretsLoaderOptions): Promise<SecretsProvider | undefined>;
|
|
45
|
+
/**
|
|
46
|
+
* Resolves the base directory for configuration files based on the provided configuration
|
|
47
|
+
* or defaults to the application's standard config directory
|
|
48
|
+
*/
|
|
49
|
+
private resolveBaseDirectory;
|
|
50
|
+
/**
|
|
51
|
+
* Resolves the default configuration directory path and logs it
|
|
52
|
+
*/
|
|
53
|
+
private resolveDefaultConfigDirectory;
|
|
54
|
+
/**
|
|
55
|
+
* Recursively resolves secrets in configuration objects
|
|
56
|
+
*/
|
|
57
|
+
private resolveSecrets;
|
|
58
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var SecretsLoaderService_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.SecretsLoaderService = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const config_1 = require("@nestjs/config");
|
|
13
|
+
const node_fs_1 = require("node:fs");
|
|
14
|
+
const yaml = require("js-yaml");
|
|
15
|
+
const node_path_1 = require("node:path");
|
|
16
|
+
const lodash_1 = require("lodash");
|
|
17
|
+
/**
|
|
18
|
+
* Configuration loader with support for secret resolution
|
|
19
|
+
*/
|
|
20
|
+
let SecretsLoaderService = SecretsLoaderService_1 = class SecretsLoaderService {
|
|
21
|
+
logger = new common_1.Logger(SecretsLoaderService_1.name);
|
|
22
|
+
/**
|
|
23
|
+
* Creates a config factory for use with ConfigModule.forRoot()
|
|
24
|
+
* @param options Configuration options
|
|
25
|
+
* @returns A config factory function
|
|
26
|
+
*/
|
|
27
|
+
createConfigFactory(options) {
|
|
28
|
+
return async () => {
|
|
29
|
+
const provider = await this.loadProvider(options);
|
|
30
|
+
return await this.loadConfigFiles(provider, options);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates a secrets provider based on the provided key and client.
|
|
35
|
+
* @param key The provider type identifier
|
|
36
|
+
* @param client The client instance to be used by the provider
|
|
37
|
+
* @returns A promise that resolves to the created SecretsProvider or undefined if not supported
|
|
38
|
+
*/
|
|
39
|
+
async createSecretProvider(key, client) {
|
|
40
|
+
switch (key) {
|
|
41
|
+
case 'AwsSecretsManagerProvider':
|
|
42
|
+
case 'SecretsManager':
|
|
43
|
+
const { AwsSecretsManagerProvider } = await Promise.resolve().then(() => require('../providers/aws-secrets-manager.provider'));
|
|
44
|
+
return new AwsSecretsManagerProvider(client);
|
|
45
|
+
case 'AwsParameterStoreProvider':
|
|
46
|
+
case 'SSMClient':
|
|
47
|
+
const { AwsParameterStoreProvider } = await Promise.resolve().then(() => require('../providers/aws-parameter-store.provider'));
|
|
48
|
+
return new AwsParameterStoreProvider(client);
|
|
49
|
+
case 'AzureKeyVaultProvider':
|
|
50
|
+
case 'SecretClient':
|
|
51
|
+
const { AzureKeyVaultProvider } = await Promise.resolve().then(() => require('../providers/azure-key-vault.provider'));
|
|
52
|
+
return new AzureKeyVaultProvider(client);
|
|
53
|
+
case 'GoogleSecretManagerProvider':
|
|
54
|
+
case 'SecretManagerServiceClient':
|
|
55
|
+
const { GoogleSecretManagerProvider } = await Promise.resolve().then(() => require('../providers/google-secret-manager.provider'));
|
|
56
|
+
return new GoogleSecretManagerProvider(client);
|
|
57
|
+
}
|
|
58
|
+
this.logger.warn(`Unsupported secret provider: ${client.constructor.name}`);
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Finds the application root directory
|
|
63
|
+
* (Usually one level up from where this code is running in a typical NestJS app)
|
|
64
|
+
*/
|
|
65
|
+
findAppRootDirectory() {
|
|
66
|
+
// Get the directory of the currently executing file
|
|
67
|
+
let currentDir = __dirname;
|
|
68
|
+
const specialDirs = ['dist', 'src', 'lib'];
|
|
69
|
+
// Check if we're in a special directory and move up if needed
|
|
70
|
+
const dirName = (0, node_path_1.basename)(currentDir);
|
|
71
|
+
if (specialDirs.includes(dirName)) {
|
|
72
|
+
currentDir = (0, node_path_1.resolve)(currentDir, '..');
|
|
73
|
+
}
|
|
74
|
+
// Handle the case where we might be in a deeper directory structure
|
|
75
|
+
const nodeModulesIndex = currentDir.indexOf('node_modules');
|
|
76
|
+
if (nodeModulesIndex > -1) {
|
|
77
|
+
currentDir = currentDir.substring(0, nodeModulesIndex);
|
|
78
|
+
}
|
|
79
|
+
return currentDir;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Determines if the path is specified relative to the current working directory
|
|
83
|
+
*/
|
|
84
|
+
isRelativePathFromCwd(path) {
|
|
85
|
+
return path.startsWith('./') || path.startsWith('../');
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Loads configuration and resolves secrets
|
|
89
|
+
* @param options Configuration options
|
|
90
|
+
* @returns ConfigService instance
|
|
91
|
+
*/
|
|
92
|
+
async load(options) {
|
|
93
|
+
const provider = await this.loadProvider(options);
|
|
94
|
+
const config = await this.loadConfigFiles(provider, options);
|
|
95
|
+
return new config_1.ConfigService(config);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Loads and merges configuration files, resolving secrets if a provider is available
|
|
99
|
+
* @param provider The instantiated secret provider
|
|
100
|
+
* @param options Configuration options
|
|
101
|
+
* @returns Merged configuration object
|
|
102
|
+
*/
|
|
103
|
+
async loadConfigFiles(provider, options) {
|
|
104
|
+
const { files, fileType = 'yaml' } = options;
|
|
105
|
+
// Resolve the base directory
|
|
106
|
+
const baseDirectory = this.resolveBaseDirectory(options.root);
|
|
107
|
+
if (!files.length) {
|
|
108
|
+
this.logger.warn('No configuration files specified');
|
|
109
|
+
return {};
|
|
110
|
+
}
|
|
111
|
+
let mergedConfig = {};
|
|
112
|
+
for (const filename of files) {
|
|
113
|
+
const filePath = (0, node_path_1.join)(baseDirectory, filename);
|
|
114
|
+
if ((0, node_fs_1.existsSync)(filePath)) {
|
|
115
|
+
try {
|
|
116
|
+
this.logger.debug(`Loading config from ${filePath}`);
|
|
117
|
+
const fileContent = (0, node_fs_1.readFileSync)(filePath, 'utf8');
|
|
118
|
+
let fileConfig;
|
|
119
|
+
if (fileType === 'yaml' || filename.endsWith('.yml') || filename.endsWith('.yaml')) {
|
|
120
|
+
fileConfig = yaml.load(fileContent);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
fileConfig = JSON.parse(fileContent);
|
|
124
|
+
}
|
|
125
|
+
// Merge with existing config, with the new config taking precedence
|
|
126
|
+
// Using lodash's merge function
|
|
127
|
+
mergedConfig = (0, lodash_1.merge)({}, mergedConfig, fileConfig);
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
this.logger.error(`Failed to load config from ${filePath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
this.logger.debug(`Config file not found: ${filePath}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Resolve secrets if provider is available
|
|
138
|
+
if (provider) {
|
|
139
|
+
await this.resolveSecrets(mergedConfig, '', provider);
|
|
140
|
+
}
|
|
141
|
+
return mergedConfig;
|
|
142
|
+
}
|
|
143
|
+
async loadProvider(options) {
|
|
144
|
+
if (typeof options.provider === 'object') {
|
|
145
|
+
return options.provider;
|
|
146
|
+
}
|
|
147
|
+
if (typeof options.provider === 'string' && options.client) {
|
|
148
|
+
return this.createSecretProvider(options.provider, options.client);
|
|
149
|
+
}
|
|
150
|
+
if (options.client) {
|
|
151
|
+
return this.createSecretProvider(options.client.constructor.name, options.client);
|
|
152
|
+
}
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Resolves the base directory for configuration files based on the provided configuration
|
|
157
|
+
* or defaults to the application's standard config directory
|
|
158
|
+
*/
|
|
159
|
+
resolveBaseDirectory(directoryPath) {
|
|
160
|
+
const appRoot = this.findAppRootDirectory();
|
|
161
|
+
// If no directory path is specified, use the default config location
|
|
162
|
+
if (!directoryPath) {
|
|
163
|
+
return this.resolveDefaultConfigDirectory(appRoot, 'config');
|
|
164
|
+
}
|
|
165
|
+
// If it's an absolute path, use it directly
|
|
166
|
+
if ((0, node_path_1.isAbsolute)(directoryPath)) {
|
|
167
|
+
return directoryPath;
|
|
168
|
+
}
|
|
169
|
+
// Resolve from the current working directory
|
|
170
|
+
if (this.isRelativePathFromCwd(directoryPath)) {
|
|
171
|
+
return (0, node_path_1.resolve)(process.cwd(), directoryPath);
|
|
172
|
+
}
|
|
173
|
+
// If it's just a directory name, resolve from app root
|
|
174
|
+
return (0, node_path_1.join)(appRoot, directoryPath);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Resolves the default configuration directory path and logs it
|
|
178
|
+
*/
|
|
179
|
+
resolveDefaultConfigDirectory(appRoot, configDir) {
|
|
180
|
+
configDir = (0, node_path_1.join)(appRoot, configDir);
|
|
181
|
+
this.logger.debug(`No base directory specified, using: ${configDir}`);
|
|
182
|
+
return configDir;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Recursively resolves secrets in configuration objects
|
|
186
|
+
*/
|
|
187
|
+
async resolveSecrets(config, path = '', secretProvider) {
|
|
188
|
+
for (const key in config) {
|
|
189
|
+
const fullPath = path ? `${path}.${key}` : key;
|
|
190
|
+
// Using lodash's isString and isObject
|
|
191
|
+
if ((0, lodash_1.isString)(config[key])) {
|
|
192
|
+
if (secretProvider.isSecretReference(config[key])) {
|
|
193
|
+
try {
|
|
194
|
+
config[key] = await secretProvider.resolveSecret(config[key]);
|
|
195
|
+
this.logger.debug(`Loaded secret from provider [${fullPath}]`);
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
this.logger.error(`Failed to load secret [${fullPath}]: ${error instanceof Error ? error.message : String(error)}`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
else if ((0, lodash_1.isObject)(config[key]) && !Array.isArray(config[key])) {
|
|
203
|
+
await this.resolveSecrets(config[key], fullPath, secretProvider);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
exports.SecretsLoaderService = SecretsLoaderService;
|
|
209
|
+
exports.SecretsLoaderService = SecretsLoaderService = SecretsLoaderService_1 = __decorate([
|
|
210
|
+
(0, common_1.Injectable)()
|
|
211
|
+
], SecretsLoaderService);
|
|
212
|
+
//# sourceMappingURL=secrets-loader.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets-loader.service.js","sourceRoot":"","sources":["../../src/services/secrets-loader.service.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAkD;AAClD,2CAA4D;AAC5D,qCAAiD;AACjD,gCAAgC;AAChC,yCAA8D;AAC9D,mCAAiD;AAIjD;;GAEG;AAEI,IAAM,oBAAoB,4BAA1B,MAAM,oBAAoB;IACZ,MAAM,GAAG,IAAI,eAAM,CAAC,sBAAoB,CAAC,IAAI,CAAC,CAAC;IAEhE;;;;OAIG;IACI,mBAAmB,CAAC,OAA6B;QACpD,OAAO,KAAK,IAAI,EAAE;YACd,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;YAClD,OAAO,MAAM,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACzD,CAAC,CAAC;IACN,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,oBAAoB,CAAC,GAAW,EAAE,MAAW;QAC/C,QAAQ,GAAG,EAAE,CAAC;YACV,KAAK,2BAA2B,CAAC;YACjC,KAAK,gBAAgB;gBACjB,MAAM,EAAC,yBAAyB,EAAC,GAAG,2CAAa,2CAA2C,EAAC,CAAC;gBAC9F,OAAO,IAAI,yBAAyB,CAAC,MAAM,CAAC,CAAC;YACjD,KAAK,2BAA2B,CAAC;YACjC,KAAK,WAAW;gBACZ,MAAM,EAAC,yBAAyB,EAAC,GAAG,2CAAa,2CAA2C,EAAC,CAAC;gBAC9F,OAAO,IAAI,yBAAyB,CAAC,MAAM,CAAC,CAAC;YACjD,KAAK,uBAAuB,CAAC;YAC7B,KAAK,cAAc;gBACf,MAAM,EAAC,qBAAqB,EAAC,GAAG,2CAAa,uCAAuC,EAAC,CAAC;gBACtF,OAAO,IAAI,qBAAqB,CAAC,MAAM,CAAC,C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