@solidactions/cli 3.10.1 → 3.10.2
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.
|
@@ -10,6 +10,7 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
10
10
|
const chalk_1 = __importDefault(require("chalk"));
|
|
11
11
|
const readline_1 = __importDefault(require("readline"));
|
|
12
12
|
const api_1 = require("../utils/api");
|
|
13
|
+
const secure_write_1 = require("../utils/secure-write");
|
|
13
14
|
/**
|
|
14
15
|
* Prompt the user for confirmation (unless --yes flag is set).
|
|
15
16
|
*/
|
|
@@ -96,7 +97,7 @@ async function envPull(projectName, options = {}) {
|
|
|
96
97
|
// No .env file — create with just OAuth vars
|
|
97
98
|
console.log(chalk_1.default.yellow('No .env file found — creating with OAuth vars only. Run a full env:pull for all variables.'));
|
|
98
99
|
const content = oauthLines.join('\n') + '\n';
|
|
99
|
-
|
|
100
|
+
(0, secure_write_1.writeSecretFileSync)(outputPath, content);
|
|
100
101
|
}
|
|
101
102
|
else {
|
|
102
103
|
// Merge into existing .env file
|
|
@@ -133,7 +134,7 @@ async function envPull(projectName, options = {}) {
|
|
|
133
134
|
preservedLines.push(`# OAuth tokens (updated ${new Date().toISOString()})`);
|
|
134
135
|
preservedLines.push(...oauthLines);
|
|
135
136
|
preservedLines.push('');
|
|
136
|
-
|
|
137
|
+
(0, secure_write_1.writeSecretFileSync)(outputPath, preservedLines.join('\n'));
|
|
137
138
|
}
|
|
138
139
|
console.log(chalk_1.default.green(`\n✓ Updated ${oauthVars.length} OAuth token(s) in ${outputFile}`));
|
|
139
140
|
// Print any OAuth warnings
|
|
@@ -190,7 +191,7 @@ async function envPull(projectName, options = {}) {
|
|
|
190
191
|
}
|
|
191
192
|
lines.push('');
|
|
192
193
|
// Write to file
|
|
193
|
-
|
|
194
|
+
(0, secure_write_1.writeSecretFileSync)(outputPath, lines.join('\n'));
|
|
194
195
|
console.log(chalk_1.default.green(`\n✓ Wrote ${count} variables to ${outputFile}`));
|
|
195
196
|
if (secretCount > 0) {
|
|
196
197
|
console.log(chalk_1.default.yellow(` (includes ${secretCount} secret value${secretCount > 1 ? 's' : ''})`));
|
|
@@ -228,6 +229,10 @@ async function envPull(projectName, options = {}) {
|
|
|
228
229
|
console.error(chalk_1.default.red(`Failed: ${error.response.status}`), error.response.data);
|
|
229
230
|
}
|
|
230
231
|
}
|
|
232
|
+
else if (!axios_1.default.isAxiosError(error) && error.code) {
|
|
233
|
+
// A filesystem failure writing the .env — not a connection problem.
|
|
234
|
+
console.error(chalk_1.default.red(`Failed to write ${outputFile}: ${error.message}`));
|
|
235
|
+
}
|
|
231
236
|
else {
|
|
232
237
|
console.error(chalk_1.default.red('Connection failed:'), error.message);
|
|
233
238
|
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.writeSecretFileSync = writeSecretFileSync;
|
|
7
|
+
exports.writeViaTempFileSync = writeViaTempFileSync;
|
|
8
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
/** The kernel's own symlink-resolution limit. */
|
|
12
|
+
const MAX_SYMLINK_HOPS = 40;
|
|
13
|
+
/**
|
|
14
|
+
* Find where a path that does not currently resolve should be created,
|
|
15
|
+
* following any symlink chain by hand.
|
|
16
|
+
*
|
|
17
|
+
* realpathSync cannot be used here: it throws ENOENT on a dangling symlink,
|
|
18
|
+
* and today's writeFileSync creates the link's target instead of failing.
|
|
19
|
+
*/
|
|
20
|
+
function resolveCreationPath(filePath) {
|
|
21
|
+
let current = filePath;
|
|
22
|
+
for (let hop = 0; hop <= MAX_SYMLINK_HOPS; hop++) {
|
|
23
|
+
let stats;
|
|
24
|
+
try {
|
|
25
|
+
stats = fs_1.default.lstatSync(current);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return current; // nothing here — this is the creation point
|
|
29
|
+
}
|
|
30
|
+
if (!stats.isSymbolicLink()) {
|
|
31
|
+
return current;
|
|
32
|
+
}
|
|
33
|
+
current = path_1.default.resolve(path_1.default.dirname(current), fs_1.default.readlinkSync(current));
|
|
34
|
+
}
|
|
35
|
+
// Defensive guard, unreachable in practice: statSync raises ELOOP first.
|
|
36
|
+
const error = new Error(`Too many symbolic links resolving ${filePath}`);
|
|
37
|
+
error.code = 'ELOOP';
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Write a secret-bearing file so the result is owner-only, whether or not the
|
|
42
|
+
* destination already exists.
|
|
43
|
+
*
|
|
44
|
+
* writeFileSync's `mode` only applies when it creates the file, so an existing
|
|
45
|
+
* world-readable file would silently keep its mode and receive fresh plaintext
|
|
46
|
+
* secrets. Writing to a sibling temp file at 0600 and renaming over the
|
|
47
|
+
* destination gives the final path a fresh inode carrying 0600 on both the
|
|
48
|
+
* create and the overwrite path, and makes the replacement atomic — readers
|
|
49
|
+
* never observe a partial file.
|
|
50
|
+
*
|
|
51
|
+
* The mode is masked by the process umask, which can only subtract bits, so
|
|
52
|
+
* the result is always <= 0600: never group- or world-readable.
|
|
53
|
+
*/
|
|
54
|
+
function writeSecretFileSync(filePath, contents) {
|
|
55
|
+
let stats;
|
|
56
|
+
try {
|
|
57
|
+
// statSync follows the whole chain, including magic /proc links.
|
|
58
|
+
stats = fs_1.default.statSync(filePath);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (error.code !== 'ENOENT') {
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// FIFOs, sockets and character devices (`-o /dev/stdout`) have no
|
|
66
|
+
// persistent inode to protect, and a temp+rename beside them fails.
|
|
67
|
+
// Directories deliberately stay on the temp+rename path so they keep
|
|
68
|
+
// failing loudly.
|
|
69
|
+
if (stats && !stats.isFile() && !stats.isDirectory()) {
|
|
70
|
+
fs_1.default.writeFileSync(filePath, contents);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const target = stats ? fs_1.default.realpathSync(filePath) : resolveCreationPath(filePath);
|
|
74
|
+
const tempPath = path_1.default.join(path_1.default.dirname(target), `.${path_1.default.basename(target)}.${process.pid}.${crypto_1.default.randomBytes(4).toString('hex')}.tmp`);
|
|
75
|
+
writeViaTempFileSync(target, tempPath, contents);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Write `contents` to `tempPath` at 0600 and rename it over `target`.
|
|
79
|
+
*
|
|
80
|
+
* Exported so tests can stage a collision at a known temp path; production
|
|
81
|
+
* callers go through writeSecretFileSync, which randomizes that path.
|
|
82
|
+
*/
|
|
83
|
+
function writeViaTempFileSync(target, tempPath, contents) {
|
|
84
|
+
let created = false;
|
|
85
|
+
try {
|
|
86
|
+
// 'wx' refuses to follow or clobber an existing (or planted) temp path.
|
|
87
|
+
fs_1.default.writeFileSync(tempPath, contents, { flag: 'wx', mode: 0o600 });
|
|
88
|
+
created = true;
|
|
89
|
+
fs_1.default.renameSync(tempPath, target);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
// Only our own temp file may be removed: a failed 'wx' means the path
|
|
93
|
+
// holds someone else's file, which is not ours to delete.
|
|
94
|
+
if (created) {
|
|
95
|
+
try {
|
|
96
|
+
fs_1.default.unlinkSync(tempPath);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
// Nothing to clean up.
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
}
|