kubiy-paas-cli 0.1.17 → 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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Kubiy CLI (`kubiy-cli`)
1
+ # Kubiy CLI (`kubiy-paas-cli`)
2
2
 
3
3
  **English:** Official CLI for the Kubiy PaaS platform. Install from npm and use the `kubiy` command to manage your apps and services deployed on Kubiy.
4
4
 
@@ -9,7 +9,7 @@
9
9
  ### Installation / Instalación
10
10
 
11
11
  ```bash
12
- npm install -g kubiy-cli
12
+ npm install -g kubiy-paas-cli
13
13
 
14
14
  # Get help / Ver ayuda
15
15
  kubiy
@@ -73,7 +73,7 @@ Recomendaciones: No compartas tu `cliToken` ni apikeys. No subas archivos `.kubi
73
73
 
74
74
  **English:** This package is ready to be published as a public npm package:
75
75
 
76
- - Package name: `kubiy-cli`
76
+ - Package name: `kubiy-paas-cli`
77
77
  - Global command: `kubiy` (defined in the `bin` field)
78
78
  - Only the needed files are published (`index.js` and `src/`)
79
79
 
@@ -84,19 +84,19 @@ To publish a new version:
84
84
 
85
85
  cd kubiy-npm-cli
86
86
  npm login # once, if you haven't already
87
- npm publish # publishes kubiy-cli as a public package
87
+ npm publish # publishes kubiy-paas-cli as a public package
88
88
  ```
89
89
 
90
90
  After publishing, users can install it with:
91
91
 
92
92
  ```bash
93
- npm install -g kubiy-cli
93
+ npm install -g kubiy-paas-cli
94
94
  kubiy version
95
95
  ```
96
96
 
97
97
  **Español:** Este paquete está preparado para publicarse como paquete público en npm:
98
98
 
99
- - Nombre del paquete: `kubiy-cli`
99
+ - Nombre del paquete: `kubiy-paas-cli`
100
100
  - Comando global: `kubiy` (definido en el campo `bin`)
101
101
  - Solo se publican los archivos necesarios (`index.js` y `src/`)
102
102
 
@@ -107,12 +107,12 @@ Para publicar una nueva versión:
107
107
 
108
108
  cd kubiy-npm-cli
109
109
  npm login # una sola vez, si aún no lo hiciste
110
- npm publish # publica kubiy-cli como paquete público
110
+ npm publish # publica kubiy-paas-cli como paquete público
111
111
  ```
112
112
 
113
113
  Después de publicar, los usuarios pueden instalarlo con:
114
114
 
115
115
  ```bash
116
- npm install -g kubiy-cli
116
+ npm install -g kubiy-paas-cli
117
117
  kubiy version
118
118
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kubiy-paas-cli",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "description": "CLI para la plataforma PaaS de Kubiy",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -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") {
@@ -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 resolveServiceIdFromLink() {
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 = resolveServiceIdFromLink();
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
- const token = getCliToken();
69
- if (!token) {
70
- logError("No hay CLI token. Ejecuta: kubiy login <cliToken>");
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); // { stdout, stderr, ... }
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
 
@@ -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 ? { appId: json.appId, serviceId: json.serviceId } : null;
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
- const token = getCliToken();
42
- if (!token) {
43
- logError("No hay CLI token. Ejecuta: kubiy login <cliToken>");
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: { "X-Kubiy-Token": token } }
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
- const { getCliToken } = require("../config");
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 token = getCliToken();
14
- if (!token) {
15
- logError("No hay CLI token. Ejecuta: kubiy login <cliToken>");
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
  }