@ps-aux/nodebup 0.1.1 → 0.3.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.
Files changed (41) hide show
  1. package/README.md +0 -0
  2. package/lib/bup/AggregateBackupController.js +95 -0
  3. package/lib/cli/app.js +55 -0
  4. package/lib/cli/bin.js +2 -8
  5. package/lib/config/Config.js +64 -0
  6. package/lib/config/expandAndCreatePath.js +24 -0
  7. package/lib/config/validateConfigAgainstSchema.js +65 -0
  8. package/lib/config/validateConfigAgainstSchema.spec.js +29 -0
  9. package/lib/ctx/Context.js +23 -16
  10. package/lib/ctx/ContextSymbols.js +14 -0
  11. package/lib/fs/Fs.js +81 -0
  12. package/lib/fs/areDirsSame.js +20 -0
  13. package/lib/fs/areDirsSame.test.js +20 -0
  14. package/lib/fs/fssync/FsSync.spec.js +33 -0
  15. package/lib/fs/fssync/FsSyncer.js +54 -0
  16. package/lib/fs/path/Path.js +59 -0
  17. package/lib/fs/readYaml.js +20 -0
  18. package/lib/globald.d.js +3 -0
  19. package/lib/log/AppLogger.js +28 -0
  20. package/lib/log/ConsoleLogger.js +5 -3
  21. package/lib/log/MinimalLogger.js +10 -4
  22. package/lib/storage/StorageBackendProvider.js +53 -0
  23. package/lib/storage/local-file/LocalFileStorageBackend.js +22 -0
  24. package/lib/storage/restic/ResticClient.js +86 -0
  25. package/lib/storage/restic/ResticClient.spec.js +91 -0
  26. package/lib/storage/restic/ResticClientFactory.js +77 -0
  27. package/lib/storage/restic/ResticController.js +39 -0
  28. package/lib/storage/restic/ResticStorageBackend.js +23 -0
  29. package/lib/storage/types.d.js +5 -0
  30. package/lib/tools/gpg/Gpg.js +28 -0
  31. package/lib/tools/gpg/Gpg.spec.js +14 -0
  32. package/lib/tools/shell/Shell.js +52 -0
  33. package/lib/{shell → tools/shell}/shellCmd.js +4 -2
  34. package/lib/tools/ssh/SshKeyManager.js +36 -0
  35. package/lib/tools/ssh/SshKeyManager.spec.js +14 -0
  36. package/lib/types.js +5 -0
  37. package/package.json +54 -48
  38. package/lib/cli/entrypoint.js +0 -27
  39. package/lib/foo/foo.command.js +0 -16
  40. package/lib/shell/LocalShellCmdExecutor.js +0 -46
  41. package/lib/types.d.js +0 -1
@@ -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;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+
3
+ require("jest-extended");
@@ -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;
@@ -11,15 +11,17 @@ class ConsoleLogger {
11
11
  constructor() {
12
12
  _defineProperty(this, "enabled", true);
13
13
 
14
+ _defineProperty(this, "print", (...args) => console.log(...args.map(a => a.toString())));
15
+
14
16
  _defineProperty(this, "debug", (...args) => {
15
- if (this.enabled) console.log(...args);
17
+ if (this.enabled) this.print(args);
16
18
  });
17
19
 
18
20
  _defineProperty(this, "info", (...args) => {
19
- if (this.enabled) console.log(...args);
21
+ if (this.enabled) this.print(args);
20
22
  });
21
23
 
22
- _defineProperty(this, "error", console.error);
24
+ _defineProperty(this, "error", this.print);
23
25
 
24
26
  _defineProperty(this, "setEnabled", enabled => {
25
27
  this.enabled = enabled;
@@ -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
- _defineProperty(this, "debug", () => {// no op
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", () => {// no op
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,91 @@
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
+ var _testHelper = require("../../../test/testHelper");
20
+
21
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
+
23
+ const getBackblazeConfig = () => {
24
+ const path = _path.default.resolve(__dirname, '../../../.keys.json');
25
+
26
+ if (!_fs.default.existsSync(path)) return undefined;
27
+ const data = JSON.parse(_fs.default.readFileSync(path).toString());
28
+ return {
29
+ accountId: data.restic.backblaze.keyID,
30
+ accountKey: data.restic.backblaze.applicationKey
31
+ };
32
+ };
33
+
34
+ describe('ResticClient', () => {
35
+ const l = new _AppLogger.AppLogger();
36
+ const password = 'foo123';
37
+ const backupDir = (0, _test.testDir)('backup-me');
38
+ describe('local', () => {
39
+ const repoDir = (0, _test.testdataDir)('my-repo');
40
+ const restoreDir = (0, _test.testdataDir)('restore/local');
41
+ const sut = new _ResticClient.ResticClient({
42
+ repo: {
43
+ password,
44
+ url: `local:${repoDir}`
45
+ }
46
+ }, new _Shell.Shell(l), l);
47
+ afterAll(() => {
48
+ (0, _testHelper.cleanDir)(repoDir);
49
+ (0, _testHelper.cleanDir)(restoreDir);
50
+ });
51
+ it('create repo', () => {
52
+ sut.prepareRepo();
53
+ });
54
+ it('push data', () => {
55
+ sut.backup(_Path.AbsPath.from(backupDir), _Path.RelativePath.from('.'));
56
+ });
57
+ it('restore data', () => {
58
+ sut.restore(_Path.AbsPath.from(restoreDir));
59
+ const res = (0, _dirCompare.compareSync)(backupDir, restoreDir);
60
+ expect(res.same).toBeTrue();
61
+ });
62
+ });
63
+ describe('b2', () => {
64
+ const b2Cfg = getBackblazeConfig();
65
+
66
+ if (!b2Cfg) {
67
+ console.log('No B2 config - skipping');
68
+ return;
69
+ }
70
+
71
+ const restoreDir = (0, _test.testdataDir)('restore/b2');
72
+ const repoUrl = `b2:psaux-nodepub-test`;
73
+ const sut = new _ResticClient.ResticClient({
74
+ repo: {
75
+ password,
76
+ url: repoUrl
77
+ },
78
+ backblaze: b2Cfg
79
+ }, new _Shell.Shell(l), l);
80
+ afterAll(() => {
81
+ (0, _testHelper.cleanDir)(restoreDir);
82
+ });
83
+ it('push adn restore data', () => {
84
+ // sut.prepareRepo(repoUrl, password)
85
+ sut.backup(_Path.AbsPath.from(backupDir), _Path.RelativePath.from('.'));
86
+ sut.restore(_Path.AbsPath.from(restoreDir));
87
+ const res = (0, _dirCompare.compareSync)(backupDir, restoreDir);
88
+ expect(res.same).toBeTrue();
89
+ });
90
+ });
91
+ });
@@ -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,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -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;