@ps-aux/nodebup 0.1.1 → 0.2.0
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 +0 -0
- package/lib/bup/TaskRunner.js +82 -0
- package/lib/cli/app.js +30 -0
- package/lib/cli/bin.js +2 -8
- package/lib/config/Config.js +41 -0
- package/lib/config/expandPath.js +20 -0
- package/lib/config/validateConfigAgainstSchema.js +46 -0
- package/lib/ctx/Context.js +21 -16
- package/lib/ctx/ContextSymbols.js +12 -0
- package/lib/fs/Fs.js +60 -0
- package/lib/fs/areDirsSame.js +20 -0
- package/lib/fs/areDirsSame.test.js +20 -0
- package/lib/fs/fssync/FsSync.spec.js +37 -0
- package/lib/fs/fssync/FsSyncer.js +48 -0
- package/lib/fs/path/Path.js +59 -0
- package/lib/fs/readYaml.js +20 -0
- package/lib/globald.d.js +3 -0
- package/lib/log/AppLogger.js +28 -0
- package/lib/log/MinimalLogger.js +10 -4
- package/lib/storage/PlainCopyDataStorage.js +40 -0
- package/lib/storage/restic/ResticClient.js +70 -0
- package/lib/storage/restic/ResticClient.spec.js +50 -0
- package/lib/storage/types.d.js +5 -0
- package/lib/tools/gpg/Gpg.js +28 -0
- package/lib/tools/gpg/Gpg.spec.js +14 -0
- package/lib/tools/shell/Shell.js +52 -0
- package/lib/{shell → tools/shell}/shellCmd.js +4 -2
- package/lib/tools/ssh/SshKeyManager.js +36 -0
- package/lib/tools/ssh/SshKeyManager.spec.js +14 -0
- package/lib/types.js +5 -0
- package/package.json +53 -48
- package/lib/cli/entrypoint.js +0 -27
- package/lib/foo/foo.command.js +0 -16
- package/lib/shell/LocalShellCmdExecutor.js +0 -46
- package/lib/types.d.js +0 -1
package/README.md
ADDED
File without changes
|
@@ -0,0 +1,82 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.TaskRunner = void 0;
|
7
|
+
|
8
|
+
var _FsSyncer = require("../fs/fssync/FsSyncer");
|
9
|
+
|
10
|
+
var _Config = require("../config/Config");
|
11
|
+
|
12
|
+
var _Gpg = require("../tools/gpg/Gpg");
|
13
|
+
|
14
|
+
var _Fs = require("../fs/Fs");
|
15
|
+
|
16
|
+
var _SshKeyManager = require("../tools/ssh/SshKeyManager");
|
17
|
+
|
18
|
+
var _inversify = require("inversify");
|
19
|
+
|
20
|
+
var _ContextSymbols = require("../ctx/ContextSymbols");
|
21
|
+
|
22
|
+
var _PlainCopyDataStorage = require("../storage/PlainCopyDataStorage");
|
23
|
+
|
24
|
+
var _AppLogger = require("../log/AppLogger");
|
25
|
+
|
26
|
+
var _dec, _dec2, _dec3, _dec4, _class;
|
27
|
+
|
28
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
29
|
+
|
30
|
+
let TaskRunner = (_dec = (0, _inversify.injectable)(), _dec2 = function (target, key) {
|
31
|
+
return (0, _inversify.inject)(_ContextSymbols.TaskConfig_)(target, undefined, 6);
|
32
|
+
}, _dec3 = Reflect.metadata("design:type", Function), _dec4 = Reflect.metadata("design:paramtypes", [typeof _FsSyncer.FsSyncer === "undefined" ? Object : _FsSyncer.FsSyncer, typeof _Gpg.Gpg === "undefined" ? Object : _Gpg.Gpg, typeof _SshKeyManager.SshKeyManager === "undefined" ? Object : _SshKeyManager.SshKeyManager, typeof _Fs.Fs === "undefined" ? Object : _Fs.Fs, typeof _PlainCopyDataStorage.PlainCopyDataStorage === "undefined" ? Object : _PlainCopyDataStorage.PlainCopyDataStorage, typeof _AppLogger.AppLogger === "undefined" ? Object : _AppLogger.AppLogger, typeof _Config.Tasks === "undefined" ? Object : _Config.Tasks]), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = class TaskRunner {
|
33
|
+
constructor(sync, gpg, ssh, fs, storage, log, tasks) {
|
34
|
+
this.sync = sync;
|
35
|
+
this.gpg = gpg;
|
36
|
+
this.ssh = ssh;
|
37
|
+
this.fs = fs;
|
38
|
+
this.storage = storage;
|
39
|
+
this.log = log;
|
40
|
+
this.tasks = tasks;
|
41
|
+
|
42
|
+
_defineProperty(this, "runAll", async () => {
|
43
|
+
const tasks = this.tasks;
|
44
|
+
|
45
|
+
if (tasks.file.length > 0) {
|
46
|
+
for (const t of tasks.file) {
|
47
|
+
await this.runFileTask(t);
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
return; // eslint-disable-next-line no-unreachable
|
52
|
+
|
53
|
+
if (tasks.gpgKey.length > 0) tasks.gpgKey.forEach(this.runGpgKeyTask);
|
54
|
+
if (tasks.sshKey.length > 0) tasks.sshKey.forEach(this.runSshKeyTask);
|
55
|
+
});
|
56
|
+
|
57
|
+
_defineProperty(this, "runGpgKeyTask", t => {
|
58
|
+
this.log.info('Running GPG key task', t);
|
59
|
+
const key = this.gpg.exportKey(t.id);
|
60
|
+
const to = this.storagePath(t.to || `keys/gpg/${t.id}.asc`);
|
61
|
+
this.fs.writeFile(to, key);
|
62
|
+
});
|
63
|
+
|
64
|
+
_defineProperty(this, "runSshKeyTask", t => {
|
65
|
+
this.log.info('Running SSH key task', t);
|
66
|
+
const key = this.ssh.exportKey(t.id);
|
67
|
+
const to = this.storagePath(t.to || `keys/ssh/${t.id}`);
|
68
|
+
this.fs.writeFile(to, key);
|
69
|
+
});
|
70
|
+
|
71
|
+
_defineProperty(this, "runFileTask", async t => {
|
72
|
+
this.log.info('Running file task', t);
|
73
|
+
this.storage.store(t.from, t.to);
|
74
|
+
});
|
75
|
+
|
76
|
+
_defineProperty(this, "storagePath", path => {
|
77
|
+
throw new Error('Unspported');
|
78
|
+
});
|
79
|
+
}
|
80
|
+
|
81
|
+
}) || _class) || _class) || _class) || _class);
|
82
|
+
exports.TaskRunner = TaskRunner;
|
package/lib/cli/app.js
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.createApp = void 0;
|
7
|
+
|
8
|
+
require("reflect-metadata");
|
9
|
+
|
10
|
+
var _nclif = require("@ps-aux/nclif");
|
11
|
+
|
12
|
+
var _Config = require("../config/Config");
|
13
|
+
|
14
|
+
var _Context = require("../ctx/Context");
|
15
|
+
|
16
|
+
var _TaskRunner = require("../bup/TaskRunner");
|
17
|
+
|
18
|
+
const createApp = () => _nclif.CliApp.of({
|
19
|
+
options: [],
|
20
|
+
commands: {
|
21
|
+
go: (0, _nclif.cmd)({
|
22
|
+
description: 'Run backup',
|
23
|
+
run: (_, ctx) => ctx.get(_TaskRunner.TaskRunner).runAll()
|
24
|
+
})
|
25
|
+
}
|
26
|
+
}).addObjectConfig(pwd => (0, _Config.readConfig)(pwd + '/bup.yaml')).context(({
|
27
|
+
config
|
28
|
+
}) => (0, _Context.createContext)(config));
|
29
|
+
|
30
|
+
exports.createApp = createApp;
|
package/lib/cli/bin.js
CHANGED
@@ -1,12 +1,6 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
"use strict";
|
3
3
|
|
4
|
-
var
|
4
|
+
var _app = require("./app");
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
9
|
-
|
10
|
-
const rootDir = process.cwd();
|
11
|
-
const ctx = (0, _Context.createContext)(rootDir);
|
12
|
-
(0, _entrypoint.default)(ctx);
|
6
|
+
(0, _app.createApp)().run();
|
@@ -0,0 +1,41 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.readConfig = void 0;
|
7
|
+
|
8
|
+
var _Path = require("../fs/path/Path");
|
9
|
+
|
10
|
+
var _readYaml = require("../fs/readYaml");
|
11
|
+
|
12
|
+
var _validateConfigAgainstSchema = require("./validateConfigAgainstSchema");
|
13
|
+
|
14
|
+
var _expandPath = require("./expandPath");
|
15
|
+
|
16
|
+
const readConfig = path => {
|
17
|
+
const file = _Path.AbsPath.from(path);
|
18
|
+
|
19
|
+
const obj = (0, _readYaml.readYaml)(file.str());
|
20
|
+
(0, _validateConfigAgainstSchema.validateConfigAgainstSchema)(obj);
|
21
|
+
const rootDir = file.parent();
|
22
|
+
|
23
|
+
const expand = str => {
|
24
|
+
const p = (0, _expandPath.expandPath)(str, rootDir);
|
25
|
+
return p;
|
26
|
+
};
|
27
|
+
|
28
|
+
if (!obj.tasks.file) obj.tasks.file = [];
|
29
|
+
if (!obj.tasks.gpgKey) obj.tasks.gpgKey = [];
|
30
|
+
if (!obj.tasks.sshKey) obj.tasks.sshKey = [];
|
31
|
+
obj.tasks.file.forEach(t => {
|
32
|
+
t.from = expand(t.from);
|
33
|
+
t.to = _Path.RelativePath.from(t.to);
|
34
|
+
});
|
35
|
+
obj.storage.forEach(s => {
|
36
|
+
s.path = expand(s.path);
|
37
|
+
});
|
38
|
+
return obj;
|
39
|
+
};
|
40
|
+
|
41
|
+
exports.readConfig = readConfig;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.expandPath = void 0;
|
7
|
+
|
8
|
+
var _Path = require("../fs/path/Path");
|
9
|
+
|
10
|
+
var _os = _interopRequireDefault(require("os"));
|
11
|
+
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
|
+
|
14
|
+
const expandPath = (path, rootDir) => {
|
15
|
+
path = path.replace('<cwd>', rootDir.str);
|
16
|
+
path = path.replace('~', _os.default.homedir());
|
17
|
+
return _Path.AbsPath.from(path);
|
18
|
+
};
|
19
|
+
|
20
|
+
exports.expandPath = expandPath;
|
@@ -0,0 +1,46 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.validateConfigAgainstSchema = void 0;
|
7
|
+
|
8
|
+
var _joi = _interopRequireDefault(require("@hapi/joi"));
|
9
|
+
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11
|
+
|
12
|
+
const DirTaskSchema = _joi.default.object({
|
13
|
+
from: _joi.default.string(),
|
14
|
+
to: _joi.default.string()
|
15
|
+
});
|
16
|
+
|
17
|
+
const FileTaskSchema = DirTaskSchema;
|
18
|
+
|
19
|
+
const KeyTaskSchema = _joi.default.object({
|
20
|
+
id: _joi.default.string(),
|
21
|
+
to: _joi.default.string().optional()
|
22
|
+
});
|
23
|
+
|
24
|
+
const StorageSchema = _joi.default.object({
|
25
|
+
path: _joi.default.string()
|
26
|
+
});
|
27
|
+
|
28
|
+
const Schema = () => _joi.default.object({
|
29
|
+
storage: _joi.default.array().items(StorageSchema),
|
30
|
+
tasks: _joi.default.object({
|
31
|
+
dir: _joi.default.array().items(DirTaskSchema).optional(),
|
32
|
+
file: _joi.default.array().items(FileTaskSchema).optional(),
|
33
|
+
gpgKey: _joi.default.array().items(KeyTaskSchema).optional(),
|
34
|
+
sshKey: _joi.default.array().items(KeyTaskSchema).optional()
|
35
|
+
})
|
36
|
+
});
|
37
|
+
|
38
|
+
const validateConfigAgainstSchema = cfg => {
|
39
|
+
const r = Schema().validate(cfg, {
|
40
|
+
presence: 'required',
|
41
|
+
allowUnknown: false
|
42
|
+
});
|
43
|
+
if (r.error) throw new Error('Invalid config.' + r.error.message);
|
44
|
+
};
|
45
|
+
|
46
|
+
exports.validateConfigAgainstSchema = validateConfigAgainstSchema;
|
package/lib/ctx/Context.js
CHANGED
@@ -5,32 +5,37 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.createContext = void 0;
|
7
7
|
|
8
|
-
var
|
8
|
+
var _Shell = require("../tools/shell/Shell");
|
9
9
|
|
10
|
-
var
|
10
|
+
var _FsSyncer = require("../fs/fssync/FsSyncer");
|
11
11
|
|
12
|
-
|
12
|
+
var _Gpg = require("../tools/gpg/Gpg");
|
13
13
|
|
14
|
-
|
15
|
-
constructor(rootDir) {
|
16
|
-
_defineProperty(this, "_log", void 0);
|
14
|
+
var _Fs = require("../fs/Fs");
|
17
15
|
|
18
|
-
|
16
|
+
var _SshKeyManager = require("../tools/ssh/SshKeyManager");
|
19
17
|
|
20
|
-
|
18
|
+
var _inversify = require("inversify");
|
21
19
|
|
22
|
-
|
20
|
+
var _PlainCopyDataStorage = require("../storage/PlainCopyDataStorage");
|
23
21
|
|
24
|
-
|
22
|
+
var _ContextSymbols = require("./ContextSymbols");
|
25
23
|
|
26
|
-
|
27
|
-
this.sh = new _LocalShellCmdExecutor.LocalShellCmdExecutor(this._log);
|
28
|
-
}
|
24
|
+
var _TaskRunner = require("../bup/TaskRunner");
|
29
25
|
|
30
|
-
|
26
|
+
var _AppLogger = require("../log/AppLogger");
|
31
27
|
|
32
|
-
const createContext =
|
33
|
-
|
28
|
+
const createContext = cfg => {
|
29
|
+
if (cfg.storage.length !== 1) throw new Error('Exactly one storage path is required');
|
30
|
+
const c = new _inversify.Container();
|
31
|
+
c.bind(_ContextSymbols.TaskConfig_).toConstantValue(cfg.tasks);
|
32
|
+
c.bind(_ContextSymbols.StorageConfig_).toConstantValue(cfg.storage[0]);
|
33
|
+
const log = new _AppLogger.AppLogger();
|
34
|
+
c.bind(_ContextSymbols.Log_).toConstantValue(log);
|
35
|
+
c.bind(_AppLogger.AppLogger).toConstantValue(log);
|
36
|
+
const self = [_Gpg.Gpg, _Shell.Shell, _Fs.Fs, _FsSyncer.FsSyncer, _SshKeyManager.SshKeyManager, _PlainCopyDataStorage.PlainCopyDataStorage, _TaskRunner.TaskRunner];
|
37
|
+
self.forEach(s => c.bind(s).toSelf());
|
38
|
+
return c;
|
34
39
|
};
|
35
40
|
|
36
41
|
exports.createContext = createContext;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.TaskConfig_ = exports.StorageConfig_ = exports.Log_ = void 0;
|
7
|
+
const Log_ = Symbol.for('Log');
|
8
|
+
exports.Log_ = Log_;
|
9
|
+
const TaskConfig_ = Symbol.for('config.Tasks');
|
10
|
+
exports.TaskConfig_ = TaskConfig_;
|
11
|
+
const StorageConfig_ = Symbol.for('config.Storage');
|
12
|
+
exports.StorageConfig_ = StorageConfig_;
|
package/lib/fs/Fs.js
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.Fs = void 0;
|
7
|
+
|
8
|
+
var _fs = _interopRequireDefault(require("fs"));
|
9
|
+
|
10
|
+
var _inversify = require("inversify");
|
11
|
+
|
12
|
+
var _AppLogger = require("../log/AppLogger");
|
13
|
+
|
14
|
+
var _dec, _dec2, _dec3, _class;
|
15
|
+
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
|
+
|
18
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
19
|
+
|
20
|
+
let Fs = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.metadata("design:type", Function), _dec3 = Reflect.metadata("design:paramtypes", [typeof _AppLogger.AppLogger === "undefined" ? Object : _AppLogger.AppLogger]), _dec(_class = _dec2(_class = _dec3(_class = class Fs {
|
21
|
+
constructor(log) {
|
22
|
+
this.log = log;
|
23
|
+
|
24
|
+
_defineProperty(this, "writeFile", (path, content) => {
|
25
|
+
this.log.debug('Writing into file', path);
|
26
|
+
this.ensureParentDir(path);
|
27
|
+
|
28
|
+
_fs.default.writeFileSync(path.str(), content);
|
29
|
+
});
|
30
|
+
|
31
|
+
_defineProperty(this, "isFile", path => !_fs.default.lstatSync(path.str()).isDirectory());
|
32
|
+
|
33
|
+
_defineProperty(this, "readFile", path => {
|
34
|
+
this.log.debug('Reading from file', path.str);
|
35
|
+
return _fs.default.readFileSync(path.str()).toString();
|
36
|
+
});
|
37
|
+
|
38
|
+
_defineProperty(this, "ensureDir", path => {
|
39
|
+
if (!this.exists(path)) {
|
40
|
+
this.log.debug('Dir ', path, 'does not exist. Wil be created');
|
41
|
+
|
42
|
+
_fs.default.mkdirSync(path.str(), {
|
43
|
+
recursive: true
|
44
|
+
});
|
45
|
+
} else {
|
46
|
+
if (this.isFile(path)) throw new Error(`${path.str()} exists and is not a directory`);
|
47
|
+
}
|
48
|
+
});
|
49
|
+
|
50
|
+
_defineProperty(this, "ensureParentDir", path => {
|
51
|
+
const parent = path.parent();
|
52
|
+
if (this.exists(parent)) return;
|
53
|
+
this.ensureDir(parent);
|
54
|
+
});
|
55
|
+
|
56
|
+
_defineProperty(this, "exists", path => _fs.default.existsSync(path.str()));
|
57
|
+
}
|
58
|
+
|
59
|
+
}) || _class) || _class) || _class);
|
60
|
+
exports.Fs = Fs;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.areDirsSame = void 0;
|
7
|
+
|
8
|
+
var _dirCompare = require("dir-compare");
|
9
|
+
|
10
|
+
const opts = {
|
11
|
+
compareContent: true,
|
12
|
+
compareDate: true
|
13
|
+
};
|
14
|
+
|
15
|
+
const areDirsSame = (a, b) => {
|
16
|
+
const res = (0, _dirCompare.compareSync)(a.str(), b.str(), opts);
|
17
|
+
return res.same;
|
18
|
+
};
|
19
|
+
|
20
|
+
exports.areDirsSame = areDirsSame;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _areDirsSame = require("./areDirsSame");
|
4
|
+
|
5
|
+
var _test = require("../../test");
|
6
|
+
|
7
|
+
var _Path = require("./path/Path");
|
8
|
+
|
9
|
+
const thisDir = _Path.AbsPath.from(__dirname);
|
10
|
+
|
11
|
+
it('same', () => {
|
12
|
+
const res = (0, _areDirsSame.areDirsSame)(thisDir, thisDir);
|
13
|
+
expect(res).toBe(true);
|
14
|
+
});
|
15
|
+
it('not same', () => {
|
16
|
+
const otherDir = _Path.AbsPath.from((0, _test.testDir)());
|
17
|
+
|
18
|
+
const res = (0, _areDirsSame.areDirsSame)(thisDir, otherDir);
|
19
|
+
expect(res).toBe(false);
|
20
|
+
});
|
@@ -0,0 +1,37 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _FsSyncer = require("./FsSyncer");
|
4
|
+
|
5
|
+
var _Shell = require("../../tools/shell/Shell");
|
6
|
+
|
7
|
+
var _test = require("../../../test");
|
8
|
+
|
9
|
+
var _fs = _interopRequireDefault(require("fs"));
|
10
|
+
|
11
|
+
var _areDirsSame = require("../areDirsSame");
|
12
|
+
|
13
|
+
var _Fs = require("../Fs");
|
14
|
+
|
15
|
+
var _Path = require("../path/Path");
|
16
|
+
|
17
|
+
var _AppLogger = require("../../log/AppLogger");
|
18
|
+
|
19
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
20
|
+
|
21
|
+
describe('FsSync', () => {
|
22
|
+
const from = _Path.AbsPath.from((0, _test.testDir)('fs/fssync/src'));
|
23
|
+
|
24
|
+
const to = _Path.AbsPath.from((0, _test.testDir)('fs/fssync/dst/inner'));
|
25
|
+
|
26
|
+
it('syncs dir', () => {
|
27
|
+
const l = new _AppLogger.AppLogger();
|
28
|
+
const sut = new _FsSyncer.FsSyncer(new _Shell.Shell(l), new _Fs.Fs(l), l);
|
29
|
+
sut.syncDirs(from, to);
|
30
|
+
expect((0, _areDirsSame.areDirsSame)(from, to)).toBe(true);
|
31
|
+
});
|
32
|
+
afterAll(() => {
|
33
|
+
_fs.default.rmdirSync(to.str(), {
|
34
|
+
recursive: true
|
35
|
+
});
|
36
|
+
});
|
37
|
+
});
|
@@ -0,0 +1,48 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.FsSyncer = void 0;
|
7
|
+
|
8
|
+
var _Shell = require("../../tools/shell/Shell");
|
9
|
+
|
10
|
+
var _Fs = require("../Fs");
|
11
|
+
|
12
|
+
var _inversify = require("inversify");
|
13
|
+
|
14
|
+
var _AppLogger = require("../../log/AppLogger");
|
15
|
+
|
16
|
+
var _dec, _dec2, _dec3, _class;
|
17
|
+
|
18
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
19
|
+
|
20
|
+
const toUnixDirString = path => {
|
21
|
+
const val = path.str();
|
22
|
+
if (val.endsWith('/')) return val;
|
23
|
+
return val + '/';
|
24
|
+
};
|
25
|
+
|
26
|
+
let FsSyncer = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.metadata("design:type", Function), _dec3 = Reflect.metadata("design:paramtypes", [typeof _Shell.Shell === "undefined" ? Object : _Shell.Shell, typeof _Fs.Fs === "undefined" ? Object : _Fs.Fs, typeof _AppLogger.AppLogger === "undefined" ? Object : _AppLogger.AppLogger]), _dec(_class = _dec2(_class = _dec3(_class = class FsSyncer {
|
27
|
+
constructor(sh, fs, log) {
|
28
|
+
this.sh = sh;
|
29
|
+
this.fs = fs;
|
30
|
+
this.log = log;
|
31
|
+
|
32
|
+
_defineProperty(this, "syncDirs", (from, to) => {
|
33
|
+
this.log.info('Syncing dir', from.str(), '==>', to.str());
|
34
|
+
const fromPath = toUnixDirString(from);
|
35
|
+
const toPath = toUnixDirString(to);
|
36
|
+
this.fs.ensureParentDir(to);
|
37
|
+
this.sh.exec(`rsync -rtv ${fromPath} ${toPath}`);
|
38
|
+
});
|
39
|
+
|
40
|
+
_defineProperty(this, "syncFile", (from, to) => {
|
41
|
+
this.log.info('Syncing file', from.str(), '==>', to.str());
|
42
|
+
this.fs.ensureParentDir(to);
|
43
|
+
this.sh.exec(`rsync -rtv ${from.str()} ${to.str()}`);
|
44
|
+
});
|
45
|
+
}
|
46
|
+
|
47
|
+
}) || _class) || _class) || _class);
|
48
|
+
exports.FsSyncer = FsSyncer;
|
@@ -0,0 +1,59 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.RelativePath = exports.AbsPath = void 0;
|
7
|
+
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
9
|
+
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11
|
+
|
12
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
13
|
+
|
14
|
+
class AbsPath {
|
15
|
+
constructor(path) {
|
16
|
+
this.path = path;
|
17
|
+
|
18
|
+
_defineProperty(this, "resolve", path => {
|
19
|
+
const str = typeof path === 'string' ? path : path.str();
|
20
|
+
return AbsPath.from(_path.default.resolve(this.str(), str));
|
21
|
+
});
|
22
|
+
|
23
|
+
_defineProperty(this, "parent", () => {
|
24
|
+
return AbsPath.from(_path.default.resolve(this.path, '..'));
|
25
|
+
});
|
26
|
+
|
27
|
+
_defineProperty(this, "str", () => this.path);
|
28
|
+
|
29
|
+
if (!_path.default.isAbsolute(path)) throw new Error(`Path ${path} must be absolute`);
|
30
|
+
}
|
31
|
+
|
32
|
+
toString() {
|
33
|
+
return `AbsPath(${this.str()})`;
|
34
|
+
}
|
35
|
+
|
36
|
+
}
|
37
|
+
|
38
|
+
exports.AbsPath = AbsPath;
|
39
|
+
|
40
|
+
_defineProperty(AbsPath, "from", str => {
|
41
|
+
const p = new AbsPath(str);
|
42
|
+
return p;
|
43
|
+
});
|
44
|
+
|
45
|
+
class RelativePath {
|
46
|
+
constructor(path) {
|
47
|
+
this.path = path;
|
48
|
+
|
49
|
+
_defineProperty(this, "str", () => this.path);
|
50
|
+
|
51
|
+
if (_path.default.isAbsolute(path)) throw new Error(`Path ${path} must be relative`);
|
52
|
+
}
|
53
|
+
|
54
|
+
} // AbsPath.prototype.toString = () => 'hovno'
|
55
|
+
|
56
|
+
|
57
|
+
exports.RelativePath = RelativePath;
|
58
|
+
|
59
|
+
_defineProperty(RelativePath, "from", str => new RelativePath(str));
|
@@ -0,0 +1,20 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.readYaml = void 0;
|
7
|
+
|
8
|
+
var _fs = _interopRequireDefault(require("fs"));
|
9
|
+
|
10
|
+
var _yaml = _interopRequireDefault(require("yaml"));
|
11
|
+
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
|
+
|
14
|
+
const readYaml = path => {
|
15
|
+
const content = _fs.default.readFileSync(path).toString();
|
16
|
+
|
17
|
+
return _yaml.default.parse(content);
|
18
|
+
};
|
19
|
+
|
20
|
+
exports.readYaml = readYaml;
|
package/lib/globald.d.js
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.AppLogger = void 0;
|
7
|
+
|
8
|
+
var _ConsoleLogger = require("./ConsoleLogger");
|
9
|
+
|
10
|
+
var _inversify = require("inversify");
|
11
|
+
|
12
|
+
var _dec, _class;
|
13
|
+
|
14
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
15
|
+
|
16
|
+
let AppLogger = (_dec = (0, _inversify.injectable)(), _dec(_class = class AppLogger {
|
17
|
+
constructor() {
|
18
|
+
_defineProperty(this, "log", new _ConsoleLogger.ConsoleLogger());
|
19
|
+
|
20
|
+
_defineProperty(this, "debug", this.log.debug);
|
21
|
+
|
22
|
+
_defineProperty(this, "info", this.log.info);
|
23
|
+
|
24
|
+
_defineProperty(this, "error", this.log.error);
|
25
|
+
}
|
26
|
+
|
27
|
+
}) || _class);
|
28
|
+
exports.AppLogger = AppLogger;
|
package/lib/log/MinimalLogger.js
CHANGED
@@ -8,11 +8,17 @@ exports.minimalLogger = void 0;
|
|
8
8
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
9
9
|
|
10
10
|
class MinimalLogger {
|
11
|
-
constructor() {
|
12
|
-
|
11
|
+
constructor(onlyError = true) {
|
12
|
+
this.onlyError = onlyError;
|
13
|
+
|
14
|
+
_defineProperty(this, "debug", (...args) => {
|
15
|
+
if (this.onlyError) return;
|
16
|
+
console.log(...args);
|
13
17
|
});
|
14
18
|
|
15
|
-
_defineProperty(this, "info", () => {
|
19
|
+
_defineProperty(this, "info", (...args) => {
|
20
|
+
if (this.onlyError) return;
|
21
|
+
console.log(...args);
|
16
22
|
});
|
17
23
|
|
18
24
|
_defineProperty(this, "error", console.error);
|
@@ -20,6 +26,6 @@ class MinimalLogger {
|
|
20
26
|
|
21
27
|
}
|
22
28
|
|
23
|
-
const minimalLogger = () => new MinimalLogger();
|
29
|
+
const minimalLogger = (onlyError = true) => new MinimalLogger(onlyError);
|
24
30
|
|
25
31
|
exports.minimalLogger = minimalLogger;
|
@@ -0,0 +1,40 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.PlainCopyDataStorage = void 0;
|
7
|
+
|
8
|
+
var _inversify = require("inversify");
|
9
|
+
|
10
|
+
var _FsSyncer = require("../fs/fssync/FsSyncer");
|
11
|
+
|
12
|
+
var _Config = require("../config/Config");
|
13
|
+
|
14
|
+
var _ContextSymbols = require("../ctx/ContextSymbols");
|
15
|
+
|
16
|
+
var _Fs = require("../fs/Fs");
|
17
|
+
|
18
|
+
var _AppLogger = require("../log/AppLogger");
|
19
|
+
|
20
|
+
var _dec, _dec2, _dec3, _dec4, _class;
|
21
|
+
|
22
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
23
|
+
|
24
|
+
let PlainCopyDataStorage = (_dec = (0, _inversify.injectable)(), _dec2 = function (target, key) {
|
25
|
+
return (0, _inversify.inject)(_ContextSymbols.StorageConfig_)(target, undefined, 1);
|
26
|
+
}, _dec3 = Reflect.metadata("design:type", Function), _dec4 = Reflect.metadata("design:paramtypes", [typeof _FsSyncer.FsSyncer === "undefined" ? Object : _FsSyncer.FsSyncer, typeof _Config.StorageInstance === "undefined" ? Object : _Config.StorageInstance, typeof _Fs.Fs === "undefined" ? Object : _Fs.Fs, typeof _AppLogger.AppLogger === "undefined" ? Object : _AppLogger.AppLogger]), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = class PlainCopyDataStorage {
|
27
|
+
constructor(fsSyncer, storage, fs, log) {
|
28
|
+
this.fsSyncer = fsSyncer;
|
29
|
+
this.storage = storage;
|
30
|
+
this.fs = fs;
|
31
|
+
this.log = log;
|
32
|
+
|
33
|
+
_defineProperty(this, "store", async (from, to) => {
|
34
|
+
this.log.info(`Storing ${from} to ${to}`);
|
35
|
+
if (this.fs.isFile(from)) this.fsSyncer.syncFile(from, this.storage.path.resolve(to));else this.fsSyncer.syncDirs(from, this.storage.path.resolve(to));
|
36
|
+
});
|
37
|
+
}
|
38
|
+
|
39
|
+
}) || _class) || _class) || _class) || _class);
|
40
|
+
exports.PlainCopyDataStorage = PlainCopyDataStorage;
|
@@ -0,0 +1,70 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.ResticClient = void 0;
|
7
|
+
|
8
|
+
var _inversify = require("inversify");
|
9
|
+
|
10
|
+
var _types = require("../../types");
|
11
|
+
|
12
|
+
var _ContextSymbols = require("../../ctx/ContextSymbols");
|
13
|
+
|
14
|
+
var _Shell = require("../../tools/shell/Shell");
|
15
|
+
|
16
|
+
var _dec, _dec2, _dec3, _dec4, _class;
|
17
|
+
|
18
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
19
|
+
|
20
|
+
const normalizeUrl = url => {
|
21
|
+
if (url.startsWith('local:')) {
|
22
|
+
url = url.replace(/^local:/, '');
|
23
|
+
}
|
24
|
+
|
25
|
+
return url;
|
26
|
+
};
|
27
|
+
/**
|
28
|
+
* TODO forwarding stdout to the logger
|
29
|
+
*/
|
30
|
+
|
31
|
+
|
32
|
+
let ResticClient = (_dec = (0, _inversify.injectable)(), _dec2 = function (target, key) {
|
33
|
+
return (0, _inversify.inject)(_ContextSymbols.TaskConfig_)(target, undefined, 1);
|
34
|
+
}, _dec3 = Reflect.metadata("design:type", Function), _dec4 = Reflect.metadata("design:paramtypes", [typeof _Shell.Shell === "undefined" ? Object : _Shell.Shell, typeof _types.Log === "undefined" ? Object : _types.Log]), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = class ResticClient {
|
35
|
+
constructor(shell, log) {
|
36
|
+
this.shell = shell;
|
37
|
+
this.log = log;
|
38
|
+
|
39
|
+
_defineProperty(this, "prepareRepo", (url, password) => {
|
40
|
+
url = normalizeUrl(url);
|
41
|
+
this.log.info('Preparing a restic repo', url);
|
42
|
+
this.shell.exec(`restic init --repo ${url}`, {
|
43
|
+
env: {
|
44
|
+
RESTIC_PASSWORD: password
|
45
|
+
}
|
46
|
+
});
|
47
|
+
});
|
48
|
+
|
49
|
+
_defineProperty(this, "backup", (url, cwd, from, password) => {
|
50
|
+
url = normalizeUrl(url);
|
51
|
+
this.shell.exec(`restic --repo ${url} backup ${from.str()}`, {
|
52
|
+
cwd: cwd.str(),
|
53
|
+
env: {
|
54
|
+
RESTIC_PASSWORD: password
|
55
|
+
}
|
56
|
+
});
|
57
|
+
});
|
58
|
+
|
59
|
+
_defineProperty(this, "restore", (url, to, password) => {
|
60
|
+
url = normalizeUrl(url);
|
61
|
+
this.shell.exec(`restic --repo ${url} restore latest --target ${to.str()}`, {
|
62
|
+
env: {
|
63
|
+
RESTIC_PASSWORD: password
|
64
|
+
}
|
65
|
+
});
|
66
|
+
});
|
67
|
+
}
|
68
|
+
|
69
|
+
}) || _class) || _class) || _class) || _class);
|
70
|
+
exports.ResticClient = ResticClient;
|
@@ -0,0 +1,50 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _ResticClient = require("./ResticClient");
|
4
|
+
|
5
|
+
var _AppLogger = require("../../log/AppLogger");
|
6
|
+
|
7
|
+
var _Shell = require("../../tools/shell/Shell");
|
8
|
+
|
9
|
+
var _test = require("../../../test");
|
10
|
+
|
11
|
+
var _fs = _interopRequireDefault(require("fs"));
|
12
|
+
|
13
|
+
var _Path = require("../../fs/path/Path");
|
14
|
+
|
15
|
+
var _dirCompare = require("dir-compare");
|
16
|
+
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
18
|
+
|
19
|
+
/*
|
20
|
+
* Tested with: restic 0.9.6 compiled with go1.12.12 on linux/amd64
|
21
|
+
*/
|
22
|
+
describe.skip('ResticClient', () => {
|
23
|
+
const l = new _AppLogger.AppLogger();
|
24
|
+
const sut = new _ResticClient.ResticClient(new _Shell.Shell(l), l);
|
25
|
+
const password = 'foo123';
|
26
|
+
const repoDir = (0, _test.testdataDir)('my-repo');
|
27
|
+
const backupDir = (0, _test.testDir)('backup-me');
|
28
|
+
const restoreDir = (0, _test.testdataDir)('restore');
|
29
|
+
const repoUrl = `local:${repoDir}`;
|
30
|
+
afterAll(() => {
|
31
|
+
_fs.default.rmdirSync(repoDir, {
|
32
|
+
recursive: true
|
33
|
+
});
|
34
|
+
|
35
|
+
_fs.default.rmdirSync(restoreDir, {
|
36
|
+
recursive: true
|
37
|
+
});
|
38
|
+
});
|
39
|
+
it('create repo', () => {
|
40
|
+
sut.prepareRepo(repoUrl, password);
|
41
|
+
});
|
42
|
+
it('push data', () => {
|
43
|
+
sut.backup(repoUrl, _Path.AbsPath.from(backupDir), _Path.RelativePath.from('.'), password);
|
44
|
+
});
|
45
|
+
it('restore data', () => {
|
46
|
+
sut.restore(repoUrl, _Path.AbsPath.from(restoreDir), password);
|
47
|
+
const res = (0, _dirCompare.compareSync)(backupDir, restoreDir);
|
48
|
+
expect(res.same).toBeTrue();
|
49
|
+
});
|
50
|
+
});
|
@@ -0,0 +1,28 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.Gpg = void 0;
|
7
|
+
|
8
|
+
var _Shell = require("../shell/Shell");
|
9
|
+
|
10
|
+
var _inversify = require("inversify");
|
11
|
+
|
12
|
+
var _dec, _dec2, _dec3, _class;
|
13
|
+
|
14
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
15
|
+
|
16
|
+
let Gpg = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.metadata("design:type", Function), _dec3 = Reflect.metadata("design:paramtypes", [typeof _Shell.Shell === "undefined" ? Object : _Shell.Shell]), _dec(_class = _dec2(_class = _dec3(_class = class Gpg {
|
17
|
+
constructor(sh) {
|
18
|
+
this.sh = sh;
|
19
|
+
|
20
|
+
_defineProperty(this, "exportKey", id => {
|
21
|
+
const res = this.sh.execAndReturnVal(`gpg --export-secret-key --armor ${id}`);
|
22
|
+
if (!res) throw new Error(`Key '${id}' not in keyring`);
|
23
|
+
return res;
|
24
|
+
});
|
25
|
+
}
|
26
|
+
|
27
|
+
}) || _class) || _class) || _class);
|
28
|
+
exports.Gpg = Gpg;
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _AppLogger = require("../../log/AppLogger");
|
4
|
+
|
5
|
+
var _Gpg = require("./Gpg");
|
6
|
+
|
7
|
+
var _Shell = require("../shell/Shell");
|
8
|
+
|
9
|
+
// TODO setup ci to make tests work
|
10
|
+
it.skip('works', () => {
|
11
|
+
const sut = new _Gpg.Gpg(new _Shell.Shell(new _AppLogger.AppLogger()));
|
12
|
+
const key = sut.exportKey('foo');
|
13
|
+
console.log('key', key);
|
14
|
+
});
|
@@ -0,0 +1,52 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.Shell = void 0;
|
7
|
+
|
8
|
+
var _shellCmd = require("./shellCmd");
|
9
|
+
|
10
|
+
var _inversify = require("inversify");
|
11
|
+
|
12
|
+
var _AppLogger = require("../../log/AppLogger");
|
13
|
+
|
14
|
+
var _dec, _dec2, _dec3, _class;
|
15
|
+
|
16
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
17
|
+
|
18
|
+
// TODO copy pasted from my other project
|
19
|
+
let Shell = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.metadata("design:type", Function), _dec3 = Reflect.metadata("design:paramtypes", [typeof _AppLogger.AppLogger === "undefined" ? Object : _AppLogger.AppLogger]), _dec(_class = _dec2(_class = _dec3(_class = class Shell {
|
20
|
+
constructor(log) {
|
21
|
+
this.log = log;
|
22
|
+
|
23
|
+
_defineProperty(this, "exec", (cmd, opts = {}) => {
|
24
|
+
this.log.debug(cmd);
|
25
|
+
(0, _shellCmd.shellCmd)(cmd, { ...opts,
|
26
|
+
returnStdout: false
|
27
|
+
});
|
28
|
+
});
|
29
|
+
|
30
|
+
_defineProperty(this, "execWithStdIn", ({
|
31
|
+
cmd,
|
32
|
+
stdin,
|
33
|
+
opts = {}
|
34
|
+
}) => {
|
35
|
+
this.log.debug(`"${stdin}" > ${cmd}`);
|
36
|
+
(0, _shellCmd.shellCmd)(cmd, { ...opts,
|
37
|
+
stdin,
|
38
|
+
returnStdout: false
|
39
|
+
});
|
40
|
+
});
|
41
|
+
|
42
|
+
_defineProperty(this, "execAndReturnVal", (cmd, ops = {}) => {
|
43
|
+
this.log.debug(cmd, '[stdout consumed]');
|
44
|
+
return (0, _shellCmd.shellCmd)(cmd, {
|
45
|
+
returnStdout: true,
|
46
|
+
...ops
|
47
|
+
});
|
48
|
+
});
|
49
|
+
}
|
50
|
+
|
51
|
+
}) || _class) || _class) || _class);
|
52
|
+
exports.Shell = Shell;
|
@@ -10,12 +10,14 @@ var _child_process = require("child_process");
|
|
10
10
|
const shellCmd = (cmd, {
|
11
11
|
returnStdout,
|
12
12
|
cwd,
|
13
|
-
stdin
|
13
|
+
stdin,
|
14
|
+
env
|
14
15
|
} = {}) => {
|
15
16
|
const res = (0, _child_process.execSync)(cmd, {
|
16
17
|
cwd,
|
17
18
|
input: stdin,
|
18
|
-
stdio: [stdin ? undefined : 'inherit', returnStdout ? undefined : 'inherit', 'inherit']
|
19
|
+
stdio: [stdin ? undefined : 'inherit', returnStdout ? undefined : 'inherit', 'inherit'],
|
20
|
+
env
|
19
21
|
});
|
20
22
|
if (returnStdout) return res.toString().trim();
|
21
23
|
return null;
|
@@ -0,0 +1,36 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.SshKeyManager = void 0;
|
7
|
+
|
8
|
+
var _Fs = require("../../fs/Fs");
|
9
|
+
|
10
|
+
var _Path = require("../../fs/path/Path");
|
11
|
+
|
12
|
+
var _os = _interopRequireDefault(require("os"));
|
13
|
+
|
14
|
+
var _inversify = require("inversify");
|
15
|
+
|
16
|
+
var _dec, _dec2, _dec3, _class;
|
17
|
+
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19
|
+
|
20
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
21
|
+
|
22
|
+
let SshKeyManager = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.metadata("design:type", Function), _dec3 = Reflect.metadata("design:paramtypes", [typeof _Fs.Fs === "undefined" ? Object : _Fs.Fs]), _dec(_class = _dec2(_class = _dec3(_class = class SshKeyManager {
|
23
|
+
constructor(fs) {
|
24
|
+
this.fs = fs;
|
25
|
+
|
26
|
+
_defineProperty(this, "sshDir", void 0);
|
27
|
+
|
28
|
+
_defineProperty(this, "exportKey", id => {
|
29
|
+
return this.fs.readFile(this.sshDir);
|
30
|
+
});
|
31
|
+
|
32
|
+
this.sshDir = _Path.AbsPath.from(_os.default.homedir()).resolve('.ssh');
|
33
|
+
}
|
34
|
+
|
35
|
+
}) || _class) || _class) || _class);
|
36
|
+
exports.SshKeyManager = SshKeyManager;
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _SshKeyManager = require("./SshKeyManager");
|
4
|
+
|
5
|
+
var _Fs = require("../../fs/Fs");
|
6
|
+
|
7
|
+
var _AppLogger = require("../../log/AppLogger");
|
8
|
+
|
9
|
+
// TODO setup ci to make tests work
|
10
|
+
it.skip('works', () => {
|
11
|
+
const sut = new _SshKeyManager.SshKeyManager(new _Fs.Fs(new _AppLogger.AppLogger()));
|
12
|
+
const key = sut.exportKey('id_rsa');
|
13
|
+
console.log('key', key);
|
14
|
+
});
|
package/lib/types.js
ADDED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ps-aux/nodebup",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.2.0",
|
4
4
|
"description": "",
|
5
5
|
"module": "lib/index.js",
|
6
6
|
"main": "lib/index.js",
|
@@ -8,11 +8,13 @@
|
|
8
8
|
"build": "rm -rf build && babel --extensions '.ts,.js' src -d lib src",
|
9
9
|
"pub": "npm publish --access public",
|
10
10
|
"test": "jest",
|
11
|
-
"
|
11
|
+
"tc": "tsc --noEmit",
|
12
12
|
"format": "prettier \"**/*.{js,ts,tsx}\" --write",
|
13
13
|
"build-n-run": "npm run build && ",
|
14
14
|
"lint": "eslint '**/*.{js,ts,tsx}' --fix",
|
15
|
-
"update-deps": "ncu --upgrade"
|
15
|
+
"update-deps": "ncu --upgrade",
|
16
|
+
"prepare": "husky install",
|
17
|
+
"pre-commit": "lint-staged"
|
16
18
|
},
|
17
19
|
"keywords": [],
|
18
20
|
"author": "",
|
@@ -25,58 +27,61 @@
|
|
25
27
|
},
|
26
28
|
"typings": "src/types.d.ts",
|
27
29
|
"devDependencies": {
|
28
|
-
"@babel/cli": "^7.
|
29
|
-
"@babel/core": "^7.
|
30
|
-
"@babel/
|
31
|
-
"@babel/
|
32
|
-
"@babel/plugin-proposal-
|
33
|
-
"@babel/plugin-proposal-
|
34
|
-
"@babel/
|
35
|
-
"@babel/
|
36
|
-
"@
|
37
|
-
"@
|
38
|
-
"@types/
|
39
|
-
"@types/
|
40
|
-
"@
|
41
|
-
"@
|
42
|
-
"
|
43
|
-
"
|
44
|
-
"babel-plugin-module-resolver": "^4.
|
45
|
-
"
|
46
|
-
"
|
47
|
-
"eslint
|
48
|
-
"eslint-
|
49
|
-
"eslint-plugin-
|
50
|
-
"eslint-plugin-
|
51
|
-
"eslint-plugin-
|
52
|
-
"
|
53
|
-
"
|
54
|
-
"
|
55
|
-
"
|
56
|
-
"
|
57
|
-
"
|
58
|
-
"
|
59
|
-
|
60
|
-
|
61
|
-
"
|
62
|
-
|
63
|
-
}
|
30
|
+
"@babel/cli": "^7.16.0",
|
31
|
+
"@babel/core": "^7.16.5",
|
32
|
+
"@babel/eslint-parser": "^7.16.5",
|
33
|
+
"@babel/node": "^7.16.5",
|
34
|
+
"@babel/plugin-proposal-class-properties": "^7.16.5",
|
35
|
+
"@babel/plugin-proposal-decorators": "^7.16.5",
|
36
|
+
"@babel/plugin-proposal-object-rest-spread": "^7.16.5",
|
37
|
+
"@babel/plugin-proposal-optional-chaining": "^7.16.5",
|
38
|
+
"@babel/preset-env": "^7.16.5",
|
39
|
+
"@babel/preset-typescript": "^7.16.5",
|
40
|
+
"@types/jest": "^27.0.3",
|
41
|
+
"@types/jest-when": "^2.7.4",
|
42
|
+
"@types/node": "^17.0.5",
|
43
|
+
"@types/ramda": "^0.27.62",
|
44
|
+
"@typescript-eslint/eslint-plugin": "^5.8.1",
|
45
|
+
"@typescript-eslint/parser": "^5.8.1",
|
46
|
+
"babel-plugin-module-resolver": "^4.1.0",
|
47
|
+
"babel-plugin-transform-typescript-metadata": "^0.3.2",
|
48
|
+
"dir-compare": "^4.0.0",
|
49
|
+
"eslint": "^8.5.0",
|
50
|
+
"eslint-config-standard": "^16.0.3",
|
51
|
+
"eslint-plugin-import": "^2.25.3",
|
52
|
+
"eslint-plugin-node": "^11.1.0",
|
53
|
+
"eslint-plugin-prettier": "^4.0.0",
|
54
|
+
"eslint-plugin-promise": "^6.0.0",
|
55
|
+
"eslint-plugin-standard": "^5.0.0",
|
56
|
+
"husky": "^7.0.4",
|
57
|
+
"jest": "^27.4.5",
|
58
|
+
"jest-extended": "^1.2.0",
|
59
|
+
"jest-when": "^3.5.0",
|
60
|
+
"lint-staged": "^12.1.4",
|
61
|
+
"npm-check-updates": "^12.0.5",
|
62
|
+
"prettier": "^2.5.1",
|
63
|
+
"ts-jest": "^27.1.2",
|
64
|
+
"typescript": "^4.5.4"
|
64
65
|
},
|
65
66
|
"lint-staged": {
|
66
67
|
"./**/*.{js,ts,tsx}": [
|
67
68
|
"prettier --write",
|
68
|
-
"eslint --fix"
|
69
|
-
"git add"
|
69
|
+
"eslint --fix"
|
70
70
|
]
|
71
71
|
},
|
72
72
|
"dependencies": {
|
73
73
|
"@hapi/joi": "^17.1.1",
|
74
|
-
"@
|
75
|
-
"
|
76
|
-
"
|
77
|
-
"
|
78
|
-
"
|
79
|
-
"
|
80
|
-
"
|
74
|
+
"@ps-aux/nclif": "^0.0.6-alpha.2",
|
75
|
+
"@types/hapi__joi": "^17.1.8",
|
76
|
+
"axios": "^0.24.0",
|
77
|
+
"handlebars": "^4.7.7",
|
78
|
+
"inversify": "^6.0.1",
|
79
|
+
"js-yaml": "^4.1.0",
|
80
|
+
"pino": "^7.6.2",
|
81
|
+
"ramda": "^0.27.1",
|
82
|
+
"reflect-metadata": "^0.1.13",
|
83
|
+
"wait-on": "^6.0.0",
|
84
|
+
"yaml": "^1.10.2",
|
85
|
+
"yargs": "^17.3.1"
|
81
86
|
}
|
82
87
|
}
|
package/lib/cli/entrypoint.js
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.default = void 0;
|
7
|
-
|
8
|
-
var _yargs = _interopRequireDefault(require("yargs"));
|
9
|
-
|
10
|
-
var _foo = require("../foo/foo.command");
|
11
|
-
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
|
-
|
14
|
-
const entrypoint = ctx => {
|
15
|
-
try {
|
16
|
-
// eslint-disable-next-line no-unused-expressions
|
17
|
-
_yargs.default.scriptName('bup').usage('$0 <cmd> [args]').command((0, _foo.fooCmd)()).alias('h', 'help').help() // https://github.com/yargs/yargs/issues/895#issuecomment-392893305
|
18
|
-
.demandCommand().recommendCommands().strict().argv;
|
19
|
-
} catch (err) {
|
20
|
-
console.log(err);
|
21
|
-
console.error('Error:', err.message);
|
22
|
-
process.exit(1);
|
23
|
-
}
|
24
|
-
};
|
25
|
-
|
26
|
-
var _default = entrypoint;
|
27
|
-
exports.default = _default;
|
package/lib/foo/foo.command.js
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.fooCmd = void 0;
|
7
|
-
|
8
|
-
const fooCmd = () => ({
|
9
|
-
command: 'foo',
|
10
|
-
describe: 'Do foo',
|
11
|
-
handler: args => {
|
12
|
-
console.log('haha'); // throw new Error('Assertion error')
|
13
|
-
}
|
14
|
-
});
|
15
|
-
|
16
|
-
exports.fooCmd = fooCmd;
|
@@ -1,46 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.LocalShellCmdExecutor = void 0;
|
7
|
-
|
8
|
-
var _MinimalLogger = require("../log/MinimalLogger");
|
9
|
-
|
10
|
-
var _shellCmd = require("./shellCmd");
|
11
|
-
|
12
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
13
|
-
|
14
|
-
class LocalShellCmdExecutor {
|
15
|
-
constructor(log) {
|
16
|
-
_defineProperty(this, "log", void 0);
|
17
|
-
|
18
|
-
_defineProperty(this, "exec", cmd => {
|
19
|
-
this.log.debug(cmd);
|
20
|
-
(0, _shellCmd.shellCmd)(cmd, {
|
21
|
-
returnStdout: false
|
22
|
-
});
|
23
|
-
});
|
24
|
-
|
25
|
-
_defineProperty(this, "execWithStdIn", (cmd, stdin) => {
|
26
|
-
this.log.debug(`"${stdin}" > ${cmd}`);
|
27
|
-
(0, _shellCmd.shellCmd)(cmd, {
|
28
|
-
stdin,
|
29
|
-
returnStdout: false
|
30
|
-
});
|
31
|
-
});
|
32
|
-
|
33
|
-
_defineProperty(this, "execAndReturnVal", (cmd, ops) => {
|
34
|
-
this.log.debug(cmd, '[stdout consumed]');
|
35
|
-
return (0, _shellCmd.shellCmd)(cmd, {
|
36
|
-
returnStdout: true,
|
37
|
-
...ops
|
38
|
-
});
|
39
|
-
});
|
40
|
-
|
41
|
-
this.log = log || (0, _MinimalLogger.minimalLogger)();
|
42
|
-
}
|
43
|
-
|
44
|
-
}
|
45
|
-
|
46
|
-
exports.LocalShellCmdExecutor = LocalShellCmdExecutor;
|
package/lib/types.d.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
"use strict";
|