@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Michael De Soto | Flora Codex
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# NestJS Secrets: Effortless Cloud Secrets in Your NestJS Configuration
|
|
2
|
+
|
|
3
|
+
`NestJS Secrets` simplifies how you manage configuration and securely integrate secrets from cloud providers into your NestJS applications. It enhances NestJS's standard `ConfigModule` without reinventing the wheel, allowing you to keep sensitive data out of your codebase and easily handle environment-specific settings.
|
|
4
|
+
|
|
5
|
+
**For full documentation, please visit our [GitHub Wiki](https://github.com/floracodex/nestjs-secrets/wiki).**
|
|
6
|
+
|
|
7
|
+
## Key Features
|
|
8
|
+
|
|
9
|
+
* Load configuration from YAML or JSON files.
|
|
10
|
+
* Merge multiple configuration files with defined precedence.
|
|
11
|
+
* Resolve secrets directly from native identifiers of major cloud providers:
|
|
12
|
+
* [AWS Parameter Store](https://github.com/floracodex/nestjs-secrets/wiki/5.1.-Using-with-AWS-Parameter-Store)
|
|
13
|
+
* [AWS Secrets Manager](https://github.com/floracodex/nestjs-secrets/wiki/5.2.-Using-with-AWS-Secrets-Manager)
|
|
14
|
+
* [Azure Key Vault](https://github.com/floracodex/nestjs-secrets/wiki/5.3.-Using-with-Azure-Key-Vault)
|
|
15
|
+
* [Google Cloud Secret Manager](https://github.com/floracodex/nestjs-secrets/wiki/5.4.-Using-with-Google-Cloud-Secret-Manager)
|
|
16
|
+
* Extensible architecture to support custom secret providers.
|
|
17
|
+
* Seamless integration with the standard NestJS `ConfigService`.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @floracodex/nestjs-secrets @nestjs/config
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Requirements
|
|
26
|
+
|
|
27
|
+
* **Node.js:** `^18.x || ^20.x || ^22.x` (Node.js 18.x or newer is recommended, preferably an active LTS version as of May 2025)
|
|
28
|
+
* **NestJS:** Requires NestJS version `^10.0.0` or `^11.0.0`.
|
|
29
|
+
* `@nestjs/config`: Requires `@nestjs/config` version `^3.0.0` or `^4.0.0`.
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
### 1. Create a configuration file (e.g., `settings.yaml`):
|
|
34
|
+
|
|
35
|
+
```yaml
|
|
36
|
+
# settings.yaml
|
|
37
|
+
db:
|
|
38
|
+
host: db.example.com
|
|
39
|
+
# Example: Native ARN for an AWS Parameter Store secret
|
|
40
|
+
password: 'arn:aws:ssm:us-east-1:123456789012:parameter/myapplication/dev/db_password'
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 2. Import and configure `SecretsModule` in your `AppModule`:
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
// app.module.ts
|
|
47
|
+
import {Module} from '@nestjs/common';
|
|
48
|
+
import {SecretsModule} from '@floracodex/nestjs-secrets';
|
|
49
|
+
import {SSMClient} from '@aws-sdk/client-ssm'; // Example for AWS Parameter Store
|
|
50
|
+
|
|
51
|
+
@Module({
|
|
52
|
+
imports: [
|
|
53
|
+
SecretsModule.forRoot({
|
|
54
|
+
// Provide the SDK client for your secret provider
|
|
55
|
+
client: new SSMClient({region: 'us-east-1'}),
|
|
56
|
+
files: ['settings.yaml'],
|
|
57
|
+
isGlobal: true,
|
|
58
|
+
cache: true
|
|
59
|
+
})
|
|
60
|
+
]
|
|
61
|
+
})
|
|
62
|
+
export class AppModule {
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
_NestJS Secrets often auto-detects the provider from the client. See the [Cloud Provider Guides on our Wiki](https://github.com/floracodex/nestjs-secrets/wiki/5.-Cloud-Provider-Integration-Guides) for specifics._
|
|
67
|
+
|
|
68
|
+
### 3. Access configuration in your services:
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
// any.service.ts
|
|
72
|
+
import {Injectable} from '@nestjs/common';
|
|
73
|
+
import {ConfigService} from '@nestjs/config';
|
|
74
|
+
|
|
75
|
+
@Injectable()
|
|
76
|
+
export class AnyService {
|
|
77
|
+
constructor(private configService: ConfigService) {
|
|
78
|
+
const dbPassword = this.configService.get<string>('db.password');
|
|
79
|
+
// db.password now holds the resolved secret value
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
For more detailed examples and explanations, please see the [Basic Usage Guide on our Wiki](https://github.com/floracodex/nestjs-secrets/wiki/4.-Basic-Usage-Guide).
|
|
85
|
+
|
|
86
|
+
## Advanced Usage
|
|
87
|
+
`NestJS Secrets` also supports custom secret providers and manual configuration for more complex scenarios.
|
|
88
|
+
|
|
89
|
+
Learn more in the [Advanced Usage section of our Wiki](https://github.com/floracodex/nestjs-secrets/wiki/6.-Advanced-Usage).
|
|
90
|
+
|
|
91
|
+
## Contributing
|
|
92
|
+
We welcome contributions! If you'd like to report a bug, suggest a feature, or contribute code (especially new secret providers), please see our [Contributing Guidelines on the Wiki](https://github.com/floracodex/nestjs-secrets/wiki/7.-Contributing-Guidelines).
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
This project is licensed under the [MIT License](https://github.com/floracodex/nestjs-secrets/blob/main/LICENSE).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export * from './interfaces/secrets-loader-options.interface';
|
|
2
|
+
export * from './interfaces/secrets-module-options.interface';
|
|
3
|
+
export * from './interfaces/secrets-provider.interface';
|
|
4
|
+
export * from './modules/secrets.module';
|
|
5
|
+
export * from './services/secrets-loader.service';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./interfaces/secrets-loader-options.interface"), exports);
|
|
18
|
+
__exportStar(require("./interfaces/secrets-module-options.interface"), exports);
|
|
19
|
+
__exportStar(require("./interfaces/secrets-provider.interface"), exports);
|
|
20
|
+
__exportStar(require("./modules/secrets.module"), exports);
|
|
21
|
+
__exportStar(require("./services/secrets-loader.service"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gFAA8D;AAC9D,gFAA8D;AAC9D,0EAAwD;AACxD,2DAAyC;AACzC,oEAAkD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SecretsProvider, SecretsProviderType } from './secrets-provider.interface';
|
|
2
|
+
export interface SecretsLoaderOptions {
|
|
3
|
+
provider?: SecretsProviderType | SecretsProvider;
|
|
4
|
+
client?: any;
|
|
5
|
+
/**
|
|
6
|
+
* Base directory for config files (absolute or relative). If relative and not specified, defaults to
|
|
7
|
+
* <app_root>/config. If just a directory name is given (e.g. 'config'), it's resolved relative to app root
|
|
8
|
+
*/
|
|
9
|
+
root?: string;
|
|
10
|
+
files: string[];
|
|
11
|
+
fileType?: 'yaml' | 'json';
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets-loader-options.interface.js","sourceRoot":"","sources":["../../src/interfaces/secrets-loader-options.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets-module-options.interface.js","sourceRoot":"","sources":["../../src/interfaces/secrets-module-options.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for secret providers
|
|
3
|
+
*/
|
|
4
|
+
export declare abstract class SecretsProvider {
|
|
5
|
+
/**
|
|
6
|
+
* Checks if a string is a valid secret reference for this provider
|
|
7
|
+
* @param value The string to check
|
|
8
|
+
* @returns True if the string is a valid secret reference
|
|
9
|
+
*/
|
|
10
|
+
abstract isSecretReference(value: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Resolves a secret reference to its actual value.
|
|
13
|
+
* @param secretRef The reference to the secret
|
|
14
|
+
* @returns The resolved secret value (string or array of strings)
|
|
15
|
+
* @throws Error when the secret cannot be retrieved or has an invalid format
|
|
16
|
+
*/
|
|
17
|
+
abstract resolveSecret(secretRef: string): Promise<string | string[]>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The secret providers included with this library.
|
|
21
|
+
*
|
|
22
|
+
* Note: You can also use a custom provider by passing an instance of your provider class to the SecretsLoaderService.
|
|
23
|
+
* Open a PR or reach out to us at support@floracodex.com if you implement your own provider. We'd love to officially
|
|
24
|
+
* support it if it makes sense to add it to this list.
|
|
25
|
+
*/
|
|
26
|
+
export type SecretsProviderType = 'AwsParameterStoreProvider' | 'AwsSecretsManagerProvider' | 'AzureKeyVaultProvider' | 'GoogleSecretManagerProvider';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SecretsProvider = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Interface for secret providers
|
|
6
|
+
*/
|
|
7
|
+
class SecretsProvider {
|
|
8
|
+
}
|
|
9
|
+
exports.SecretsProvider = SecretsProvider;
|
|
10
|
+
//# sourceMappingURL=secrets-provider.interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets-provider.interface.js","sourceRoot":"","sources":["../../src/interfaces/secrets-provider.interface.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAsB,eAAe;CAepC;AAfD,0CAeC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
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 SecretsModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.SecretsModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const config_1 = require("@nestjs/config");
|
|
13
|
+
const secrets_loader_service_1 = require("../services/secrets-loader.service");
|
|
14
|
+
let SecretsModule = SecretsModule_1 = class SecretsModule {
|
|
15
|
+
static async forRoot(options) {
|
|
16
|
+
const secretsLoaderService = new secrets_loader_service_1.SecretsLoaderService();
|
|
17
|
+
const configFactory = secretsLoaderService.createConfigFactory(options);
|
|
18
|
+
return {
|
|
19
|
+
module: SecretsModule_1,
|
|
20
|
+
imports: [
|
|
21
|
+
await config_1.ConfigModule.forRoot({
|
|
22
|
+
...options,
|
|
23
|
+
load: [configFactory],
|
|
24
|
+
// Override any options that we handle ourselves
|
|
25
|
+
ignoreEnvFile: true
|
|
26
|
+
})
|
|
27
|
+
],
|
|
28
|
+
exports: [config_1.ConfigModule]
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
exports.SecretsModule = SecretsModule;
|
|
33
|
+
exports.SecretsModule = SecretsModule = SecretsModule_1 = __decorate([
|
|
34
|
+
(0, common_1.Global)(),
|
|
35
|
+
(0, common_1.Module)({})
|
|
36
|
+
], SecretsModule);
|
|
37
|
+
//# sourceMappingURL=secrets.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.module.js","sourceRoot":"","sources":["../../src/modules/secrets.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAA6D;AAC7D,2CAA4C;AAC5C,+EAAwE;AAKjE,IAAM,aAAa,qBAAnB,MAAM,aAAa;IACtB,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAA6B;QAC9C,MAAM,oBAAoB,GAAG,IAAI,6CAAoB,EAAE,CAAC;QACxD,MAAM,aAAa,GAAG,oBAAoB,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;QAExE,OAAO;YACH,MAAM,EAAE,eAAa;YACrB,OAAO,EAAE;gBACL,MAAM,qBAAY,CAAC,OAAO,CAAC;oBACvB,GAAG,OAAO;oBACV,IAAI,EAAE,CAAC,aAAa,CAAC;oBACrB,gDAAgD;oBAChD,aAAa,EAAE,IAAI;iBACtB,CAAC;aACL;YACD,OAAO,EAAE,CAAC,qBAAY,CAAC;SAC1B,CAAC;IACN,CAAC;CACJ,CAAA;AAlBY,sCAAa;wBAAb,aAAa;IAFzB,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,aAAa,CAkBzB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { SSMClient } from '@aws-sdk/client-ssm';
|
|
2
|
+
import { SecretsProvider } from '../interfaces/secrets-provider.interface';
|
|
3
|
+
export declare class AwsParameterStoreProvider implements SecretsProvider {
|
|
4
|
+
private readonly client;
|
|
5
|
+
private readonly logger;
|
|
6
|
+
/**
|
|
7
|
+
* Regular expression to validate AWS Parameter Store paths.
|
|
8
|
+
* Matches either:
|
|
9
|
+
* - Path format: /path/to/parameter
|
|
10
|
+
* - ARN format: arn:aws:ssm:region:account:parameter/path/to/parameter
|
|
11
|
+
*/
|
|
12
|
+
private readonly parameterPathPattern;
|
|
13
|
+
constructor(client: SSMClient);
|
|
14
|
+
/**
|
|
15
|
+
* Checks if a string is a valid Parameter Store reference.
|
|
16
|
+
* @param value The string to check
|
|
17
|
+
* @returns True if the string is a valid Parameter Store reference
|
|
18
|
+
*/
|
|
19
|
+
isSecretReference(value: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Resolves a Parameter Store reference to its actual value
|
|
22
|
+
* @param secretRef The reference to the secret in AWS Parameter Store
|
|
23
|
+
* @returns The resolved secret value as a string
|
|
24
|
+
* @throws Error when the secret cannot be retrieved or has an invalid format
|
|
25
|
+
*/
|
|
26
|
+
resolveSecret(secretRef: string): Promise<string | string[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves all parameters under a specific path.
|
|
29
|
+
* @param pathRef The parameter path reference ending with '/*'
|
|
30
|
+
* @returns Array of parameter values
|
|
31
|
+
*/
|
|
32
|
+
private retrieveParametersByPath;
|
|
33
|
+
/**
|
|
34
|
+
* Retrieves a single parameter by name.
|
|
35
|
+
* @param paramName The parameter name or ARN
|
|
36
|
+
* @returns The parameter value
|
|
37
|
+
*/
|
|
38
|
+
private retrieveSingleParameter;
|
|
39
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
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 AwsParameterStoreProvider_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.AwsParameterStoreProvider = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const client_ssm_1 = require("@aws-sdk/client-ssm");
|
|
16
|
+
let AwsParameterStoreProvider = AwsParameterStoreProvider_1 = class AwsParameterStoreProvider {
|
|
17
|
+
client;
|
|
18
|
+
logger = new common_1.Logger(AwsParameterStoreProvider_1.name);
|
|
19
|
+
/**
|
|
20
|
+
* Regular expression to validate AWS Parameter Store paths.
|
|
21
|
+
* Matches either:
|
|
22
|
+
* - Path format: /path/to/parameter
|
|
23
|
+
* - ARN format: arn:aws:ssm:region:account:parameter/path/to/parameter
|
|
24
|
+
*/
|
|
25
|
+
parameterPathPattern = /^(?:\/[a-zA-Z0-9_./-]+|arn:[a-z-]+:ssm:[a-z0-9-]+:\d{12}:parameter\/[a-zA-Z0-9_./-]+)$/;
|
|
26
|
+
constructor(client) {
|
|
27
|
+
this.client = client;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Checks if a string is a valid Parameter Store reference.
|
|
31
|
+
* @param value The string to check
|
|
32
|
+
* @returns True if the string is a valid Parameter Store reference
|
|
33
|
+
*/
|
|
34
|
+
isSecretReference(value) {
|
|
35
|
+
return this.parameterPathPattern.test(value);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Resolves a Parameter Store reference to its actual value
|
|
39
|
+
* @param secretRef The reference to the secret in AWS Parameter Store
|
|
40
|
+
* @returns The resolved secret value as a string
|
|
41
|
+
* @throws Error when the secret cannot be retrieved or has an invalid format
|
|
42
|
+
*/
|
|
43
|
+
async resolveSecret(secretRef) {
|
|
44
|
+
if (secretRef.endsWith('/*')) {
|
|
45
|
+
return await this.retrieveParametersByPath(secretRef);
|
|
46
|
+
}
|
|
47
|
+
return await this.retrieveSingleParameter(secretRef);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Retrieves all parameters under a specific path.
|
|
51
|
+
* @param pathRef The parameter path reference ending with '/*'
|
|
52
|
+
* @returns Array of parameter values
|
|
53
|
+
*/
|
|
54
|
+
async retrieveParametersByPath(pathRef) {
|
|
55
|
+
const basePath = pathRef.slice(0, -2);
|
|
56
|
+
const command = new client_ssm_1.GetParametersByPathCommand({
|
|
57
|
+
Path: basePath,
|
|
58
|
+
WithDecryption: true,
|
|
59
|
+
Recursive: true
|
|
60
|
+
});
|
|
61
|
+
const response = await this.client.send(command);
|
|
62
|
+
if (!response.Parameters || response.Parameters.length === 0) {
|
|
63
|
+
throw new Error(`No parameters found at path: ${basePath}`);
|
|
64
|
+
}
|
|
65
|
+
return response.Parameters.map((param) => {
|
|
66
|
+
if (!param.Value) {
|
|
67
|
+
this.logger.warn(`Parameter ${param.Name} has no value`);
|
|
68
|
+
return '';
|
|
69
|
+
}
|
|
70
|
+
return param.Value;
|
|
71
|
+
}).filter(Boolean);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Retrieves a single parameter by name.
|
|
75
|
+
* @param paramName The parameter name or ARN
|
|
76
|
+
* @returns The parameter value
|
|
77
|
+
*/
|
|
78
|
+
async retrieveSingleParameter(paramName) {
|
|
79
|
+
const command = new client_ssm_1.GetParameterCommand({
|
|
80
|
+
Name: paramName,
|
|
81
|
+
WithDecryption: true
|
|
82
|
+
});
|
|
83
|
+
const response = await this.client.send(command);
|
|
84
|
+
if (!response.Parameter) {
|
|
85
|
+
throw new Error(`Parameter not found: ${paramName}`);
|
|
86
|
+
}
|
|
87
|
+
if (!response.Parameter.Value) {
|
|
88
|
+
throw new Error(`Parameter value is empty for: ${paramName}`);
|
|
89
|
+
}
|
|
90
|
+
return response.Parameter.Value;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
exports.AwsParameterStoreProvider = AwsParameterStoreProvider;
|
|
94
|
+
exports.AwsParameterStoreProvider = AwsParameterStoreProvider = AwsParameterStoreProvider_1 = __decorate([
|
|
95
|
+
(0, common_1.Injectable)(),
|
|
96
|
+
__metadata("design:paramtypes", [client_ssm_1.SSMClient])
|
|
97
|
+
], AwsParameterStoreProvider);
|
|
98
|
+
//# sourceMappingURL=aws-parameter-store.provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aws-parameter-store.provider.js","sourceRoot":"","sources":["../../src/providers/aws-parameter-store.provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAkD;AAClD,oDAA0G;AAInG,IAAM,yBAAyB,iCAA/B,MAAM,yBAAyB;IAWL;IAVZ,MAAM,GAAG,IAAI,eAAM,CAAC,2BAAyB,CAAC,IAAI,CAAC,CAAC;IAErE;;;;;OAKG;IACc,oBAAoB,GAAG,wFAAwF,CAAC;IAEjI,YAA6B,MAAiB;QAAjB,WAAM,GAAN,MAAM,CAAW;IAC9C,CAAC;IAED;;;;OAIG;IACH,iBAAiB,CAAC,KAAa;QAC3B,OAAO,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACjD,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,aAAa,CAAC,SAAiB;QACjC,IAAI,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3B,OAAO,MAAM,IAAI,CAAC,wBAAwB,CAAC,SAAS,CAAC,CAAC;QAC1D,CAAC;QAED,OAAO,MAAM,IAAI,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;IACzD,CAAC;IAED;;;;OAIG;IACK,KAAK,CAAC,wBAAwB,CAAC,OAAe;QAClD,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAEtC,MAAM,OAAO,GAAG,IAAI,uCAA0B,CAAC;YAC3C,IAAI,EAAE,QAAQ;YACd,cAAc,EAAE,IAAI;YACpB,SAAS,EAAE,IAAI;SAClB,CAAC,CAAC;QAEH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAEjD,IAAI,CAAC,QAAQ,CAAC,UAAU,IAAI,QAAQ,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3D,MAAM,IAAI,KAAK,CAAC,gCAAgC,QAAQ,EAAE,CAAC,CAAC;QAChE,CAAC;QAED,OAAO,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,KAAgB,EAAE,EAAE;YAChD,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,KAAK,CAAC,IAAI,eAAe,CAAC,CAAC;gBACzD,OAAO,EAAE,CAAC;YACd,CAAC;YACD,OAAO,KAAK,CAAC,KAAK,CAAC;QACvB,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACK,KAAK,CAAC,uBAAuB,CAAC,SAAiB;QACnD,MAAM,OAAO,GAAG,IAAI,gCAAmB,CAAC;YACpC,IAAI,EAAE,SAAS;YACf,cAAc,EAAE,IAAI;SACvB,CAAC,CAAC;QAEH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAEjD,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,wBAAwB,SAAS,EAAE,CAAC,CAAC;QACzD,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,iCAAiC,SAAS,EAAE,CAAC,CAAC;QAClE,CAAC;QAED,OAAO,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC;IACpC,CAAC;CACJ,CAAA;AAzFY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,mBAAU,GAAE;qCAY4B,sBAAS;GAXrC,yBAAyB,CAyFrC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { SecretsManager } from '@aws-sdk/client-secrets-manager';
|
|
2
|
+
import { SecretsProvider } from '../interfaces/secrets-provider.interface';
|
|
3
|
+
export declare class AwsSecretsManagerProvider implements SecretsProvider {
|
|
4
|
+
private readonly client;
|
|
5
|
+
private readonly logger;
|
|
6
|
+
/**
|
|
7
|
+
* Regular expression pattern for validating AWS Secrets Manager ARNs
|
|
8
|
+
*/
|
|
9
|
+
private readonly arnPattern;
|
|
10
|
+
constructor(client: SecretsManager);
|
|
11
|
+
/**
|
|
12
|
+
* Checks if a string is a valid AWS Secrets Manager ARN.
|
|
13
|
+
* @param value The string to check
|
|
14
|
+
* @returns True if the string is a valid AWS Secrets Manager ARN
|
|
15
|
+
*/
|
|
16
|
+
isSecretReference(value: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Resolves an AWS Secrets Manager ARN to its actual value
|
|
19
|
+
* @param secretRef The AWS Secrets Manager ARN
|
|
20
|
+
* @returns The resolved secret value as a string
|
|
21
|
+
* @throws Error when the secret cannot be retrieved or has an invalid format
|
|
22
|
+
*/
|
|
23
|
+
resolveSecret(secretRef: string): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Decodes a binary secret to a string.
|
|
26
|
+
* @param binaryData The binary data to decode
|
|
27
|
+
* @returns The decoded string
|
|
28
|
+
*/
|
|
29
|
+
private decodeBinarySecret;
|
|
30
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 AwsSecretsManagerProvider_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.AwsSecretsManagerProvider = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const client_secrets_manager_1 = require("@aws-sdk/client-secrets-manager");
|
|
16
|
+
let AwsSecretsManagerProvider = AwsSecretsManagerProvider_1 = class AwsSecretsManagerProvider {
|
|
17
|
+
client;
|
|
18
|
+
logger = new common_1.Logger(AwsSecretsManagerProvider_1.name);
|
|
19
|
+
/**
|
|
20
|
+
* Regular expression pattern for validating AWS Secrets Manager ARNs
|
|
21
|
+
*/
|
|
22
|
+
arnPattern = /^arn:aws:secretsmanager:[a-z0-9-]+:[0-9]+:secret:.+$/;
|
|
23
|
+
constructor(client) {
|
|
24
|
+
this.client = client;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Checks if a string is a valid AWS Secrets Manager ARN.
|
|
28
|
+
* @param value The string to check
|
|
29
|
+
* @returns True if the string is a valid AWS Secrets Manager ARN
|
|
30
|
+
*/
|
|
31
|
+
isSecretReference(value) {
|
|
32
|
+
return this.arnPattern.test(value);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Resolves an AWS Secrets Manager ARN to its actual value
|
|
36
|
+
* @param secretRef The AWS Secrets Manager ARN
|
|
37
|
+
* @returns The resolved secret value as a string
|
|
38
|
+
* @throws Error when the secret cannot be retrieved or has an invalid format
|
|
39
|
+
*/
|
|
40
|
+
async resolveSecret(secretRef) {
|
|
41
|
+
const response = await this.client.getSecretValue({ SecretId: secretRef });
|
|
42
|
+
if (response.SecretString) {
|
|
43
|
+
return response.SecretString;
|
|
44
|
+
}
|
|
45
|
+
else if (response.SecretBinary) {
|
|
46
|
+
return this.decodeBinarySecret(response.SecretBinary);
|
|
47
|
+
}
|
|
48
|
+
throw new Error('Secret value is empty');
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Decodes a binary secret to a string.
|
|
52
|
+
* @param binaryData The binary data to decode
|
|
53
|
+
* @returns The decoded string
|
|
54
|
+
*/
|
|
55
|
+
decodeBinarySecret(binaryData) {
|
|
56
|
+
const buff = Buffer.from(binaryData, 'base64');
|
|
57
|
+
return buff.toString('utf8');
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
exports.AwsSecretsManagerProvider = AwsSecretsManagerProvider;
|
|
61
|
+
exports.AwsSecretsManagerProvider = AwsSecretsManagerProvider = AwsSecretsManagerProvider_1 = __decorate([
|
|
62
|
+
(0, common_1.Injectable)(),
|
|
63
|
+
__metadata("design:paramtypes", [client_secrets_manager_1.SecretsManager])
|
|
64
|
+
], AwsSecretsManagerProvider);
|
|
65
|
+
//# sourceMappingURL=aws-secrets-manager.provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aws-secrets-manager.provider.js","sourceRoot":"","sources":["../../src/providers/aws-secrets-manager.provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAkD;AAClD,4EAA+D;AAIxD,IAAM,yBAAyB,iCAA/B,MAAM,yBAAyB;IAQL;IAPZ,MAAM,GAAG,IAAI,eAAM,CAAC,2BAAyB,CAAC,IAAI,CAAC,CAAC;IAErE;;OAEG;IACc,UAAU,GAAG,sDAAsD,CAAC;IAErF,YAA6B,MAAsB;QAAtB,WAAM,GAAN,MAAM,CAAgB;IACnD,CAAC;IAED;;;;OAIG;IACH,iBAAiB,CAAC,KAAa;QAC3B,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,aAAa,CAAC,SAAiB;QACjC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,EAAC,QAAQ,EAAE,SAAS,EAAC,CAAC,CAAC;QAEzE,IAAI,QAAQ,CAAC,YAAY,EAAE,CAAC;YACxB,OAAO,QAAQ,CAAC,YAAY,CAAC;QACjC,CAAC;aAAM,IAAI,QAAQ,CAAC,YAAY,EAAE,CAAC;YAC/B,OAAO,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;QAC1D,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC7C,CAAC;IAED;;;;OAIG;IACK,kBAAkB,CAAC,UAAe;QACtC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,UAA+B,EAAE,QAAQ,CAAC,CAAC;QACpE,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;CAEJ,CAAA;AAhDY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,mBAAU,GAAE;qCAS4B,uCAAc;GAR1C,yBAAyB,CAgDrC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { SecretClient } from '@azure/keyvault-secrets';
|
|
2
|
+
import { SecretsProvider } from '../interfaces/secrets-provider.interface';
|
|
3
|
+
export declare class AzureKeyVaultProvider implements SecretsProvider {
|
|
4
|
+
private readonly client;
|
|
5
|
+
private readonly logger;
|
|
6
|
+
/**
|
|
7
|
+
* Regular expression to validate Azure Vault paths.
|
|
8
|
+
* - Standard format: https://<vault-name>.vault.azure.net/secrets/<secret-name>
|
|
9
|
+
* - With versions: https://<vault-name>.vault.azure.net/secrets/<secret-name>/<version>
|
|
10
|
+
* - With paths in secret names: https://<vault-name>.vault.azure.net/secrets/<path>/<secret-name>
|
|
11
|
+
*/
|
|
12
|
+
private readonly secretUrlPattern;
|
|
13
|
+
constructor(client: SecretClient);
|
|
14
|
+
/**
|
|
15
|
+
* Checks if the provided string is a valid Azure Key Vault secret reference.
|
|
16
|
+
* @param value The string to check
|
|
17
|
+
* @returns True if the string is a valid Azure Key Vault secret reference
|
|
18
|
+
*/
|
|
19
|
+
isSecretReference(value: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Resolves an Azure Key Vault secret reference to its actual value.
|
|
22
|
+
* @param secretRef The reference URL to the secret (https://<vault-name>.vault.azure.net/secrets/<secret-name>[/<version>])
|
|
23
|
+
* @returns The resolved secret value as a string
|
|
24
|
+
* @throws Error when the secret reference is invalid or cannot be retrieved
|
|
25
|
+
*/
|
|
26
|
+
resolveSecret(secretRef: string): Promise<string>;
|
|
27
|
+
/**
|
|
28
|
+
* Parses an Azure Key Vault secret reference and extracts the secret name.
|
|
29
|
+
* @param secretRef The Azure Key Vault secret reference URL
|
|
30
|
+
* @returns The extracted secret name
|
|
31
|
+
* @throws Error when the secret reference format is invalid
|
|
32
|
+
*/
|
|
33
|
+
private parseSecretReference;
|
|
34
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
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 AzureKeyVaultProvider_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.AzureKeyVaultProvider = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const keyvault_secrets_1 = require("@azure/keyvault-secrets");
|
|
16
|
+
let AzureKeyVaultProvider = AzureKeyVaultProvider_1 = class AzureKeyVaultProvider {
|
|
17
|
+
client;
|
|
18
|
+
logger = new common_1.Logger(AzureKeyVaultProvider_1.name);
|
|
19
|
+
/**
|
|
20
|
+
* Regular expression to validate Azure Vault paths.
|
|
21
|
+
* - Standard format: https://<vault-name>.vault.azure.net/secrets/<secret-name>
|
|
22
|
+
* - With versions: https://<vault-name>.vault.azure.net/secrets/<secret-name>/<version>
|
|
23
|
+
* - With paths in secret names: https://<vault-name>.vault.azure.net/secrets/<path>/<secret-name>
|
|
24
|
+
*/
|
|
25
|
+
secretUrlPattern = /^https:\/\/[\w-]+\.vault\.azure\.net\/secrets\/([^/\s]+)(?:\/([^/\s]+))?$/;
|
|
26
|
+
constructor(client) {
|
|
27
|
+
this.client = client;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Checks if the provided string is a valid Azure Key Vault secret reference.
|
|
31
|
+
* @param value The string to check
|
|
32
|
+
* @returns True if the string is a valid Azure Key Vault secret reference
|
|
33
|
+
*/
|
|
34
|
+
isSecretReference(value) {
|
|
35
|
+
return this.secretUrlPattern.test(value);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Resolves an Azure Key Vault secret reference to its actual value.
|
|
39
|
+
* @param secretRef The reference URL to the secret (https://<vault-name>.vault.azure.net/secrets/<secret-name>[/<version>])
|
|
40
|
+
* @returns The resolved secret value as a string
|
|
41
|
+
* @throws Error when the secret reference is invalid or cannot be retrieved
|
|
42
|
+
*/
|
|
43
|
+
async resolveSecret(secretRef) {
|
|
44
|
+
const secretName = this.parseSecretReference(secretRef);
|
|
45
|
+
const response = await this.client.getSecret(secretName);
|
|
46
|
+
if (!response || !response.value) {
|
|
47
|
+
throw new Error(`Secret '${secretName}' was retrieved but has an empty value`);
|
|
48
|
+
}
|
|
49
|
+
return response.value;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Parses an Azure Key Vault secret reference and extracts the secret name.
|
|
53
|
+
* @param secretRef The Azure Key Vault secret reference URL
|
|
54
|
+
* @returns The extracted secret name
|
|
55
|
+
* @throws Error when the secret reference format is invalid
|
|
56
|
+
*/
|
|
57
|
+
parseSecretReference(secretRef) {
|
|
58
|
+
const match = secretRef.match(this.secretUrlPattern);
|
|
59
|
+
if (!match) {
|
|
60
|
+
throw new Error(`Invalid Azure Key Vault secret reference: ${secretRef}. Expected format: https://<vault-name>.vault.azure.net/secrets/<secret-name>[/<version>]`);
|
|
61
|
+
}
|
|
62
|
+
// Extract the vault name (match[0]) and secret name (match[1])
|
|
63
|
+
const vaultName = match[0];
|
|
64
|
+
const secretName = match[1];
|
|
65
|
+
this.logger.debug(`Parsed secret reference from vault: ${vaultName}, secret: ${secretName}`);
|
|
66
|
+
return secretName;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
exports.AzureKeyVaultProvider = AzureKeyVaultProvider;
|
|
70
|
+
exports.AzureKeyVaultProvider = AzureKeyVaultProvider = AzureKeyVaultProvider_1 = __decorate([
|
|
71
|
+
(0, common_1.Injectable)(),
|
|
72
|
+
__metadata("design:paramtypes", [keyvault_secrets_1.SecretClient])
|
|
73
|
+
], AzureKeyVaultProvider);
|
|
74
|
+
//# sourceMappingURL=azure-key-vault.provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"azure-key-vault.provider.js","sourceRoot":"","sources":["../../src/providers/azure-key-vault.provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAkD;AAClD,8DAAqD;AAI9C,IAAM,qBAAqB,6BAA3B,MAAM,qBAAqB;IAWD;IAVZ,MAAM,GAAG,IAAI,eAAM,CAAC,uBAAqB,CAAC,IAAI,CAAC,CAAC;IAEjE;;;;;OAKG;IACc,gBAAgB,GAAG,2EAA2E,CAAC;IAEhH,YAA6B,MAAoB;QAApB,WAAM,GAAN,MAAM,CAAc;IACjD,CAAC;IAED;;;;OAIG;IACH,iBAAiB,CAAC,KAAa;QAC3B,OAAO,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,aAAa,CAAC,SAAiB;QACjC,MAAM,UAAU,GAAG,IAAI,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC;QAExD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAEzD,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,WAAW,UAAU,wCAAwC,CAAC,CAAC;QACnF,CAAC;QAED,OAAO,QAAQ,CAAC,KAAK,CAAC;IAC1B,CAAC;IAED;;;;;OAKG;IACK,oBAAoB,CAAC,SAAiB;QAC1C,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAErD,IAAI,CAAC,KAAK,EAAE,CAAC;YACT,MAAM,IAAI,KAAK,CAAC,6CAA6C,SAAS,2FAA2F,CAAC,CAAC;QACvK,CAAC;QAED,+DAA+D;QAC/D,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QAC3B,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QAE5B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,uCAAuC,SAAS,aAAa,UAAU,EAAE,CAAC,CAAC;QAC7F,OAAO,UAAU,CAAC;IACtB,CAAC;CAEJ,CAAA;AA9DY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,mBAAU,GAAE;qCAY4B,+BAAY;GAXxC,qBAAqB,CA8DjC"}
|