Commit graph

2849 commits

Author SHA1 Message Date
muxator
2955740a6e Settings.js: support syntax for default values
+---------------------------+---------------+------------------+
| Configuration string in   | Value of      | Resulting confi- |
| settings.json             | ENV_VAR       | guration value   |
|---------------------------|---------------|------------------|
| "${ENV_VAR}"              | "some_string" | "some_string"    |
| "${ENV_VAR}"              | "9001"        | 9001             |
| "${ENV_VAR}"              | undefined     | null             |
| "${ENV_VAR:some_default}" | "some_string" | "some_string"    |
| "${ENV_VAR:some_default}" | undefined     | "some_default"   |
+---------------------------+---------------+------------------+

Mention this briefly in the main README.md, also.

Closes #3578.
2019-03-21 23:32:08 +01:00
muxator
c3bca6506e Settings.js: extracted into coerceValue() the logic for string -> number|bool conversion
This will be user in a later commit for implementing support for default values
2019-03-21 23:32:08 +01:00
muxator
59b1eed4a8 Settings.js: rephrased a log message 2019-03-21 23:32:08 +01:00
muxator
21ac37170e doc: rephrase settings.json.template and Settings.js
Better document current behaviour.
In this revision, ENV_VAR are supported, default values are not.
2019-03-21 23:32:08 +01:00
translatewiki.net
346d823279 Localisation updates from https://translatewiki.net. 2019-03-21 10:57:28 +01:00
translatewiki.net
e4db905f3c Localisation updates from https://translatewiki.net. 2019-03-18 08:46:50 +01:00
David Mehren
43c4fa9c2e Await padManager.getPad in getPadLines 2019-03-16 09:07:06 +01:00
muxator
6d400050a3 Settings.js: support configuration via environment variables.
All the configuration values can be read from environment variables using the
syntax "${ENV_VAR_NAME}".
This is useful, for example, when running in a Docker container.

EXAMPLE:
   "port":     "${PORT}"
   "minify":   "${MINIFY}"
   "skinName": "${SKIN_NAME}"

Would read the configuration values for those items from the environment
variables PORT, MINIFY and SKIN_NAME.

REMARKS:
Please note that a variable substitution always needs to be quoted.
   "port":   9001,          <-- Literal values. When not using substitution,
   "minify": false              only strings must be quoted: booleans and
   "skin":   "colibris"         numbers must not.

   "port":   ${PORT}        <-- ERROR: this is not valid json
   "minify": ${MINIFY}
   "skin":   ${SKIN_NAME}

   "port":   "${PORT}"      <-- CORRECT: if you want to use a variable
   "minify": "${MINIFY}"        substitution, put quotes around its name,
   "skin":   "${SKIN_NAME}"     even if the required value is a number or a
                                boolean.
                                Etherpad will take care of rewriting it to
                                the proper type if necessary.

Resolves #3543
2019-03-11 08:11:30 +01:00
muxator
f96e139b17 Settings.js: factored out parseSettings()
No functional changes.
2019-03-11 08:11:30 +01:00
muxator
6353768256 Settings.js: factored out storeSettings()
Grouped copied & pasted code into a single function.
2019-03-11 08:11:30 +01:00
muxator
ab57edef33 Settings.js: exit gracefully if an invalid credentials.json is passed.
Before this commit, when passed a malformed credentials.json the application
crashed with a stack dump. Now we catch the error and fail in a controlled way
(like already done for settings.json).

Example of exception we no longer throw:
  MALFORMEDJSON
  ^

  SyntaxError: Unexpected token M in JSON at position 0
      at JSON.parse (<anonymous>)
      at Object.reloadSettings (<BASEDIR>/src/node/utils/Settings.js:390:24)
      at Object.<anonymous> (<BASEDIR>/src/node/utils/Settings.js:543:9)
      at Module._compile (module.js:635:30)
      at Object.Module._extensions..js (module.js:646:10)
      at Module.load (module.js:554:32)
      at tryModuleLoad (module.js:497:12)
      at Function.Module._load (module.js:489:3)
      at Module.require (module.js:579:17)
      at require (internal/module.js:11:18)
