env-secrets 0.1.10 → 0.3.0
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/.devcontainer/devcontainer.json +33 -0
- package/.dockerignore +9 -0
- package/.eslintignore +4 -2
- package/.github/dependabot.yml +4 -0
- package/.github/workflows/build-main.yml +6 -2
- package/.github/workflows/deploy-docs.yml +50 -0
- package/.github/workflows/e2e-tests.yaml +54 -0
- package/.github/workflows/lint.yaml +6 -2
- package/.github/workflows/release.yml +13 -3
- package/.github/workflows/snyk.yaml +5 -1
- package/.github/workflows/unittests.yaml +18 -6
- package/.lintstagedrc +2 -7
- package/.prettierignore +6 -0
- package/AGENTS.md +149 -0
- package/Dockerfile +14 -0
- package/README.md +507 -36
- package/__e2e__/README.md +160 -0
- package/__e2e__/index.test.ts +339 -0
- package/__e2e__/setup.ts +58 -0
- package/__e2e__/utils/debug-logger.ts +45 -0
- package/__e2e__/utils/test-utils.ts +645 -0
- package/__tests__/index.test.ts +573 -31
- package/__tests__/vaults/secretsmanager.test.ts +460 -0
- package/__tests__/vaults/utils.test.ts +183 -0
- package/__tests__/version.test.ts +8 -0
- package/dist/index.js +36 -10
- package/dist/vaults/secretsmanager.js +44 -43
- package/dist/vaults/utils.js +2 -2
- package/docker-compose.yaml +29 -0
- package/docs/AWS.md +257 -0
- package/jest.config.js +4 -1
- package/jest.e2e.config.js +8 -0
- package/package.json +18 -10
- package/src/index.ts +44 -10
- package/src/vaults/secretsmanager.ts +48 -48
- package/src/vaults/utils.ts +6 -4
- package/website/docs/advanced-usage.mdx +399 -0
- package/website/docs/best-practices.mdx +416 -0
- package/website/docs/cli-reference.mdx +204 -0
- package/website/docs/examples.mdx +960 -0
- package/website/docs/faq.mdx +302 -0
- package/website/docs/index.mdx +56 -0
- package/website/docs/installation.mdx +30 -0
- package/website/docs/overview.mdx +17 -0
- package/website/docs/production-deployment.mdx +622 -0
- package/website/docs/providers/aws-secrets-manager.mdx +28 -0
- package/website/docs/security.mdx +122 -0
- package/website/docs/troubleshooting.mdx +236 -0
- package/website/docs/tutorials/local-dev/devcontainer-localstack.mdx +31 -0
- package/website/docs/tutorials/local-dev/docker-compose.mdx +22 -0
- package/website/docs/tutorials/local-dev/nextjs.mdx +18 -0
- package/website/docs/tutorials/local-dev/node-python-go.mdx +39 -0
- package/website/docs/tutorials/local-dev/quickstart.mdx +23 -0
- package/website/docusaurus.config.ts +89 -0
- package/website/package.json +21 -0
- package/website/sidebars.ts +33 -0
- package/website/src/css/custom.css +1 -0
- package/website/static/img/env-secrets.png +0 -0
- package/website/static/img/favicon.ico +0 -0
- package/website/static/img/logo.svg +4 -0
- package/website/yarn.lock +8764 -0
package/README.md
CHANGED
|
@@ -1,133 +1,600 @@
|
|
|
1
1
|
# env-secrets
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A Node.js CLI tool that retrieves secrets from vaults and injects them as environment variables into your running applications.
|
|
4
4
|
|
|
5
5
|
[](https://npmjs.org/package/env-secrets)
|
|
6
6
|
[](https://github.com/markcallen/env-secrets/tree/main)
|
|
7
7
|
[](https://github.com/markcallen/env-secrets/tree/main)
|
|
8
8
|
[](https://npmjs.org/package/env-secrets)
|
|
9
9
|
[](https://github.com/markcallen/env-secrets/blob/main/LICENSE)
|
|
10
|
+
[](https://markcallen.github.io/env-secrets/)
|
|
10
11
|
|
|
11
|
-
##
|
|
12
|
+
## Features
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
- 🔐 Retrieve secrets from AWS Secrets Manager
|
|
15
|
+
- 🌍 Inject secrets as environment variables
|
|
16
|
+
- 📁 Output secrets to file with secure permissions (0400)
|
|
17
|
+
- 🚀 Run any command with injected secrets
|
|
18
|
+
- 🔍 Debug logging support
|
|
19
|
+
- 📦 Works globally or project-specific
|
|
20
|
+
- 🛡️ Secure credential handling
|
|
21
|
+
- 🔄 JSON secret parsing
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
1. **Install the tool:**
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install -g env-secrets
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
2. **Run a command with secrets:**
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
env-secrets aws -s my-secret-name -r us-east-1 -- echo "Hello, ${USER_NAME}!"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
3. **Run your application with secrets:**
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
env-secrets aws -s my-app-secrets -r us-west-2 -- node app.js
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
4. **Output secrets to a file:**
|
|
44
|
+
```bash
|
|
45
|
+
env-secrets aws -s my-app-secrets -r us-west-2 -o secrets.env
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Prerequisites
|
|
49
|
+
|
|
50
|
+
- Node.js 18.0.0 or higher
|
|
51
|
+
- AWS CLI (for AWS Secrets Manager integration)
|
|
52
|
+
- AWS credentials configured (via AWS CLI, environment variables, or IAM roles)
|
|
14
53
|
|
|
15
54
|
## Installation
|
|
16
55
|
|
|
17
|
-
|
|
56
|
+
### Global Installation
|
|
18
57
|
|
|
19
|
-
```
|
|
58
|
+
```bash
|
|
20
59
|
npm install -g env-secrets
|
|
21
60
|
```
|
|
22
61
|
|
|
23
|
-
Project
|
|
62
|
+
### Project-Specific Installation
|
|
24
63
|
|
|
25
|
-
```
|
|
64
|
+
```bash
|
|
26
65
|
npm install env-secrets
|
|
27
66
|
```
|
|
28
67
|
|
|
29
|
-
|
|
68
|
+
When using project-specific installation, run using `npx`:
|
|
30
69
|
|
|
31
|
-
```
|
|
70
|
+
```bash
|
|
32
71
|
npx env-secrets ...
|
|
33
72
|
```
|
|
34
73
|
|
|
35
74
|
## Usage
|
|
36
75
|
|
|
37
|
-
AWS
|
|
76
|
+
For detailed AWS setup instructions, see [AWS Configuration Guide](docs/AWS.md).
|
|
77
|
+
|
|
78
|
+
### AWS Secrets Manager
|
|
38
79
|
|
|
80
|
+
Retrieve secrets from AWS Secrets Manager and inject them as environment variables:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
env-secrets aws -s <secret-name> -r <region> -p <profile> [-- <program-to-run>] [-o <output-file>]
|
|
39
84
|
```
|
|
40
|
-
|
|
85
|
+
|
|
86
|
+
#### Quick Example
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
# Create a secret
|
|
90
|
+
aws secretsmanager create-secret \
|
|
91
|
+
--name my-app-secrets \
|
|
92
|
+
--secret-string '{"DATABASE_URL":"postgres://user:pass@localhost:5432/db","API_KEY":"abc123"}'
|
|
93
|
+
|
|
94
|
+
# Use the secret in your application
|
|
95
|
+
env-secrets aws -s my-app-secrets -r us-east-1 -- node app.js
|
|
41
96
|
```
|
|
42
97
|
|
|
43
|
-
|
|
98
|
+
#### Parameters
|
|
44
99
|
|
|
45
|
-
|
|
100
|
+
- `-s, --secret <secret-name>` (required): The name of the secret in AWS Secrets Manager
|
|
101
|
+
- `-r, --region <region>` (optional): AWS region where the secret is stored. If not provided, uses `AWS_DEFAULT_REGION` environment variable
|
|
102
|
+
- `-p, --profile <profile>` (optional): Local AWS profile to use. If not provided, uses `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables
|
|
103
|
+
- `-o, --output <file>` (optional): Output secrets to a file instead of injecting into environment variables. File will be created with 0400 permissions and will not overwrite existing files
|
|
104
|
+
- `-- <program-to-run>`: The program to run with the injected environment variables (only used when `-o` is not specified)
|
|
46
105
|
|
|
47
|
-
|
|
106
|
+
#### Examples
|
|
48
107
|
|
|
49
|
-
|
|
108
|
+
1. **Create a secret using AWS CLI:**
|
|
50
109
|
|
|
51
|
-
|
|
110
|
+
Using a profile:
|
|
52
111
|
|
|
112
|
+
```bash
|
|
113
|
+
aws secretsmanager create-secret \
|
|
114
|
+
--region us-east-1 \
|
|
115
|
+
--profile testuser \
|
|
116
|
+
--name local/sample \
|
|
117
|
+
--description "local/sample secret" \
|
|
118
|
+
--secret-string "{\"user\":\"testuser\",\"password\":\"mypassword\"}"
|
|
53
119
|
```
|
|
120
|
+
|
|
121
|
+
Using env vars
|
|
122
|
+
|
|
123
|
+
```bash
|
|
54
124
|
aws secretsmanager create-secret \
|
|
55
125
|
--region us-east-1 \
|
|
56
|
-
--profile marka \
|
|
57
126
|
--name local/sample \
|
|
58
127
|
--description "local/sample secret" \
|
|
59
128
|
--secret-string "{\"user\":\"marka\",\"password\":\"mypassword\"}"
|
|
60
129
|
```
|
|
61
130
|
|
|
62
|
-
List the secret using AWS
|
|
131
|
+
2. **List the secret using AWS CLI:**
|
|
63
132
|
|
|
64
|
-
|
|
133
|
+
Using a profile:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
65
136
|
aws secretsmanager get-secret-value \
|
|
66
137
|
--region us-east-1 \
|
|
67
138
|
--profile marka \
|
|
68
|
-
--secret-id
|
|
139
|
+
--secret-id local/sample \
|
|
69
140
|
--query SecretString
|
|
70
141
|
```
|
|
71
142
|
|
|
143
|
+
Using env vars:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
aws secretsmanager get-secret-value \
|
|
147
|
+
--region us-east-1 \
|
|
148
|
+
--secret-id local/sample \
|
|
149
|
+
--query SecretString
|
|
72
150
|
```
|
|
151
|
+
|
|
152
|
+
3. **Run a command with injected secrets:**
|
|
153
|
+
|
|
154
|
+
Using a profile:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
73
157
|
env-secrets aws -s local/sample -r us-east-1 -p marka -- echo \${user}/\${password}
|
|
74
158
|
```
|
|
75
159
|
|
|
76
|
-
|
|
160
|
+
Using env vars:
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
env-secrets aws -s local/sample -r us-east-1 -- echo \${user}/\${password}
|
|
164
|
+
```
|
|
77
165
|
|
|
78
|
-
|
|
166
|
+
4. **Run a Node.js application with secrets:**
|
|
79
167
|
|
|
168
|
+
```bash
|
|
169
|
+
env-secrets aws -s my-app-secrets -r us-west-2 -- node app.js
|
|
80
170
|
```
|
|
81
|
-
|
|
171
|
+
|
|
172
|
+
5. **Check environment variables:**
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
env-secrets aws -s local/sample -r us-east-1 -p marka -- env | grep -E "(user|password)"
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
6. **Use with Docker containers:**
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
env-secrets aws -s docker-secrets -r us-east-1 -- docker run -e DATABASE_URL -e API_KEY my-app
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
7. **Output secrets to a file:**
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
# Output secrets to a file (file will have 0400 permissions)
|
|
188
|
+
env-secrets aws -s my-app-secrets -r us-east-1 -o secrets.env
|
|
189
|
+
|
|
190
|
+
# The file will contain export statements like:
|
|
191
|
+
# export DATABASE_URL=postgres://user:pass@localhost:5432/db
|
|
192
|
+
# export API_KEY=abc123
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
8. **File output with profile:**
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
env-secrets aws -s my-secret -r us-east-1 -p my-profile -o /tmp/secrets.env
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
9. **File output prevents overwriting existing files:**
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
# First run - creates the file
|
|
205
|
+
env-secrets aws -s my-secret -r us-east-1 -o secrets.env
|
|
206
|
+
|
|
207
|
+
# Second run - will fail with error message
|
|
208
|
+
env-secrets aws -s my-secret -r us-east-1 -o secrets.env
|
|
209
|
+
# Error: File secrets.env already exists and will not be overwritten
|
|
82
210
|
```
|
|
83
211
|
|
|
84
|
-
|
|
212
|
+
## Security Considerations
|
|
213
|
+
|
|
214
|
+
- 🔐 **Credential Management**: The tool respects AWS credential precedence (environment variables, IAM roles, profiles)
|
|
215
|
+
- 🛡️ **Secret Exposure**: Secrets are only injected into the child process environment, not logged
|
|
216
|
+
- 🔒 **Network Security**: Uses AWS SDK's built-in security features for API calls
|
|
217
|
+
- 📝 **Audit Trail**: AWS CloudTrail logs all Secrets Manager API calls
|
|
218
|
+
- 🚫 **No Persistence**: Secrets are not stored locally or cached (unless using `-o` flag)
|
|
219
|
+
- 📁 **File Security**: When using `-o` flag, files are created with 0400 permissions (read-only for owner) and existing files are never overwritten
|
|
220
|
+
|
|
221
|
+
## Troubleshooting
|
|
222
|
+
|
|
223
|
+
### Common Issues
|
|
224
|
+
|
|
225
|
+
1. **"Unable to connect to AWS"**
|
|
226
|
+
|
|
227
|
+
- Verify AWS credentials are configured correctly
|
|
228
|
+
- Check if the specified region is valid
|
|
229
|
+
- Ensure network connectivity to AWS services
|
|
230
|
+
|
|
231
|
+
2. **"Secret not found"**
|
|
232
|
+
|
|
233
|
+
- Verify the secret name exists in the specified region
|
|
234
|
+
- Check if you have permissions to access the secret
|
|
235
|
+
- Ensure the secret name is correct (case-sensitive)
|
|
236
|
+
|
|
237
|
+
3. **"ConfigError"**
|
|
238
|
+
|
|
239
|
+
- Verify AWS profile configuration in `~/.aws/credentials`
|
|
240
|
+
- Check if environment variables are set correctly
|
|
241
|
+
- Ensure IAM role permissions if using EC2/ECS
|
|
242
|
+
|
|
243
|
+
4. **Environment variables not injected**
|
|
244
|
+
- Verify the secret contains valid JSON
|
|
245
|
+
- Check if the secret is accessible
|
|
246
|
+
- Use debug mode to troubleshoot: `DEBUG=env-secrets env-secrets aws ...`
|
|
247
|
+
|
|
248
|
+
### Debug Mode
|
|
249
|
+
|
|
250
|
+
Enable debug logging to troubleshoot issues:
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
# Debug main application
|
|
254
|
+
DEBUG=env-secrets env-secrets aws -s my-secret -r us-east-1 -- env
|
|
85
255
|
|
|
256
|
+
# Debug vault-specific operations
|
|
257
|
+
DEBUG=env-secrets,env-secrets:secretsmanager env-secrets aws -s my-secret -r us-east-1 -- env
|
|
86
258
|
```
|
|
87
|
-
|
|
259
|
+
|
|
260
|
+
## Documentation
|
|
261
|
+
|
|
262
|
+
The docs site (Docusaurus) lives under [`website/`](./website). Run it locally:
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
cd website
|
|
266
|
+
npm install
|
|
267
|
+
npm run start
|
|
88
268
|
```
|
|
89
269
|
|
|
90
|
-
|
|
270
|
+
To build static files:
|
|
91
271
|
|
|
272
|
+
```bash
|
|
273
|
+
npm run build
|
|
274
|
+
npm run serve
|
|
92
275
|
```
|
|
276
|
+
|
|
277
|
+
The site is configured for GitHub Pages at https://markcallen.github.io/env-secrets/
|
|
278
|
+
|
|
279
|
+
## Development
|
|
280
|
+
|
|
281
|
+
### Setup
|
|
282
|
+
|
|
283
|
+
1. **Install Node.js using nvm (recommended):**
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
nvm use
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
Or use Node.js 20 (LTS) directly.
|
|
290
|
+
|
|
291
|
+
2. **Install dependencies:**
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
npm install -g yarn
|
|
93
295
|
yarn
|
|
94
296
|
```
|
|
95
297
|
|
|
96
|
-
|
|
298
|
+
### Running in Development
|
|
97
299
|
|
|
98
300
|
```
|
|
99
301
|
npx ts-node src/index.ts aws -s local/sample -r us-east-1 -p marka -- env
|
|
100
302
|
```
|
|
101
303
|
|
|
102
|
-
###
|
|
304
|
+
### Debugging
|
|
305
|
+
|
|
306
|
+
The application uses `debug-js` for logging. Enable debug logs by setting the `DEBUG` environment variable:
|
|
103
307
|
|
|
104
|
-
|
|
105
|
-
|
|
308
|
+
Debug just env-secrets
|
|
309
|
+
|
|
310
|
+
```bash
|
|
311
|
+
DEBUG=env-secrets npx ts-node src/index.ts aws -s local/sample -r us-east-1 -p marka -- env
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
Debug env-secrets and the secretsmanager vault
|
|
106
315
|
|
|
107
316
|
```
|
|
108
317
|
DEBUG=env-secrets,env-secrets:secretsmanager npx ts-node src/index.ts aws -s local/sample -r us-east-1 -p marka -- env
|
|
109
318
|
```
|
|
110
319
|
|
|
111
|
-
|
|
320
|
+
### LocalStack Development
|
|
321
|
+
|
|
322
|
+
For local development without AWS, you can use LocalStack to emulate AWS services.
|
|
112
323
|
|
|
113
|
-
|
|
324
|
+
1. **Install LocalStack:**
|
|
325
|
+
|
|
326
|
+
If you've started a devcontainer then localstack is already installed and has access to your hosts docker.
|
|
327
|
+
|
|
328
|
+
For local development use docker compose.
|
|
329
|
+
|
|
330
|
+
For kubernetes you can install it via the helm chart:
|
|
114
331
|
|
|
115
332
|
```
|
|
116
|
-
|
|
333
|
+
|
|
334
|
+
helm repo add localstack-repo https://helm.localstack.cloud
|
|
335
|
+
helm upgrade --install localstack localstack-repo/localstack --namespace localstack --create-namespace
|
|
336
|
+
|
|
117
337
|
```
|
|
118
338
|
|
|
119
|
-
|
|
339
|
+
1. **Start LocalStack:**
|
|
340
|
+
|
|
341
|
+
To use localstack from within a devcontainer run:
|
|
120
342
|
|
|
121
343
|
```
|
|
122
|
-
|
|
344
|
+
|
|
345
|
+
localstack start -d
|
|
346
|
+
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
For local development you can start it with docker compose.
|
|
350
|
+
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
docker compose up -d
|
|
354
|
+
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
3. **Configure AWS CLI for LocalStack:**
|
|
358
|
+
|
|
359
|
+
Set up your AWS CLI to work with LocalStack by creating a profile:
|
|
360
|
+
|
|
123
361
|
```
|
|
124
362
|
|
|
125
|
-
|
|
363
|
+
aws configure --profile localstack
|
|
126
364
|
|
|
127
365
|
```
|
|
366
|
+
|
|
367
|
+
Use:
|
|
368
|
+
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
AWS Access Key ID [None]: test
|
|
372
|
+
AWS Secret Access Key [None]: test
|
|
373
|
+
Default region name [None]: us-east-1
|
|
374
|
+
Default output format [None]:
|
|
375
|
+
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
Then export the profile and the endpoint url:
|
|
379
|
+
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
export AWS_PROFILE=localstack
|
|
383
|
+
export AWS_ENDPOINT_URL=http://localhost:4566
|
|
384
|
+
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
To use the env vars set:
|
|
388
|
+
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
export AWS_ACCESS_KEY_ID=test
|
|
392
|
+
export AWS_SECRET_ACCESS_KEY=test
|
|
393
|
+
export AWS_DEFAULT_REGION=us-east-1
|
|
394
|
+
export AWS_ENDPOINT_URL=http://localhost:4566
|
|
395
|
+
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
for kubernetes the endpoint url is:
|
|
399
|
+
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
export AWS_ENDPOINT_URL=http://localstack.localstack:4566
|
|
403
|
+
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
4. **Using awslocal**
|
|
407
|
+
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
awslocal secretsmanager create-secret \
|
|
411
|
+
--name local/sample \
|
|
412
|
+
--secret-string '{"username": "marka", "password": "mypassword"}'
|
|
413
|
+
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
awslocal secretsmanager list-secrets
|
|
419
|
+
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
awslocal secretsmanager get-secret-value \
|
|
425
|
+
--secret-id local/sample
|
|
426
|
+
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
### Devpod Setup
|
|
430
|
+
|
|
431
|
+
Create a devpod using Kubernetes provider:
|
|
432
|
+
|
|
433
|
+
```bash
|
|
434
|
+
devpod up --id env-secretes-dev --provider kubernetes --ide cursor git@github.com:markcallen/env-secrets.git
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
## Testing
|
|
438
|
+
|
|
439
|
+
This project includes both unit tests and comprehensive end-to-end tests.
|
|
440
|
+
|
|
441
|
+
### Unit Tests
|
|
442
|
+
|
|
443
|
+
Run the unit test suite:
|
|
444
|
+
|
|
445
|
+
```bash
|
|
446
|
+
# Run all unit tests
|
|
447
|
+
npm run test:unit
|
|
448
|
+
|
|
449
|
+
# Run unit tests with coverage
|
|
450
|
+
npm run test:unit:coverage
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
### End-to-End Tests
|
|
454
|
+
|
|
455
|
+
The end-to-end tests use LocalStack to emulate AWS Secrets Manager and test the full CLI functionality.
|
|
456
|
+
|
|
457
|
+
#### Prerequisites
|
|
458
|
+
|
|
459
|
+
1. **Install awslocal** (required for e2e tests):
|
|
460
|
+
|
|
461
|
+
```bash
|
|
462
|
+
# Using pip (recommended)
|
|
463
|
+
pip install awscli-local
|
|
464
|
+
|
|
465
|
+
# Or using npm
|
|
466
|
+
npm install -g awscli-local
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
2. **Start LocalStack**:
|
|
470
|
+
|
|
471
|
+
```bash
|
|
472
|
+
docker-compose up -d localstack
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
3. **Wait for LocalStack to be ready**:
|
|
476
|
+
|
|
477
|
+
```bash
|
|
478
|
+
# Check LocalStack status
|
|
479
|
+
docker-compose logs localstack
|
|
480
|
+
|
|
481
|
+
# Test connectivity
|
|
482
|
+
awslocal sts get-caller-identity
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
#### Running E2E Tests
|
|
486
|
+
|
|
487
|
+
```bash
|
|
488
|
+
# Run all tests (unit + e2e)
|
|
489
|
+
npm test
|
|
490
|
+
|
|
491
|
+
# Run only end-to-end tests
|
|
492
|
+
npm run test:e2e
|
|
493
|
+
|
|
494
|
+
# Run e2e tests with coverage
|
|
495
|
+
npm run test:e2e:coverage
|
|
496
|
+
|
|
497
|
+
# Run specific e2e test
|
|
498
|
+
yarn build && npx jest --config jest.e2e.config.js __e2e__/index.test.ts -t "test name"
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
#### E2E Test Features
|
|
502
|
+
|
|
503
|
+
The end-to-end test suite includes:
|
|
504
|
+
|
|
505
|
+
- **CLI Help Commands**: Tests for help, version, and general CLI functionality
|
|
506
|
+
- **AWS Secrets Manager Integration**: Tests for secret retrieval using different credential methods
|
|
507
|
+
- **Output to File**: Tests for writing secrets to files with proper permissions
|
|
508
|
+
- **Program Execution**: Tests for executing programs with injected environment variables
|
|
509
|
+
- **Error Handling**: Tests for various error scenarios and edge cases
|
|
510
|
+
- **AWS Profile Support**: Tests for both default and custom AWS profiles
|
|
511
|
+
- **Region Support**: Tests for different AWS regions
|
|
512
|
+
|
|
513
|
+
#### Troubleshooting E2E Tests
|
|
514
|
+
|
|
515
|
+
**awslocal not found**:
|
|
516
|
+
|
|
517
|
+
```bash
|
|
518
|
+
# Install awslocal
|
|
519
|
+
pip install awscli-local
|
|
520
|
+
|
|
521
|
+
# Verify installation
|
|
522
|
+
awslocal --version
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
**LocalStack not responding**:
|
|
526
|
+
|
|
527
|
+
```bash
|
|
528
|
+
# Check LocalStack status
|
|
529
|
+
docker-compose ps
|
|
530
|
+
|
|
531
|
+
# Restart LocalStack
|
|
532
|
+
docker-compose restart localstack
|
|
533
|
+
|
|
534
|
+
# Check logs
|
|
535
|
+
docker-compose logs localstack
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
**Tests timing out**:
|
|
539
|
+
|
|
540
|
+
- Ensure LocalStack is fully started before running tests
|
|
541
|
+
- Check that port 4566 is not blocked
|
|
542
|
+
- Verify Docker is running properly
|
|
543
|
+
|
|
544
|
+
#### Environment Variables
|
|
545
|
+
|
|
546
|
+
The e2e tests use these environment variables:
|
|
547
|
+
|
|
548
|
+
- `LOCALSTACK_URL`: LocalStack endpoint (default: `http://localhost:4566`)
|
|
549
|
+
- `AWS_ACCESS_KEY_ID`: AWS access key (default: `test`)
|
|
550
|
+
- `AWS_SECRET_ACCESS_KEY`: AWS secret key (default: `test`)
|
|
551
|
+
- `AWS_DEFAULT_REGION`: AWS region (default: `us-east-1`)
|
|
552
|
+
- `DEBUG`: Enable debug output (optional)
|
|
553
|
+
|
|
554
|
+
**Note**: The tests automatically clean up AWS environment variables (like `AWS_PROFILE`, `AWS_SESSION_TOKEN`, etc.) to ensure a clean test environment.
|
|
555
|
+
|
|
556
|
+
For more detailed information, see the [E2E Test Documentation](__e2e__/README.md).
|
|
557
|
+
|
|
558
|
+
## Publishing
|
|
559
|
+
|
|
560
|
+
1. **Login to npm:**
|
|
561
|
+
|
|
562
|
+
```bash
|
|
563
|
+
npm login
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
2. **Dry run release:**
|
|
567
|
+
|
|
568
|
+
```bash
|
|
569
|
+
npm run release -- patch --dry-run
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
3. **Publish release:**
|
|
573
|
+
|
|
574
|
+
```bash
|
|
128
575
|
npm run release -- patch
|
|
129
576
|
```
|
|
130
577
|
|
|
578
|
+
## Contributing
|
|
579
|
+
|
|
580
|
+
We welcome contributions! Please follow these steps:
|
|
581
|
+
|
|
582
|
+
1. Fork the repository
|
|
583
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
584
|
+
3. Make your changes
|
|
585
|
+
4. Add tests for new functionality
|
|
586
|
+
5. Run the test suite (`npm test`)
|
|
587
|
+
6. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
588
|
+
7. Push to the branch (`git push origin feature/amazing-feature`)
|
|
589
|
+
8. Open a Pull Request
|
|
590
|
+
|
|
591
|
+
### Development Guidelines
|
|
592
|
+
|
|
593
|
+
- Follow the existing code style (ESLint + Prettier)
|
|
594
|
+
- Add tests for new functionality
|
|
595
|
+
- Update documentation for new features
|
|
596
|
+
- Ensure all tests pass before submitting
|
|
597
|
+
|
|
131
598
|
## License
|
|
132
599
|
|
|
133
600
|
Distributed under the MIT License. See `LICENSE` for more information.
|
|
@@ -137,3 +604,7 @@ Distributed under the MIT License. See `LICENSE` for more information.
|
|
|
137
604
|
Mark C Allen - [@markcallen](https://www.linkedin.com/in/markcallen/)
|
|
138
605
|
|
|
139
606
|
Project Link: [https://github.com/markcallen/env-secrets](https://github.com/markcallen/env-secrets)
|
|
607
|
+
|
|
608
|
+
## Changelog
|
|
609
|
+
|
|
610
|
+
See [GitHub Releases](https://github.com/markcallen/env-secrets/releases) for a complete changelog.
|