kubiy-paas-cli 0.1.18 → 0.1.19
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/package.json
CHANGED
package/src/commands/deploy.js
CHANGED
|
@@ -6,7 +6,6 @@ const os = require("os");
|
|
|
6
6
|
const https = require("https");
|
|
7
7
|
const { apiPost } = require("../api");
|
|
8
8
|
const { logInfo, logSuccess, logError } = require("../logger");
|
|
9
|
-
const { getCliToken } = require("../config");
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* Helpers para .kubiy.json
|
|
@@ -368,16 +367,19 @@ async function run(args = []) {
|
|
|
368
367
|
|
|
369
368
|
try {
|
|
370
369
|
const opts = parseArgs(args);
|
|
371
|
-
const token = getCliToken();
|
|
372
|
-
if (!token) {
|
|
373
|
-
logError("No hay CLI token. Ejecuta: kubiy login <cliToken>");
|
|
374
|
-
process.exit(1);
|
|
375
|
-
}
|
|
376
370
|
|
|
377
371
|
// 3) Cargar config del proyecto (.kubiy.json)
|
|
378
372
|
const kubiyConfig = loadProjectKubiyConfig();
|
|
379
373
|
const { appId, serviceId, environment, healthPath, apikey, configPath, config } = kubiyConfig;
|
|
380
374
|
|
|
375
|
+
// La autenticación se hace con el apikey de .kubiy.json (generado por `kubiy link`),
|
|
376
|
+
// no con el CLI token. Si falta el apikey, hay que re-linkear el proyecto.
|
|
377
|
+
if (!apikey) {
|
|
378
|
+
logError("No se encontró 'apikey' en .kubiy.json. Vuelve a linkear el proyecto:");
|
|
379
|
+
logError(" kubiy link <appId> --apikey=<tu-api-key>");
|
|
380
|
+
process.exit(1);
|
|
381
|
+
}
|
|
382
|
+
|
|
381
383
|
// Validar que deployType coincida con el modo de deploy
|
|
382
384
|
const deployType = config.deployType;
|
|
383
385
|
if (!opts.static && deployType === "static") {
|
package/src/commands/logs.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
const fs = require("fs");
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const { apiGet } = require("../api");
|
|
5
|
-
const { getCliToken } = require("../config");
|
|
6
5
|
const { logInfo, logError } = require("../logger");
|
|
7
6
|
|
|
8
7
|
function parseArgs(args) {
|
|
@@ -27,7 +26,7 @@ function parseArgs(args) {
|
|
|
27
26
|
return { serviceId: clean[0] || null, opts };
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
function
|
|
29
|
+
function loadKubiyLink() {
|
|
31
30
|
const filepath = path.join(process.cwd(), ".kubiy.json");
|
|
32
31
|
|
|
33
32
|
if (!fs.existsSync(filepath)) {
|
|
@@ -38,7 +37,7 @@ function resolveServiceIdFromLink() {
|
|
|
38
37
|
const raw = fs.readFileSync(filepath, "utf8");
|
|
39
38
|
const cfg = JSON.parse(raw);
|
|
40
39
|
|
|
41
|
-
return cfg.serviceId || null;
|
|
40
|
+
return { serviceId: cfg.serviceId || null, apikey: cfg.apikey || null };
|
|
42
41
|
} catch (err) {
|
|
43
42
|
// Si el json está roto, que el usuario se entere
|
|
44
43
|
logError("No se pudo leer .kubiy.json:", err.message || String(err));
|
|
@@ -49,11 +48,13 @@ function resolveServiceIdFromLink() {
|
|
|
49
48
|
async function run(args) {
|
|
50
49
|
const { serviceId: cliServiceId, opts } = parseArgs(args);
|
|
51
50
|
|
|
51
|
+
const linked = loadKubiyLink();
|
|
52
52
|
let serviceId = cliServiceId;
|
|
53
|
+
const apikey = linked && linked.apikey;
|
|
53
54
|
|
|
54
55
|
// 🍀 Si no viene serviceId por CLI, intentamos usar el del link
|
|
55
56
|
if (!serviceId) {
|
|
56
|
-
const linkedServiceId =
|
|
57
|
+
const linkedServiceId = linked && linked.serviceId;
|
|
57
58
|
if (!linkedServiceId) {
|
|
58
59
|
logError(
|
|
59
60
|
"Uso: kubiy logs <serviceId> --kind=deploy|app --lines=200\n" +
|
|
@@ -65,9 +66,9 @@ async function run(args) {
|
|
|
65
66
|
logInfo(`Usando serviceId del link (.kubiy.json): ${serviceId}`);
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
logError("
|
|
69
|
+
if (!apikey) {
|
|
70
|
+
logError("No se encontró 'apikey' en .kubiy.json. Vuelve a linkear el proyecto:");
|
|
71
|
+
logError(" kubiy link <appId> --apikey=<tu-api-key>");
|
|
71
72
|
process.exit(1);
|
|
72
73
|
}
|
|
73
74
|
|
|
@@ -86,7 +87,9 @@ async function run(args) {
|
|
|
86
87
|
|
|
87
88
|
const pathUrl = `/services/${encodeURIComponent(serviceId)}/logs?${qs}`;
|
|
88
89
|
|
|
89
|
-
const resp = await apiGet(pathUrl
|
|
90
|
+
const resp = await apiGet(pathUrl, {
|
|
91
|
+
headers: { "x-kubiy-token": apikey },
|
|
92
|
+
}); // { stdout, stderr, ... }
|
|
90
93
|
const stdout = resp.stdout || "";
|
|
91
94
|
const stderr = resp.stderr || "";
|
|
92
95
|
|
package/src/commands/rollback.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const { apiPost } = require("../api");
|
|
5
|
-
const { getCliToken } = require("../config");
|
|
6
5
|
const { logInfo, logError, logSuccess } = require("../logger");
|
|
7
6
|
|
|
8
7
|
function loadProjectKubiyConfig() {
|
|
@@ -10,7 +9,9 @@ function loadProjectKubiyConfig() {
|
|
|
10
9
|
if (!fs.existsSync(configPath)) return null;
|
|
11
10
|
try {
|
|
12
11
|
const json = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
13
|
-
return json.appId && json.serviceId
|
|
12
|
+
return json.appId && json.serviceId
|
|
13
|
+
? { appId: json.appId, serviceId: json.serviceId, apikey: json.apikey }
|
|
14
|
+
: null;
|
|
14
15
|
} catch {
|
|
15
16
|
return null;
|
|
16
17
|
}
|
|
@@ -22,6 +23,7 @@ async function run(args) {
|
|
|
22
23
|
const appId = args.length === 3 ? args[0] : (linked && linked.appId);
|
|
23
24
|
const serviceId = args.length === 3 ? args[1] : (linked && linked.serviceId);
|
|
24
25
|
const deployId = args.length === 3 ? args[2] : args[0];
|
|
26
|
+
const apikey = linked && linked.apikey;
|
|
25
27
|
|
|
26
28
|
if (!deployId) {
|
|
27
29
|
logError("Uso: kubiy rollback <deployId>\n kubiy rollback <appId> <serviceId> <deployId>\nO ejecuta desde un proyecto con kubiy link y pasa <deployId>.");
|
|
@@ -38,9 +40,9 @@ async function run(args) {
|
|
|
38
40
|
process.exit(1);
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
logError("
|
|
43
|
+
if (!apikey) {
|
|
44
|
+
logError("No se encontró 'apikey' en .kubiy.json. Vuelve a linkear el proyecto:");
|
|
45
|
+
logError(" kubiy link <appId> --apikey=<tu-api-key>");
|
|
44
46
|
process.exit(1);
|
|
45
47
|
}
|
|
46
48
|
|
|
@@ -50,7 +52,7 @@ async function run(args) {
|
|
|
50
52
|
const resp = await apiPost(
|
|
51
53
|
`/rollback`,
|
|
52
54
|
{ appId, serviceId, deployId },
|
|
53
|
-
{ headers: { "
|
|
55
|
+
{ headers: { "x-kubiy-token": apikey } }
|
|
54
56
|
);
|
|
55
57
|
logSuccess("Rollback enviado a Kubiy.");
|
|
56
58
|
|
|
@@ -1,6 +1,18 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
1
3
|
const { apiGet } = require("../api");
|
|
2
4
|
const { logError, logSuccess } = require("../logger");
|
|
3
|
-
|
|
5
|
+
|
|
6
|
+
function loadApiKeyFromLink() {
|
|
7
|
+
const filepath = path.join(process.cwd(), ".kubiy.json");
|
|
8
|
+
if (!fs.existsSync(filepath)) return null;
|
|
9
|
+
try {
|
|
10
|
+
const cfg = JSON.parse(fs.readFileSync(filepath, "utf8"));
|
|
11
|
+
return cfg.apikey || null;
|
|
12
|
+
} catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
4
16
|
|
|
5
17
|
async function run(args) {
|
|
6
18
|
const serviceId = args[0];
|
|
@@ -10,13 +22,16 @@ async function run(args) {
|
|
|
10
22
|
process.exit(1);
|
|
11
23
|
}
|
|
12
24
|
|
|
13
|
-
const
|
|
14
|
-
if (!
|
|
15
|
-
logError("No
|
|
25
|
+
const apikey = loadApiKeyFromLink();
|
|
26
|
+
if (!apikey) {
|
|
27
|
+
logError("No se encontró 'apikey' en .kubiy.json. Vuelve a linkear el proyecto:");
|
|
28
|
+
logError(" kubiy link <appId> --apikey=<tu-api-key>");
|
|
16
29
|
process.exit(1);
|
|
17
30
|
}
|
|
18
31
|
|
|
19
|
-
const service = await apiGet(`/services/${serviceId}
|
|
32
|
+
const service = await apiGet(`/services/${serviceId}`, {
|
|
33
|
+
headers: { "x-kubiy-token": apikey },
|
|
34
|
+
});
|
|
20
35
|
logSuccess("Servicio obtenido:");
|
|
21
36
|
console.log(JSON.stringify(service, null, 2));
|
|
22
37
|
}
|