Skip to content

Commit 0b69f23

Browse files
authored
Merge pull request #11654 from IQSS/11639-db-opts-idempotency
Database Settings: idempotent mass operations, necessary cleanup and script using it for real use case
2 parents fc9363f + 757f2e5 commit 0b69f23

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2701
-204
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## Database Settings Cleanup
2+
3+
With this release, we remove some legacy specialties around Database Settings and provide better Admin API endpoints for them.
4+
5+
Most important changes:
6+
7+
1. Setting `BuiltinUsers.KEY` was renamed to `:BuiltinUsersKey`, aligned with our general naming pattern for options.
8+
2. Setting `WorkflowsAdmin#IP_WHITELIST_KEY` was renamed to `:WorkflowsAdminIpWhitelist`, aligned with our general naming pattern for options.
9+
3. Setting `:TabularIngestSizeLimit` no longer uses suffixes for formats and becomes a JSON-based setting instead.
10+
4. If set, all three settings will be migrated to their new form automatically for you (Flyway migration).
11+
5. You can no longer (accidentally) create or use arbitrary setting names or languages.
12+
All Admin API endpoints for settings now validate setting names and languages for existence and compliance.
13+
14+
As an administrator of a Dataverse instance, you can now make use of enhanced Bulk Operations on the Settings Admin API:
15+
16+
1. Retrieving all settings as JSON via `GET /api/admin/settings` supports localized options now, too.
17+
2. You can replace all existing settings in an idempotent way sending JSON to `PUT /api/admin/settings`.
18+
This will create, update and remove settings as necessary in one atomic operation.
19+
The new endpoint is especially useful to admins using GitOps or other automations.
20+
It allows control over all Database Settings from a single source without risking an undefined state.
21+
22+
Note: Despite the validation of setting names and languages, the content of any database setting is still not being validated when using the Settings Admin API!
23+
24+
### Updated Database Settings
25+
26+
The following database settings are were added to the official list within the code (to remain valid with the settings cleanup mentioned above):
27+
28+
- `:BagGeneratorThreads`
29+
- `:BagItHandlerEnabled`
30+
- `:BagItLocalPath`
31+
- `:BagValidatorJobPoolSize`
32+
- `:BagValidatorJobWaitInterval`
33+
- `:BagValidatorMaxErrors`
34+
- `:BuiltinUsersKey` - formerly `BuiltinUsers.KEY`
35+
- `:CreateDataFilesMaxErrorsToDisplay`
36+
- `:DRSArchiverConfig` - a Harvard-specific setting
37+
- `:DuraCloudContext`
38+
- `:DuraCloudHost`
39+
- `:DuraCloudPort`
40+
- `:FileCategories`
41+
- `:GoogleCloudBucket`
42+
- `:GoogleCloudProject`
43+
- `:LDNAnnounceRequiredFields`
44+
- `:LDNTarget`
45+
- `:WorkflowsAdminIpWhitelist` - formerly `WorkflowsAdmin#IP_WHITELIST_KEY`

doc/sphinx-guides/source/api/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ This API changelog is experimental and we would love feedback on its usefulness.
99

1010
v6.9
1111
----
12+
1213
- The POST /api/admin/makeDataCount/{id}/updateCitationsForDataset processing is now asynchronous and the response no longer includes the number of citations. The response can be OK if the request is queued or 503 if the queue is full (default queue size is 1000).
14+
- The way to set per-format size limits for tabular ingest has changed. JSON input is now used. See :ref:`:TabularIngestSizeLimit`.
15+
- In the past, the settings API would accept any key and value. This is no longer the case because validation has been added. See :ref:`settings_put_single`, for example.
1316

1417
v6.8
1518
----

doc/sphinx-guides/source/api/native-api.rst

