@ps-aux/nodebup 0.5.0 → 0.6.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/lib/bup/AggregateBackupController.js +6 -6
- package/lib/bup/BackupController.js +17 -10
- package/lib/cli/InvalidInput.js +10 -0
- package/lib/cli/app.js +46 -31
- package/lib/config/Config.js +2 -7
- package/lib/config/expandAndCreatePath.js +3 -1
- package/lib/config/index.js +1 -9
- package/lib/config/validateConfigAgainstSchema.js +2 -17
- package/lib/ctx/Context.js +6 -2
- package/lib/ctx/ContextSymbols.js +4 -2
- package/lib/fs/Fs.js +11 -2
- package/lib/fs/fssync/FsSync.spec.js +1 -1
- package/lib/storage/StorageBackendProvider.js +13 -16
- package/lib/storage/StorageConfigProvider.js +89 -0
- package/lib/storage/StoreConfig.js +39 -0
- package/lib/storage/b2/B2CredentialsProvider.js +6 -2
- package/lib/storage/rclone/RCloneClientFactory.js +4 -4
- package/lib/storage/restic/ResticClientFactory.js +5 -5
- package/lib/storage/restic/ResticController.js +12 -7
- package/lib/storage/types.js +13 -0
- package/lib/tools/ssh/SshKeyManager.spec.js +3 -1
- package/package.json +2 -2
- package/lib/storage/types.d.js +0 -5
@@ -23,7 +23,7 @@ var _Path = require("../fs/path/Path");
|
|
23
23
|
|
24
24
|
var _config = require("../config");
|
25
25
|
|
26
|
-
var
|
26
|
+
var _StorageBackendProvider = require("../storage/StorageBackendProvider");
|
27
27
|
|
28
28
|
var _dec, _dec2, _dec3, _dec4, _class;
|
29
29
|
|
@@ -31,17 +31,17 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
31
31
|
|
32
32
|
let AggregateBackupController = (_dec = (0, _inversify.injectable)(), _dec2 = function (target, key) {
|
33
33
|
return (0, _inversify.inject)(_ContextSymbols.AppConfig_)(target, undefined, 6);
|
34
|
-
}, _dec3 = Reflect.metadata("design:type", Function), _dec4 = Reflect.metadata("design:paramtypes", [typeof _Gpg.Gpg === "undefined" ? Object : _Gpg.Gpg, typeof _SshKeyManager.SshKeyManager === "undefined" ? Object : _SshKeyManager.SshKeyManager, typeof _Fs.Fs === "undefined" ? Object : _Fs.Fs, typeof _FsSyncer.FsSyncer === "undefined" ? Object : _FsSyncer.FsSyncer, typeof _AppLogger.AppLogger === "undefined" ? Object : _AppLogger.AppLogger, typeof
|
35
|
-
constructor(gpg, ssh, fs, fsSyncer, log,
|
34
|
+
}, _dec3 = Reflect.metadata("design:type", Function), _dec4 = Reflect.metadata("design:paramtypes", [typeof _Gpg.Gpg === "undefined" ? Object : _Gpg.Gpg, typeof _SshKeyManager.SshKeyManager === "undefined" ? Object : _SshKeyManager.SshKeyManager, typeof _Fs.Fs === "undefined" ? Object : _Fs.Fs, typeof _FsSyncer.FsSyncer === "undefined" ? Object : _FsSyncer.FsSyncer, typeof _AppLogger.AppLogger === "undefined" ? Object : _AppLogger.AppLogger, typeof _StorageBackendProvider.StorageBackendProvider === "undefined" ? Object : _StorageBackendProvider.StorageBackendProvider, typeof _config.Config === "undefined" ? Object : _config.Config]), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = class AggregateBackupController {
|
35
|
+
constructor(gpg, ssh, fs, fsSyncer, log, storageProvider, cfg) {
|
36
36
|
this.gpg = gpg;
|
37
37
|
this.ssh = ssh;
|
38
38
|
this.fs = fs;
|
39
39
|
this.fsSyncer = fsSyncer;
|
40
40
|
this.log = log;
|
41
|
-
this.
|
41
|
+
this.storageProvider = storageProvider;
|
42
42
|
this.cfg = cfg;
|
43
43
|
|
44
|
-
_defineProperty(this, "backup", async
|
44
|
+
_defineProperty(this, "backup", async aggrName => {
|
45
45
|
const aggrDir = this.cfg.pwd.resolve('.aggr');
|
46
46
|
const aggr = this.cfg.aggregates.find(a => a.name === aggrName);
|
47
47
|
if (!aggr) throw new Error(`No backup aggregate with name '${aggrName}'`);
|
@@ -56,7 +56,7 @@ let AggregateBackupController = (_dec = (0, _inversify.injectable)(), _dec2 = fu
|
|
56
56
|
file.forEach(f => this.runFileTask(f, aggrDir));
|
57
57
|
sshKey.forEach(k => this.runSshKeyTask(k, aggrDir));
|
58
58
|
gpgKey.forEach(k => this.runGpgKeyTask(k, aggrDir));
|
59
|
-
this.
|
59
|
+
this.storageProvider.provide().store(aggrDir);
|
60
60
|
} finally {
|
61
61
|
this.log.debug();
|
62
62
|
this.fs.rmDir(aggrDir);
|
@@ -19,6 +19,8 @@ var _ContextSymbols = require("../ctx/ContextSymbols");
|
|
19
19
|
|
20
20
|
var _AppLogger = require("../log/AppLogger");
|
21
21
|
|
22
|
+
var _Path = require("../fs/path/Path");
|
23
|
+
|
22
24
|
var _StorageBackendProvider = require("../storage/StorageBackendProvider");
|
23
25
|
|
24
26
|
var _config = require("../config");
|
@@ -39,17 +41,22 @@ let BackupController = (_dec = (0, _inversify.injectable)(), _dec2 = function (t
|
|
39
41
|
this.storageBackendProvider = storageBackendProvider;
|
40
42
|
this.cfg = cfg;
|
41
43
|
|
42
|
-
_defineProperty(this, "
|
43
|
-
this.
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
44
|
+
_defineProperty(this, "storage", inp => {
|
45
|
+
const storage = this.storageBackendProvider.provide();
|
46
|
+
|
47
|
+
const path = _Path.AbsPath.from(inp.path);
|
48
|
+
|
49
|
+
return {
|
50
|
+
backup: () => {
|
51
|
+
this.log.info(`Backing up from ${path} to '${storage}'`);
|
52
|
+
storage.store(path);
|
53
|
+
},
|
54
|
+
restore: () => {
|
55
|
+
this.log.info(`Restoring from '${storage}' to ${path}`);
|
56
|
+
storage.restore(path);
|
57
|
+
}
|
58
|
+
};
|
50
59
|
});
|
51
|
-
|
52
|
-
_defineProperty(this, "storage", name => this.storageBackendProvider.provide(name));
|
53
60
|
}
|
54
61
|
|
55
62
|
}) || _class) || _class) || _class) || _class);
|
package/lib/cli/app.js
CHANGED
@@ -19,62 +19,77 @@ var _ResticController = require("../storage/restic/ResticController");
|
|
19
19
|
|
20
20
|
var _BackupController = require("../bup/BackupController");
|
21
21
|
|
22
|
-
|
22
|
+
const storageNameOpt = {
|
23
|
+
name: 'storage-name',
|
24
|
+
convertCase: true,
|
25
|
+
fromConfig: 'storage.name'
|
26
|
+
};
|
23
27
|
|
24
28
|
const createApp = () => _nclif.CliApp.of({
|
25
29
|
commands: {
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
data: (0, _nclif.cmdGroup)({
|
31
|
+
options: [storageNameOpt, {
|
32
|
+
name: 'storage-type',
|
33
|
+
convertCase: true,
|
34
|
+
fromConfig: 'storage.type'
|
31
35
|
}, {
|
32
|
-
name: '
|
33
|
-
|
34
|
-
|
35
|
-
run: (a, c) => c.get(_BackupController.BackupController).backup(a.storageName, _Path.AbsPath.from(a.path))
|
36
|
-
}),
|
37
|
-
restore: (0, _nclif.cmd)({
|
38
|
-
description: 'Restore the storage to the given dir',
|
39
|
-
positionals: [{
|
40
|
-
name: 'storageName',
|
41
|
-
required: true
|
36
|
+
name: 'storage-repo',
|
37
|
+
convertCase: true,
|
38
|
+
fromConfig: 'storage.repo'
|
42
39
|
}, {
|
43
|
-
name: '
|
44
|
-
|
40
|
+
name: 'storage-password',
|
41
|
+
convertCase: true,
|
42
|
+
fromConfig: 'storage.password'
|
43
|
+
}, {
|
44
|
+
name: 'storage-credentials',
|
45
|
+
convertCase: true,
|
46
|
+
fromConfig: 'storage.credentials'
|
45
47
|
}],
|
46
|
-
|
48
|
+
commands: {
|
49
|
+
backup: (0, _nclif.cmd)({
|
50
|
+
description: 'Backup a dir to the given storage',
|
51
|
+
positionals: [{
|
52
|
+
name: 'path',
|
53
|
+
required: true
|
54
|
+
}],
|
55
|
+
run: (cmd, c) => c.get(_BackupController.BackupController).storage(cmd).backup()
|
56
|
+
}),
|
57
|
+
restore: (0, _nclif.cmd)({
|
58
|
+
description: 'Restore the storage to the given dir',
|
59
|
+
positionals: [{
|
60
|
+
name: 'path',
|
61
|
+
required: true
|
62
|
+
}],
|
63
|
+
run: (cmd, c) => c.get(_BackupController.BackupController).storage(cmd).restore()
|
64
|
+
})
|
65
|
+
}
|
47
66
|
}),
|
48
67
|
aggr: (0, _nclif.cmdGroup)({
|
49
68
|
commands: {
|
50
69
|
backup: (0, _nclif.cmd)({
|
51
70
|
description: 'Run backup',
|
71
|
+
options: [storageNameOpt],
|
52
72
|
positionals: [{
|
53
73
|
name: 'aggregateName',
|
54
74
|
required: true
|
55
|
-
}, {
|
56
|
-
name: 'storageName',
|
57
|
-
required: true
|
58
75
|
}],
|
59
|
-
run: (a, c) => c.get(_AggregateBackupController.AggregateBackupController).backup(a.aggregateName
|
76
|
+
run: (a, c) => c.get(_AggregateBackupController.AggregateBackupController).backup(a.aggregateName)
|
60
77
|
})
|
61
78
|
}
|
62
79
|
}),
|
63
80
|
restic
|
64
81
|
}
|
65
|
-
}).addObjectConfig(pwd => (0, _Config.readConfig)(pwd)).context(({
|
66
|
-
config
|
67
|
-
|
82
|
+
}).envConfig('NODEBUP').addObjectConfig(pwd => (0, _Config.readConfig)(pwd)).context(({
|
83
|
+
config,
|
84
|
+
inputs
|
85
|
+
}) => (0, _Context.createContext)(config, inputs));
|
68
86
|
|
69
87
|
exports.createApp = createApp;
|
70
88
|
const restic = (0, _nclif.cmdGroup)({
|
71
89
|
commands: {
|
72
90
|
'init-repo': (0, _nclif.cmd)({
|
73
|
-
|
74
|
-
|
75
|
-
required: true
|
76
|
-
}],
|
77
|
-
run: (arg, c) => c.get(_ResticController.ResticController).initRepo(arg.resticStorageName)
|
91
|
+
options: [storageNameOpt],
|
92
|
+
run: (arg, c) => c.get(_ResticController.ResticController).initRepo()
|
78
93
|
})
|
79
94
|
}
|
80
95
|
});
|
package/lib/config/Config.js
CHANGED
@@ -13,12 +13,7 @@ var _validateConfigAgainstSchema = require("./validateConfigAgainstSchema");
|
|
13
13
|
|
14
14
|
var _expandAndCreatePath = require("./expandAndCreatePath");
|
15
15
|
|
16
|
-
const expandPaths = (cfg, exp
|
17
|
-
cfg.storage.filter(s => s.type === 'restic' || s.type === 'rclone').map(s => s).forEach(s => {
|
18
|
-
if (s.credentialsFile) s.credentialsFile = exp(s.credentialsFile);
|
19
|
-
s.passwordFile = exp(s.passwordFile);
|
20
|
-
if (s.repo.startsWith('local:')) s.repo = (0, _expandAndCreatePath.expandStrPath)(s.repo, cwd);
|
21
|
-
});
|
16
|
+
const expandPaths = (cfg, exp) => {
|
22
17
|
cfg.aggregates.forEach(a => {
|
23
18
|
a.sources.file.forEach(f => {
|
24
19
|
f.from = exp(f.from);
|
@@ -54,7 +49,7 @@ const readConfig = pwdStr => {
|
|
54
49
|
return p;
|
55
50
|
};
|
56
51
|
|
57
|
-
expandPaths(cfg, expand
|
52
|
+
expandPaths(cfg, expand);
|
58
53
|
return cfg;
|
59
54
|
};
|
60
55
|
|
@@ -9,12 +9,14 @@ var _Path = require("../fs/path/Path");
|
|
9
9
|
|
10
10
|
var _os = _interopRequireDefault(require("os"));
|
11
11
|
|
12
|
+
var _path = _interopRequireDefault(require("path"));
|
13
|
+
|
12
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
15
|
|
14
16
|
const expandStrPath = (path, pwd) => {
|
15
17
|
path = path.replace('<cwd>', pwd.str());
|
16
18
|
path = path.replace('~', _os.default.homedir());
|
17
|
-
return path;
|
19
|
+
return _path.default.resolve(path);
|
18
20
|
};
|
19
21
|
|
20
22
|
exports.expandStrPath = expandStrPath;
|
package/lib/config/index.js
CHANGED
@@ -2,12 +2,4 @@
|
|
2
2
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
|
-
});
|
6
|
-
exports.StorageTypeConst = void 0;
|
7
|
-
let StorageTypeConst;
|
8
|
-
exports.StorageTypeConst = StorageTypeConst;
|
9
|
-
|
10
|
-
(function (StorageTypeConst) {
|
11
|
-
StorageTypeConst["Restic"] = "restic";
|
12
|
-
StorageTypeConst["RClone"] = "rclone";
|
13
|
-
})(StorageTypeConst || (exports.StorageTypeConst = StorageTypeConst = {}));
|
5
|
+
});
|
@@ -7,7 +7,7 @@ exports.validateConfigAgainstSchema = void 0;
|
|
7
7
|
|
8
8
|
var _joi = _interopRequireDefault(require("@hapi/joi"));
|
9
9
|
|
10
|
-
var
|
10
|
+
var _StoreConfig = require("../storage/StoreConfig");
|
11
11
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
13
|
|
@@ -23,21 +23,6 @@ const KeyTaskSchema = _joi.default.object({
|
|
23
23
|
to: _joi.default.string().optional()
|
24
24
|
});
|
25
25
|
|
26
|
-
const createStorageSchema = props => _joi.default.object({
|
27
|
-
name: _joi.default.string(),
|
28
|
-
type: _joi.default.string().valid(_index.StorageTypeConst.Restic, _index.StorageTypeConst.RClone),
|
29
|
-
...props
|
30
|
-
});
|
31
|
-
|
32
|
-
const FileStorageSchema = createStorageSchema({
|
33
|
-
path: _joi.default.string()
|
34
|
-
});
|
35
|
-
const ResticStorageSchema = createStorageSchema({
|
36
|
-
repo: _joi.default.string(),
|
37
|
-
credentialsFile: _joi.default.string().optional(),
|
38
|
-
passwordFile: _joi.default.string()
|
39
|
-
});
|
40
|
-
|
41
26
|
const Sources = _joi.default.object({
|
42
27
|
dir: _joi.default.array().items(DirTaskSchema).optional(),
|
43
28
|
file: _joi.default.array().items(FileTaskSchema).optional(),
|
@@ -52,7 +37,7 @@ const Aggregate = _joi.default.object({
|
|
52
37
|
|
53
38
|
const Schema = () => _joi.default.object({
|
54
39
|
// TODO undescriptive error msg. Invalid config."storage[0]" does not match any of the allowed types
|
55
|
-
storage: _joi.default.array().items(
|
40
|
+
storage: _joi.default.array().items((0, _StoreConfig.NamedStorageSchema)()),
|
56
41
|
aggregates: _joi.default.array().items(Aggregate)
|
57
42
|
});
|
58
43
|
|
package/lib/ctx/Context.js
CHANGED
@@ -35,13 +35,17 @@ var _RCloneClientFactory = require("../storage/rclone/RCloneClientFactory");
|
|
35
35
|
|
36
36
|
var _BackupController = require("../bup/BackupController");
|
37
37
|
|
38
|
-
|
38
|
+
var _StorageConfigProvider = require("../storage/StorageConfigProvider");
|
39
|
+
|
40
|
+
const createContext = (cfg, inp) => {
|
39
41
|
const c = new _inversify.Container();
|
40
42
|
c.bind(_ContextSymbols.AppConfig_).toConstantValue(cfg);
|
43
|
+
c.bind(_ContextSymbols.Inputs_).toConstantValue(inp);
|
41
44
|
const log = new _AppLogger.AppLogger();
|
42
45
|
c.bind(_ContextSymbols.Log_).toConstantValue(log);
|
43
46
|
c.bind(_AppLogger.AppLogger).toConstantValue(log);
|
44
|
-
|
47
|
+
c.bind(_Fs.Fs).toConstantValue(new _Fs.Fs(cfg.pwd, log));
|
48
|
+
const self = [_Gpg.Gpg, _Shell.Shell, _FsSyncer.FsSyncer, _SshKeyManager.SshKeyManager, _StorageBackendProvider.StorageBackendProvider, _StorageConfigProvider.StorageConfigProvider, _ResticClientFactory.ResticClientFactory, _AggregateBackupController.AggregateBackupController, _ResticController.ResticController, _B2CredentialsProvider.B2CredentialsProvider, _RCloneClientFactory.RCloneClientFactory, _BackupController.BackupController];
|
45
49
|
self.forEach(s => c.bind(s).toSelf());
|
46
50
|
return c;
|
47
51
|
};
|
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.TaskConfig_ = exports.StorageConfig_ = exports.Log_ = exports.AppConfig_ = void 0;
|
6
|
+
exports.TaskConfig_ = exports.StorageConfig_ = exports.Log_ = exports.Inputs_ = exports.AppConfig_ = void 0;
|
7
7
|
const Log_ = Symbol.for('Log');
|
8
8
|
exports.Log_ = Log_;
|
9
9
|
const TaskConfig_ = Symbol.for('config.Tasks');
|
@@ -11,4 +11,6 @@ exports.TaskConfig_ = TaskConfig_;
|
|
11
11
|
const StorageConfig_ = Symbol.for('config.Storage');
|
12
12
|
exports.StorageConfig_ = StorageConfig_;
|
13
13
|
const AppConfig_ = Symbol.for('config.app');
|
14
|
-
exports.AppConfig_ = AppConfig_;
|
14
|
+
exports.AppConfig_ = AppConfig_;
|
15
|
+
const Inputs_ = Symbol.for('cmd.input');
|
16
|
+
exports.Inputs_ = Inputs_;
|
package/lib/fs/Fs.js
CHANGED
@@ -7,18 +7,23 @@ exports.Fs = void 0;
|
|
7
7
|
|
8
8
|
var _fs = _interopRequireDefault(require("fs"));
|
9
9
|
|
10
|
+
var _Path = require("./path/Path");
|
11
|
+
|
10
12
|
var _inversify = require("inversify");
|
11
13
|
|
12
14
|
var _AppLogger = require("../log/AppLogger");
|
13
15
|
|
16
|
+
var _expandAndCreatePath = require("../config/expandAndCreatePath");
|
17
|
+
|
14
18
|
var _dec, _dec2, _dec3, _class;
|
15
19
|
|
16
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
21
|
|
18
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; }
|
19
23
|
|
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) {
|
24
|
+
let Fs = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.metadata("design:type", Function), _dec3 = Reflect.metadata("design:paramtypes", [typeof _Path.AbsPath === "undefined" ? Object : _Path.AbsPath, typeof _AppLogger.AppLogger === "undefined" ? Object : _AppLogger.AppLogger]), _dec(_class = _dec2(_class = _dec3(_class = class Fs {
|
25
|
+
constructor(cwd, log) {
|
26
|
+
this.cwd = cwd;
|
22
27
|
this.log = log;
|
23
28
|
|
24
29
|
_defineProperty(this, "writeFile", (path, content) => {
|
@@ -75,6 +80,10 @@ let Fs = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.metadata("design:
|
|
75
80
|
});
|
76
81
|
|
77
82
|
_defineProperty(this, "exists", path => _fs.default.existsSync(path.str()));
|
83
|
+
|
84
|
+
_defineProperty(this, "expand", strPath => (0, _expandAndCreatePath.expandAndCreatePath)(strPath, this.cwd));
|
85
|
+
|
86
|
+
_defineProperty(this, "expandStrPath", strPath => (0, _expandAndCreatePath.expandStrPath)(strPath, this.cwd));
|
78
87
|
}
|
79
88
|
|
80
89
|
}) || _class) || _class) || _class);
|
@@ -23,7 +23,7 @@ describe('FsSync', () => {
|
|
23
23
|
|
24
24
|
it('syncs dir', () => {
|
25
25
|
const l = new _AppLogger.AppLogger();
|
26
|
-
const sut = new _FsSyncer.FsSyncer(new _Shell.Shell(l), new _Fs.Fs(l), l);
|
26
|
+
const sut = new _FsSyncer.FsSyncer(new _Shell.Shell(l), new _Fs.Fs(_Path.AbsPath.from(__dirname), l), l);
|
27
27
|
sut.syncDirs(from, to);
|
28
28
|
expect((0, _areDirsSame.areDirsSame)(from, to)).toBe(true);
|
29
29
|
});
|
@@ -7,9 +7,7 @@ exports.StorageBackendProvider = void 0;
|
|
7
7
|
|
8
8
|
var _inversify = require("inversify");
|
9
9
|
|
10
|
-
var
|
11
|
-
|
12
|
-
var _config = require("../config");
|
10
|
+
var _types = require("./types");
|
13
11
|
|
14
12
|
var _ResticClientFactory = require("./restic/ResticClientFactory");
|
15
13
|
|
@@ -17,29 +15,28 @@ var _BackupClientStorageBackend = require("./BackupClientStorageBackend");
|
|
17
15
|
|
18
16
|
var _RCloneClientFactory = require("./rclone/RCloneClientFactory");
|
19
17
|
|
20
|
-
var
|
18
|
+
var _StorageConfigProvider = require("./StorageConfigProvider");
|
19
|
+
|
20
|
+
var _dec, _dec2, _dec3, _class;
|
21
21
|
|
22
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
23
|
|
24
|
-
let StorageBackendProvider = (_dec = (0, _inversify.injectable)(), _dec2 =
|
25
|
-
|
26
|
-
}, _dec3 = Reflect.metadata("design:type", Function), _dec4 = Reflect.metadata("design:paramtypes", [typeof _ResticClientFactory.ResticClientFactory === "undefined" ? Object : _ResticClientFactory.ResticClientFactory, typeof _RCloneClientFactory.RCloneClientFactory === "undefined" ? Object : _RCloneClientFactory.RCloneClientFactory, typeof _config.Config === "undefined" ? Object : _config.Config]), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = class StorageBackendProvider {
|
27
|
-
constructor(resticFac, rcloneFac, cfg) {
|
24
|
+
let StorageBackendProvider = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.metadata("design:type", Function), _dec3 = Reflect.metadata("design:paramtypes", [typeof _ResticClientFactory.ResticClientFactory === "undefined" ? Object : _ResticClientFactory.ResticClientFactory, typeof _RCloneClientFactory.RCloneClientFactory === "undefined" ? Object : _RCloneClientFactory.RCloneClientFactory, typeof _StorageConfigProvider.StorageConfigProvider === "undefined" ? Object : _StorageConfigProvider.StorageConfigProvider]), _dec(_class = _dec2(_class = _dec3(_class = class StorageBackendProvider {
|
25
|
+
constructor(resticFac, rcloneFac, cfgProvider) {
|
28
26
|
this.resticFac = resticFac;
|
29
27
|
this.rcloneFac = rcloneFac;
|
30
|
-
this.
|
28
|
+
this.cfgProvider = cfgProvider;
|
31
29
|
|
32
|
-
_defineProperty(this, "provide",
|
33
|
-
const s = this.
|
34
|
-
|
35
|
-
let b;
|
30
|
+
_defineProperty(this, "provide", () => {
|
31
|
+
const s = this.cfgProvider.provide();
|
32
|
+
let b = null;
|
36
33
|
|
37
34
|
switch (s.type) {
|
38
|
-
case
|
35
|
+
case _types.StorageType.Restic:
|
39
36
|
b = this.resticFac.create(s);
|
40
37
|
break;
|
41
38
|
|
42
|
-
case
|
39
|
+
case _types.StorageType.RClone:
|
43
40
|
b = this.rcloneFac.create(s);
|
44
41
|
break;
|
45
42
|
}
|
@@ -49,5 +46,5 @@ let StorageBackendProvider = (_dec = (0, _inversify.injectable)(), _dec2 = funct
|
|
49
46
|
});
|
50
47
|
}
|
51
48
|
|
52
|
-
}) || _class) || _class) || _class)
|
49
|
+
}) || _class) || _class) || _class);
|
53
50
|
exports.StorageBackendProvider = StorageBackendProvider;
|
@@ -0,0 +1,89 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.StorageConfigProvider = void 0;
|
7
|
+
|
8
|
+
var _inversify = require("inversify");
|
9
|
+
|
10
|
+
var _ContextSymbols = require("../ctx/ContextSymbols");
|
11
|
+
|
12
|
+
var _config = require("../config");
|
13
|
+
|
14
|
+
var _Fs = require("../fs/Fs");
|
15
|
+
|
16
|
+
var _InvalidInput = require("../cli/InvalidInput");
|
17
|
+
|
18
|
+
var _StoreConfig = require("./StoreConfig");
|
19
|
+
|
20
|
+
var _dec, _dec2, _dec3, _dec4, _dec5, _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 StorageConfigProvider = (_dec = (0, _inversify.injectable)(), _dec2 = function (target, key) {
|
25
|
+
return (0, _inversify.inject)(_ContextSymbols.AppConfig_)(target, undefined, 1);
|
26
|
+
}, _dec3 = function (target, key) {
|
27
|
+
return (0, _inversify.inject)(_ContextSymbols.Inputs_)(target, undefined, 2);
|
28
|
+
}, _dec4 = Reflect.metadata("design:type", Function), _dec5 = Reflect.metadata("design:paramtypes", [typeof _Fs.Fs === "undefined" ? Object : _Fs.Fs, typeof _config.Config === "undefined" ? Object : _config.Config, typeof StorageInputs === "undefined" ? Object : StorageInputs]), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = _dec5(_class = class StorageConfigProvider {
|
29
|
+
constructor(fs, cfg, inputs) {
|
30
|
+
this.fs = fs;
|
31
|
+
this.cfg = cfg;
|
32
|
+
this.inputs = inputs;
|
33
|
+
|
34
|
+
_defineProperty(this, "provide", () => {
|
35
|
+
const {
|
36
|
+
storageName,
|
37
|
+
storagePassword,
|
38
|
+
storageRepo,
|
39
|
+
storageType
|
40
|
+
} = this.inputs;
|
41
|
+
let res;
|
42
|
+
|
43
|
+
if (storageName) {
|
44
|
+
if (storageType || storageRepo || storagePassword) throw new _InvalidInput.InvalidInput('Storage config provided. Storage name is therefore invalid input');
|
45
|
+
res = this.getByName(storageName);
|
46
|
+
} else {
|
47
|
+
res = this.getByCliConfig(this.inputs);
|
48
|
+
}
|
49
|
+
|
50
|
+
if (res.repo.startsWith('local:')) {
|
51
|
+
const path = res.repo.split('local:')[1];
|
52
|
+
res.repo = 'local:' + this.fs.expandStrPath(path);
|
53
|
+
}
|
54
|
+
|
55
|
+
return res;
|
56
|
+
});
|
57
|
+
|
58
|
+
_defineProperty(this, "getByCliConfig", inp => {
|
59
|
+
// // TODO unify validation usage
|
60
|
+
const r = (0, _StoreConfig.CliStorageConfigSchema)().validate(inp, {
|
61
|
+
presence: 'required',
|
62
|
+
allowUnknown: true
|
63
|
+
});
|
64
|
+
if (r.error) throw new _InvalidInput.InvalidInput(r.error.toString());
|
65
|
+
const cfg = inp;
|
66
|
+
return {
|
67
|
+
type: cfg.storageType,
|
68
|
+
repo: cfg.storageRepo,
|
69
|
+
encryptionPassword: cfg.storagePassword,
|
70
|
+
credentials: cfg.storageCredentials
|
71
|
+
};
|
72
|
+
});
|
73
|
+
|
74
|
+
_defineProperty(this, "getByName", name => {
|
75
|
+
const cfg = this.cfg.storage.find(s => s.name === name);
|
76
|
+
if (!cfg) throw new Error(`No such storage '${name}'`);
|
77
|
+
const encryptionPassword = cfg.passwordFile ? this.fs.readFile(this.fs.expand(cfg.passwordFile)).trim() : undefined;
|
78
|
+
const credentials = cfg.credentialsFile ? this.fs.readFile(this.fs.expand(cfg.credentialsFile)).trim() : undefined;
|
79
|
+
return {
|
80
|
+
type: cfg.type,
|
81
|
+
repo: cfg.repo,
|
82
|
+
credentials,
|
83
|
+
encryptionPassword
|
84
|
+
};
|
85
|
+
});
|
86
|
+
}
|
87
|
+
|
88
|
+
}) || _class) || _class) || _class) || _class) || _class);
|
89
|
+
exports.StorageConfigProvider = StorageConfigProvider;
|
@@ -0,0 +1,39 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.StorageSchema = exports.NamedStorageSchema = exports.CliStorageConfigSchema = void 0;
|
7
|
+
|
8
|
+
var _joi = _interopRequireDefault(require("@hapi/joi"));
|
9
|
+
|
10
|
+
var _types = require("./types");
|
11
|
+
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
|
+
|
14
|
+
const props = {
|
15
|
+
type: _joi.default.string().valid(_types.StorageType.Restic, _types.StorageType.RClone),
|
16
|
+
repo: _joi.default.string(),
|
17
|
+
credentialsFile: _joi.default.string().optional(),
|
18
|
+
passwordFile: _joi.default.string().optional()
|
19
|
+
};
|
20
|
+
|
21
|
+
const StorageSchema = () => _joi.default.object(props);
|
22
|
+
|
23
|
+
exports.StorageSchema = StorageSchema;
|
24
|
+
|
25
|
+
const CliStorageConfigSchema = () => _joi.default.object({
|
26
|
+
storageType: _joi.default.string().valid(_types.StorageType.Restic, _types.StorageType.RClone),
|
27
|
+
storageRepo: _joi.default.string(),
|
28
|
+
storageCredentials: _joi.default.string().optional(),
|
29
|
+
storagePassword: _joi.default.string().optional()
|
30
|
+
});
|
31
|
+
|
32
|
+
exports.CliStorageConfigSchema = CliStorageConfigSchema;
|
33
|
+
|
34
|
+
const NamedStorageSchema = () => _joi.default.object({
|
35
|
+
name: _joi.default.string(),
|
36
|
+
...props
|
37
|
+
});
|
38
|
+
|
39
|
+
exports.NamedStorageSchema = NamedStorageSchema;
|
@@ -36,11 +36,15 @@ let B2CredentialsProvider = (_dec = (0, _inversify.injectable)(), _dec2 = Reflec
|
|
36
36
|
this.fs = fs;
|
37
37
|
|
38
38
|
_defineProperty(this, "fromFile", path => {
|
39
|
-
|
39
|
+
return this.fromString(this.fs.readFile(path));
|
40
|
+
});
|
41
|
+
|
42
|
+
_defineProperty(this, "fromString", str => {
|
43
|
+
const credJson = JSON.parse(str);
|
40
44
|
const validationErr = validateCredentials(credJson);
|
41
45
|
|
42
46
|
if (validationErr) {
|
43
|
-
throw new Error(`Invalid B2 credential in ${
|
47
|
+
throw new Error(`Invalid B2 credential in '${str.substring(0, 3)}...': ${validationErr}`);
|
44
48
|
}
|
45
49
|
|
46
50
|
const creds = credJson;
|
@@ -48,15 +48,15 @@ let RCloneClientFactory = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.
|
|
48
48
|
type,
|
49
49
|
location
|
50
50
|
};
|
51
|
-
const password = cfg.
|
51
|
+
const password = cfg.encryptionPassword;
|
52
52
|
if (password) props.encryption = {
|
53
53
|
password
|
54
54
|
};
|
55
|
-
const creds = cfg.
|
55
|
+
const creds = cfg.credentials;
|
56
56
|
|
57
57
|
if (type === 'b2') {
|
58
|
-
if (!creds) throw new Error(`Credentials are required for '${cfg.
|
59
|
-
props.creds = creds;
|
58
|
+
if (!creds) throw new Error(`Credentials are required for RClone storage repo='${cfg.repo}'`);
|
59
|
+
props.creds = this.b2.fromString(creds);
|
60
60
|
} else {
|
61
61
|
if (creds) throw new Error(`Credentials not supported for local rclone`);
|
62
62
|
}
|
@@ -29,18 +29,18 @@ let ResticClientFactory = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.
|
|
29
29
|
this.b2 = b2;
|
30
30
|
|
31
31
|
_defineProperty(this, "create", cfg => {
|
32
|
-
|
32
|
+
if (!cfg.encryptionPassword) throw new Error(`Restic needs encryptionPassword. Repo=${cfg.repo}`);
|
33
33
|
const props = {
|
34
34
|
repo: {
|
35
|
-
password,
|
35
|
+
password: cfg.encryptionPassword,
|
36
36
|
url: cfg.repo
|
37
37
|
}
|
38
38
|
};
|
39
|
-
const creds = cfg.
|
39
|
+
const creds = cfg.credentials;
|
40
40
|
|
41
41
|
if (cfg.repo.startsWith('b2:')) {
|
42
|
-
if (!creds) throw new Error(`Credentials must be provided for b2 repo in '${
|
43
|
-
props.backblaze = creds;
|
42
|
+
if (!creds) throw new Error(`Credentials must be provided for b2 repo in '${props.repo.url}'`);
|
43
|
+
props.backblaze = this.b2.fromString(creds);
|
44
44
|
} else {
|
45
45
|
if (creds) throw new Error('Credentials can be supported only for the B2 restic backend');
|
46
46
|
}
|
@@ -15,23 +15,28 @@ var _ResticClientFactory = require("./ResticClientFactory");
|
|
15
15
|
|
16
16
|
var _AppLogger = require("../../log/AppLogger");
|
17
17
|
|
18
|
+
var _StorageConfigProvider = require("../StorageConfigProvider");
|
19
|
+
|
20
|
+
var _types = require("../types");
|
21
|
+
|
18
22
|
var _dec, _dec2, _dec3, _dec4, _class;
|
19
23
|
|
20
24
|
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
25
|
|
22
26
|
let ResticController = (_dec = (0, _inversify.injectable)(), _dec2 = function (target, key) {
|
23
27
|
return (0, _inversify.inject)(_ContextSymbols.AppConfig_)(target, undefined, 2);
|
24
|
-
}, _dec3 = Reflect.metadata("design:type", Function), _dec4 = Reflect.metadata("design:paramtypes", [typeof _ResticClientFactory.ResticClientFactory === "undefined" ? Object : _ResticClientFactory.ResticClientFactory, typeof _AppLogger.AppLogger === "undefined" ? Object : _AppLogger.AppLogger, typeof _config.Config === "undefined" ? Object : _config.Config]), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = class ResticController {
|
25
|
-
constructor(restFact, log, cfg) {
|
28
|
+
}, _dec3 = Reflect.metadata("design:type", Function), _dec4 = Reflect.metadata("design:paramtypes", [typeof _ResticClientFactory.ResticClientFactory === "undefined" ? Object : _ResticClientFactory.ResticClientFactory, typeof _AppLogger.AppLogger === "undefined" ? Object : _AppLogger.AppLogger, typeof _config.Config === "undefined" ? Object : _config.Config, typeof _StorageConfigProvider.StorageConfigProvider === "undefined" ? Object : _StorageConfigProvider.StorageConfigProvider]), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = class ResticController {
|
29
|
+
constructor(restFact, log, cfg, storageConfigProvider) {
|
26
30
|
this.restFact = restFact;
|
27
31
|
this.log = log;
|
28
32
|
this.cfg = cfg;
|
33
|
+
this.storageConfigProvider = storageConfigProvider;
|
29
34
|
|
30
|
-
_defineProperty(this, "initRepo",
|
31
|
-
const
|
32
|
-
if (
|
33
|
-
this.log.info('Initializing repo',
|
34
|
-
this.restFact.create(
|
35
|
+
_defineProperty(this, "initRepo", () => {
|
36
|
+
const props = this.storageConfigProvider.provide();
|
37
|
+
if (props.type !== _types.StorageType.Restic) throw new Error('Storage is not Restic storage');
|
38
|
+
this.log.info('Initializing repo', props.repo);
|
39
|
+
this.restFact.create(props).prepareRepo();
|
35
40
|
});
|
36
41
|
}
|
37
42
|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.StorageType = void 0;
|
7
|
+
let StorageType;
|
8
|
+
exports.StorageType = StorageType;
|
9
|
+
|
10
|
+
(function (StorageType) {
|
11
|
+
StorageType["Restic"] = "restic";
|
12
|
+
StorageType["RClone"] = "rclone";
|
13
|
+
})(StorageType || (exports.StorageType = StorageType = {}));
|
@@ -6,9 +6,11 @@ var _Fs = require("../../fs/Fs");
|
|
6
6
|
|
7
7
|
var _AppLogger = require("../../log/AppLogger");
|
8
8
|
|
9
|
+
var _Path = require("../../fs/path/Path");
|
10
|
+
|
9
11
|
// TODO setup ci to make tests work
|
10
12
|
it.skip('works', () => {
|
11
|
-
const sut = new _SshKeyManager.SshKeyManager(new _Fs.Fs(new _AppLogger.AppLogger()));
|
13
|
+
const sut = new _SshKeyManager.SshKeyManager(new _Fs.Fs(_Path.AbsPath.from(__dirname), new _AppLogger.AppLogger()));
|
12
14
|
const key = sut.exportKey('id_rsa');
|
13
15
|
console.log('key', key);
|
14
16
|
});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ps-aux/nodebup",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.6.0",
|
4
4
|
"description": "",
|
5
5
|
"module": "lib/index.js",
|
6
6
|
"main": "lib/index.js",
|
@@ -72,7 +72,7 @@
|
|
72
72
|
},
|
73
73
|
"dependencies": {
|
74
74
|
"@hapi/joi": "^17.1.1",
|
75
|
-
"@ps-aux/nclif": "^0.0.
|
75
|
+
"@ps-aux/nclif": "^0.0.7-alpha.1",
|
76
76
|
"@types/hapi__joi": "^17.1.8",
|
77
77
|
"axios": "^0.24.0",
|
78
78
|
"handlebars": "^4.7.7",
|