@lxdhub/dbsync
Version:
Display, search and copy LXD-images using a web interface.
137 lines • 5.08 kB
JavaScript
;
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);
};
Object.defineProperty(exports, "__esModule", { value: true });
const clime_1 = require("clime");
const castable_1 = require("clime/bld/castable");
const fs = require("fs-extra");
const YAML = require("js-yaml");
const __1 = require("../../..");
class StartOptions extends clime_1.Options {
constructor() {
super(...arguments);
this.databaseName = 'lxdhub';
this.databaseHost = 'localhost';
this.databasePassword = 'lxdhub';
this.databasePort = 5432;
this.databaseUsername = 'lxdhub';
}
}
__decorate([
clime_1.option({
description: 'The name of the database to connect to. Default is lxdhub',
type: String
}),
__metadata("design:type", Object)
], StartOptions.prototype, "databaseName", void 0);
__decorate([
clime_1.option({
description: 'The host of the database to connect to. Default is localhost',
type: String
}),
__metadata("design:type", String)
], StartOptions.prototype, "databaseHost", void 0);
__decorate([
clime_1.option({
description: 'The database password for the given user. Default is lxdhub',
type: String
}),
__metadata("design:type", String)
], StartOptions.prototype, "databasePassword", void 0);
__decorate([
clime_1.option({
description: 'The database port to connect to. Default is 5432',
type: Number
}),
__metadata("design:type", Number)
], StartOptions.prototype, "databasePort", void 0);
__decorate([
clime_1.option({
description: 'The database username. Default is lxdhub',
type: String
}),
__metadata("design:type", String)
], StartOptions.prototype, "databaseUsername", void 0);
__decorate([
clime_1.option({
description: 'The LXD certificate for the remote',
type: castable_1.File,
default: `${process.env.HOME}/.config/lxc/client.crt`
}),
__metadata("design:type", castable_1.File)
], StartOptions.prototype, "cert", void 0);
__decorate([
clime_1.option({
description: 'The LXC key for the remote',
type: castable_1.File,
default: `${process.env.HOME}/.config/lxc/client.key`
}),
__metadata("design:type", castable_1.File)
], StartOptions.prototype, "key", void 0);
__decorate([
clime_1.option({
description: 'The lxdhub.yml file with the configured remotes',
required: true,
type: castable_1.File,
flag: 'c'
}),
__metadata("design:type", castable_1.File)
], StartOptions.prototype, "config", void 0);
__decorate([
clime_1.option({
description: 'Whether it should enforce the database synchronization run',
type: Boolean,
default: false
}),
__metadata("design:type", Boolean)
], StartOptions.prototype, "force", void 0);
exports.StartOptions = StartOptions;
let default_1 = class default_1 extends clime_1.Command {
async execute(options) {
const database = {
database: options.databaseName || 'lxdhub',
host: options.databaseHost || 'localhost',
password: options.databasePassword || 'lxdhub',
port: options.databasePort || 5432,
username: options.databaseUsername || 'lxdhub'
};
const lxd = {
cert: fs.readFileSync(options.cert.fullName),
key: fs.readFileSync(options.key.fullName)
};
// Read the config file
await fs
.readFile(options.config.fullName, 'utf8')
// Convert from YAML to JSON
.then(content => YAML.safeLoad(content))
// Create the database sync instance
.then((lxdhubConfig) => new __1.LXDHubDbSync({
lxd,
database,
lxdhubConfig,
force: options.force
}))
// Run the database sync script
.then(dbSync => dbSync.run());
}
};
__decorate([
clime_1.metadata,
__metadata("design:type", Function),
__metadata("design:paramtypes", [StartOptions]),
__metadata("design:returntype", Promise)
], default_1.prototype, "execute", null);
default_1 = __decorate([
clime_1.command({
description: 'Start the lxdhub database synchronization'
})
], default_1);
exports.default = default_1;
//# sourceMappingURL=default.js.map