1 Commits

Author SHA1 Message Date
Morten Olsen
70f1cf9134 chore: updated dependencies 2025-10-03 14:59:39 +02:00
5 changed files with 1225 additions and 1134 deletions

0
.npmrc Normal file
View File

View File

@@ -6,38 +6,37 @@
"license": "GPL-3.0", "license": "GPL-3.0",
"scripts": { "scripts": {
"test:lint": "eslint", "test:lint": "eslint",
"build": "ncc build src/start.ts -o dist", "build": "ncc build src/start.ts -s -o dist",
"build:dev": "ncc build src/start.ts -o dist --watch", "build:dev": "ncc build src/start.ts -s -o dist --watch",
"test:unit": "vitest --run --passWithNoTests", "test:unit": "vitest --run --passWithNoTests",
"test": "pnpm run \"/^test:/\"" "test": "pnpm run \"/^test:/\""
}, },
"packageManager": "pnpm@10.6.0", "packageManager": "pnpm@10.17.0",
"files": [ "files": [
"dist" "dist"
], ],
"devDependencies": { "devDependencies": {
"@aws-sdk/client-ssm": "^3.863.0", "@aws-sdk/client-ssm": "^3.901.0",
"@aws-sdk/client-sts": "^3.901.0",
"@dotenvx/dotenvx": "^1.51.0",
"@eslint/eslintrc": "3.3.1", "@eslint/eslintrc": "3.3.1",
"@eslint/js": "9.32.0", "@eslint/js": "9.36.0",
"@pnpm/find-workspace-packages": "6.0.9", "@pnpm/find-workspace-packages": "6.0.9",
"@types/node": "24.2.0", "@types/node": "24.6.2",
"@types/yargs": "^17.0.33", "@types/yargs": "^17.0.33",
"@vercel/ncc": "^0.38.3", "@vercel/ncc": "^0.38.4",
"@vitest/coverage-v8": "3.2.4", "@vitest/coverage-v8": "3.2.4",
"eslint": "9.32.0", "eslint": "9.36.0",
"eslint-config-prettier": "10.1.8", "eslint-config-prettier": "10.1.8",
"eslint-plugin-import": "2.32.0", "eslint-plugin-import": "2.32.0",
"eslint-plugin-prettier": "5.5.4", "eslint-plugin-prettier": "5.5.4",
"execa": "^9.6.0", "execa": "^9.6.0",
"prettier": "3.6.2", "prettier": "3.6.2",
"typescript": "5.9.2", "typescript": "5.9.3",
"typescript-eslint": "8.39.0", "typescript-eslint": "8.45.0",
"vitest": "3.2.4", "vitest": "3.2.4",
"yargs": "^18.0.0" "yargs": "^18.0.0"
}, },
"name": "@morten-olsen/with-ssm", "name": "@morten-olsen/with-ssm",
"version": "1.0.0", "version": "1.0.0"
"dependencies": { }
"@dotenvx/dotenvx": "^1.51.0"
}
}

2299
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

20
src/utils/aws.ts Normal file
View 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 };

View File

@@ -1,6 +1,7 @@
import { GetParametersCommand, SSMClient, type Parameter } from '@aws-sdk/client-ssm'; import { GetParametersCommand, SSMClient, type Parameter } from '@aws-sdk/client-ssm';
import { debug } from './debug.js'; import { debug } from './debug.js';
import { ensureAWS } from './aws.js';
const PREFIX = 'SSM:'; const PREFIX = 'SSM:';
@@ -13,11 +14,6 @@ const replaceParams = async (
env: Record<string, string | undefined>, env: Record<string, string | undefined>,
{ region, profile }: ReplaceParamsOptions = {}, { region, profile }: ReplaceParamsOptions = {},
) => { ) => {
const ssm = new SSMClient({
region,
profile,
});
const names = Object.entries(env) const names = Object.entries(env)
.filter(([, value]) => value?.startsWith(PREFIX)) .filter(([, value]) => value?.startsWith(PREFIX))
.map(([, value]) => value?.slice(PREFIX.length)) .map(([, value]) => value?.slice(PREFIX.length))
@@ -30,6 +26,11 @@ const replaceParams = async (
return env; return env;
} }
await ensureAWS(region, profile);
const ssm = new SSMClient({
region,
profile,
});
// Chunk names into groups of 10 (AWS SSM GetParametersCommand limit) // Chunk names into groups of 10 (AWS SSM GetParametersCommand limit)
const chunks: string[][] = []; const chunks: string[][] = [];
debug(`Chunking ${names.length} names into groups of 10`); debug(`Chunking ${names.length} names into groups of 10`);