cht-conf 3.22.0 → 3.23.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/CHANGELOG.md +7 -0
- package/README.md +6 -0
- package/package.json +2 -1
- package/src/lib/api.js +27 -1
- package/src/lib/db.js +4 -2
- package/src/lib/environment.js +5 -2
- package/src/lib/main.js +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [3.23.0](https://github.com/medic/cht-conf/compare/v3.22.0...v3.23.0) (2024-06-20)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* session token authentication ([efbc9cf](https://github.com/medic/cht-conf/commit/efbc9cfc5dc972f355fa07b3a394c63d84b352de))
|
|
7
|
+
|
|
1
8
|
# [3.22.0](https://github.com/medic/cht-conf/compare/v3.21.5...v3.22.0) (2024-04-29)
|
|
2
9
|
|
|
3
10
|
|
package/README.md
CHANGED
|
@@ -106,6 +106,12 @@ If a different username is required, add the `--user` switch:
|
|
|
106
106
|
|
|
107
107
|
**NB** - When specifying the URL with `--url`, be sure not to specify the CouchDB database name in the URL. The CHT API will find the correct database.
|
|
108
108
|
|
|
109
|
+
### Using a session token for authentication
|
|
110
|
+
|
|
111
|
+
CHT Conf supports authentication using a session token by adding `--session-token` parameter:
|
|
112
|
+
|
|
113
|
+
cht --url=https://example.com:12345 --session-token=*my_token*
|
|
114
|
+
|
|
109
115
|
### Into an archive to be uploaded later
|
|
110
116
|
|
|
111
117
|
cht --archive
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cht-conf",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.23.0",
|
|
4
4
|
"description": "Configure CHT deployments",
|
|
5
5
|
"main": "./src/lib/main.js",
|
|
6
6
|
"engines": {
|
|
@@ -58,6 +58,7 @@
|
|
|
58
58
|
"pouchdb-adapter-http": "^7.2.2",
|
|
59
59
|
"pouchdb-core": "^7.2.2",
|
|
60
60
|
"pouchdb-mapreduce": "^7.2.2",
|
|
61
|
+
"pouchdb-session-authentication": "^1.3.0",
|
|
61
62
|
"properties": "^1.2.1",
|
|
62
63
|
"queue-promise": "^2.2.1",
|
|
63
64
|
"readline-sync": "^1.4.10",
|
package/src/lib/api.js
CHANGED
|
@@ -7,8 +7,34 @@ const log = require('./log');
|
|
|
7
7
|
const url = require('url');
|
|
8
8
|
|
|
9
9
|
const cache = new Map();
|
|
10
|
+
const sessionCookieName = 'AuthSession';
|
|
11
|
+
|
|
12
|
+
// Helper function to create request headers with session token (if available)
|
|
13
|
+
const withSessionCookie = (...args) => {
|
|
14
|
+
const options = typeof args[0] === 'object' ? Object.assign({}, args[0]) : { url: args[0] };
|
|
15
|
+
|
|
16
|
+
if (args.length > 1) {
|
|
17
|
+
// Merge remaining arguments
|
|
18
|
+
Object.assign(options, ...args.slice(1));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const sessionToken = environment.sessionToken;
|
|
22
|
+
if (sessionToken || options.headers) {
|
|
23
|
+
options.headers = Object.assign(
|
|
24
|
+
{},
|
|
25
|
+
options.headers || {},
|
|
26
|
+
sessionToken ? { Cookie: `${sessionCookieName}=${sessionToken}` } : {}
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return options;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const _request = (method) => (...args) => {
|
|
34
|
+
const requestOptions = withSessionCookie(...args);
|
|
35
|
+
return retry(() => rpn[method](requestOptions), { retries: 5, randomize: false, factor: 1.5 });
|
|
36
|
+
};
|
|
10
37
|
|
|
11
|
-
const _request = (method) => (...args) => retry(() => rpn[method](...args), { retries: 5, randomize: false, factor: 1.5 });
|
|
12
38
|
const request = {
|
|
13
39
|
get: _request('get'),
|
|
14
40
|
post: _request('post'),
|
package/src/lib/db.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const PouchDB = require('pouchdb-core');
|
|
2
2
|
PouchDB.plugin(require('pouchdb-adapter-http'));
|
|
3
3
|
PouchDB.plugin(require('pouchdb-mapreduce'));
|
|
4
|
+
PouchDB.plugin(require('pouchdb-session-authentication'));
|
|
4
5
|
|
|
5
6
|
const ArchivingDB = require('./archiving-db');
|
|
6
7
|
const environment = require('./environment');
|
|
@@ -10,6 +11,7 @@ module.exports = () => {
|
|
|
10
11
|
return new ArchivingDB(environment.archiveDestination);
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
return new PouchDB(environment.apiUrl, {
|
|
14
|
+
return new PouchDB(environment.apiUrl, {
|
|
15
|
+
session: environment.sessionToken,
|
|
16
|
+
});
|
|
14
17
|
};
|
|
15
|
-
|
package/src/lib/environment.js
CHANGED
|
@@ -13,7 +13,8 @@ const initialize = (
|
|
|
13
13
|
apiUrl,
|
|
14
14
|
force,
|
|
15
15
|
skipTranslationCheck,
|
|
16
|
-
skipValidate
|
|
16
|
+
skipValidate,
|
|
17
|
+
sessionToken
|
|
17
18
|
) => {
|
|
18
19
|
if (state.initialized) {
|
|
19
20
|
throw Error('environment is already initialized');
|
|
@@ -28,7 +29,8 @@ const initialize = (
|
|
|
28
29
|
pathToProject,
|
|
29
30
|
force,
|
|
30
31
|
skipTranslationCheck,
|
|
31
|
-
skipValidate
|
|
32
|
+
skipValidate,
|
|
33
|
+
sessionToken
|
|
32
34
|
});
|
|
33
35
|
};
|
|
34
36
|
|
|
@@ -54,6 +56,7 @@ module.exports = {
|
|
|
54
56
|
get force() { return getState('force'); },
|
|
55
57
|
get skipTranslationCheck() { return getState('skipTranslationCheck'); },
|
|
56
58
|
get skipValidate() { return getState('skipValidate'); },
|
|
59
|
+
get sessionToken() { return getState('sessionToken'); },
|
|
57
60
|
|
|
58
61
|
/**
|
|
59
62
|
* Return `true` if the environment **seems** to be production.
|
package/src/lib/main.js
CHANGED