2019-03-11 08:11:30 +01:00
muxator
8fa52659f5 Settings.js: trivial rewording of abiword and soffice (libreoffice) error messages 2019-03-11 08:11:30 +01:00
muxator
d526c5ccca Settings.js: trivial reformatting 2019-03-11 08:11:30 +01:00
translatewiki.net
e9be94e3cf Localisation updates from https://translatewiki.net. 2019-03-07 16:09:56 +01:00
Ray Bellis
ac7663c337 db/DB.js: prevent DB layer from returning undefined
ueberDB2 can return either undefined or null for a missing key, depending on
which DB driver is used. This patch changes the promise version of the API so
that it will always return null.
2019-03-05 10:46:57 +00:00
Ray Bellis
769933786c allow some operations to proceed in parallel
some code chunks previously used `async.parallel` but if you
use `await` that forces them to be run serially.  Instead,
you can initiate the operation (getting a Promise) and then
_later_ `await` the result of that Promise.
2019-02-01 09:57:50 +00:00
Ray Bellis
e7c2fad7b0 convert some async loops into parallel loops
If you use `await` inside a loop it makes the loop inherently serial.

If you omit the `await` however, the tasks will all start but the loop
will finish while the tasks are still being scheduled.

So, to make a set of tasks run in parallel but then have the
code block after the loop once all the tasks have been completed
you have to get an array of Promises (one for each iteration) and
then use `Promise.all()` to wait for those promises to be resolved.
Using `Array#map` is a convenient way to go from an array of inputs
to the require array of Promises.
2019-02-01 00:07:06 +00:00
Ray Bellis
07ae44ddf4 PadMessageHandler.js: cope better with session disconnects 2019-01-31 15:46:25 +00:00
Ray Bellis
b1c5024bcf remove thenify use - no longer required 2019-01-31 14:48:22 +00:00
Ray Bellis
ccb49dcdc1 padDiff.js: convert to Promises/async 2019-01-31 14:38:56 +00:00
Ray Bellis
4622309dc2 TidyHtml.js: convert to promises
test case uses "nodeify" to convert the calls to TidyHtml back
into nodeback because it integrates better with the test framework
2019-01-31 13:42:41 +00:00
Ray Bellis
6d1b6b2796 db/Pad.js: convert to promises/async
Also updated some small chunks of dependent code that couldn't be converted
until this one had been done.
2019-01-31 11:14:38 +00:00
Ray Bellis
ebb8a64e3c errorhandling.js: use promise db.doShutdown interface 2019-01-31 11:14:27 +00:00
Ray Bellis
b664eb488c ImportHandler.js: ensure import connection closing happens at the right point 2019-02-08 14:46:05 +00:00
Ray Bellis
62345ac8f7 import/export: conversion to Promises/async
NB1: needs additional review and testing - no abiword available on my test bed
NB2: in ImportHandler.js, directly delete the file, and handle the eventual
     error later: checking before for existence is prone to race conditions,
     and does not handle any errors anyway.
2019-01-31 08:55:36 +00:00
Ray Bellis
5192a0c498 db/ReadOnlyManager.js: completed conversion
Requires temporary hack within `Pad.remove()` to allow for the lack of
callback on the rewritten version.
2019-01-30 16:19:51 +00:00
Ray Bellis
bb80325d2c PadMessageHandler.js: completed conversion 2019-01-30 15:27:42 +00:00
Ray Bellis
9246a1de26 PadMessageHandler.js: further conversion 2019-01-30 13:55:49 +00:00
Ray Bellis
d543d5ae6a PadMessageHandler.js: convert handleUserChanges() to Promises
- the call site still expects a nodeback function, so also introduced the
  `nodeify` module to allow that function to work as expected.
2019-01-30 10:43:01 +00:00
Ray Bellis
58d0e6cea4 APIHandler.js: further cleanup
- removed possible issue with failing to sanitize `padName` if `padId` was also
  supplied
