@wocker/mariadb-plugin
Version:
Mariadb plugin for wocker
413 lines (412 loc) • 16.6 kB
JavaScript
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MariadbController = void 0;
const core_1 = require("@wocker/core");
const core_2 = require("@wocker/core");
const MariadbService_1 = require("../services/MariadbService");
let MariadbController = class MariadbController {
constructor(appConfigService, dockerService, mariadbService) {
this.appConfigService = appConfigService;
this.dockerService = dockerService;
this.mariadbService = mariadbService;
}
mariadb(service, database) {
return __awaiter(this, void 0, void 0, function* () {
yield this.mariadbService.mariadb(service, database);
});
}
init(adminHostname) {
return __awaiter(this, void 0, void 0, function* () {
yield this.mariadbService.init(adminHostname);
});
}
create(name, username, password, rootPassword, host, storage, imageName, imageVersion, volume, containerPort) {
return __awaiter(this, void 0, void 0, function* () {
yield this.mariadbService.create({
name,
username,
password,
rootPassword,
host,
storage,
imageName,
imageVersion,
volume,
containerPort
});
if (host) {
yield this.mariadbService.startAdmin();
}
});
}
destroy(service, force, yes) {
return __awaiter(this, void 0, void 0, function* () {
yield this.mariadbService.destroy(service, yes, force);
yield this.mariadbService.startAdmin();
});
}
upgrade(name, storage, volume, imageName, imageVersion, containerPort, enableAdmin, disableAdmin) {
return __awaiter(this, void 0, void 0, function* () {
yield this.mariadbService.upgrade({
name,
storage,
volume,
imageName,
imageVersion,
containerPort
});
if (typeof enableAdmin !== "undefined") {
this.mariadbService.config.admin.enabled = true;
this.mariadbService.config.save();
}
if (typeof disableAdmin !== "undefined") {
this.mariadbService.config.admin.enabled = false;
this.mariadbService.config.save();
}
});
}
default(service) {
return __awaiter(this, void 0, void 0, function* () {
if (!service) {
const data = this.mariadbService.config.getDefaultService();
return `${data.name}\n`;
}
yield this.mariadbService.setDefault(service);
});
}
start(service, restart) {
return __awaiter(this, void 0, void 0, function* () {
yield this.mariadbService.start(service, restart);
yield this.mariadbService.startAdmin();
});
}
stop(service) {
return __awaiter(this, void 0, void 0, function* () {
yield this.mariadbService.stop(service);
yield this.mariadbService.startAdmin();
});
}
dump(service, database) {
return __awaiter(this, void 0, void 0, function* () {
yield this.mariadbService.dump(service, database);
});
}
backup(service, yes, del, database, filename) {
return __awaiter(this, void 0, void 0, function* () {
if (del) {
yield this.mariadbService.deleteBackup(service, database, filename, yes);
return;
}
yield this.mariadbService.backup(service, database, filename);
});
}
restore(service, database, filename) {
return __awaiter(this, void 0, void 0, function* () {
yield this.mariadbService.restore(service, database, filename);
});
}
list() {
return __awaiter(this, void 0, void 0, function* () {
return this.mariadbService.list();
});
}
getEmp() {
return [];
}
getDatabases(name) {
return __awaiter(this, void 0, void 0, function* () {
try {
const service = this.mariadbService.config.getServiceOrDefault(name);
return yield this.mariadbService.getDatabases(service);
}
catch (err) {
return [];
}
});
}
getFilename(service, database) {
return __awaiter(this, void 0, void 0, function* () {
if (!service || !database) {
return [];
}
return [];
});
}
getExistsServices() {
return this.mariadbService.getServices();
}
};
exports.MariadbController = MariadbController;
__decorate([
(0, core_1.Command)("mariadb [service]"),
(0, core_1.Description)("Interacts with a specified MariaDB service, optionally targeting a specific database within that service."),
__param(0, (0, core_1.Param)("service")),
__param(1, (0, core_1.Option)("database", {
type: "string",
alias: "d",
description: "<name> Specify the database to target within the service"
})),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, String]),
__metadata("design:returntype", Promise)
], MariadbController.prototype, "mariadb", null);
__decorate([
(0, core_1.Command)("mariadb:init"),
(0, core_1.Description)("Initializes the MariaDB configuration."),
__param(0, (0, core_1.Option)("admin-hostname", {
type: "string",
alias: "A",
description: "Specifies the phpmyadmin hostname."
})),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], MariadbController.prototype, "init", null);
__decorate([
(0, core_1.Command)("mariadb:create [service]"),
(0, core_1.Description)("Creates a MariaDB service with configurable credentials, host, and storage options."),
__param(0, (0, core_1.Param)("service")),
__param(1, (0, core_1.Option)("username", {
type: "string",
alias: "u",
description: "User name"
})),
__param(2, (0, core_1.Option)("password", {
type: "string",
alias: "p",
description: "Password"
})),
__param(3, (0, core_1.Option)("root-password", {
type: "string",
alias: "P",
description: "Root password"
})),
__param(4, (0, core_1.Option)("host", {
type: "string",
alias: "h",
description: "External host"
})),
__param(5, (0, core_1.Option)("storage", {
type: "string",
alias: "s",
description: "Storage type"
})),
__param(6, (0, core_1.Option)("image", {
type: "string",
alias: "i",
description: "The image name to start the service with"
})),
__param(7, (0, core_1.Option)("image-version", {
type: "string",
alias: "I",
description: "The image version to start the service with"
})),
__param(8, (0, core_1.Option)("volume", {
type: "string",
alias: "v",
description: "Specify volume name"
})),
__param(9, (0, core_1.Option)("container-port")),
__param(9, (0, core_1.Description)("Port on which the database container will be accessible on the host")),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, String, String, String, String, String, String, String, String, Number]),
__metadata("design:returntype", Promise)
], MariadbController.prototype, "create", null);
__decorate([
(0, core_1.Command)("mariadb:destroy [service]"),
(0, core_1.Description)("Destroys a specified MariaDB service instance with an option to force deletion."),
__param(0, (0, core_1.Param)("service")),
__param(1, (0, core_1.Option)("force", {
type: "boolean",
alias: "f",
description: "Force deletion"
})),
__param(2, (0, core_1.Option)("yes", {
type: "boolean",
alias: "y",
description: "Skip confirmation"
})),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Boolean, Boolean]),
__metadata("design:returntype", Promise)
], MariadbController.prototype, "destroy", null);
__decorate([
(0, core_1.Command)("mariadb:upgrade [name]"),
__param(0, (0, core_1.Param)("name")),
__param(1, (0, core_1.Option)("storage", {
type: "string",
alias: "s",
description: "Specify storage type"
})),
__param(2, (0, core_1.Option)("volume", {
type: "string",
alias: "v",
description: "Specify volume name"
})),
__param(3, (0, core_1.Option)("image", {
type: "string",
alias: "i"
})),
__param(4, (0, core_1.Option)("image-version", {
type: "string",
alias: "I"
})),
__param(5, (0, core_1.Option)("container-port")),
__param(5, (0, core_1.Description)("Port on which the database container will be accessible on the host")),
__param(6, (0, core_1.Option)("enable-admin")),
__param(7, (0, core_1.Option)("disable-admin")),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, String, String, String, String, Number, Boolean, Boolean]),
__metadata("design:returntype", Promise)
], MariadbController.prototype, "upgrade", null);
__decorate([
(0, core_1.Command)("mariadb:use [service]"),
(0, core_1.Description)("Sets a specified MariaDB service as the default or retrieves the current default service name if no service is specified."),
__param(0, (0, core_1.Param)("service")),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], MariadbController.prototype, "default", null);
__decorate([
(0, core_1.Command)("mariadb:start [service]"),
(0, core_1.Description)("Starts a specified MariaDB service and optionally restarts it if already running."),
__param(0, (0, core_1.Param)("service")),
__param(1, (0, core_1.Option)("restart", {
type: "boolean",
alias: "r",
description: "Restart the service if already running"
})),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Boolean]),
__metadata("design:returntype", Promise)
], MariadbController.prototype, "start", null);
__decorate([
(0, core_1.Command)("mariadb:stop [service]"),
(0, core_1.Description)("Stops a specified MariaDB service instance."),
__param(0, (0, core_1.Param)("service")),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], MariadbController.prototype, "stop", null);
__decorate([
(0, core_1.Command)("mariadb:dump [service]"),
(0, core_1.Description)("Creates a dump of the specified MariaDB service with an optional database selection."),
__param(0, (0, core_1.Param)("service")),
__param(1, (0, core_1.Option)("database", {
type: "string",
alias: "d",
description: "Name of the database to dump"
})),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, String]),
__metadata("design:returntype", Promise)
], MariadbController.prototype, "dump", null);
__decorate([
(0, core_1.Command)("mariadb:backup [service]"),
(0, core_1.Description)("Creates or deletes a database backup for a MariaDB service."),
__param(0, (0, core_1.Param)("service")),
__param(1, (0, core_1.Option)("yes", {
type: "boolean",
alias: "y",
description: "Auto confirm file deletion"
})),
__param(2, (0, core_1.Option)("delete", {
type: "boolean",
alias: "D",
description: "Delete the specified backup file"
})),
__param(3, (0, core_1.Option)("database", {
type: "string",
alias: "d",
description: "Database name to back up"
})),
__param(4, (0, core_1.Option)("filename", {
type: "string",
alias: "f",
description: "Name of the backup file"
})),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Boolean, Boolean, String, String]),
__metadata("design:returntype", Promise)
], MariadbController.prototype, "backup", null);
__decorate([
(0, core_1.Command)("mariadb:restore [service]"),
(0, core_1.Description)("Restores a MariaDB database from specified backup file."),
__param(0, (0, core_1.Param)("service")),
__param(1, (0, core_1.Option)("database", {
type: "string",
alias: "d",
description: "The name of the database to restore"
})),
__param(2, (0, core_1.Option)("filename", {
type: "string",
alias: "f",
description: "The name of the backup file to restore\n"
})),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, String, String]),
__metadata("design:returntype", Promise)
], MariadbController.prototype, "restore", null);
__decorate([
(0, core_1.Command)("mariadb:ls"),
(0, core_1.Command)("mariadb:list"),
(0, core_1.Description)("Lists all MariaDB services."),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], MariadbController.prototype, "list", null);
__decorate([
(0, core_1.Completion)("service", "mariadb:create [service]"),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Array)
], MariadbController.prototype, "getEmp", null);
__decorate([
(0, core_1.Completion)("database", "mariadb:backup [service]"),
__param(0, (0, core_1.Param)("service")),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], MariadbController.prototype, "getDatabases", null);
__decorate([
(0, core_1.Completion)("filename"),
__param(0, (0, core_1.Param)("service")),
__param(1, (0, core_1.Option)("database")),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, String]),
__metadata("design:returntype", Promise)
], MariadbController.prototype, "getFilename", null);
__decorate([
(0, core_1.Completion)("service"),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Array)
], MariadbController.prototype, "getExistsServices", null);
exports.MariadbController = MariadbController = __decorate([
(0, core_1.Controller)(),
(0, core_1.Description)("MariaDB commands"),
__metadata("design:paramtypes", [core_2.AppConfigService,
core_2.DockerService,
MariadbService_1.MariadbService])
], MariadbController);