Lines changed: 175 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5843,13 +5843,13 @@ Builtin users are known as "Username/Email and Password" users in the :doc:`/use
58435843
Create a Builtin User
58445844
~~~~~~~~~~~~~~~~~~~~~
58455845
5846-
For security reasons, builtin users cannot be created via API unless the team who runs the Dataverse installation has populated a database setting called ``BuiltinUsers.KEY``, which is described under :ref:`securing-your-installation` and :ref:`database-settings` sections of Configuration in the Installation Guide. You will need to know the value of ``BuiltinUsers.KEY`` before you can proceed.
5846+
For security reasons, builtin users cannot be created via API unless the team who runs the Dataverse installation has populated a database setting called ``:BuiltinUsersKey``, which is described under :ref:`securing-your-installation` and :ref:`database-settings` sections of Configuration in the Installation Guide. You will need to know the value of ``:BuiltinUsersKey`` before you can proceed.
58475847
58485848
To create a builtin user via API, you must first construct a JSON document. You can download :download:`user-add.json <../_static/api/user-add.json>` or copy the text below as a starting point and edit as necessary.
58495849
58505850
.. literalinclude:: ../_static/api/user-add.json
58515851
5852-
Place this ``user-add.json`` file in your current directory and run the following curl command, substituting variables as necessary. Note that both the password of the new user and the value of ``BuiltinUsers.KEY`` are passed as query parameters::
5852+
Place this ``user-add.json`` file in your current directory and run the following curl command, substituting variables as necessary. Note that both the password of the new user and the value of ``:BuiltinUsersKey`` are passed as query parameters::
58535853
58545854
curl -d @user-add.json -H "Content-type:application/json" "$SERVER_URL/api/builtin-users?password=$NEWUSER_PASSWORD&key=$BUILTIN_USERS_KEY"
58555855
@@ -7133,35 +7133,193 @@ If the PID is not managed by Dataverse, this call will report if the PID is reco
71337133
Admin
71347134
-----
71357135
7136-
This is the administrative part of the API. For security reasons, it is absolutely essential that you block it before allowing public access to a Dataverse installation. Blocking can be done using settings. See the ``post-install-api-block.sh`` script in the ``scripts/api`` folder for details. See :ref:`blocking-api-endpoints` in Securing Your Installation section of the Configuration page of the Installation Guide.
7136+
This is the administrative part of the API.
7137+
For security reasons, it is absolutely essential that you block it before allowing public access to a Dataverse installation.
7138+
See :ref:`blocking-api-endpoints` in the Installation Guide for details.
7139+
7140+
.. note:: See :ref:`curl-examples-and-environment-variables` if you are unfamiliar with the use of export below.
7141+
7142+
.. _admin-api-db-settings:
7143+
7144+
Manage Database Settings
7145+
~~~~~~~~~~~~~~~~~~~~~~~~
7146+
7147+
These are the API endpoints for managing the :ref:`database-settings` listed in the Installation Guide.
7148+
7149+
.. _settings_get_all:
71377150
71387151
List All Database Settings
7139-
~~~~~~~~~~~~~~~~~~~~~~~~~~
7152+
^^^^^^^^^^^^^^^^^^^^^^^^^^
7153+
7154+
.. code-block:: bash
71407155
7141-
List all settings::
7156+
export SERVER_URL="http://localhost:8080"
7157+
7158+
curl "$SERVER_URL/api/admin/settings"
71427159
7143-
GET http://$SERVER/api/admin/settings
7160+
The fully expanded example above (without environment variables) looks like this:
71447161
7145-
Configure Database Setting
7146-
~~~~~~~~~~~~~~~~~~~~~~~~~~
7162+
.. code-block:: bash
71477163
7148-
Sets setting ``name`` to the body of the request::
7164+
curl http://localhost:8080/api/admin/settings
71497165
7150-
PUT http://$SERVER/api/admin/settings/$name
7166+
.. _settings_get_single:
71517167
71527168
Get Single Database Setting
7153-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
7169+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
71547170
7155-
Get the setting under ``name``::
7171+
.. code-block:: bash
71567172
7157-
GET http://$SERVER/api/admin/settings/$name
7173+
export SERVER_URL="http://localhost:8080"
7174+
export NAME=":UploadMethods"
7175+
7176+
curl "$SERVER_URL/api/admin/settings/$NAME"
71587177
7159-
Delete Database Setting
7160-
~~~~~~~~~~~~~~~~~~~~~~~
7178+
The fully expanded example above (without environment variables) looks like this:
7179+
7180+
.. code-block:: bash
7181+
7182+
curl http://localhost:8080/api/admin/settings/:UploadMethods
7183+
7184+
.. _settings_get_single_lang:
7185+
7186+
Get Single Database Setting With Language/Locale
7187+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7188+
7189+
A small number of settings, most notably :ref:`:ApplicationTermsOfUse`, can be saved in multiple languages.
7190+
7191+
Use two-character ISO 639-1 language codes.
7192+
7193+
.. code-block:: bash
7194+
7195+
export SERVER_URL="http://localhost:8080"
7196+
export NAME=":ApplicationTermsOfUse"
7197+
export LANG="en"
7198+
7199+
curl "$SERVER_URL/api/admin/settings/$NAME/lang/$LANG"
7200+
7201+
The fully expanded example above (without environment variables) looks like this:
7202+
7203+
.. code-block:: bash
7204+
7205+
curl http://localhost:8080/api/admin/settings/:ApplicationTermsOfUse/lang/en
7206+
7207+
.. _settings_put_single:
7208+
7209+
Configure Single Database Setting
7210+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7211+
7212+
.. code-block:: bash
7213+
7214+
export SERVER_URL="http://localhost:8080"
7215+
export NAME=":InstallationName"
7216+
export VALUE="LibreScholar"
7217+
7218+
curl -X PUT "$SERVER_URL/api/admin/settings/$NAME" -d "$VALUE"
7219+
7220+
The fully expanded example above (without environment variables) looks like this:
7221+
7222+
.. code-block:: bash
7223+
7224+
curl -X PUT http://localhost:8080/api/admin/settings/:InstallationName -d LibreScholar
7225+
7226+
Note: ``NAME`` values are validated for existence and compliance.
7227+
7228+
.. _settings_put_single_lang:
7229+
7230+
Configure Single Database Setting With Language/Locale
7231+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7232+
7233+
A small number of settings, most notably :ref:`:ApplicationTermsOfUse`, can be saved in multiple languages.
7234+
7235+
Use two-character ISO 639-1 language codes.
71617236
7162-
Delete the setting under ``name``::
7237+
.. code-block:: bash
7238+
7239+
export SERVER_URL="http://localhost:8080"
7240+
export NAME=":ApplicationTermsOfUse"
7241+
export LANG="fr"
7242+
7243+
curl -X PUT "$SERVER_URL/api/admin/settings/$NAME/lang/$LANG" --upload-file /tmp/apptou_fr.html
7244+
7245+
The fully expanded example above (without environment variables) looks like this:
7246+
7247+
.. code-block:: bash
7248+
7249+
curl -X PUT http://localhost:8080/api/admin/settings/:ApplicationTermsOfUse/lang/fr --upload-file /tmp/apptou_fr.html
7250+
7251+
Note: ``NAME`` and ``LANG`` values are validated for existence and compliance.
7252+
7253+
.. _settings_put_bulk:
7254+
7255+
Configure All Database Settings
7256+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7257+
7258+
Using a JSON file, replace all settings in a single idempotent and atomic operation and delete any settings not present in that JSON file.
7259+
7260+
Use the JSON ``data`` object in output of ``GET /api/admin/settings`` (:ref:`settings_get_all`) for the JSON input structure for this endpoint.
7261+
To put this concretely, you can save just the ``data`` object for your existing settings to disk by filtering them through ``jq`` like this:
7262+
7263+
.. code-block:: bash
7264+
7265+
curl http://localhost:8080/api/admin/settings | jq '.data' > /tmp/all-settings.json
7266+
7267+
Then you can use this "all-settings.json" file as a starting point for your input file.
7268+
The :doc:`../installation/config` page of the Installation Guide has a :ref:`complete list of all the available settings <database-settings>`.
7269+
Note that settings in the JSON file are validated for existence and compliance.
7270+
7271+
.. code-block:: bash
7272+
7273+
export SERVER_URL="http://localhost:8080"
7274+
7275+
curl -X PUT -H "Content-type:application/json" "$SERVER_URL/api/admin/settings" --upload-file /tmp/all-settings.json
7276+
7277+
The fully expanded example above (without environment variables) looks like this:
7278+
7279+
.. code-block:: bash
7280+
7281+
curl -X PUT -H "Content-type:application/json" http://localhost:8080/api/admin/settings --upload-file /tmp/all-settings.json
7282+
7283+
.. _settings_delete_single:
7284+
7285+
Delete Single Database Setting
7286+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7287+
7288+
.. code-block:: bash
7289+
7290+
export SERVER_URL="http://localhost:8080"
7291+
export NAME=":InstallationName"
7292+
7293+
curl -X DELETE "$SERVER_URL/api/admin/settings/$NAME"
7294+
7295+
The fully expanded example above (without environment variables) looks like this:
7296+
7297+
.. code-block:: bash
7298+
7299+
curl -X DELETE http://localhost:8080/api/admin/settings/:InstallationName
7300+
7301+
.. _settings_delete_single_lang:
7302+
7303+
Delete Single Database Setting With Language/Locale
7304+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7305+
7306+
A small number of settings, most notably :ref:`:ApplicationTermsOfUse`, can be saved in multiple languages.
7307+
7308+
Use two-character ISO 639-1 language codes.
7309+
7310+
.. code-block:: bash
7311+
7312+
export SERVER_URL="http://localhost:8080"
7313+
export NAME=":ApplicationTermsOfUse"
7314+
export LANG="fr"
7315+
7316+
curl -X DELETE "$SERVER_URL/api/admin/settings/$NAME/lang/$LANG"
7317+
7318+
The fully expanded example above (without environment variables) looks like this:
7319+
7320+
.. code-block:: bash
71637321
7164-
DELETE http://$SERVER/api/admin/settings/$name
7322+
curl -X DELETE http://localhost:8080/api/admin/settings/:ApplicationTermsOfUse/lang/fr
71657323
71667324
.. _list-all-feature-flags:
71677325

doc/sphinx-guides/source/developers/testing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ The Burrito Key
209209

210210
For reasons that have been lost to the mists of time, the Dataverse software really wants you to to have a burrito. Specifically, if you're trying to run REST Assured tests and see the error "Dataverse config issue: No API key defined for built in user management", you must run the following curl command (or make an equivalent change to your database):
211211

212-
``curl -X PUT -d 'burrito' http://localhost:8080/api/admin/settings/BuiltinUsers.KEY``
212+
``curl -X PUT -d 'burrito' http://localhost:8080/api/admin/settings/:BuiltinUsersKey``
213213

214214
Without this "burrito" key in place, REST Assured will not be able to create users. We create users to create objects we want to test, such as collections, datasets, and files.
215215

0 commit comments

Comments
 (0)