Skip to content

Commit 9328388

Browse files
Isabella Siukay-kim
authored andcommitted
DOCS-12014 document __rest
1 parent d04f90e commit 9328388

File tree

6 files changed

+268
-4
lines changed

6 files changed

+268
-4
lines changed

source/includes/options-mongod.yaml

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,42 @@ description: |
3939
optional: true
4040
---
4141
program: mongod
42+
name: configExpand
43+
args: <none|rest>
44+
default: |
45+
none
46+
directive: option
47+
description: |
48+
.. versionadded:: 4.2
49+
50+
Enables using :ref:`Expansion Directives <externally-sourced-values>` to set
51+
externally sourced values for configuration file options.
52+
53+
.. list-table::
54+
:header-rows: 1
55+
:widths: 20 40
56+
57+
* - Value
58+
59+
- Description
60+
61+
* - ``none``
62+
63+
- Default. {{program}} does not expand expansion directives. {{program}}
64+
fails to start if any configuration file settings use expansion
65+
directives.
66+
67+
* - ``rest``
68+
69+
- {{program}} only expands ``__rest`` expansion directives. {{program}}
70+
fails to start if any configuration file settings use any other
71+
expansion directive.
72+
73+
See :ref:`externally-sourced-values` for configuration files
74+
for more information on expansion directives.
75+
optional: true
76+
---
77+
program: mongod
4278
name: verbose
4379
inherit:
4480
name: verbose
@@ -3271,10 +3307,10 @@ description: |
32713307
.. versionadded:: 4.2
32723308
32733309
Outputs the resolved YAML configuration document for the {{program}} to ``stdout``
3274-
and halts the server instance. For configuration options using externally
3275-
sourced values, {{role}} returns the resolved value for those options. This
3276-
may include any configured passwords or secrets previously obfuscated through
3277-
the external source.
3310+
and halts the server instance. For configuration options using
3311+
:ref:`externally-sourced-values`, {{role}} returns the resolved value for those
3312+
options. This may include any configured passwords or secrets previously
3313+
obfuscated through the external source.
32783314
32793315
optional: true
32803316
---

source/includes/options-mongos.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ inherit:
2727
file: options-mongod.yaml
2828
---
2929
program: mongos
30+
name: configExpand
31+
inherit:
32+
name: configExpand
33+
program: mongod
34+
file: options-mongod.yaml
35+
---
36+
program: mongos
3037
name: verbose
3138
inherit:
3239
name: verbose

source/reference/configuration-options.txt

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,99 @@ configuration file, :binary:`~bin.mongod` may not start.
8484

