[FEATURE] New Infisical SDK

This commit is contained in:
Dunemask 2024-08-03 21:10:14 -06:00
parent 70168074dc
commit df893d1d29
3 changed files with 257 additions and 155 deletions

View file

@ -1,32 +1,36 @@
import fs from "node:fs";
import os from "node:os";
import InfisicalClient from "infisical-node";
import rls from "readline-sync";
import { InfisicalClient } from "@infisical/sdk";
import { loadConfig, upsertConfig } from "./configurator.js";
const envpath = `${os.homedir()}/.env`;
//upsertConfig(); //TODO Build Configuration Generator
const config = loadConfig();
const secrets = {};
const siteURL = config.infisicalInstance;
const siteUrl = config.infisicalInstance;
const projects = config.projects;
const pendingSecrets = [];
async function getProjectSecrets(
project,
projectName,
projectId,
environment,
token,
clientId,
clientSecret,
path = "/",
includeImports = true,
) {
const client = new InfisicalClient({ token, siteURL });
const secrets = await client.getAllSecrets({
const client = new InfisicalClient({
siteUrl,
auth: { universalAuth: { clientId, clientSecret } },
});
const secrets = await client.listSecrets({
projectId,
environment,
path,
includeImports,
attachToProcessEnv: false,
});
return secrets.map((s) => ({ ...s, project, path }));
return secrets.map((s) => ({ ...s, project: projectName, path }));
}
function mapToFile(proj, secrets) {
@ -39,7 +43,7 @@ function mapToFile(proj, secrets) {
(p) =>
`# ---${p}--- ${dateString}\n` +
secrets[p]
.map((s) => `export ${s.secretName}=${s.secretValue}`)
.map((s) => `export ${s.secretKey}=${s.secretValue}`)
.join("\n"),
);
const fileData = lines.join("\n");
@ -48,10 +52,20 @@ function mapToFile(proj, secrets) {
for (var p of projects) {
for (var e of p.environments) {
if (!process.env[e.envar]) throw Error(`${e.envar} could not be found!`);
if (!process.env[e.clientIdEnvar])
throw Error(`${e.clientIdEnvar} could not be found!`);
if (!process.env[e.clientSecretEnvar])
throw Error(`${e.clientSecretEnvar} could not be found!`);
for (var path of e.paths) {
pendingSecrets.push(
getProjectSecrets(p.name, e.slug, process.env[e.envar], path),
getProjectSecrets(
p.name,
p.projectId,
e.slug,
process.env[e.clientIdEnvar],
process.env[e.clientSecretEnvar],
path,
),
);
}
}

370
package-lock.json generated
View file

@ -9,11 +9,213 @@
"version": "0.0.1",
"license": "LGPL-2.1-only",
"dependencies": {
"infisical-node": "^1.5.0",
"@infisical/sdk": "^2.3.1",
"readline-sync": "^1.4.10"
},
"devDependencies": {
"nodemon": "^3.0.1"
"nodemon": "^3.1.4"
}
},
"node_modules/@infisical/sdk": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/@infisical/sdk/-/sdk-2.3.1.tgz",
"integrity": "sha512-jyP9ecT3jKGaEsRXiH7VSsIgtt81F0yMgsSuQ3jhOSYz3uCupVlc2yvoOq0z063kMDQWtEKHp2rauaeSadjr7w==",
"engines": {
"node": ">= 10"
},
"optionalDependencies": {
"@infisical/sdk-android-arm-eabi": "2.3.1",
"@infisical/sdk-android-arm64": "2.3.1",
"@infisical/sdk-darwin-arm64": "2.3.1",
"@infisical/sdk-darwin-x64": "2.3.1",
"@infisical/sdk-linux-arm-gnueabihf": "2.3.1",
"@infisical/sdk-linux-arm64-gnu": "2.3.1",
"@infisical/sdk-linux-arm64-musl": "2.3.1",
"@infisical/sdk-linux-x64-gnu": "2.3.1",
"@infisical/sdk-linux-x64-musl": "2.3.1",
"@infisical/sdk-win32-arm64-msvc": "2.3.1",
"@infisical/sdk-win32-ia32-msvc": "2.3.1",
"@infisical/sdk-win32-x64-msvc": "2.3.1"
}
},
"node_modules/@infisical/sdk-android-arm-eabi": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/@infisical/sdk-android-arm-eabi/-/sdk-android-arm-eabi-2.3.1.tgz",
"integrity": "sha512-Br+wZBtlcOwe3iY/LMpVIGxu4b9R+1K7vvuN5mU8tbreNTVDUfAq5f2B+0QR2XCaFazmowu/I3Ggg6/Eq/c+Aw==",
"cpu": [
"arm"
],
"optional": true,
"os": [
"android"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@infisical/sdk-android-arm64": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/@infisical/sdk-android-arm64/-/sdk-android-arm64-2.3.1.tgz",
"integrity": "sha512-hNbLu3NCWGG4ArBM+EMasW1hGqoOHwAn3SKZkfRb5QSnY17tFgZD4LQGnG1gP4/KEOxU0rcOM7qslCXmBiSMYA==",
"cpu": [
"arm64"
],
"optional": true,
"os": [
"android"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@infisical/sdk-darwin-arm64": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/@infisical/sdk-darwin-arm64/-/sdk-darwin-arm64-2.3.1.tgz",
"integrity": "sha512-8ulY///R8UA95GAS+i5AJPrYt31kcM48qegh/pj5zL4NB3oT80Hme1kc6lS6loWy69B+SW7u5QK6nlpl3HhJGw==",
"cpu": [
"arm64"
],
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@infisical/sdk-darwin-x64": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/@infisical/sdk-darwin-x64/-/sdk-darwin-x64-2.3.1.tgz",
"integrity": "sha512-2ekYpDrb6nzqfche7joPgBHBnKNj7OqBitgZCgogHRTf4IBmokFM6T4Z7BDvrs/qWgO3KBUyCtJMKGfrwMQscA==",
"cpu": [
"x64"
],
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@infisical/sdk-linux-arm-gnueabihf": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/@infisical/sdk-linux-arm-gnueabihf/-/sdk-linux-arm-gnueabihf-2.3.1.tgz",
"integrity": "sha512-i0cnb8+N3VvgPlbrKRZgh/krSr9BizZn5t2DCOgjzugI4BPOWLqe80fytg1aWBCfkuztweTWvAO4QLjIaveNcQ==",
"cpu": [
"arm"
],
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@infisical/sdk-linux-arm64-gnu": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/@infisical/sdk-linux-arm64-gnu/-/sdk-linux-arm64-gnu-2.3.1.tgz",
"integrity": "sha512-6+GlUet4E4eKOJsD6wStLX4jXC0qHCmF5l1yucX3kUIWKyFrlLwA50ts2oeyJwY3RhewwjS+pGnX3TjytMleCg==",
"cpu": [
"arm64"
],
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@infisical/sdk-linux-arm64-musl": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/@infisical/sdk-linux-arm64-musl/-/sdk-linux-arm64-musl-2.3.1.tgz",
"integrity": "sha512-Qlrcu/0sMrLR0SHhwyDppPEWGDXJ4nYvSrtrMnF/UOVBsiBTpYKOv+kr7YbR/xX0+SH9o8rV+w5exNbW21ZL4g==",
"cpu": [
"arm64"
],
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@infisical/sdk-linux-x64-gnu": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/@infisical/sdk-linux-x64-gnu/-/sdk-linux-x64-gnu-2.3.1.tgz",
"integrity": "sha512-GhxNh8n1f6sV3U/ZXrAeJLw1vhlVk48mzMypJ7v411JopA5BkOLpT63NlyhHZwo1i7Y/JP0Rxwz8iCIpnINpmQ==",
"cpu": [
"x64"
],
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@infisical/sdk-linux-x64-musl": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/@infisical/sdk-linux-x64-musl/-/sdk-linux-x64-musl-2.3.1.tgz",
"integrity": "sha512-Rgc4Mj/8oTPnBIqMJugOsDd3BChyAGyH9Q4SlvJUsusiYAra3V4tvVYYB4J8NOJNoLIAdM45N1LuM/naeG+sLQ==",
"cpu": [
"x64"
],
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@infisical/sdk-win32-arm64-msvc": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/@infisical/sdk-win32-arm64-msvc/-/sdk-win32-arm64-msvc-2.3.1.tgz",
"integrity": "sha512-Wf5ypgXsSOtvWwIpkj9VPyHFFr1SeF+tqeW+eevjayqtOVNS6Bs5kjHlCVTfutHsir0Dbo7L6xcWxN7M68mE/g==",
"cpu": [
"arm64"
],
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@infisical/sdk-win32-ia32-msvc": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/@infisical/sdk-win32-ia32-msvc/-/sdk-win32-ia32-msvc-2.3.1.tgz",
"integrity": "sha512-b3NYTSF3pWA274uxhVfzGSZsQIsBvYZ1cyJ69x9ps5IBaw6LiPInCH/J7dooPQenDydklFIwJDogLRIt59E31Q==",
"cpu": [
"ia32"
],
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@infisical/sdk-win32-x64-msvc": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/@infisical/sdk-win32-x64-msvc/-/sdk-win32-x64-msvc-2.3.1.tgz",
"integrity": "sha512-Gu6qqiB342fUsyIrdhohhJCS5Ga2Bg7f3i+i0xlnPQ96kPLXyrKvlrT+GS2PBEWoAyiabB4gXMPZdcPe9EVoGg==",
"cpu": [
"x64"
],
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/abbrev": {
@ -35,21 +237,6 @@
"node": ">= 8"
}
},
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
},
"node_modules/axios": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.6.0.tgz",
"integrity": "sha512-EZ1DYihju9pwVB+jg67ogm+Tmqc6JmhamRN6I4Zt8DfZu5lbcQGw3ozH9lFejSJgs/ibaef3A9PMXPLeefFGJg==",
"dependencies": {
"follow-redirects": "^1.15.0",
"form-data": "^4.0.0",
"proxy-from-env": "^1.1.0"
}
},
"node_modules/balanced-match": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
@ -76,12 +263,12 @@
}
},
"node_modules/braces": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
"integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz",
"integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==",
"dev": true,
"dependencies": {
"fill-range": "^7.0.1"
"fill-range": "^7.1.1"
},
"engines": {
"node": ">=8"
@ -114,17 +301,6 @@
"fsevents": "~2.3.2"
}
},
"node_modules/combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"dependencies": {
"delayed-stream": "~1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@ -132,37 +308,26 @@
"dev": true
},
"node_modules/debug": {
"version": "3.2.7",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz",
"integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==",
"version": "4.3.6",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.6.tgz",
"integrity": "sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==",
"dev": true,
"dependencies": {
"ms": "^2.1.1"
}
},
"node_modules/delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/dotenv": {
"version": "16.3.1",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.3.1.tgz",
"integrity": "sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==",
"engines": {
"node": ">=12"
"ms": "2.1.2"
},
"funding": {
"url": "https://github.com/motdotla/dotenv?sponsor=1"
"engines": {
"node": ">=6.0"
},
"peerDependenciesMeta": {
"supports-color": {
"optional": true
}
}
},
"node_modules/fill-range": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
"integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==",
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
"integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==",
"dev": true,
"dependencies": {
"to-regex-range": "^5.0.1"
@ -171,38 +336,6 @@
"node": ">=8"
}
},
"node_modules/follow-redirects": {
"version": "1.15.3",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz",
"integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/form-data": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/fsevents": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
@ -244,17 +377,6 @@
"integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==",
"dev": true
},
"node_modules/infisical-node": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/infisical-node/-/infisical-node-1.5.0.tgz",
"integrity": "sha512-mMdhhu50J7pI4Y89M2HMbNWRyRY6ian3oBIXW+pAWz1z8XWn5yT0ge6/YNXwTPKLnBuR1py+GwiNQUaqxkOXZw==",
"dependencies": {
"axios": "^1.3.3",
"dotenv": "^16.0.3",
"tweetnacl": "^1.0.3",
"tweetnacl-util": "^0.15.1"
}
},
"node_modules/is-binary-path": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz",
@ -309,25 +431,6 @@
"node": ">=10"
}
},
"node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-types": {
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"dependencies": {
"mime-db": "1.52.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/minimatch": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
@ -341,19 +444,19 @@
}
},
"node_modules/ms": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
"dev": true
},
"node_modules/nodemon": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.0.1.tgz",
"integrity": "sha512-g9AZ7HmkhQkqXkRc20w+ZfQ73cHLbE8hnPbtaFbFtCumZsjyMhKk9LajQ07U5Ux28lvFjZ5X7HvWR1xzU8jHVw==",
"version": "3.1.4",
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.1.4.tgz",
"integrity": "sha512-wjPBbFhtpJwmIeY2yP7QF+UKzPfltVGtfce1g/bB15/8vCGZj8uxD62b/b9M9/WVgme0NZudpownKN+c0plXlQ==",
"dev": true,
"dependencies": {
"chokidar": "^3.5.2",
"debug": "^3.2.7",
"debug": "^4",
"ignore-by-default": "^1.0.1",
"minimatch": "^3.1.2",
"pstree.remy": "^1.1.8",
@ -410,11 +513,6 @@
"url": "https://github.com/sponsors/jonschlinkert"
}
},
"node_modules/proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
},
"node_modules/pstree.remy": {
"version": "1.1.8",
"resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz",
@ -504,16 +602,6 @@
"nodetouch": "bin/nodetouch.js"
}
},
"node_modules/tweetnacl": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz",
"integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw=="
},
"node_modules/tweetnacl-util": {
"version": "0.15.1",
"resolved": "https://registry.npmjs.org/tweetnacl-util/-/tweetnacl-util-0.15.1.tgz",
"integrity": "sha512-RKJBIj8lySrShN4w6i/BonWp2Z/uxwC3h4y7xsRrpP59ZboCd0GpEVsOnMDYLMmKBpYhb5TgHzZXy7wTfYFBRw=="
},
"node_modules/undefsafe": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz",

View file

@ -19,10 +19,10 @@
"author": "dunemask",
"license": "LGPL-2.1-only",
"dependencies": {
"infisical-node": "^1.5.0",
"@infisical/sdk": "^2.3.1",
"readline-sync": "^1.4.10"
},
"devDependencies": {
"nodemon": "^3.0.1"
"nodemon": "^3.1.4"
}
}