- removed unnecessary `try` block
- simplified API and function name matching tests
2019-01-30 10:41:10 +00:00
Ray Bellis
982d4f380a db/Pad.js: start use of promise DB methods 2019-01-30 10:25:46 +00:00
Ray Bellis
7f19033cc0 SocketIORouter: code formatting cleanups 2019-01-30 10:25:01 +00:00
Ray Bellis
bbe4a5f756 db/PadManager.js: more conversion to Promises/async 2019-01-28 16:20:30 +00:00
Ray Bellis
8108964472 db/AuthorManager.js: further conversion
also fixes a missing await calling `.createAuthor` in db/Pad.js
2019-01-28 15:36:36 +00:00
Ray Bellis
005c0afa97 db/SessionManager.js: completely converted to Promises/async 2019-01-28 14:44:36 +00:00
Ray Bellis
e58da69cfb db/SecurityManager.js: converted checkAccess() to pure Promises
Also converted the handler functions that depend on checkAccess() into async
functions too.

NB: this commit needs specific attention to it because it touches a lot of
security related code!
2019-01-28 13:13:24 +00:00
Ray Bellis
e7dc0766fd db/API.js: complete conversion to Promises
This patch also contains significant refactoring relating to error checking of
arguments supplied to the functions (e.g. rev) facilitated by use of `throw`
instead of nodeback errors.
2019-01-25 18:08:34 +00:00
Ray Bellis
1b6430ae9f db/PadMessageHandler.js: partial conversion to Promises
Converted those functions that API.js still depends on, and others that at this
point are never called via the nodeback mechanism.
2019-01-25 18:07:01 +00:00
Ray Bellis
8f53e4407e db/AuthorManager.js: partial conversion to Promises 2019-01-25 15:47:25 +00:00
Ray Bellis
eedae98e2f db/PadManager.js: convert sanitizePadId() to Promises
The function is now iterative rather than recursive.
2019-01-25 15:15:16 +00:00
Ray Bellis
bf9e3f92b5 db/PadManager.js: renamed doesPadExists() -> doesPadExist()
Removed the 's' for consistency with the other `doesFooExist()` manager calls.
Retained an alias for plugins that might be using it.
2019-01-25 15:05:12 +00:00
Ray Bellis
a875ca6c30 db/SessionManager.js: mostly converted to Promises 2019-01-25 14:53:24 +00:00
Ray Bellis
16c4c33f49 db/AuthorManager.js: renamed doesAuthorExists() -> doesAuthorExist()
Removed the 's' for consistency with the other `doesFooExist()` manager calls.
Retained an alias for plugins that might be using it.
2019-01-25 13:37:24 +00:00
Ray Bellis
70a045ad3c db/GroupManager.js: mostly converted to Promises / async 2019-01-25 12:56:57 +00:00
Ray Bellis
29e9f86cad db/DB.js: add Promise-only API methods
Promisified methods:
  - get()
  - set()
  - findKeys()
  - getSub()
  - setSub()
  - remove()
  - doShutdown()
2019-01-23 18:08:47 +00:00
Ray Bellis
583ea92aaf db/SessionStore.js: do not migrate to Promises. Make optional all(), clear() and length()
1. This module was not migrated to Promises, because it is only used via
   express-session, which can't actually use promises anyway.

2. all(), clear() and length() depend on the presence of the `db.forEach()`
   function, which in ueberdb2 doesn't even exist.

   Fortunately those three methods are optional, so I made their existence
   conditional on the presence of `db.forEach`.

3. in SessionStore.clear(), replaced a call to db.db.remove() with db.remove()
2019-01-23 16:58:43 +00:00
muxator
630af9af7d db/SessionStore.js: call nextTick() only if there is something to do
Changed two occurrences of:

  process.nextTick(function() {
     if (fn) fn();
  });

with

  if (fn) {
    process.nextTick(fn);
  }

i.e. such that no function even gets added to the `nextTick` queue unless
there's actually a function to be called.

Extracted from Ray's work.
2019-02-09 00:14:53 +01:00
Ray Bellis
96d875b4d1 padurlsanitize.js: rewritten to consume promises 2019-01-23 16:36:28 +00:00
muxator
b699621e5a padurlsanitize.js: invert a condition prior to refactoring
Extracted from Ray's work.
2019-02-09 00:05:21 +01:00
Ray Bellis
d5d28717c4 access controls: promisification
`getPadAccess()` (src/node/padaccess.js) is now "promise only", resolving to
`true` or `false` as appropriate, and throwing an exception if there's an
error.

The two call sites (padreadonly.js and importexport.js) updated to match.
2019-01-23 16:29:36 +00:00