8585
.. [#yaml-json] YAML is a superset of :term:`JSON`.
8686

87+
.. _externally-sourced-values:
88+
89+
Externally Sourced Values
90+
~~~~~~~~~~~~~~~~~~~~~~~~~
91+
92+
.. versionadded:: 4.2
93+
94+
Starting in MongoDB 4.2, users can use expansion directives in the
95+
configuration file to define the value of configuration file options with
96+
values from an external source. The following expansion directives are
97+
available:
98+
99+
- :configexpansion:`__rest`
100+
101+
You must use the :option:`--configExpand <mongod --configExpand>`
102+
option for the :binary:`~bin.mongod`/:binary:`~bin.mongos` to enable parsing of
103+
expansion directives. If you specify any expansion directives in the
104+
configuration file and start the :binary:`~bin.mongod`/:binary:`~bin.mongos`
105+
without this option, the :binary:`~bin.mongod`/:binary:`~bin.mongos` fails
106+
to start. This option must be configured on the command line only, and can not
107+
be expressed in either YAML or INI configuration files.
108+
109+
.. configexpansion:: __rest
110+
111+
The ``__rest`` expansion directive allows users to use externally sourced
112+
values in a configuration file. ``__rest`` makes http(s) calls for values
113+
and can be used two ways.
114+
115+
``__rest`` can fetch field values:
116+
117+
.. code-block:: yaml
118+
119+
<field> :
120+
__rest: <string>
121+
type: string
122+
trim: < none | whitespace >
123+
124+
``__rest`` can also be used to fetch entire configuration files:
125+
126+
.. code-block:: yaml
127+
128+
__rest: <string>
129+
type: yaml
130+
trim: < none | whitespace >
131+
132+
The ``__rest`` expansion directive takes a string representing the url for
133+
which the mongod or mongos issues a ``GET`` request to retrieve the value.
134+
135+
.. note::
136+
137+
- ``__rest`` URLs must be HTTPS unless they are referring to
138+
localhost, in which case they can use unencrypted HTTP URLs.
139+
- If the REST endpoint requires authentication, encode credentials into the
140+
URL with standard
141+
`RFC 3986 User Information <https://tools.ietf.org/html/rfc3986#section-3.2.1>`_
142+
format.
143+
- HTTPS requests require TLS 1.1 or later on the client and the host.
144+
145+
The following optional fields affect the behavior of the ``__rest``
146+
expansion directive:
147+
148+
.. list-table::
149+
:header-rows: 1
150+
:widths: 20 80
151+
152+
* - Field
153+
- Description
154+
155+
* - ``type``
156+
157+
- Optional. Defaults to ``string``
158+
159+
For ``string``, the :binary:`~bin.mongod`/:binary:`~bin.mongos` uses
160+
the value returned from the endpoint as a literal string. This value
161+
is not parsed for additional structure beyond what is specific to the
162+
setting.
163+
164+
For ``yaml``, the ``__rest`` directive must be the *only* block in
165+
the entire configuration file. Users must define their entire
166+
configuration file within the specified endpoint, and the return type
167+
must be YAML. See the :ref:`yaml example<rest-yaml-example>`.
168+
169+
.. warning::
170+
Recursive ``__rest`` expansion directives are forbidden. If the
171+
value returned from a ``__rest`` expansion directive contains an
172+
expansion directive, the :binary:`~bin.mongod`/
173+
:binary:`~bin.mongos` throws an error and fails to start.
174+
175+
* - ``trim``
176+
177+
- Optional. Defaults to ``none``. Specify ``whitespace`` to trim any
178+
leading or trailing whitespace from the resulting response.
179+
87180
Use the Configuration File
88181
~~~~~~~~~~~~~~~~~~~~~~~~~~
89182

@@ -114,6 +207,121 @@ If you installed from a package and have started MongoDB using your
114207
system's :term:`init script`, you are already using a configuration
115208
file.
116209

210+
.. _rest-yaml-example:
211+
212+
``__rest`` Expansion with YAML Example
213+
``````````````````````````````````````
214+
215+
When using expansion directives, you must include the :option:`--configExpand
216+
<mongod --configExpand>` command line option when starting the the
217+
:binary:`~bin.mongod`/:binary:`~bin.mongos`.
218+
219+
For example, the configuration file ``mongod.conf`` consists of the following
220+
``__rest`` expansion directive.
221+
222+
.. code-block:: yaml
223+
224+
__rest: "https://mongoconf.example.net:8080/record/1"
225+
type: yaml
226+
227+
.. note::
228+
When using the ``__rest`` expansion directive with ``type : yaml``, the
229+
configuration file must include only the expansion directive and its
230+
related options. All other required configuration options must exist on
231+
the remote resource specified in ``__rest``.
232+
233+
The YAML document recorded at the URL is:
234+
235+
.. code-block:: yaml
236+
237+
net:
238+
port: 20128
239+
240+
To start :binary:`~bin.mongod` using the configuration, include both the
241+
configuration file and the :option:`--configExpand <mongod --configExpand>`
242+
options:
243+
244+
.. code-block:: yaml
245+
246+
mongod -f mongod.conf --configExpand rest
247+
248+
To verify the configuration, you can include the
249+
:option:`--outputConfig <mongod --outputConfig>` option.
250+
The :option:`--outputConfig <mongod --outputConfig>` option prints the
251+
specified configuration, including any resolved values, to ``stdout`` and
252+
halts the :binary:`~bin.mongod`.
253+
254+
.. warning::
255+
256+
The :option:`--outputConfig <mongod --outputConfig>` option returns the
257+
resolved values for any field using an expansion directive. This includes
258+
any private or sensitive information previously obscured by using an
259+
external source for configuration.
260+
261+
For example:
262+
263+
.. code-block:: yaml
264+
265+
mongod -f mongod.conf --configExpand rest --outputConfig
266+
267+
Will output:
268+
269+
.. code-block:: yaml
270+
271+
config: mongod.conf
272+
configExpand: rest
273+
net:
274+
port: 20128
275+
outputConfig: true
276+
277+
``--outputConfig`` with Configuration Files
278+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
279+
280+
The :option:`--outputConfig <mongod --outputConfig>` option causes the
281+
:binary:`~bin.mongod` or :binary:`~bin.mongos` to output its resolved YAML
282+
configuration document to ``stdout`` and halt. For configuration options using
283+
externally sourced values, :option:`--outputConfig <mongod --outputConfig>`
284+
returns the resolved value for those options.
285+
286+
.. warning::
287+
288+
The :option:`--outputConfig <mongod --outputConfig>` option returns the
289+
resolved values for any field using an expansion directive. This includes
290+
any private or sensitive information previously obscured by using an
291+
external source for configuration.
292+
293+
.. example::
294+
295+
The following configuration file ``mongod.conf`` contains a ``__rest``
296+
expansion directive.
297+
298+
.. code-block:: yaml
299+
300+
net:
301+
port:
302+
__rest: "https://mongoconf.example.net:8080/record/1"
303+
304+
The string recorded at the URL is:
305+
306+
.. code-block:: yaml
307+
308+
20128
309+
310+
After starting the :binary:`~bin.mongod` with:
311+
312+
.. code-block:: yaml
313+
314+
mongod -f mongod.conf --configExpand rest --outputConfig
315+
316+
The output is:
317+
318+
.. code-block:: yaml
319+
320+
config: mongod.conf
321+
net:
322+
port: 20128
323+
outputConfig: true
324+
117325
Core Options
118326
------------
119327

source/reference/program/mongod.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ Core Options
5353

5454
.. include:: /includes/option/option-mongod-config.rst
5555

56+
.. _mongod-configExpand:
57+
.. include:: /includes/option/option-mongod-configExpand.rst
58+
5659
.. include:: /includes/option/option-mongod-verbose.rst
5760

5861
.. include:: /includes/option/option-mongod-quiet.rst

source/reference/program/mongos.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ Core Options
5656

5757
.. include:: /includes/option/option-mongos-config.rst
5858

59+
.. include:: /includes/option/option-mongos-configExpand.rst
60+
5961
.. include:: /includes/option/option-mongos-verbose.rst
6062

6163
.. include:: /includes/option/option-mongos-quiet.rst

source/release-notes/4.2.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,14 @@ applies.
267267

268268
.. seealso:: :ref:`4.2-compatibility-enabled`
269269

270+
Externally Sourced Values for Configuration Files
271+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
272+
273+
MongoDB 4.2 allows users to use :ref:`externally-sourced-values` to define the
274+
value of configuration options in a configuration file. MongoDB supports
275+
``__rest`` expansion directives for retrieving values as both strings and YAML
276+
documents.
277+
270278
Changes Affecting Compatibility
271279
-------------------------------
272280

0 commit comments

Comments
 (0)