kubiy-paas-cli 0.1.2 → 0.1.4
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.
- package/.github/workflows/publish.yml +51 -0
- package/fix-link.js +72 -72
- package/index.js +54 -54
- package/package.json +1 -1
- package/src/api.js +79 -79
- package/src/commands/deploy.js +206 -206
- package/src/commands/git-connect.js +113 -113
- package/src/commands/login.js +16 -16
- package/src/commands/service-get.js +24 -24
- package/src/commands/version.js +17 -17
- package/src/commands/whoami.js +15 -15
- package/src/config.js +47 -47
- package/src/git.js +24 -24
- package/src/logger.js +30 -30
- package/src/ssh-config.js +51 -51
- package/src/ssh.js +40 -40
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
const { apiGet } = require("../api");
|
|
2
|
-
const { logError, logSuccess } = require("../logger");
|
|
3
|
-
const { getCliToken } = require("../config");
|
|
4
|
-
|
|
5
|
-
async function run(args) {
|
|
6
|
-
const serviceId = args[0];
|
|
7
|
-
|
|
8
|
-
if (!serviceId) {
|
|
9
|
-
logError("Uso: kubiy service:get <serviceId>");
|
|
10
|
-
process.exit(1);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const token = getCliToken();
|
|
14
|
-
if (!token) {
|
|
15
|
-
logError("No hay CLI token. Ejecuta: kubiy login <cliToken>");
|
|
16
|
-
process.exit(1);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const service = await apiGet(`/services/${serviceId}`);
|
|
20
|
-
logSuccess("Servicio obtenido:");
|
|
21
|
-
console.log(JSON.stringify(service, null, 2));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
module.exports = { run };
|
|
1
|
+
const { apiGet } = require("../api");
|
|
2
|
+
const { logError, logSuccess } = require("../logger");
|
|
3
|
+
const { getCliToken } = require("../config");
|
|
4
|
+
|
|
5
|
+
async function run(args) {
|
|
6
|
+
const serviceId = args[0];
|
|
7
|
+
|
|
8
|
+
if (!serviceId) {
|
|
9
|
+
logError("Uso: kubiy service:get <serviceId>");
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const token = getCliToken();
|
|
14
|
+
if (!token) {
|
|
15
|
+
logError("No hay CLI token. Ejecuta: kubiy login <cliToken>");
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const service = await apiGet(`/services/${serviceId}`);
|
|
20
|
+
logSuccess("Servicio obtenido:");
|
|
21
|
+
console.log(JSON.stringify(service, null, 2));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = { run };
|
package/src/commands/version.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
const { logInfo } = require("../logger");
|
|
2
|
-
const { API_BASE, apiGet } = require("../api");
|
|
3
|
-
const pkg = require("../../package.json");
|
|
4
|
-
|
|
5
|
-
async function run() {
|
|
6
|
-
logInfo(`Kubiy CLI version: ${pkg.version}`);
|
|
7
|
-
logInfo(`API base: ${API_BASE}`);
|
|
8
|
-
|
|
9
|
-
try {
|
|
10
|
-
const status = await apiGet("/status"); // ajusta si no tienes este endpoint
|
|
11
|
-
console.log("API status:", status);
|
|
12
|
-
} catch (e) {
|
|
13
|
-
console.log("No se pudo consultar /status de la API:", e.message);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
module.exports = { run };
|
|
1
|
+
const { logInfo } = require("../logger");
|
|
2
|
+
const { API_BASE, apiGet } = require("../api");
|
|
3
|
+
const pkg = require("../../package.json");
|
|
4
|
+
|
|
5
|
+
async function run() {
|
|
6
|
+
logInfo(`Kubiy CLI version: ${pkg.version}`);
|
|
7
|
+
logInfo(`API base: ${API_BASE}`);
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
const status = await apiGet("/status"); // ajusta si no tienes este endpoint
|
|
11
|
+
console.log("API status:", status);
|
|
12
|
+
} catch (e) {
|
|
13
|
+
console.log("No se pudo consultar /status de la API:", e.message);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = { run };
|
package/src/commands/whoami.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
const { getCliToken } = require("../config");
|
|
2
|
-
const { logInfo, logWarn } = require("../logger");
|
|
3
|
-
|
|
4
|
-
async function run() {
|
|
5
|
-
const token = getCliToken();
|
|
6
|
-
if (!token) {
|
|
7
|
-
logWarn("No hay CLI token configurado. Ejecuta: kubiy login <cliToken>");
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
logInfo("CLI configurado.");
|
|
12
|
-
console.log("Token (truncado):", token.slice(0, 6) + "****");
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
module.exports = { run };
|
|
1
|
+
const { getCliToken } = require("../config");
|
|
2
|
+
const { logInfo, logWarn } = require("../logger");
|
|
3
|
+
|
|
4
|
+
async function run() {
|
|
5
|
+
const token = getCliToken();
|
|
6
|
+
if (!token) {
|
|
7
|
+
logWarn("No hay CLI token configurado. Ejecuta: kubiy login <cliToken>");
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
logInfo("CLI configurado.");
|
|
12
|
+
console.log("Token (truncado):", token.slice(0, 6) + "****");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = { run };
|
package/src/config.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const os = require("os");
|
|
3
|
-
const path = require("path");
|
|
4
|
-
|
|
5
|
-
const CONFIG_DIR = path.join(os.homedir(), ".kubiy");
|
|
6
|
-
const CONFIG_FILE = path.join(CONFIG_DIR, "config.json");
|
|
7
|
-
|
|
8
|
-
function ensureConfigDir() {
|
|
9
|
-
if (!fs.existsSync(CONFIG_DIR)) {
|
|
10
|
-
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function readConfig() {
|
|
15
|
-
try {
|
|
16
|
-
if (!fs.existsSync(CONFIG_FILE)) return {};
|
|
17
|
-
const raw = fs.readFileSync(CONFIG_FILE, "utf8");
|
|
18
|
-
return JSON.parse(raw);
|
|
19
|
-
} catch (e) {
|
|
20
|
-
return {};
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function writeConfig(obj) {
|
|
25
|
-
ensureConfigDir();
|
|
26
|
-
fs.writeFileSync(CONFIG_FILE, JSON.stringify(obj, null, 2), "utf8");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function getCliToken() {
|
|
30
|
-
const cfg = readConfig();
|
|
31
|
-
return cfg.cliToken;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function setCliToken(token) {
|
|
35
|
-
const cfg = readConfig();
|
|
36
|
-
cfg.cliToken = token;
|
|
37
|
-
writeConfig(cfg);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
module.exports = {
|
|
41
|
-
CONFIG_DIR,
|
|
42
|
-
CONFIG_FILE,
|
|
43
|
-
readConfig,
|
|
44
|
-
writeConfig,
|
|
45
|
-
getCliToken,
|
|
46
|
-
setCliToken
|
|
47
|
-
};
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const os = require("os");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
|
|
5
|
+
const CONFIG_DIR = path.join(os.homedir(), ".kubiy");
|
|
6
|
+
const CONFIG_FILE = path.join(CONFIG_DIR, "config.json");
|
|
7
|
+
|
|
8
|
+
function ensureConfigDir() {
|
|
9
|
+
if (!fs.existsSync(CONFIG_DIR)) {
|
|
10
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function readConfig() {
|
|
15
|
+
try {
|
|
16
|
+
if (!fs.existsSync(CONFIG_FILE)) return {};
|
|
17
|
+
const raw = fs.readFileSync(CONFIG_FILE, "utf8");
|
|
18
|
+
return JSON.parse(raw);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function writeConfig(obj) {
|
|
25
|
+
ensureConfigDir();
|
|
26
|
+
fs.writeFileSync(CONFIG_FILE, JSON.stringify(obj, null, 2), "utf8");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function getCliToken() {
|
|
30
|
+
const cfg = readConfig();
|
|
31
|
+
return cfg.cliToken;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function setCliToken(token) {
|
|
35
|
+
const cfg = readConfig();
|
|
36
|
+
cfg.cliToken = token;
|
|
37
|
+
writeConfig(cfg);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = {
|
|
41
|
+
CONFIG_DIR,
|
|
42
|
+
CONFIG_FILE,
|
|
43
|
+
readConfig,
|
|
44
|
+
writeConfig,
|
|
45
|
+
getCliToken,
|
|
46
|
+
setCliToken
|
|
47
|
+
};
|
package/src/git.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
const { execSync } = require("child_process");
|
|
2
|
-
const { logInfo, logSuccess, logWarn } = require("./logger");
|
|
3
|
-
|
|
4
|
-
function run(cmd) {
|
|
5
|
-
execSync(cmd, { stdio: "inherit" });
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function addRemote(name, url) {
|
|
9
|
-
try {
|
|
10
|
-
// quitar si existe
|
|
11
|
-
execSync(`git remote remove ${name}`, { stdio: "ignore" });
|
|
12
|
-
} catch (_) {
|
|
13
|
-
// no pasa nada si no existe
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
logInfo(`Agregando remote '${name}' -> ${url}`);
|
|
17
|
-
execSync(`git remote add ${name} "${url}"`, { stdio: "inherit" });
|
|
18
|
-
logSuccess(`Remote '${name}' configurado.`);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
module.exports = {
|
|
22
|
-
run,
|
|
23
|
-
addRemote
|
|
24
|
-
};
|
|
1
|
+
const { execSync } = require("child_process");
|
|
2
|
+
const { logInfo, logSuccess, logWarn } = require("./logger");
|
|
3
|
+
|
|
4
|
+
function run(cmd) {
|
|
5
|
+
execSync(cmd, { stdio: "inherit" });
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function addRemote(name, url) {
|
|
9
|
+
try {
|
|
10
|
+
// quitar si existe
|
|
11
|
+
execSync(`git remote remove ${name}`, { stdio: "ignore" });
|
|
12
|
+
} catch (_) {
|
|
13
|
+
// no pasa nada si no existe
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
logInfo(`Agregando remote '${name}' -> ${url}`);
|
|
17
|
+
execSync(`git remote add ${name} "${url}"`, { stdio: "inherit" });
|
|
18
|
+
logSuccess(`Remote '${name}' configurado.`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = {
|
|
22
|
+
run,
|
|
23
|
+
addRemote
|
|
24
|
+
};
|
package/src/logger.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
const COLORS = {
|
|
2
|
-
reset: "\x1b[0m",
|
|
3
|
-
green: "\x1b[32m",
|
|
4
|
-
yellow: "\x1b[33m",
|
|
5
|
-
red: "\x1b[31m",
|
|
6
|
-
cyan: "\x1b[36m"
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
function logInfo(...args) {
|
|
10
|
-
console.log(COLORS.cyan + "ℹ" + COLORS.reset, ...args);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function logSuccess(...args) {
|
|
14
|
-
console.log(COLORS.green + "✔" + COLORS.reset, ...args);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function logWarn(...args) {
|
|
18
|
-
console.log(COLORS.yellow + "⚠" + COLORS.reset, ...args);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function logError(...args) {
|
|
22
|
-
console.error(COLORS.red + "✖" + COLORS.reset, ...args);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
module.exports = {
|
|
26
|
-
logInfo,
|
|
27
|
-
logSuccess,
|
|
28
|
-
logWarn,
|
|
29
|
-
logError
|
|
30
|
-
};
|
|
1
|
+
const COLORS = {
|
|
2
|
+
reset: "\x1b[0m",
|
|
3
|
+
green: "\x1b[32m",
|
|
4
|
+
yellow: "\x1b[33m",
|
|
5
|
+
red: "\x1b[31m",
|
|
6
|
+
cyan: "\x1b[36m"
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
function logInfo(...args) {
|
|
10
|
+
console.log(COLORS.cyan + "ℹ" + COLORS.reset, ...args);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function logSuccess(...args) {
|
|
14
|
+
console.log(COLORS.green + "✔" + COLORS.reset, ...args);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function logWarn(...args) {
|
|
18
|
+
console.log(COLORS.yellow + "⚠" + COLORS.reset, ...args);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function logError(...args) {
|
|
22
|
+
console.error(COLORS.red + "✖" + COLORS.reset, ...args);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = {
|
|
26
|
+
logInfo,
|
|
27
|
+
logSuccess,
|
|
28
|
+
logWarn,
|
|
29
|
+
logError
|
|
30
|
+
};
|
|
31
31
|
|
package/src/ssh-config.js
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
// src/ssh-config.js
|
|
2
|
-
const fs = require("fs");
|
|
3
|
-
const os = require("os");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const { logInfo, logSuccess } = require("./logger");
|
|
6
|
-
|
|
7
|
-
const SSH_DIR = path.join(os.homedir(), ".ssh");
|
|
8
|
-
const SSH_CONFIG = path.join(SSH_DIR, "config");
|
|
9
|
-
|
|
10
|
-
function ensureSshHostConfig(hostAlias, hostName, identityFile) {
|
|
11
|
-
if (!fs.existsSync(SSH_DIR)) {
|
|
12
|
-
fs.mkdirSync(SSH_DIR, { recursive: true });
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
let existing = "";
|
|
16
|
-
if (fs.existsSync(SSH_CONFIG)) {
|
|
17
|
-
existing = fs.readFileSync(SSH_CONFIG, "utf8");
|
|
18
|
-
const already = new RegExp(`^Host\\s+${hostAlias}\\b`, "m").test(existing);
|
|
19
|
-
if (already) {
|
|
20
|
-
logInfo(`SSH config ya tiene entrada para Host '${hostAlias}'`);
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const identityPath = identityFile.replace(/\\/g, "/");
|
|
26
|
-
|
|
27
|
-
const block = [
|
|
28
|
-
"",
|
|
29
|
-
`Host ${hostAlias}`,
|
|
30
|
-
` HostName ${hostName}`,
|
|
31
|
-
` User deploy`,
|
|
32
|
-
` IdentityFile ${identityPath}`,
|
|
33
|
-
` IdentitiesOnly yes`,
|
|
34
|
-
// 🎯 Para evitar el prompt interactivo de host key:
|
|
35
|
-
` StrictHostKeyChecking no`,
|
|
36
|
-
// opcional, para no llenar el known_hosts global:
|
|
37
|
-
` UserKnownHostsFile ~/.ssh/kubiy_known_hosts`,
|
|
38
|
-
""
|
|
39
|
-
].join("\n");
|
|
40
|
-
|
|
41
|
-
const newContent = existing ? `${existing.trimEnd()}\n${block}` : block.trimStart();
|
|
42
|
-
|
|
43
|
-
fs.writeFileSync(SSH_CONFIG, newContent, "utf8");
|
|
44
|
-
logSuccess(`Configurado ~/.ssh/config para Host '${hostAlias}'`);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
module.exports = {
|
|
48
|
-
ensureSshHostConfig,
|
|
49
|
-
SSH_DIR,
|
|
50
|
-
SSH_CONFIG,
|
|
51
|
-
};
|
|
1
|
+
// src/ssh-config.js
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const os = require("os");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { logInfo, logSuccess } = require("./logger");
|
|
6
|
+
|
|
7
|
+
const SSH_DIR = path.join(os.homedir(), ".ssh");
|
|
8
|
+
const SSH_CONFIG = path.join(SSH_DIR, "config");
|
|
9
|
+
|
|
10
|
+
function ensureSshHostConfig(hostAlias, hostName, identityFile) {
|
|
11
|
+
if (!fs.existsSync(SSH_DIR)) {
|
|
12
|
+
fs.mkdirSync(SSH_DIR, { recursive: true });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let existing = "";
|
|
16
|
+
if (fs.existsSync(SSH_CONFIG)) {
|
|
17
|
+
existing = fs.readFileSync(SSH_CONFIG, "utf8");
|
|
18
|
+
const already = new RegExp(`^Host\\s+${hostAlias}\\b`, "m").test(existing);
|
|
19
|
+
if (already) {
|
|
20
|
+
logInfo(`SSH config ya tiene entrada para Host '${hostAlias}'`);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const identityPath = identityFile.replace(/\\/g, "/");
|
|
26
|
+
|
|
27
|
+
const block = [
|
|
28
|
+
"",
|
|
29
|
+
`Host ${hostAlias}`,
|
|
30
|
+
` HostName ${hostName}`,
|
|
31
|
+
` User deploy`,
|
|
32
|
+
` IdentityFile ${identityPath}`,
|
|
33
|
+
` IdentitiesOnly yes`,
|
|
34
|
+
// 🎯 Para evitar el prompt interactivo de host key:
|
|
35
|
+
` StrictHostKeyChecking no`,
|
|
36
|
+
// opcional, para no llenar el known_hosts global:
|
|
37
|
+
` UserKnownHostsFile ~/.ssh/kubiy_known_hosts`,
|
|
38
|
+
""
|
|
39
|
+
].join("\n");
|
|
40
|
+
|
|
41
|
+
const newContent = existing ? `${existing.trimEnd()}\n${block}` : block.trimStart();
|
|
42
|
+
|
|
43
|
+
fs.writeFileSync(SSH_CONFIG, newContent, "utf8");
|
|
44
|
+
logSuccess(`Configurado ~/.ssh/config para Host '${hostAlias}'`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
module.exports = {
|
|
48
|
+
ensureSshHostConfig,
|
|
49
|
+
SSH_DIR,
|
|
50
|
+
SSH_CONFIG,
|
|
51
|
+
};
|
package/src/ssh.js
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const os = require("os");
|
|
3
|
-
const path = require("path");
|
|
4
|
-
const { execSync } = require("child_process");
|
|
5
|
-
const { logInfo, logSuccess, logWarn } = require("./logger");
|
|
6
|
-
|
|
7
|
-
const SSH_DIR = path.join(os.homedir(), ".kubiy");
|
|
8
|
-
const SSH_PRIV = path.join(SSH_DIR, "id_ed25519");
|
|
9
|
-
const SSH_PUB = SSH_PRIV + ".pub";
|
|
10
|
-
|
|
11
|
-
function ensureSshKey() {
|
|
12
|
-
if (!fs.existsSync(SSH_DIR)) {
|
|
13
|
-
fs.mkdirSync(SSH_DIR, { recursive: true });
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (!fs.existsSync(SSH_PRIV) || !fs.existsSync(SSH_PUB)) {
|
|
17
|
-
logInfo("No existe llave SSH de Kubiy, generando una nueva...");
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
execSync(
|
|
21
|
-
`ssh-keygen -t ed25519 -f "${SSH_PRIV}" -N "" -C "kubiy-cli"`,
|
|
22
|
-
{ stdio: "inherit" }
|
|
23
|
-
);
|
|
24
|
-
logSuccess("Llave SSH generada en ~/.kubiy/");
|
|
25
|
-
} catch (e) {
|
|
26
|
-
logWarn("Error generando llave SSH:", e.message);
|
|
27
|
-
throw e;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const pub = fs.readFileSync(SSH_PUB, "utf8").trim();
|
|
32
|
-
return pub;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
module.exports = {
|
|
36
|
-
SSH_DIR,
|
|
37
|
-
SSH_PRIV,
|
|
38
|
-
SSH_PUB,
|
|
39
|
-
ensureSshKey
|
|
40
|
-
};
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const os = require("os");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const { execSync } = require("child_process");
|
|
5
|
+
const { logInfo, logSuccess, logWarn } = require("./logger");
|
|
6
|
+
|
|
7
|
+
const SSH_DIR = path.join(os.homedir(), ".kubiy");
|
|
8
|
+
const SSH_PRIV = path.join(SSH_DIR, "id_ed25519");
|
|
9
|
+
const SSH_PUB = SSH_PRIV + ".pub";
|
|
10
|
+
|
|
11
|
+
function ensureSshKey() {
|
|
12
|
+
if (!fs.existsSync(SSH_DIR)) {
|
|
13
|
+
fs.mkdirSync(SSH_DIR, { recursive: true });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (!fs.existsSync(SSH_PRIV) || !fs.existsSync(SSH_PUB)) {
|
|
17
|
+
logInfo("No existe llave SSH de Kubiy, generando una nueva...");
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
execSync(
|
|
21
|
+
`ssh-keygen -t ed25519 -f "${SSH_PRIV}" -N "" -C "kubiy-cli"`,
|
|
22
|
+
{ stdio: "inherit" }
|
|
23
|
+
);
|
|
24
|
+
logSuccess("Llave SSH generada en ~/.kubiy/");
|
|
25
|
+
} catch (e) {
|
|
26
|
+
logWarn("Error generando llave SSH:", e.message);
|
|
27
|
+
throw e;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const pub = fs.readFileSync(SSH_PUB, "utf8").trim();
|
|
32
|
+
return pub;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = {
|
|
36
|
+
SSH_DIR,
|
|
37
|
+
SSH_PRIV,
|
|
38
|
+
SSH_PUB,
|
|
39
|
+
ensureSshKey
|
|
40
|
+
};
|