@ps-aux/nodebup 0.1.0 → 0.2.2
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/AggregateBackupController.js +84 -0
- package/lib/cli/app.js +55 -0
- package/lib/cli/bin.js +2 -8
- package/lib/config/Config.js +58 -0
- package/lib/config/expandAndCreatePath.js +24 -0
- package/lib/config/validateConfigAgainstSchema.js +65 -0
- package/lib/config/validateConfigAgainstSchema.spec.js +29 -0
- package/lib/ctx/Context.js +23 -16
- package/lib/ctx/ContextSymbols.js +14 -0
- package/lib/fs/Fs.js +81 -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 +54 -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/StorageBackendProvider.js +53 -0
- package/lib/storage/local-file/LocalFileStorageBackend.js +22 -0
- package/lib/storage/restic/ResticClient.js +86 -0
- package/lib/storage/restic/ResticClient.spec.js +96 -0
- package/lib/storage/restic/ResticClientFactory.js +77 -0
- package/lib/storage/restic/ResticController.js +39 -0
- package/lib/storage/restic/ResticStorageBackend.js +23 -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
@@ -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,53 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.StorageBackendProvider = void 0;
|
7
|
+
|
8
|
+
var _inversify = require("inversify");
|
9
|
+
|
10
|
+
var _FsSyncer = require("../fs/fssync/FsSyncer");
|
11
|
+
|
12
|
+
var _LocalFileStorageBackend = require("./local-file/LocalFileStorageBackend");
|
13
|
+
|
14
|
+
var _ContextSymbols = require("../ctx/ContextSymbols");
|
15
|
+
|
16
|
+
var _Config = require("../config/Config");
|
17
|
+
|
18
|
+
var _ResticClientFactory = require("./restic/ResticClientFactory");
|
19
|
+
|
20
|
+
var _ResticStorageBackend = require("./restic/ResticStorageBackend");
|
21
|
+
|
22
|
+
var _Fs = require("../fs/Fs");
|
23
|
+
|
24
|
+
var _dec, _dec2, _dec3, _dec4, _class;
|
25
|
+
|
26
|
+
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; }
|
27
|
+
|
28
|
+
let StorageBackendProvider = (_dec = (0, _inversify.injectable)(), _dec2 = function (target, key) {
|
29
|
+
return (0, _inversify.inject)(_ContextSymbols.AppConfig_)(target, undefined, 3);
|
30
|
+
}, _dec3 = Reflect.metadata("design:type", Function), _dec4 = Reflect.metadata("design:paramtypes", [typeof _FsSyncer.FsSyncer === "undefined" ? Object : _FsSyncer.FsSyncer, typeof _ResticClientFactory.ResticClientFactory === "undefined" ? Object : _ResticClientFactory.ResticClientFactory, typeof _Fs.Fs === "undefined" ? Object : _Fs.Fs, typeof _Config.Config === "undefined" ? Object : _Config.Config]), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = class StorageBackendProvider {
|
31
|
+
constructor(fsSyncer, resticFac, fs, cfg) {
|
32
|
+
this.fsSyncer = fsSyncer;
|
33
|
+
this.resticFac = resticFac;
|
34
|
+
this.fs = fs;
|
35
|
+
this.cfg = cfg;
|
36
|
+
|
37
|
+
_defineProperty(this, "provide", name => {
|
38
|
+
const s = this.cfg.storage.find(s => s.name === name);
|
39
|
+
if (!s) throw new Error(`No such storage '${name}'`);
|
40
|
+
if (s.type === 'restic') return this.restic(s);else if (s.type === 'file') return this.localFile(s);else throw new Error(`Unsupported storage type ${s.type}`);
|
41
|
+
});
|
42
|
+
|
43
|
+
_defineProperty(this, "restic", cfg => {
|
44
|
+
return new _ResticStorageBackend.ResticStorageBackend(this.resticFac.create(cfg));
|
45
|
+
});
|
46
|
+
|
47
|
+
_defineProperty(this, "localFile", cfg => {
|
48
|
+
return new _LocalFileStorageBackend.LocalFileStorageBackend(this.fsSyncer, cfg.path);
|
49
|
+
});
|
50
|
+
}
|
51
|
+
|
52
|
+
}) || _class) || _class) || _class) || _class);
|
53
|
+
exports.StorageBackendProvider = StorageBackendProvider;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.LocalFileStorageBackend = void 0;
|
7
|
+
|
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
|
+
|
10
|
+
class LocalFileStorageBackend {
|
11
|
+
constructor(fsSyncer, dst) {
|
12
|
+
this.fsSyncer = fsSyncer;
|
13
|
+
this.dst = dst;
|
14
|
+
|
15
|
+
_defineProperty(this, "store", from => {
|
16
|
+
this.fsSyncer.syncDirs(from, this.dst);
|
17
|
+
});
|
18
|
+
}
|
19
|
+
|
20
|
+
}
|
21
|
+
|
22
|
+
exports.LocalFileStorageBackend = LocalFileStorageBackend;
|
@@ -0,0 +1,86 @@
|
|
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
|
+
* Tested with: restic 0.9.6 compiled with go1.12.12 on linux/amd64
|
29
|
+
* TODO forwarding stdout to the logger
|
30
|
+
*/
|
31
|
+
|
32
|
+
|
33
|
+
let ResticClient = (_dec = (0, _inversify.injectable)(), _dec2 = function (target, key) {
|
34
|
+
return (0, _inversify.inject)(_ContextSymbols.TaskConfig_)(target, undefined, 2);
|
35
|
+
}, _dec3 = Reflect.metadata("design:type", Function), _dec4 = Reflect.metadata("design:paramtypes", [typeof ResticConfig === "undefined" ? Object : ResticConfig, typeof _Shell.Shell === "undefined" ? Object : _Shell.Shell, typeof _types.Log === "undefined" ? Object : _types.Log]), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = class ResticClient {
|
36
|
+
constructor(cfg, shell, log) {
|
37
|
+
this.cfg = cfg;
|
38
|
+
this.shell = shell;
|
39
|
+
this.log = log;
|
40
|
+
|
41
|
+
_defineProperty(this, "url", void 0);
|
42
|
+
|
43
|
+
_defineProperty(this, "prepareRepo", () => {
|
44
|
+
this.log.info(`Preparing a restic repo at '${this.url}`);
|
45
|
+
this.shell.exec(`restic init`, {
|
46
|
+
env: this.env()
|
47
|
+
});
|
48
|
+
});
|
49
|
+
|
50
|
+
_defineProperty(this, "backup", (cwd, from) => {
|
51
|
+
this.shell.exec(`restic backup ${from.str()}`, {
|
52
|
+
cwd: cwd.str(),
|
53
|
+
env: this.env()
|
54
|
+
});
|
55
|
+
});
|
56
|
+
|
57
|
+
_defineProperty(this, "restore", to => {
|
58
|
+
this.shell.exec(`restic restore latest --target ${to.str()}`, {
|
59
|
+
env: this.env()
|
60
|
+
});
|
61
|
+
});
|
62
|
+
|
63
|
+
_defineProperty(this, "env", () => ({
|
64
|
+
RESTIC_PASSWORD: this.cfg.repo.password,
|
65
|
+
RESTIC_REPOSITORY: this.url,
|
66
|
+
...this.getCredentialsForUrl(this.url)
|
67
|
+
}));
|
68
|
+
|
69
|
+
_defineProperty(this, "getCredentialsForUrl", url => {
|
70
|
+
if (url.startsWith('b2:')) {
|
71
|
+
const cfg = this.cfg.backblaze;
|
72
|
+
if (!cfg) throw new Error(`Repo url ${url} refers to Backblaze but no Backblaze config provided`);
|
73
|
+
return {
|
74
|
+
B2_ACCOUNT_ID: cfg.accountId,
|
75
|
+
B2_ACCOUNT_KEY: cfg.accountKey
|
76
|
+
};
|
77
|
+
}
|
78
|
+
|
79
|
+
return {};
|
80
|
+
});
|
81
|
+
|
82
|
+
this.url = normalizeUrl(cfg.repo.url);
|
83
|
+
}
|
84
|
+
|
85
|
+
}) || _class) || _class) || _class) || _class);
|
86
|
+
exports.ResticClient = ResticClient;
|
@@ -0,0 +1,96 @@
|
|
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 = _interopRequireDefault(require("path"));
|
14
|
+
|
15
|
+
var _Path = require("../../fs/path/Path");
|
16
|
+
|
17
|
+
var _dirCompare = require("dir-compare");
|
18
|
+
|
19
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
20
|
+
|
21
|
+
const getBackblazeConfig = () => {
|
22
|
+
const path = _path.default.resolve(__dirname, '../../../.keys.json');
|
23
|
+
|
24
|
+
if (!_fs.default.existsSync(path)) return undefined;
|
25
|
+
const data = JSON.parse(_fs.default.readFileSync(path).toString());
|
26
|
+
return {
|
27
|
+
accountId: data.restic.backblaze.keyID,
|
28
|
+
accountKey: data.restic.backblaze.applicationKey
|
29
|
+
};
|
30
|
+
};
|
31
|
+
|
32
|
+
describe('ResticClient', () => {
|
33
|
+
const l = new _AppLogger.AppLogger();
|
34
|
+
const password = 'foo123';
|
35
|
+
const backupDir = (0, _test.testDir)('backup-me');
|
36
|
+
describe('local', () => {
|
37
|
+
const repoDir = (0, _test.testdataDir)('my-repo');
|
38
|
+
const restoreDir = (0, _test.testdataDir)('restore/local');
|
39
|
+
const sut = new _ResticClient.ResticClient({
|
40
|
+
repo: {
|
41
|
+
password,
|
42
|
+
url: `local:${repoDir}`
|
43
|
+
}
|
44
|
+
}, new _Shell.Shell(l), l);
|
45
|
+
afterAll(() => {
|
46
|
+
_fs.default.rmdirSync(repoDir, {
|
47
|
+
recursive: true
|
48
|
+
});
|
49
|
+
|
50
|
+
_fs.default.rmdirSync(restoreDir, {
|
51
|
+
recursive: true
|
52
|
+
});
|
53
|
+
});
|
54
|
+
it('create repo', () => {
|
55
|
+
sut.prepareRepo();
|
56
|
+
});
|
57
|
+
it('push data', () => {
|
58
|
+
sut.backup(_Path.AbsPath.from(backupDir), _Path.RelativePath.from('.'));
|
59
|
+
});
|
60
|
+
it('restore data', () => {
|
61
|
+
sut.restore(_Path.AbsPath.from(restoreDir));
|
62
|
+
const res = (0, _dirCompare.compareSync)(backupDir, restoreDir);
|
63
|
+
expect(res.same).toBeTrue();
|
64
|
+
});
|
65
|
+
});
|
66
|
+
describe('b2', () => {
|
67
|
+
const b2Cfg = getBackblazeConfig();
|
68
|
+
|
69
|
+
if (!b2Cfg) {
|
70
|
+
console.log('No B2 config - skipping');
|
71
|
+
return;
|
72
|
+
}
|
73
|
+
|
74
|
+
const restoreDir = (0, _test.testdataDir)('restore/b2');
|
75
|
+
const repoUrl = `b2:psaux-nodepub-test`;
|
76
|
+
const sut = new _ResticClient.ResticClient({
|
77
|
+
repo: {
|
78
|
+
password,
|
79
|
+
url: repoUrl
|
80
|
+
},
|
81
|
+
backblaze: b2Cfg
|
82
|
+
}, new _Shell.Shell(l), l);
|
83
|
+
afterAll(() => {
|
84
|
+
_fs.default.rmdirSync(restoreDir, {
|
85
|
+
recursive: true
|
86
|
+
});
|
87
|
+
});
|
88
|
+
it('push adn restore data', () => {
|
89
|
+
// sut.prepareRepo(repoUrl, password)
|
90
|
+
sut.backup(_Path.AbsPath.from(backupDir), _Path.RelativePath.from('.'));
|
91
|
+
sut.restore(_Path.AbsPath.from(restoreDir));
|
92
|
+
const res = (0, _dirCompare.compareSync)(backupDir, restoreDir);
|
93
|
+
expect(res.same).toBeTrue();
|
94
|
+
});
|
95
|
+
});
|
96
|
+
});
|
@@ -0,0 +1,77 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.ResticClientFactory = void 0;
|
7
|
+
|
8
|
+
var _inversify = require("inversify");
|
9
|
+
|
10
|
+
var _ResticClient = require("./ResticClient");
|
11
|
+
|
12
|
+
var _Shell = require("../../tools/shell/Shell");
|
13
|
+
|
14
|
+
var _AppLogger = require("../../log/AppLogger");
|
15
|
+
|
16
|
+
var _Fs = require("../../fs/Fs");
|
17
|
+
|
18
|
+
var _joi = _interopRequireDefault(require("@hapi/joi"));
|
19
|
+
|
20
|
+
var _dec, _dec2, _dec3, _class;
|
21
|
+
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
23
|
+
|
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; }
|
25
|
+
|
26
|
+
const CredentialsFileSchema = _joi.default.object({
|
27
|
+
keyID: _joi.default.string(),
|
28
|
+
keyName: _joi.default.string().optional(),
|
29
|
+
applicationKey: _joi.default.string()
|
30
|
+
});
|
31
|
+
|
32
|
+
const validateCredentials = obj => {
|
33
|
+
const r = CredentialsFileSchema.validate(obj, {
|
34
|
+
presence: 'required',
|
35
|
+
allowUnknown: false
|
36
|
+
});
|
37
|
+
return r.error ? JSON.stringify(r.error) : null;
|
38
|
+
};
|
39
|
+
|
40
|
+
let ResticClientFactory = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.metadata("design:type", Function), _dec3 = Reflect.metadata("design:paramtypes", [typeof _Shell.Shell === "undefined" ? Object : _Shell.Shell, typeof _AppLogger.AppLogger === "undefined" ? Object : _AppLogger.AppLogger, typeof _Fs.Fs === "undefined" ? Object : _Fs.Fs]), _dec(_class = _dec2(_class = _dec3(_class = class ResticClientFactory {
|
41
|
+
constructor(sh, log, fs) {
|
42
|
+
this.sh = sh;
|
43
|
+
this.log = log;
|
44
|
+
this.fs = fs;
|
45
|
+
|
46
|
+
_defineProperty(this, "create", cfg => {
|
47
|
+
const password = this.fs.readFile(cfg.passwordFile).trim();
|
48
|
+
const props = {
|
49
|
+
repo: {
|
50
|
+
password,
|
51
|
+
url: cfg.repo
|
52
|
+
}
|
53
|
+
};
|
54
|
+
|
55
|
+
if (cfg.credentialsFile) {
|
56
|
+
if (!cfg.repo.startsWith('b2:')) throw new Error('Credentials can be supported only for the B2 restic backend');
|
57
|
+
const credJson = this.fs.readJson(cfg.credentialsFile); //
|
58
|
+
|
59
|
+
const validationErr = validateCredentials(credJson);
|
60
|
+
|
61
|
+
if (validationErr) {
|
62
|
+
throw new Error(`Invalid Restic credential in ${cfg.credentialsFile}: ${validationErr}`);
|
63
|
+
}
|
64
|
+
|
65
|
+
const creds = credJson;
|
66
|
+
props.backblaze = {
|
67
|
+
accountId: creds.keyID,
|
68
|
+
accountKey: creds.applicationKey
|
69
|
+
};
|
70
|
+
}
|
71
|
+
|
72
|
+
return new _ResticClient.ResticClient(props, this.sh, this.log);
|
73
|
+
});
|
74
|
+
}
|
75
|
+
|
76
|
+
}) || _class) || _class) || _class);
|
77
|
+
exports.ResticClientFactory = ResticClientFactory;
|
@@ -0,0 +1,39 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.ResticController = void 0;
|
7
|
+
|
8
|
+
var _inversify = require("inversify");
|
9
|
+
|
10
|
+
var _ContextSymbols = require("../../ctx/ContextSymbols");
|
11
|
+
|
12
|
+
var _Config = require("../../config/Config");
|
13
|
+
|
14
|
+
var _ResticClientFactory = require("./ResticClientFactory");
|
15
|
+
|
16
|
+
var _AppLogger = require("../../log/AppLogger");
|
17
|
+
|
18
|
+
var _dec, _dec2, _dec3, _dec4, _class;
|
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 ResticController = (_dec = (0, _inversify.injectable)(), _dec2 = function (target, key) {
|
23
|
+
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) {
|
26
|
+
this.restFact = restFact;
|
27
|
+
this.log = log;
|
28
|
+
this.cfg = cfg;
|
29
|
+
|
30
|
+
_defineProperty(this, "initRepo", storageName => {
|
31
|
+
const s = this.cfg.storage.filter(s => s.type === 'restic').find(s => s.name === storageName);
|
32
|
+
if (!s) throw new Error(`No restic storage '${storageName}'`);
|
33
|
+
this.log.info('Initializing repo', storageName);
|
34
|
+
this.restFact.create(s).prepareRepo();
|
35
|
+
});
|
36
|
+
}
|
37
|
+
|
38
|
+
}) || _class) || _class) || _class) || _class);
|
39
|
+
exports.ResticController = ResticController;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.ResticStorageBackend = void 0;
|
7
|
+
|
8
|
+
var _Path = require("../../fs/path/Path");
|
9
|
+
|
10
|
+
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; }
|
11
|
+
|
12
|
+
class ResticStorageBackend {
|
13
|
+
constructor(client) {
|
14
|
+
this.client = client;
|
15
|
+
|
16
|
+
_defineProperty(this, "store", from => {
|
17
|
+
this.client.backup(from, _Path.RelativePath.from('.'));
|
18
|
+
});
|
19
|
+
}
|
20
|
+
|
21
|
+
}
|
22
|
+
|
23
|
+
exports.ResticStorageBackend = ResticStorageBackend;
|
@@ -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 find a way hot to provide prompt via stdin
|
10
|
+
it.skip('works', () => {
|
11
|
+
const sut = new _Gpg.Gpg(new _Shell.Shell(new _AppLogger.AppLogger()));
|
12
|
+
const key = sut.exportKey('john.doe@foo.com');
|
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
|
+
});
|