infisical-merge 1.0.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.
Files changed (2) hide show
  1. package/infisical-merge.js +88 -0
  2. package/package.json +19 -0
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env node
2
+
3
+ const axios = require("axios");
4
+ const fs = require("fs");
5
+ const { Command } = require("commander");
6
+ const pLimit = require("p-limit");
7
+
8
+ const program = new Command();
9
+
10
+ program
11
+ .option("-e, --env <env>", "environment", "dev")
12
+ .option("-o, --output <dir>", "output directory", ".")
13
+ .option("-p, --projects <list>", "project mapping (service:projectId)", "")
14
+ .option("-t, --token <token>", "Infisical token")
15
+ .option("-d, --domain <url>", "Infisical API URL", "https://app.infisical.com/api")
16
+ .option("--path <path>", "secret folder", "/")
17
+ .option("--tags <tags>", "filter by tags")
18
+ .parse(process.argv);
19
+
20
+ const opts = program.opts();
21
+
22
+ const limit = pLimit(5);
23
+
24
+ async function fetchSecrets(projectId) {
25
+
26
+ const res = await axios.get(`${opts.domain}/v3/secrets`, {
27
+ headers: {
28
+ Authorization: `Bearer ${opts.token}`
29
+ },
30
+ params: {
31
+ projectId,
32
+ environment: opts.env,
33
+ path: opts.path,
34
+ recursive: true,
35
+ tags: opts.tags
36
+ }
37
+ });
38
+
39
+ return res.data.secrets || [];
40
+ }
41
+
42
+ function generateEnvFile(filename, secrets) {
43
+
44
+ const content = Object.entries(secrets)
45
+ .map(([k, v]) => `${k}=${v}`)
46
+ .join("\n");
47
+
48
+ fs.writeFileSync(filename, content);
49
+ }
50
+
51
+ async function main() {
52
+
53
+ const mapping = opts.projects.split(",");
54
+
55
+ const jobs = mapping.map(item => {
56
+
57
+ const [service, projectId] = item.split(":");
58
+
59
+ return limit(async () => {
60
+
61
+ console.log(`Fetching ${service} -> ${projectId}`);
62
+
63
+ const secrets = await fetchSecrets(projectId);
64
+
65
+ const env = {};
66
+
67
+ secrets.forEach(s => {
68
+ env[s.secretKey] = s.secretValue;
69
+ });
70
+
71
+ const filename = `${opts.output}/.env.${service}`;
72
+
73
+ generateEnvFile(filename, env);
74
+
75
+ console.log(`Generated ${filename}`);
76
+ });
77
+
78
+ });
79
+
80
+ await Promise.all(jobs);
81
+
82
+ console.log("All env files generated");
83
+ }
84
+
85
+ main().catch(err => {
86
+ console.error("Error:", err.message);
87
+ process.exit(1);
88
+ });
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "infisical-merge",
3
+ "version": "1.0.0",
4
+ "main": "infisical-merge.js",
5
+ "bin": {
6
+ "im": "./infisical-merge.js",
7
+ "infisical-merge": "./infisical-merge.js"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "description": "",
13
+ "dependencies": {
14
+ "axios": "^1.13.6",
15
+ "commander": "^14.0.3",
16
+ "dotenv": "^17.3.1",
17
+ "p-limit": "^7.3.0"
18
+ }
19
+ }