From fa894b511524de57e7ca77a63848a54c96c0247b Mon Sep 17 00:00:00 2001 From: Nicolas Date: Tue, 14 Feb 2023 14:33:05 +0100 Subject: [PATCH 01/10] paas snapshots commands --- src/commands/paas/deploy.ts | 29 ----------- src/commands/paas/login.ts | 9 ++-- src/commands/paas/logs.ts | 41 ---------------- src/commands/paas/snapshots/cat.ts | 58 ++++++++++++++++++++++ src/commands/paas/snapshots/dump.ts | 58 ++++++++++++++++++++++ src/commands/paas/snapshots/restore.ts | 66 ++++++++++++++++++++++++++ src/support/PaasKommand.ts | 14 ++++++ 7 files changed, 200 insertions(+), 75 deletions(-) create mode 100644 src/commands/paas/snapshots/cat.ts create mode 100644 src/commands/paas/snapshots/dump.ts create mode 100644 src/commands/paas/snapshots/restore.ts diff --git a/src/commands/paas/deploy.ts b/src/commands/paas/deploy.ts index dd035a27..c1642f3b 100644 --- a/src/commands/paas/deploy.ts +++ b/src/commands/paas/deploy.ts @@ -1,9 +1,5 @@ -import fs from "fs"; - import { flags } from "@oclif/command"; -import cli from "cli-ux"; -import PaasLogin from "./login"; import { PaasKommand } from "../../support/PaasKommand"; class PaasDeploy extends PaasKommand { @@ -70,31 +66,6 @@ class PaasDeploy extends PaasKommand { this.logOk("Deployment in progress"); } - - async getCredentials() { - const project = this.getProject(); - const projectFile = this.fileProjectCredentials(project); - - if (!fs.existsSync(projectFile)) { - this.log(""); - const nextStep = await cli.prompt( - "Cannot find credentials for this project. Do you want to login first? [Y/N]", - { type: "single" } - ); - this.log(""); - - if (nextStep.toLowerCase().startsWith("y")) { - await PaasLogin.run(["--project", project]); - } else { - this.logKo("Aborting."); - process.exit(1); - } - } - - const credentials = JSON.parse(fs.readFileSync(projectFile, "utf8")); - - return credentials.apiKey; - } } export default PaasDeploy; diff --git a/src/commands/paas/login.ts b/src/commands/paas/login.ts index ad698624..e93c0957 100644 --- a/src/commands/paas/login.ts +++ b/src/commands/paas/login.ts @@ -45,12 +45,13 @@ class PaasLogin extends PaasKommand { await this.initPaasClient({ username, password }); + await this.authenticateNPM(username, password); + const apiKey: ApiKey = await this.paas.auth.createApiKey( "Kourou PaaS API Key" ); this.createProjectCredentials(apiKey); - await this.authenticateNPM(username, password); this.logOk( `Successfully logged in as ${username}. Your Kuzzle Enterprise license is now enabled on this host.` @@ -89,10 +90,8 @@ class PaasLogin extends PaasKommand { }), }; - const response = await fetch( - `https://${this.packagesHost}/-/user/org.couchdb.user:${username}`, - options - ); + const targetUrl = `https://${this.packagesHost}/-/user/org.couchdb.user:${username}`; + const response = await fetch(targetUrl, options); const json = await response.json(); if (response.status !== 201) { diff --git a/src/commands/paas/logs.ts b/src/commands/paas/logs.ts index 951bbb3e..f4ec363a 100644 --- a/src/commands/paas/logs.ts +++ b/src/commands/paas/logs.ts @@ -1,12 +1,9 @@ -import fs from "fs"; import * as readline from "readline"; import { flags } from "@oclif/command"; import chalk from "chalk"; import * as chrono from "chrono-node"; -import { cli } from "cli-ux"; -import PaasLogin from "./login"; import { PaasKommand } from "../../support/PaasKommand"; /** @@ -158,44 +155,6 @@ class PaasLogs extends PaasKommand { } } - async getCredentials() { - const project = this.getProject(); - const projectFile = this.fileProjectCredentials(project); - - if (!fs.existsSync(projectFile)) { - this.log(""); - const nextStep = await cli.prompt( - "Cannot find credentials for this project. Do you want to login first? [Y/N]", - { type: "single" } - ); - this.log(""); - - if (nextStep.toLowerCase().startsWith("y")) { - await PaasLogin.run(["--project", project]); - } else { - this.logKo("Aborting."); - process.exit(1); - } - } - - const credentials = JSON.parse(fs.readFileSync(projectFile, "utf8")); - - return credentials.apiKey; - } - - getNumberOfSpaces(names: string[], currentName: string) { - const end = 10; - let max = { name: '', length: 0 }; - - for (const name of names) { - if (max.length < name.length) { - max = { name: name, length: name.length }; - } - } - - return currentName === max.name ? end : end + (max.length - currentName.length); - } - /** * Returns the color to use for a pod name. * @param podName Name of the pod. diff --git a/src/commands/paas/snapshots/cat.ts b/src/commands/paas/snapshots/cat.ts new file mode 100644 index 00000000..defcf45f --- /dev/null +++ b/src/commands/paas/snapshots/cat.ts @@ -0,0 +1,58 @@ +import { flags } from "@oclif/command"; + +import { PaasKommand } from "../../../support/PaasKommand"; + +class PaasSnapshotsCat extends PaasKommand { + public static description = + "List all snapshots for a given kuzzle application in a environment"; + + public static flags = { + help: flags.help(), + token: flags.string({ + default: process.env.KUZZLE_PAAS_TOKEN, + description: "Authentication token", + }), + project: flags.string({ + description: "Current PaaS project", + }), + }; + + static args = [ + { + name: "environment", + description: "Project environment name", + required: true, + }, + { + name: "applicationId", + description: "Application Identifier", + required: true, + } + ]; + + async runSafe() { + const apiKey = await this.getCredentials(); + + await this.initPaasClient({ apiKey }); + + const user = await this.paas.auth.getCurrentUser(); + this.logInfo( + `Logged as "${user._id}" for project "${this.flags.project || this.getProject() + }"` + ); + + + const { result } = await this.paas.query({ + controller: "application", + action: "snapshots", + environmentId: this.args.environment, + projectId: this.flags.project || this.getProject(), + applicationId: this.args.applicationId, + body: {}, + }); + + this.logInfo(JSON.stringify(result, null, 2)); + } +} + +export default PaasSnapshotsCat; diff --git a/src/commands/paas/snapshots/dump.ts b/src/commands/paas/snapshots/dump.ts new file mode 100644 index 00000000..50bdf540 --- /dev/null +++ b/src/commands/paas/snapshots/dump.ts @@ -0,0 +1,58 @@ +import { flags } from "@oclif/command"; + +import { PaasKommand } from "../../../support/PaasKommand"; + +class PaasSnapshotsDump extends PaasKommand { + public static description = + "List all snapshots for a given kuzzle application in a environment"; + + public static flags = { + help: flags.help(), + token: flags.string({ + default: process.env.KUZZLE_PAAS_TOKEN, + description: "Authentication token", + }), + project: flags.string({ + description: "Current PaaS project", + }), + }; + + static args = [ + { + name: "environment", + description: "Project environment name", + required: true, + }, + { + name: "applicationId", + description: "Application Identifier", + required: true, + } + ]; + + async runSafe() { + const apiKey = await this.getCredentials(); + + await this.initPaasClient({ apiKey }); + + const user = await this.paas.auth.getCurrentUser(); + this.logInfo( + `Logged as "${user._id}" for project "${this.flags.project || this.getProject() + }"` + ); + + + const { result }: any = await this.paas.query({ + controller: "application", + action: "dump", + environmentId: this.args.environment, + projectId: this.flags.project || this.getProject(), + applicationId: this.args.applicationId, + body: {}, + }); + + this.logOk(result.body); + } +} + +export default PaasSnapshotsDump; diff --git a/src/commands/paas/snapshots/restore.ts b/src/commands/paas/snapshots/restore.ts new file mode 100644 index 00000000..0a396030 --- /dev/null +++ b/src/commands/paas/snapshots/restore.ts @@ -0,0 +1,66 @@ +import { flags } from "@oclif/command"; + +import { PaasKommand } from "../../../support/PaasKommand"; + +class PaasSnapshotsRestore extends PaasKommand { + public static description = + "List all snapshots for a given kuzzle application in a environment"; + + public static flags = { + help: flags.help(), + token: flags.string({ + default: process.env.KUZZLE_PAAS_TOKEN, + description: "Authentication token", + }), + project: flags.string({ + description: "Current PaaS project", + }), + }; + + static args = [ + { + name: "environment", + description: "Project environment name", + required: true, + }, + { + name: "applicationId", + description: "Application Identifier", + required: true, + }, + { + name: "snapshotId", + description: "Snapshot Identifier", + required: true, + } + ]; + + async runSafe() { + const apiKey = await this.getCredentials(); + + await this.initPaasClient({ apiKey }); + + const user = await this.paas.auth.getCurrentUser(); + this.logInfo( + `Logged as "${user._id}" for project "${this.flags.project || this.getProject() + }"` + ); + + + await this.paas.query({ + controller: "application", + action: "restore", + environmentId: this.args.environment, + projectId: this.flags.project || this.getProject(), + applicationId: this.args.applicationId, + body: { + repository: "automated", + snapshot: this.args.snapshotId, + }, + }); + + this.logInfo("Ok"); + } +} + +export default PaasSnapshotsRestore; diff --git a/src/support/PaasKommand.ts b/src/support/PaasKommand.ts index ceb2bb30..7428bfef 100644 --- a/src/support/PaasKommand.ts +++ b/src/support/PaasKommand.ts @@ -74,4 +74,18 @@ export class PaasKommand extends Kommand { return this.flags.project; } + + async getCredentials() { + const project = this.getProject(); + const projectFile = this.fileProjectCredentials(project); + + if (!fs.existsSync(projectFile)) { + this.logKo("You are not logged in. You should run paas:login first. Aborting."); + process.exit(1); + } + + const credentials = JSON.parse(fs.readFileSync(projectFile, "utf8")); + + return credentials.apiKey; + } } From e8c9c76bebd1f9a8adb41447cc1dec94d5e1d243 Mon Sep 17 00:00:00 2001 From: Alexandre Bouthinon Date: Tue, 28 Feb 2023 11:21:23 +0100 Subject: [PATCH 02/10] Remove index.history settings forwarding in es:migrate --- src/support/migrate/providers/elasticsearch.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/support/migrate/providers/elasticsearch.ts b/src/support/migrate/providers/elasticsearch.ts index 5be1ea6c..7e90015d 100644 --- a/src/support/migrate/providers/elasticsearch.ts +++ b/src/support/migrate/providers/elasticsearch.ts @@ -35,6 +35,7 @@ export class Elasticsearch implements Provider { delete specifications.settings.index.uuid; delete specifications.settings.index.version; delete specifications.settings.index.routing; + delete specifications.settings.index.history; return specifications; } From 6e54a9a80c99df607a3a5a7f46f1b43d352a8e74 Mon Sep 17 00:00:00 2001 From: Shiranuit Date: Tue, 28 Feb 2023 14:38:33 +0100 Subject: [PATCH 03/10] disable websocket heartbeat from the SDK when using the debug-proxy --- src/commands/app/debug-proxy.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/commands/app/debug-proxy.ts b/src/commands/app/debug-proxy.ts index 24316d84..666f0254 100644 --- a/src/commands/app/debug-proxy.ts +++ b/src/commands/app/debug-proxy.ts @@ -57,6 +57,9 @@ export default class DebugProxy extends Kommand { }; async runSafe() { + // @ts-ignore Disable ping pong since when debugging Kuzzle might not be responding + clearInterval(this.sdk.sdk.protocol.pingIntervalId); + const nodeVersionResponse = (await this.sdk.query({ controller: "debug", action: "nodeVersion", From 011a1a95a0f13e24da444d3a4462431b6f75252d Mon Sep 17 00:00:00 2001 From: Shiranuit Date: Tue, 28 Feb 2023 14:46:26 +0100 Subject: [PATCH 04/10] allow to disable some ts rules --- .eslintrc.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.json b/.eslintrc.json index 7b35263d..0ecc4536 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -12,6 +12,7 @@ "plugin:@typescript-eslint/recommended" ], "rules": { + "@typescript-eslint/ban-ts-comment": 0, "@typescript-eslint/explicit-module-boundary-types": 0, "@typescript-eslint/no-explicit-any": 0, "@typescript-eslint/no-shadow": "error", From 61fd65683ff6a6c6f26a25c388e5ff28b36f2968 Mon Sep 17 00:00:00 2001 From: Shiranuit Date: Mon, 6 Mar 2023 10:53:46 +0100 Subject: [PATCH 05/10] Release 0.26.0 --- README.md | 76 +++++++++++++++++++++++++++++++++++------------ package-lock.json | 4 +-- package.json | 2 +- 3 files changed, 60 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index a8339f45..d5bcc886 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ $ npm install -g kourou $ kourou COMMAND running command... $ kourou (-v|--version|version) -kourou/0.25.0 linux-x64 node-v16.15.0 +kourou/0.26.0 linux-x64 node-v14.21.2 $ kourou --help [COMMAND] USAGE $ kourou COMMAND @@ -162,7 +162,9 @@ All other arguments and options will be passed as-is to the `sdk:query` method. * [`kourou paas:deploy ENVIRONMENT APPLICATIONID IMAGE`](#kourou-paasdeploy-environment-applicationid-image) * [`kourou paas:init PROJECT`](#kourou-paasinit-project) * [`kourou paas:login`](#kourou-paaslogin) -* [`kourou paas:logs ENVIRONMENT APPLICATION`](#kourou-paaslogs-environment-application) +* [`kourou paas:snapshots:cat ENVIRONMENT APPLICATIONID`](#kourou-paassnapshotscat-environment-applicationid) +* [`kourou paas:snapshots:dump ENVIRONMENT APPLICATIONID`](#kourou-paassnapshotsdump-environment-applicationid) +* [`kourou paas:snapshots:restore ENVIRONMENT APPLICATIONID SNAPSHOTID`](#kourou-paassnapshotsrestore-environment-applicationid-snapshotid) * [`kourou profile:export`](#kourou-profileexport) * [`kourou profile:import PATH`](#kourou-profileimport-path) * [`kourou realtime:subscribe INDEX COLLECTION [FILTERS]`](#kourou-realtimesubscribe-index-collection-filters) @@ -365,7 +367,7 @@ ARGUMENTS DESTINATION Directory to scaffold the app OPTIONS - --flavor=flavor [default: generic] Template flavor ("generic", "iot-platform", "iot-console", "iot-platform"). + --flavor=flavor [default: generic] Template flavor ("generic", "iot-backend", "iot-console"). Those can be found here: https://github.com/kuzzleio/project-templates --help show CLI help @@ -409,7 +411,7 @@ EXAMPLES $ kourou autocomplete --refresh-cache ``` -_See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v1.3.10/src/commands/autocomplete/index.ts)_ +_See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v1.3.0/src/commands/autocomplete/index.ts)_ ## `kourou collection:create INDEX COLLECTION [BODY]` @@ -725,7 +727,7 @@ OPTIONS --src=src (required) Migration source provider EXAMPLES - kourou es:migrate --src http://elasticsearch:9200 --dest ./my-backup --batch-size 2000 --pattern + kourou es:migrate --src http://elasticsearch:9200 --dest ./my-backup --batch-size 2000 --pattern '&myindexes.collection-*' kourou es:migrate --src ./my-backup --dest http://elasticsearch:9200 --reset --batch-size 2000 --no-interactive ``` @@ -870,7 +872,7 @@ OPTIONS --all see all commands in CLI ``` -_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.18/src/commands/help.ts)_ +_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.2/src/commands/help.ts)_ ## `kourou import PATH` @@ -1091,30 +1093,66 @@ OPTIONS _See code: [src/commands/paas/login.ts](src/commands/paas/login.ts)_ -## `kourou paas:logs ENVIRONMENT APPLICATION` +## `kourou paas:snapshots:cat ENVIRONMENT APPLICATIONID` -Show logs of the targeted application +List all snapshots for a given kuzzle application in a environment ``` USAGE - $ kourou paas:logs ENVIRONMENT APPLICATION + $ kourou paas:snapshots:cat ENVIRONMENT APPLICATIONID ARGUMENTS - ENVIRONMENT Kuzzle PaaS environment - APPLICATION Kuzzle PaaS application + ENVIRONMENT Project environment name + APPLICATIONID Application Identifier + +OPTIONS + --help show CLI help + --project=project Current PaaS project + --token=token Authentication token +``` + +_See code: [src/commands/paas/snapshots/cat.ts](src/commands/paas/snapshots/cat.ts)_ + +## `kourou paas:snapshots:dump ENVIRONMENT APPLICATIONID` + +List all snapshots for a given kuzzle application in a environment + +``` +USAGE + $ kourou paas:snapshots:dump ENVIRONMENT APPLICATIONID + +ARGUMENTS + ENVIRONMENT Project environment name + APPLICATIONID Application Identifier OPTIONS - -f, --follow Follow log output - -n, --tail=tail Number of lines to show from the end of the logs - -t, --timestamp Show timestamp --help show CLI help - --podName=podName Name of the pod to show logs from --project=project Current PaaS project - --since=since Display logs from a specific absolute (e.g. 2022/12/02 09:41) or relative (e.g. a minute ago) time - --until=until Display logs until a specific absolute (e.g. 2022/12/02 09:41) or relative (e.g. a minute ago) time + --token=token Authentication token +``` + +_See code: [src/commands/paas/snapshots/dump.ts](src/commands/paas/snapshots/dump.ts)_ + +## `kourou paas:snapshots:restore ENVIRONMENT APPLICATIONID SNAPSHOTID` + +List all snapshots for a given kuzzle application in a environment + +``` +USAGE + $ kourou paas:snapshots:restore ENVIRONMENT APPLICATIONID SNAPSHOTID + +ARGUMENTS + ENVIRONMENT Project environment name + APPLICATIONID Application Identifier + SNAPSHOTID Snapshot Identifier + +OPTIONS + --help show CLI help + --project=project Current PaaS project + --token=token Authentication token ``` -_See code: [src/commands/paas/logs.ts](src/commands/paas/logs.ts)_ +_See code: [src/commands/paas/snapshots/restore.ts](src/commands/paas/snapshots/restore.ts)_ ## `kourou profile:export` @@ -1487,7 +1525,7 @@ DESCRIPTION You can either: - Manually re-create credentials for your users - - Use the "mustChangePasswordIfSetByAdmin" option Kuzzle password policies (see + - Use the "mustChangePasswordIfSetByAdmin" option Kuzzle password policies (see https://github.com/kuzzleio/kuzzle-plugin-auth-passport-local/#optional-properties) - Use the "--generate-credentials" flag to auto-generate credentials for your users diff --git a/package-lock.json b/package-lock.json index 465022df..c0fc336f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "kourou", - "version": "0.25.0", + "version": "0.26.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "kourou", - "version": "0.25.0", + "version": "0.26.0", "license": "Apache-2.0", "dependencies": { "@elastic/elasticsearch": "^7.12.0", diff --git a/package.json b/package.json index c18fa3df..9ac68204 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "kourou", "description": "The CLI that helps you manage your Kuzzle instances", - "version": "0.25.0", + "version": "0.26.0", "author": "The Kuzzle Team ", "bin": { "kourou": "./bin/run" From d15a8e6ce42ed4d62b52612ad6658b1dfba91870 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Tue, 14 Feb 2023 14:33:05 +0100 Subject: [PATCH 06/10] paas snapshots commands --- src/commands/paas/deploy.ts | 29 ----------- src/commands/paas/login.ts | 9 ++-- src/commands/paas/logs.ts | 46 +----------------- src/commands/paas/snapshots/cat.ts | 58 ++++++++++++++++++++++ src/commands/paas/snapshots/dump.ts | 58 ++++++++++++++++++++++ src/commands/paas/snapshots/restore.ts | 66 ++++++++++++++++++++++++++ src/support/PaasKommand.ts | 14 ++++++ 7 files changed, 201 insertions(+), 79 deletions(-) create mode 100644 src/commands/paas/snapshots/cat.ts create mode 100644 src/commands/paas/snapshots/dump.ts create mode 100644 src/commands/paas/snapshots/restore.ts diff --git a/src/commands/paas/deploy.ts b/src/commands/paas/deploy.ts index dd035a27..c1642f3b 100644 --- a/src/commands/paas/deploy.ts +++ b/src/commands/paas/deploy.ts @@ -1,9 +1,5 @@ -import fs from "fs"; - import { flags } from "@oclif/command"; -import cli from "cli-ux"; -import PaasLogin from "./login"; import { PaasKommand } from "../../support/PaasKommand"; class PaasDeploy extends PaasKommand { @@ -70,31 +66,6 @@ class PaasDeploy extends PaasKommand { this.logOk("Deployment in progress"); } - - async getCredentials() { - const project = this.getProject(); - const projectFile = this.fileProjectCredentials(project); - - if (!fs.existsSync(projectFile)) { - this.log(""); - const nextStep = await cli.prompt( - "Cannot find credentials for this project. Do you want to login first? [Y/N]", - { type: "single" } - ); - this.log(""); - - if (nextStep.toLowerCase().startsWith("y")) { - await PaasLogin.run(["--project", project]); - } else { - this.logKo("Aborting."); - process.exit(1); - } - } - - const credentials = JSON.parse(fs.readFileSync(projectFile, "utf8")); - - return credentials.apiKey; - } } export default PaasDeploy; diff --git a/src/commands/paas/login.ts b/src/commands/paas/login.ts index ad698624..e93c0957 100644 --- a/src/commands/paas/login.ts +++ b/src/commands/paas/login.ts @@ -45,12 +45,13 @@ class PaasLogin extends PaasKommand { await this.initPaasClient({ username, password }); + await this.authenticateNPM(username, password); + const apiKey: ApiKey = await this.paas.auth.createApiKey( "Kourou PaaS API Key" ); this.createProjectCredentials(apiKey); - await this.authenticateNPM(username, password); this.logOk( `Successfully logged in as ${username}. Your Kuzzle Enterprise license is now enabled on this host.` @@ -89,10 +90,8 @@ class PaasLogin extends PaasKommand { }), }; - const response = await fetch( - `https://${this.packagesHost}/-/user/org.couchdb.user:${username}`, - options - ); + const targetUrl = `https://${this.packagesHost}/-/user/org.couchdb.user:${username}`; + const response = await fetch(targetUrl, options); const json = await response.json(); if (response.status !== 201) { diff --git a/src/commands/paas/logs.ts b/src/commands/paas/logs.ts index f392579d..57de576a 100644 --- a/src/commands/paas/logs.ts +++ b/src/commands/paas/logs.ts @@ -1,12 +1,9 @@ -import fs from "fs"; import * as readline from "readline"; import { flags } from "@oclif/command"; import chalk from "chalk"; import * as chrono from "chrono-node"; -import { cli } from "cli-ux"; -import PaasLogin from "./login"; import { PaasKommand } from "../../support/PaasKommand"; /** @@ -111,8 +108,7 @@ class PaasLogs extends PaasKommand { const user = await this.paas.auth.getCurrentUser(); this.logInfo( - `Logged as "${user._id}" for project "${ - this.flags.project || this.getProject() + `Logged as "${user._id}" for project "${this.flags.project || this.getProject() }"` ); @@ -173,46 +169,6 @@ class PaasLogs extends PaasKommand { } } - async getCredentials() { - const project = this.getProject(); - const projectFile = this.fileProjectCredentials(project); - - if (!fs.existsSync(projectFile)) { - this.log(""); - const nextStep = await cli.prompt( - "Cannot find credentials for this project. Do you want to login first? [Y/N]", - { type: "single" } - ); - this.log(""); - - if (nextStep.toLowerCase().startsWith("y")) { - await PaasLogin.run(["--project", project]); - } else { - this.logKo("Aborting."); - process.exit(1); - } - } - - const credentials = JSON.parse(fs.readFileSync(projectFile, "utf8")); - - return credentials.apiKey; - } - - getNumberOfSpaces(names: string[], currentName: string) { - const end = 10; - let max = { name: "", length: 0 }; - - for (const name of names) { - if (max.length < name.length) { - max = { name: name, length: name.length }; - } - } - - return currentName === max.name - ? end - : end + (max.length - currentName.length); - } - /** * Returns the color to use for a pod name. * @param podName Name of the pod. diff --git a/src/commands/paas/snapshots/cat.ts b/src/commands/paas/snapshots/cat.ts new file mode 100644 index 00000000..defcf45f --- /dev/null +++ b/src/commands/paas/snapshots/cat.ts @@ -0,0 +1,58 @@ +import { flags } from "@oclif/command"; + +import { PaasKommand } from "../../../support/PaasKommand"; + +class PaasSnapshotsCat extends PaasKommand { + public static description = + "List all snapshots for a given kuzzle application in a environment"; + + public static flags = { + help: flags.help(), + token: flags.string({ + default: process.env.KUZZLE_PAAS_TOKEN, + description: "Authentication token", + }), + project: flags.string({ + description: "Current PaaS project", + }), + }; + + static args = [ + { + name: "environment", + description: "Project environment name", + required: true, + }, + { + name: "applicationId", + description: "Application Identifier", + required: true, + } + ]; + + async runSafe() { + const apiKey = await this.getCredentials(); + + await this.initPaasClient({ apiKey }); + + const user = await this.paas.auth.getCurrentUser(); + this.logInfo( + `Logged as "${user._id}" for project "${this.flags.project || this.getProject() + }"` + ); + + + const { result } = await this.paas.query({ + controller: "application", + action: "snapshots", + environmentId: this.args.environment, + projectId: this.flags.project || this.getProject(), + applicationId: this.args.applicationId, + body: {}, + }); + + this.logInfo(JSON.stringify(result, null, 2)); + } +} + +export default PaasSnapshotsCat; diff --git a/src/commands/paas/snapshots/dump.ts b/src/commands/paas/snapshots/dump.ts new file mode 100644 index 00000000..50bdf540 --- /dev/null +++ b/src/commands/paas/snapshots/dump.ts @@ -0,0 +1,58 @@ +import { flags } from "@oclif/command"; + +import { PaasKommand } from "../../../support/PaasKommand"; + +class PaasSnapshotsDump extends PaasKommand { + public static description = + "List all snapshots for a given kuzzle application in a environment"; + + public static flags = { + help: flags.help(), + token: flags.string({ + default: process.env.KUZZLE_PAAS_TOKEN, + description: "Authentication token", + }), + project: flags.string({ + description: "Current PaaS project", + }), + }; + + static args = [ + { + name: "environment", + description: "Project environment name", + required: true, + }, + { + name: "applicationId", + description: "Application Identifier", + required: true, + } + ]; + + async runSafe() { + const apiKey = await this.getCredentials(); + + await this.initPaasClient({ apiKey }); + + const user = await this.paas.auth.getCurrentUser(); + this.logInfo( + `Logged as "${user._id}" for project "${this.flags.project || this.getProject() + }"` + ); + + + const { result }: any = await this.paas.query({ + controller: "application", + action: "dump", + environmentId: this.args.environment, + projectId: this.flags.project || this.getProject(), + applicationId: this.args.applicationId, + body: {}, + }); + + this.logOk(result.body); + } +} + +export default PaasSnapshotsDump; diff --git a/src/commands/paas/snapshots/restore.ts b/src/commands/paas/snapshots/restore.ts new file mode 100644 index 00000000..0a396030 --- /dev/null +++ b/src/commands/paas/snapshots/restore.ts @@ -0,0 +1,66 @@ +import { flags } from "@oclif/command"; + +import { PaasKommand } from "../../../support/PaasKommand"; + +class PaasSnapshotsRestore extends PaasKommand { + public static description = + "List all snapshots for a given kuzzle application in a environment"; + + public static flags = { + help: flags.help(), + token: flags.string({ + default: process.env.KUZZLE_PAAS_TOKEN, + description: "Authentication token", + }), + project: flags.string({ + description: "Current PaaS project", + }), + }; + + static args = [ + { + name: "environment", + description: "Project environment name", + required: true, + }, + { + name: "applicationId", + description: "Application Identifier", + required: true, + }, + { + name: "snapshotId", + description: "Snapshot Identifier", + required: true, + } + ]; + + async runSafe() { + const apiKey = await this.getCredentials(); + + await this.initPaasClient({ apiKey }); + + const user = await this.paas.auth.getCurrentUser(); + this.logInfo( + `Logged as "${user._id}" for project "${this.flags.project || this.getProject() + }"` + ); + + + await this.paas.query({ + controller: "application", + action: "restore", + environmentId: this.args.environment, + projectId: this.flags.project || this.getProject(), + applicationId: this.args.applicationId, + body: { + repository: "automated", + snapshot: this.args.snapshotId, + }, + }); + + this.logInfo("Ok"); + } +} + +export default PaasSnapshotsRestore; diff --git a/src/support/PaasKommand.ts b/src/support/PaasKommand.ts index ceb2bb30..7428bfef 100644 --- a/src/support/PaasKommand.ts +++ b/src/support/PaasKommand.ts @@ -74,4 +74,18 @@ export class PaasKommand extends Kommand { return this.flags.project; } + + async getCredentials() { + const project = this.getProject(); + const projectFile = this.fileProjectCredentials(project); + + if (!fs.existsSync(projectFile)) { + this.logKo("You are not logged in. You should run paas:login first. Aborting."); + process.exit(1); + } + + const credentials = JSON.parse(fs.readFileSync(projectFile, "utf8")); + + return credentials.apiKey; + } } From 33784f7577dc95c609c968ee8975bed7cbead3a6 Mon Sep 17 00:00:00 2001 From: Shiranuit Date: Tue, 28 Feb 2023 14:38:33 +0100 Subject: [PATCH 07/10] disable websocket heartbeat from the SDK when using the debug-proxy --- src/commands/app/debug-proxy.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/commands/app/debug-proxy.ts b/src/commands/app/debug-proxy.ts index 24316d84..666f0254 100644 --- a/src/commands/app/debug-proxy.ts +++ b/src/commands/app/debug-proxy.ts @@ -57,6 +57,9 @@ export default class DebugProxy extends Kommand { }; async runSafe() { + // @ts-ignore Disable ping pong since when debugging Kuzzle might not be responding + clearInterval(this.sdk.sdk.protocol.pingIntervalId); + const nodeVersionResponse = (await this.sdk.query({ controller: "debug", action: "nodeVersion", From 23da81ee8f68996d97fcb805437ba71fb1b5bb1b Mon Sep 17 00:00:00 2001 From: Shiranuit Date: Tue, 28 Feb 2023 14:46:26 +0100 Subject: [PATCH 08/10] allow to disable some ts rules --- .eslintrc.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.json b/.eslintrc.json index 7b35263d..0ecc4536 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -12,6 +12,7 @@ "plugin:@typescript-eslint/recommended" ], "rules": { + "@typescript-eslint/ban-ts-comment": 0, "@typescript-eslint/explicit-module-boundary-types": 0, "@typescript-eslint/no-explicit-any": 0, "@typescript-eslint/no-shadow": "error", From 261aec006f9235ce0876aded79281241b13de4d0 Mon Sep 17 00:00:00 2001 From: Alexandre Bouthinon Date: Tue, 28 Feb 2023 11:21:23 +0100 Subject: [PATCH 09/10] Remove index.history settings forwarding in es:migrate --- src/support/migrate/providers/elasticsearch.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/support/migrate/providers/elasticsearch.ts b/src/support/migrate/providers/elasticsearch.ts index 5be1ea6c..7e90015d 100644 --- a/src/support/migrate/providers/elasticsearch.ts +++ b/src/support/migrate/providers/elasticsearch.ts @@ -35,6 +35,7 @@ export class Elasticsearch implements Provider { delete specifications.settings.index.uuid; delete specifications.settings.index.version; delete specifications.settings.index.routing; + delete specifications.settings.index.history; return specifications; } From 80c50aa264214bba2fa365cfeecb9e1d70ab6f3d Mon Sep 17 00:00:00 2001 From: Shiranuit Date: Mon, 6 Mar 2023 10:53:46 +0100 Subject: [PATCH 10/10] Release 0.26.0 --- README.md | 72 +++++++++++++++++++++++++++++++++++++---------- package-lock.json | 4 +-- package.json | 2 +- 3 files changed, 60 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 82e113c6..7bd8760e 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,11 @@ $ npm install -g kourou $ kourou COMMAND running command... $ kourou (-v|--version|version) +<<<<<<< HEAD kourou/0.25.2 linux-x64 node-v14.20.0 +======= +kourou/0.26.0 linux-x64 node-v14.21.2 +>>>>>>> 61fd656 (Release 0.26.0) $ kourou --help [COMMAND] USAGE $ kourou COMMAND @@ -163,7 +167,9 @@ All other arguments and options will be passed as-is to the `sdk:query` method. * [`kourou paas:deploy ENVIRONMENT APPLICATIONID IMAGE`](#kourou-paasdeploy-environment-applicationid-image) * [`kourou paas:init PROJECT`](#kourou-paasinit-project) * [`kourou paas:login`](#kourou-paaslogin) -* [`kourou paas:logs ENVIRONMENT APPLICATION`](#kourou-paaslogs-environment-application) +* [`kourou paas:snapshots:cat ENVIRONMENT APPLICATIONID`](#kourou-paassnapshotscat-environment-applicationid) +* [`kourou paas:snapshots:dump ENVIRONMENT APPLICATIONID`](#kourou-paassnapshotsdump-environment-applicationid) +* [`kourou paas:snapshots:restore ENVIRONMENT APPLICATIONID SNAPSHOTID`](#kourou-paassnapshotsrestore-environment-applicationid-snapshotid) * [`kourou profile:export`](#kourou-profileexport) * [`kourou profile:import PATH`](#kourou-profileimport-path) * [`kourou realtime:subscribe INDEX COLLECTION [FILTERS]`](#kourou-realtimesubscribe-index-collection-filters) @@ -410,7 +416,7 @@ EXAMPLES $ kourou autocomplete --refresh-cache ``` -_See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v1.3.10/src/commands/autocomplete/index.ts)_ +_See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v1.3.0/src/commands/autocomplete/index.ts)_ ## `kourou collection:create INDEX COLLECTION [BODY]` @@ -874,7 +880,7 @@ OPTIONS --all see all commands in CLI ``` -_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.18/src/commands/help.ts)_ +_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.2/src/commands/help.ts)_ ## `kourou import PATH` @@ -1097,30 +1103,66 @@ OPTIONS _See code: [src/commands/paas/login.ts](src/commands/paas/login.ts)_ -## `kourou paas:logs ENVIRONMENT APPLICATION` +## `kourou paas:snapshots:cat ENVIRONMENT APPLICATIONID` -Show logs of the targeted application +List all snapshots for a given kuzzle application in a environment ``` USAGE - $ kourou paas:logs ENVIRONMENT APPLICATION + $ kourou paas:snapshots:cat ENVIRONMENT APPLICATIONID ARGUMENTS - ENVIRONMENT Kuzzle PaaS environment - APPLICATION Kuzzle PaaS application + ENVIRONMENT Project environment name + APPLICATIONID Application Identifier + +OPTIONS + --help show CLI help + --project=project Current PaaS project + --token=token Authentication token +``` + +_See code: [src/commands/paas/snapshots/cat.ts](src/commands/paas/snapshots/cat.ts)_ + +## `kourou paas:snapshots:dump ENVIRONMENT APPLICATIONID` + +List all snapshots for a given kuzzle application in a environment + +``` +USAGE + $ kourou paas:snapshots:dump ENVIRONMENT APPLICATIONID + +ARGUMENTS + ENVIRONMENT Project environment name + APPLICATIONID Application Identifier OPTIONS - -f, --follow Follow log output - -n, --tail=tail Number of lines to show from the end of the logs - -t, --timestamp Show timestamp --help show CLI help - --podName=podName Name of the pod to show logs from --project=project Current PaaS project - --since=since Display logs from a specific absolute (e.g. 2022/12/02 09:41) or relative (e.g. a minute ago) time - --until=until Display logs until a specific absolute (e.g. 2022/12/02 09:41) or relative (e.g. a minute ago) time + --token=token Authentication token +``` + +_See code: [src/commands/paas/snapshots/dump.ts](src/commands/paas/snapshots/dump.ts)_ + +## `kourou paas:snapshots:restore ENVIRONMENT APPLICATIONID SNAPSHOTID` + +List all snapshots for a given kuzzle application in a environment + +``` +USAGE + $ kourou paas:snapshots:restore ENVIRONMENT APPLICATIONID SNAPSHOTID + +ARGUMENTS + ENVIRONMENT Project environment name + APPLICATIONID Application Identifier + SNAPSHOTID Snapshot Identifier + +OPTIONS + --help show CLI help + --project=project Current PaaS project + --token=token Authentication token ``` -_See code: [src/commands/paas/logs.ts](src/commands/paas/logs.ts)_ +_See code: [src/commands/paas/snapshots/restore.ts](src/commands/paas/snapshots/restore.ts)_ ## `kourou profile:export` diff --git a/package-lock.json b/package-lock.json index c6c8558d..c0fc336f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "kourou", - "version": "0.25.2", + "version": "0.26.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "kourou", - "version": "0.25.2", + "version": "0.26.0", "license": "Apache-2.0", "dependencies": { "@elastic/elasticsearch": "^7.12.0", diff --git a/package.json b/package.json index 1403a6c3..9ac68204 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "kourou", "description": "The CLI that helps you manage your Kuzzle instances", - "version": "0.25.2", + "version": "0.26.0", "author": "The Kuzzle Team ", "bin": { "kourou": "./bin/run"