mirror of
https://github.com/morten-olsen/with-ssm.git
synced 2026-02-08 00:46:23 +01:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
24e8726e41 | ||
|
|
efa489d524 | ||
|
|
1321ea4748 | ||
|
|
70f1cf9134 | ||
|
|
815ac86873 |
13
.github/workflows/pipeline-default.yaml
vendored
13
.github/workflows/pipeline-default.yaml
vendored
@@ -12,13 +12,13 @@ on:
|
||||
env:
|
||||
environment: test
|
||||
release_channel: latest
|
||||
DO_NOT_TRACK: '1'
|
||||
NODE_VERSION: '23.x'
|
||||
NODE_REGISTRY: 'https://registry.npmjs.org'
|
||||
DO_NOT_TRACK: "1"
|
||||
NODE_VERSION: "23.x"
|
||||
NODE_REGISTRY: "https://registry.npmjs.org"
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
DOCKER_REGISTRY: ghcr.io
|
||||
IMAGE_NAME: ${{ github.repository }}
|
||||
PNPM_VERSION: 10.6.0
|
||||
PNPM_VERSION: 10.17.0
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
@@ -56,8 +56,8 @@ jobs:
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '${{ env.NODE_VERSION }}'
|
||||
registry-url: '${{ env.NODE_REGISTRY }}'
|
||||
node-version: "${{ env.NODE_VERSION }}"
|
||||
registry-url: "${{ env.NODE_REGISTRY }}"
|
||||
|
||||
- uses: pnpm/action-setup@v4
|
||||
name: Install pnpm
|
||||
@@ -83,3 +83,4 @@ jobs:
|
||||
pnpm publish -r --no-git-checks --access public
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
||||
|
||||
27
package.json
27
package.json
@@ -6,33 +6,34 @@
|
||||
"license": "GPL-3.0",
|
||||
"scripts": {
|
||||
"test:lint": "eslint",
|
||||
"build": "ncc build src/start.ts -o dist",
|
||||
"build:dev": "ncc build src/start.ts -o dist --watch",
|
||||
"build": "ncc build src/start.ts -s -o dist",
|
||||
"build:dev": "ncc build src/start.ts -s -o dist --watch",
|
||||
"test:unit": "vitest --run --passWithNoTests",
|
||||
"test": "pnpm run \"/^test:/\""
|
||||
},
|
||||
"packageManager": "pnpm@10.6.0",
|
||||
"packageManager": "pnpm@10.17.0",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@aws-sdk/client-ssm": "^3.863.0",
|
||||
"@aws-sdk/client-ssm": "^3.947.0",
|
||||
"@aws-sdk/client-sts": "^3.947.0",
|
||||
"@dotenvx/dotenvx": "^1.51.1",
|
||||
"@eslint/eslintrc": "3.3.1",
|
||||
"@eslint/js": "9.32.0",
|
||||
"@eslint/js": "9.36.0",
|
||||
"@pnpm/find-workspace-packages": "6.0.9",
|
||||
"@types/node": "24.2.0",
|
||||
"@types/yargs": "^17.0.33",
|
||||
"@vercel/ncc": "^0.38.3",
|
||||
"@types/node": "24.6.2",
|
||||
"@types/yargs": "^17.0.35",
|
||||
"@vercel/ncc": "^0.38.4",
|
||||
"@vitest/coverage-v8": "3.2.4",
|
||||
"dotenv": "^17.2.1",
|
||||
"eslint": "9.32.0",
|
||||
"eslint": "9.36.0",
|
||||
"eslint-config-prettier": "10.1.8",
|
||||
"eslint-plugin-import": "2.32.0",
|
||||
"eslint-plugin-prettier": "5.5.4",
|
||||
"execa": "^9.6.0",
|
||||
"execa": "^9.6.1",
|
||||
"prettier": "3.6.2",
|
||||
"typescript": "5.9.2",
|
||||
"typescript-eslint": "8.39.0",
|
||||
"typescript": "5.9.3",
|
||||
"typescript-eslint": "8.45.0",
|
||||
"vitest": "3.2.4",
|
||||
"yargs": "^18.0.0"
|
||||
},
|
||||
|
||||
2627
pnpm-lock.yaml
generated
2627
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
2
pnpm-workspace.yaml
Normal file
2
pnpm-workspace.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
onlyBuiltDependencies:
|
||||
- esbuild
|
||||
@@ -19,7 +19,7 @@ const argv = await yargs(hideBin(process.argv))
|
||||
alias: 'f',
|
||||
type: 'string',
|
||||
description: 'The file to use for environment variables. (multiple files can be specified)',
|
||||
default: ['.env', '.env.with-ssm'],
|
||||
default: ['.env.with-ssm', '.env'],
|
||||
})
|
||||
.demandCommand(1, 'Error: You must provide a command to execute after --')
|
||||
.alias('h', 'help')
|
||||
@@ -36,7 +36,10 @@ if (!command) {
|
||||
|
||||
const files = argv.file && Array.isArray(argv.file) ? argv.file : [argv.file];
|
||||
const hostEnv = await getEnv(files);
|
||||
const env = await replaceParams(hostEnv);
|
||||
const env = await replaceParams(hostEnv, {
|
||||
region: argv.region,
|
||||
profile: argv.profile,
|
||||
});
|
||||
|
||||
exec({
|
||||
command,
|
||||
|
||||
20
src/utils/aws.ts
Normal file
20
src/utils/aws.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { STSClient, GetCallerIdentityCommand } from '@aws-sdk/client-sts';
|
||||
|
||||
const ensureAWS = async (region?: string, profile?: string) => {
|
||||
const sts = new STSClient({
|
||||
region,
|
||||
profile,
|
||||
});
|
||||
|
||||
const command = new GetCallerIdentityCommand({});
|
||||
|
||||
try {
|
||||
await sts.send(command);
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
||||
console.error('Failed to get caller identity', errorMessage);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
export { ensureAWS };
|
||||
@@ -2,7 +2,7 @@ import { existsSync } from 'node:fs';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { resolve } from 'node:path';
|
||||
|
||||
import { parse } from 'dotenv';
|
||||
import { parse } from '@dotenvx/dotenvx';
|
||||
|
||||
import { debug } from './debug.js';
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { GetParametersCommand, SSMClient, type Parameter } from '@aws-sdk/client-ssm';
|
||||
|
||||
import { debug } from './debug.js';
|
||||
import { ensureAWS } from './aws.js';
|
||||
|
||||
const PREFIX = 'SSM:';
|
||||
|
||||
@@ -13,11 +14,6 @@ const replaceParams = async (
|
||||
env: Record<string, string | undefined>,
|
||||
{ region, profile }: ReplaceParamsOptions = {},
|
||||
) => {
|
||||
const ssm = new SSMClient({
|
||||
region,
|
||||
profile,
|
||||
});
|
||||
|
||||
const names = Object.entries(env)
|
||||
.filter(([, value]) => value?.startsWith(PREFIX))
|
||||
.map(([, value]) => value?.slice(PREFIX.length))
|
||||
@@ -30,6 +26,11 @@ const replaceParams = async (
|
||||
return env;
|
||||
}
|
||||
|
||||
await ensureAWS(region, profile);
|
||||
const ssm = new SSMClient({
|
||||
region,
|
||||
profile,
|
||||
});
|
||||
// Chunk names into groups of 10 (AWS SSM GetParametersCommand limit)
|
||||
const chunks: string[][] = [];
|
||||
debug(`Chunking ${names.length} names into groups of 10`);
|
||||
|
||||
Reference in New Issue
Block a user