@datatruck/cli 0.4.0 → 0.5.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/Action/BackupAction.js +1 -0
- package/Action/InitAction.js +3 -0
- package/Action/PruneAction.js +1 -1
- package/Action/RestoreAction.js +4 -1
- package/Action/SnapshotsAction.d.ts +2 -1
- package/Action/SnapshotsAction.js +6 -1
- package/CHANGELOG.md +8 -0
- package/Config/RepositoryConfig.d.ts +4 -0
- package/Config/RepositoryConfig.js +19 -0
- package/Repository/ResticRepository.d.ts +7 -3
- package/Repository/ResticRepository.js +17 -3
- package/config.schema.json +50 -3
- package/package.json +1 -1
- package/util/datatruck/config-util.d.ts +4 -1
- package/util/datatruck/config-util.js +11 -1
package/Action/BackupAction.js
CHANGED
|
@@ -23,6 +23,7 @@ class BackupAction {
|
|
|
23
23
|
packageNames: this.options.packageNames,
|
|
24
24
|
repositoryNames: this.options.repositoryNames,
|
|
25
25
|
repositoryTypes: this.options.repositoryTypes,
|
|
26
|
+
sourceAction: "backup",
|
|
26
27
|
});
|
|
27
28
|
packages = (0, config_util_1.resolvePackages)(packages, {
|
|
28
29
|
snapshotId: snapshot.id,
|
package/Action/InitAction.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InitAction = void 0;
|
|
4
4
|
const RepositoryFactory_1 = require("../Factory/RepositoryFactory");
|
|
5
|
+
const config_util_1 = require("../util/datatruck/config-util");
|
|
5
6
|
class InitAction {
|
|
6
7
|
constructor(config, options) {
|
|
7
8
|
this.config = config;
|
|
@@ -10,6 +11,8 @@ class InitAction {
|
|
|
10
11
|
async exec() {
|
|
11
12
|
const result = [];
|
|
12
13
|
for (const repo of this.config.repositories) {
|
|
14
|
+
if (!(0, config_util_1.filterRepository)(repo, "init"))
|
|
15
|
+
continue;
|
|
13
16
|
if (this.options.repositoryNames &&
|
|
14
17
|
!this.options.repositoryNames.includes(repo.name))
|
|
15
18
|
continue;
|
package/Action/PruneAction.js
CHANGED
|
@@ -24,7 +24,7 @@ class PruneAction {
|
|
|
24
24
|
}
|
|
25
25
|
async exec() {
|
|
26
26
|
const snapshotsAction = new SnapshotsAction_1.SnapshotsAction(this.config, this.options);
|
|
27
|
-
const snapshots = await snapshotsAction.exec();
|
|
27
|
+
const snapshots = await snapshotsAction.exec("prune");
|
|
28
28
|
const snapshotsDeleted = [];
|
|
29
29
|
const reasons = {};
|
|
30
30
|
const inputFilter = {
|
package/Action/RestoreAction.js
CHANGED
|
@@ -203,7 +203,10 @@ class RestoreAction {
|
|
|
203
203
|
const snapshots = this.groupSnapshots(await this.findSnapshots());
|
|
204
204
|
if (!snapshots.length)
|
|
205
205
|
throw new AppError_1.AppError("None snapshot found");
|
|
206
|
-
let packages = (0, config_util_1.filterPackages)(this.config,
|
|
206
|
+
let packages = (0, config_util_1.filterPackages)(this.config, {
|
|
207
|
+
...this.options,
|
|
208
|
+
sourceAction: "restore",
|
|
209
|
+
});
|
|
207
210
|
packages = (0, config_util_1.resolvePackages)(packages, {
|
|
208
211
|
snapshotId: this.options.snapshotId,
|
|
209
212
|
snapshotDate: snapshots[0].date,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ConfigType } from "../Config/Config";
|
|
2
|
+
import { RepositoryConfigEnabledActionType } from "../Config/RepositoryConfig";
|
|
2
3
|
import { SnapshotResultType } from "../Repository/RepositoryAbstract";
|
|
3
4
|
import { IfRequireKeys } from "../util/ts-util";
|
|
4
5
|
export declare type SnapshotGroupByType = keyof Pick<SnapshotExtendedType, "packageName" | "repositoryName" | "repositoryType">;
|
|
@@ -27,5 +28,5 @@ export declare class SnapshotsAction<TRequired extends boolean = true> {
|
|
|
27
28
|
readonly config: ConfigType;
|
|
28
29
|
readonly options: IfRequireKeys<TRequired, SnapshotsActionOptionsType>;
|
|
29
30
|
constructor(config: ConfigType, options: IfRequireKeys<TRequired, SnapshotsActionOptionsType>);
|
|
30
|
-
exec(): Promise<SnapshotExtendedType[]>;
|
|
31
|
+
exec(sourceAction?: RepositoryConfigEnabledActionType): Promise<SnapshotExtendedType[]>;
|
|
31
32
|
}
|
|
@@ -2,15 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SnapshotsAction = void 0;
|
|
4
4
|
const RepositoryFactory_1 = require("../Factory/RepositoryFactory");
|
|
5
|
+
const config_util_1 = require("../util/datatruck/config-util");
|
|
5
6
|
const snapshot_util_1 = require("../util/datatruck/snapshot-util");
|
|
6
7
|
class SnapshotsAction {
|
|
7
8
|
constructor(config, options) {
|
|
8
9
|
this.config = config;
|
|
9
10
|
this.options = options;
|
|
10
11
|
}
|
|
11
|
-
async exec() {
|
|
12
|
+
async exec(sourceAction) {
|
|
13
|
+
if (!sourceAction)
|
|
14
|
+
sourceAction = "snapshots";
|
|
12
15
|
let result = [];
|
|
13
16
|
for (const repo of this.config.repositories) {
|
|
17
|
+
if (!(0, config_util_1.filterRepository)(repo, sourceAction))
|
|
18
|
+
continue;
|
|
14
19
|
if (this.options.repositoryNames &&
|
|
15
20
|
!this.options.repositoryNames.includes(repo.name))
|
|
16
21
|
continue;
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @datatruck/cli
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`5aeb2af`](https://github.com/swordev/datatruck/commit/5aeb2afb96692e00bdba501b58df9cc0e02dceaa) Thanks [@juanrgm](https://github.com/juanrgm)! - Add `enabled` option to repository config
|
|
8
|
+
|
|
9
|
+
* [`75de836`](https://github.com/swordev/datatruck/commit/75de8369356cf02ed3fd5c58b1f9bea66432cda8) Thanks [@juanrgm](https://github.com/juanrgm)! - Allow restic password without file
|
|
10
|
+
|
|
3
11
|
## 0.4.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
|
@@ -4,8 +4,12 @@ import { ResticRepositoryConfigType, resticRepositoryName } from "../Repository/
|
|
|
4
4
|
import type { JSONSchema7 } from "json-schema";
|
|
5
5
|
export declare const repositoryConfigDefinition: JSONSchema7;
|
|
6
6
|
export declare type RepositoryConfigTypeType = RepositoryConfigType["type"];
|
|
7
|
+
export declare type RepositoryConfigEnabledActionType = "backup" | "init" | "prune" | "restore" | "snapshots";
|
|
7
8
|
export declare type RepositoryConfigType = {
|
|
8
9
|
name: string;
|
|
10
|
+
enabled?: boolean | {
|
|
11
|
+
[K in "defaults" | RepositoryConfigEnabledActionType]?: boolean;
|
|
12
|
+
};
|
|
9
13
|
} & ({
|
|
10
14
|
type: typeof resticRepositoryName;
|
|
11
15
|
config: ResticRepositoryConfigType;
|
|
@@ -17,6 +17,25 @@ exports.repositoryConfigDefinition = {
|
|
|
17
17
|
properties: {
|
|
18
18
|
type: { type: "string" },
|
|
19
19
|
name: { type: "string" },
|
|
20
|
+
enabled: {
|
|
21
|
+
anyOf: [
|
|
22
|
+
{
|
|
23
|
+
type: "boolean",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
type: "object",
|
|
27
|
+
additionalProperties: false,
|
|
28
|
+
properties: {
|
|
29
|
+
defaults: { type: "boolean" },
|
|
30
|
+
backup: { type: "boolean" },
|
|
31
|
+
init: { type: "boolean" },
|
|
32
|
+
prune: { type: "boolean" },
|
|
33
|
+
restore: { type: "boolean" },
|
|
34
|
+
snapshots: { type: "boolean" },
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
},
|
|
20
39
|
config: {},
|
|
21
40
|
},
|
|
22
41
|
anyOf: Object.keys(types).map((type) => ({
|
|
@@ -2,7 +2,9 @@ import { RepositoryType } from "../util/ResticUtil";
|
|
|
2
2
|
import { RepositoryAbstract, BackupDataType, InitDataType, RestoreDataType, SnapshotsDataType, SnapshotResultType, SnapshotTagObjectType, SnapshotTagEnum, PruneDataType } from "./RepositoryAbstract";
|
|
3
3
|
import { JSONSchema7 } from "json-schema";
|
|
4
4
|
export declare type ResticRepositoryConfigType = {
|
|
5
|
-
|
|
5
|
+
password: string | {
|
|
6
|
+
path: string;
|
|
7
|
+
};
|
|
6
8
|
repository: RepositoryType;
|
|
7
9
|
};
|
|
8
10
|
export declare type ResticPackageRepositoryConfigType = {};
|
|
@@ -12,11 +14,13 @@ export declare const resticPackageRepositoryDefinition: JSONSchema7;
|
|
|
12
14
|
export declare class ResticRepository extends RepositoryAbstract<ResticRepositoryConfigType> {
|
|
13
15
|
static refPrefix: string;
|
|
14
16
|
protected env: {
|
|
15
|
-
|
|
17
|
+
RESTIC_PASSWORD?: string;
|
|
18
|
+
RESTIC_PASSWORD_FILE?: string;
|
|
16
19
|
RESTIC_REPOSITORY: string;
|
|
17
20
|
};
|
|
18
21
|
buildEnv(): Promise<{
|
|
19
|
-
|
|
22
|
+
RESTIC_PASSWORD?: string | undefined;
|
|
23
|
+
RESTIC_PASSWORD_FILE?: string | undefined;
|
|
20
24
|
RESTIC_REPOSITORY: string;
|
|
21
25
|
}>;
|
|
22
26
|
static buildSnapshotTag(name: SnapshotTagEnum, value: string): string;
|
|
@@ -18,10 +18,22 @@ const path_1 = require("path");
|
|
|
18
18
|
exports.resticRepositoryName = "restic";
|
|
19
19
|
exports.resticRepositoryDefinition = {
|
|
20
20
|
type: "object",
|
|
21
|
-
required: ["
|
|
21
|
+
required: ["password", "repository"],
|
|
22
22
|
additionalProperties: false,
|
|
23
23
|
properties: {
|
|
24
|
-
|
|
24
|
+
password: {
|
|
25
|
+
anyOf: [
|
|
26
|
+
{ type: "string" },
|
|
27
|
+
{
|
|
28
|
+
type: "object",
|
|
29
|
+
additionalProperties: false,
|
|
30
|
+
required: ["path"],
|
|
31
|
+
properties: {
|
|
32
|
+
path: { type: "string" },
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
},
|
|
25
37
|
repository: {
|
|
26
38
|
type: "object",
|
|
27
39
|
additionalProperties: false,
|
|
@@ -59,7 +71,9 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
59
71
|
if (this.env)
|
|
60
72
|
return this.env;
|
|
61
73
|
return (this.env = {
|
|
62
|
-
|
|
74
|
+
...(typeof this.config.password === "string"
|
|
75
|
+
? { RESTIC_PASSWORD: this.config.password }
|
|
76
|
+
: { RESTIC_PASSWORD_FILE: (0, path_1.resolve)(this.config.password.path) }),
|
|
63
77
|
RESTIC_REPOSITORY: await ResticUtil_1.ResticUtil.formatRepository(this.config.repository),
|
|
64
78
|
});
|
|
65
79
|
}
|
package/config.schema.json
CHANGED
|
@@ -20,6 +20,37 @@
|
|
|
20
20
|
"name": {
|
|
21
21
|
"type": "string"
|
|
22
22
|
},
|
|
23
|
+
"enabled": {
|
|
24
|
+
"anyOf": [
|
|
25
|
+
{
|
|
26
|
+
"type": "boolean"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"type": "object",
|
|
30
|
+
"additionalProperties": false,
|
|
31
|
+
"properties": {
|
|
32
|
+
"defaults": {
|
|
33
|
+
"type": "boolean"
|
|
34
|
+
},
|
|
35
|
+
"backup": {
|
|
36
|
+
"type": "boolean"
|
|
37
|
+
},
|
|
38
|
+
"init": {
|
|
39
|
+
"type": "boolean"
|
|
40
|
+
},
|
|
41
|
+
"prune": {
|
|
42
|
+
"type": "boolean"
|
|
43
|
+
},
|
|
44
|
+
"restore": {
|
|
45
|
+
"type": "boolean"
|
|
46
|
+
},
|
|
47
|
+
"snapshots": {
|
|
48
|
+
"type": "boolean"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
},
|
|
23
54
|
"config": {}
|
|
24
55
|
},
|
|
25
56
|
"anyOf": [
|
|
@@ -462,13 +493,29 @@
|
|
|
462
493
|
"restic-repository": {
|
|
463
494
|
"type": "object",
|
|
464
495
|
"required": [
|
|
465
|
-
"
|
|
496
|
+
"password",
|
|
466
497
|
"repository"
|
|
467
498
|
],
|
|
468
499
|
"additionalProperties": false,
|
|
469
500
|
"properties": {
|
|
470
|
-
"
|
|
471
|
-
"
|
|
501
|
+
"password": {
|
|
502
|
+
"anyOf": [
|
|
503
|
+
{
|
|
504
|
+
"type": "string"
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
"type": "object",
|
|
508
|
+
"additionalProperties": false,
|
|
509
|
+
"required": [
|
|
510
|
+
"path"
|
|
511
|
+
],
|
|
512
|
+
"properties": {
|
|
513
|
+
"path": {
|
|
514
|
+
"type": "string"
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
]
|
|
472
519
|
},
|
|
473
520
|
"repository": {
|
|
474
521
|
"type": "object",
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { ConfigType } from "../../Config/Config";
|
|
2
2
|
import type { PackageConfigType } from "../../Config/PackageConfig";
|
|
3
|
-
|
|
3
|
+
import { RepositoryConfigEnabledActionType, RepositoryConfigType } from "../../Config/RepositoryConfig";
|
|
4
|
+
export declare function findRepositoryOrFail(config: ConfigType, repositoryName: string): RepositoryConfigType;
|
|
5
|
+
export declare function filterRepository(repository: RepositoryConfigType, action?: RepositoryConfigEnabledActionType): boolean;
|
|
4
6
|
export declare function filterPackages(config: ConfigType, options: {
|
|
5
7
|
packageNames?: string[];
|
|
6
8
|
repositoryNames?: string[];
|
|
7
9
|
repositoryTypes?: string[];
|
|
10
|
+
sourceAction?: RepositoryConfigEnabledActionType;
|
|
8
11
|
}): PackageConfigType[];
|
|
9
12
|
declare type ResolvePackagePathParamsType = ResolvePackageParamsType & {
|
|
10
13
|
packageName: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.params = exports.dbNameParams = exports.pkgRestorePathParams = exports.pkgExcludeParams = exports.pkgIncludeParams = exports.pkgPathParams = exports.resolvePackages = exports.resolvePackage = exports.resolveDatabaseName = exports.resolvePackagePath = exports.filterPackages = exports.findRepositoryOrFail = void 0;
|
|
3
|
+
exports.params = exports.dbNameParams = exports.pkgRestorePathParams = exports.pkgExcludeParams = exports.pkgIncludeParams = exports.pkgPathParams = exports.resolvePackages = exports.resolvePackage = exports.resolveDatabaseName = exports.resolvePackagePath = exports.filterPackages = exports.filterRepository = exports.findRepositoryOrFail = void 0;
|
|
4
4
|
const AppError_1 = require("../../Error/AppError");
|
|
5
5
|
const fs_util_1 = require("../fs-util");
|
|
6
6
|
const string_util_1 = require("../string-util");
|
|
@@ -12,6 +12,14 @@ function findRepositoryOrFail(config, repositoryName) {
|
|
|
12
12
|
return repo;
|
|
13
13
|
}
|
|
14
14
|
exports.findRepositoryOrFail = findRepositoryOrFail;
|
|
15
|
+
function filterRepository(repository, action) {
|
|
16
|
+
const enabled = repository.enabled ?? true;
|
|
17
|
+
if (typeof enabled === "boolean")
|
|
18
|
+
return enabled;
|
|
19
|
+
const defaults = enabled["defaults"] ?? true;
|
|
20
|
+
return action ? enabled[action] ?? defaults : defaults;
|
|
21
|
+
}
|
|
22
|
+
exports.filterRepository = filterRepository;
|
|
15
23
|
function filterPackages(config, options) {
|
|
16
24
|
const packagePatterns = (0, string_util_1.makePathPatterns)(options.packageNames);
|
|
17
25
|
return config.packages
|
|
@@ -19,6 +27,8 @@ function filterPackages(config, options) {
|
|
|
19
27
|
pkg = Object.assign({}, pkg);
|
|
20
28
|
pkg.repositoryNames = (pkg.repositoryNames ?? []).filter((name) => {
|
|
21
29
|
const repo = findRepositoryOrFail(config, name);
|
|
30
|
+
if (!filterRepository(repo, options?.sourceAction))
|
|
31
|
+
return false;
|
|
22
32
|
return ((!options.repositoryNames ||
|
|
23
33
|
options.repositoryNames.includes(name)) &&
|
|
24
34
|
(!options.repositoryTypes ||
|