Skip to content

Commit 11f4e90

Browse files
committed
Fix #79 add dropbox-refresh-token
- add `dropboxAppKey`, `dropboxAppSecret` and `dropboxRefreshToken` (long-lived offline refresh token) : required to activate optional dropbox feature. - MT_DROPBOX_TOKEN is now deprecated - refacto about Promise reject
1 parent ec75b38 commit 11f4e90

11 files changed

+722
-1432
lines changed

README.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,16 @@ mongoTools.mongorestore({
253253
### Dropbox options
254254
You could create a dropbox app to get a token : cf. https://www.dropbox.com/developers/apps/ "Generated access token"
255255

256-
| option | env | required | default value | description |
257-
|--------------------|------------------------|-----------|-----------------|---------------------------------------------------|
258-
| `dropboxToken` | `MT_DROPBOX_TOKEN` | false | (none) | activate dropbox feature if present |
259-
| `dropboxLocalPath` | `MT_DROPBOX_LOCAL_PATH` | false | "dropbox" | local directory to receive dropbox dump |
256+
| option | env | required | default value | description |
257+
|-----------------------|----------------------------|-----------|-----------------|----------------------------------------------------------------------|
258+
| `dropboxLocalPath` | `MT_DROPBOX_LOCAL_PATH` | false | "dropbox" | local directory to receive dropbox dump |
259+
| `dropboxAppKey` | `MT_DROPBOX_APP_KEY` | false | (none) | (refresh token based) dropbox feature application key. (*1) |
260+
| `dropboxAppSecret` | `MT_DROPBOX_APP_SECRET` | false | (none) | (refresh token based) dropbox feature application secret. (*1) |
261+
| `dropboxRefreshToken` | `MT_DROPBOX_REFRESH_TOKEN` | false | (none) | (refresh token based) dropbox feature application refreshToken. (*1) |
262+
| `dropboxToken` (*2) | `MT_DROPBOX_TOKEN` | false | (none) | DEPRECATED - activate dropbox feature if present. (*2) |
263+
264+
(*1) `dropboxAppKey`, `dropboxAppSecret` and `dropboxRefreshToken` (long-lived offline refresh token) are required to activate optional dropbox feature. You have some help about how to get them in [dropbox-refresh-token](https://github.com/boly38/dropbox-refresh-token) dedicated helper repository.
265+
(*2) `dropboxToken` option is DEPRECATED : This was legacy old-long-lived access-token - this kind of token are no more available from dropbox developers portal ([src](https://dropbox.tech/developers/migrating-app-permissions-and-access-tokens)). Please switch to `dropboxAppKey`, `dropboxAppSecret`, and `dropboxRefreshToken` instead. For now this is still supported.
260266

261267
When a token is set,
262268
- the `list` feature will list the `/` + `path` dropbox directory

env/initEnv.template.sh

+12-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@ export MT_MONGO_USER=root
55
export MT_MONGO_PWD=mypass
66
export MT_MONGO_AUTH_DB=admin
77

8-
# optional dropbox feature
9-
# https://www.dropbox.com/developers/apps/
10-
export MT_DROPBOX_TOKEN=
11-
128
export MT_PATH=backup
139
# MT_SECRET: used to encrypt backup - size 32 - change it
14-
# export MT_SECRET=12345678901234567890123456789012
10+
# export MT_SECRET=12345678901234567890123456789012
11+
12+
# TIP: get key,secret from dropbox developers app dev portal : https://www.dropbox.com/developers/apps/
13+
export MT_DROPBOX_APP_KEY=
14+
export MT_DROPBOX_APP_SECRET=
15+
# TIP: long-lived offline refresh-token. cf. https://github.com/boly38/dropbox-refresh-token
16+
export MT_DROPBOX_REFRESH_TOKEN=
17+
18+
## DEPRECATED SECTION
19+
# MT_DROPBOX_TOKEN - old-long-lived access-token - no more available from dropbox developers portal
20+
# export MT_DROPBOX_TOKEN=
21+
## DEPRECATED SECTION end

eslint.config.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import js from "@eslint/js";
33
import globals from "globals";
44
import mochaPlugin from 'eslint-plugin-mocha'; // https://www.npmjs.com/package/eslint-plugin-mocha
5+
import stylisticJs from '@stylistic/eslint-plugin-js'
56
export default [
67
js.configs.recommended, // Recommended config applied to all files
78
mochaPlugin.configs.flat.recommended, // or `mochaPlugin.configs.flat.all` to enable all
@@ -19,8 +20,12 @@ export default [
1920
"allowImportExportEverywhere": true
2021
},
2122
},
23+
plugins: {
24+
'@stylistic/js': stylisticJs
25+
},
2226
"rules": {
23-
"mocha/no-mocha-arrows": "off"/* pff */
27+
"mocha/no-mocha-arrows": "off", /* pff */
28+
'@stylistic/js/no-extra-semi': "error", /* to match houndci : https://eslint.org/docs/latest/rules/no-extra-semi */
2429
}
2530
}
2631
];

lib/MTCommand.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ class MTCommand {
6565
if (action === 'list') {
6666
this.mt.list(new MTOptions()).then((listResult) => {
6767
console.log(JSON.stringify(listResult, null, 4));
68-
}).catch(cmd.logError.bind(cmd));
68+
}).catch(error => cmd.logError(error.message));
6969
return;
7070
}
7171
if (action === 'dumpz') {
7272
this.mt.mongodump(new MTOptions({
7373
"encrypt":true
7474
}))
75-
.then(cmd.logSuccess.bind(cmd)).catch(cmd.logError.bind(cmd));
75+
.then(cmd.logSuccess.bind(cmd)).catch(error => cmd.logError(error.message));
7676
return;
7777
}
7878
if (action === 'dump') {
79-
this.mt.mongodump(new MTOptions({})).then(cmd.logSuccess.bind(cmd)).catch(cmd.logError.bind(cmd));
79+
this.mt.mongodump(new MTOptions({})).then(cmd.logSuccess.bind(cmd)).catch(error => cmd.logError(error.message));
8080
return;
8181
}
8282
// restore action do need an extra argument: the file to restore
@@ -85,18 +85,17 @@ class MTCommand {
8585
this.printUsage();
8686
return;
8787
}
88-
var restoreFile = process.argv.slice(2)[1];
88+
const restoreFile = process.argv.slice(2)[1];
8989
this.mt.mongorestore(new MTOptions({
9090
dumpFile: restoreFile,
9191
dropBeforeRestore: false,
9292
deleteDumpAfterRestore: false
9393
}))
94-
.then(cmd.logSuccess.bind(cmd)).catch(cmd.logError.bind(cmd));
94+
.then(cmd.logSuccess.bind(cmd)).catch(error => cmd.logError(error.message));
9595
return;
9696
}
9797
if (action === 'rotation') {
98-
this.mt.rotation(new MTOptions()).then(cmd.logSuccess.bind(cmd)).catch(cmd.logError.bind(cmd));
99-
return;
98+
this.mt.rotation(new MTOptions()).then(cmd.logSuccess.bind(cmd)).catch(error => cmd.logError(error.message));
10099
}
101100
}
102101

0 commit comments

Comments
 (0)