rougail/docs/tutorial/domainname.rst

419 lines
16 KiB
ReStructuredText
Raw Normal View History

2025-12-03 21:13:38 +01:00
A few types suitable for our use case
================================================
2025-12-01 21:35:27 +01:00
.. objectives:: Objectives
2025-12-03 21:13:38 +01:00
There isn't just the `string` or `integer` type, there are basic types
that are much more suited to our use case, such as `domainname`, `port`, and `boolean`.
2025-12-01 21:35:27 +01:00
2025-12-02 11:08:54 +01:00
.. prerequisites:: Prerequisites
2025-12-01 21:35:27 +01:00
2025-12-02 11:08:54 +01:00
- We assume that Rougail's library is :ref:`installed <installation>` on your computer.
2025-12-01 21:35:27 +01:00
2025-12-02 11:08:54 +01:00
- It is possible to retrieve the current state of the various rougail files manipulated in this tutorial step
by checking out the corresponding tag of the Rougail-tutorials git repository.
Each tag corresponds to a stage of progress in the tutorial.
Of course, you can also decide to copy/paste or download the tutorial files contents while following the tutorial steps.
2025-12-01 21:35:27 +01:00
2025-12-02 11:08:54 +01:00
If you want to follow this tutorial with the help of the corresponding :tutorial:`Rougail-tutorials git repository <src/branch/1.1>`,
this workshop page corresponds to the tags :tutorial:`v1.1_030 <src/tag/v1.1_030>` to :tutorial:`v1.1_033 <src/tag/v1.1_033>`
in the repository.
2025-12-01 21:35:27 +01:00
2025-12-02 11:08:54 +01:00
::
git clone https://forge.cloud.silique.fr/stove/rougail-tutorials.git
git checkout v1.1_030
2025-12-01 21:35:27 +01:00
2025-12-02 11:08:54 +01:00
.. type-along:: let's recap how far we've come
2025-12-01 21:35:27 +01:00
2025-12-03 15:04:23 +01:00
We have an `http_proxy` family with an `address` variable in it.
2025-12-02 11:08:54 +01:00
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_030/firefox/10-manual.yml
:language: yaml
:caption: An `address` variable in the `http_proxy` family
..
manual: # Manual proxy configuration
http_proxy: # HTTP Proxy
address:
description: HTTP address
type: domainname
:tutorial:`Download this file from the rougail-tutorials git repository <src/tag/v1.1_030/firefox/10-manual.yml>`
2025-12-02 11:52:21 +01:00
A variable with type `domainname`
-----------------------------------
2025-12-03 15:04:23 +01:00
Notice that we have assigned a type to this variable:
2025-12-02 11:08:54 +01:00
.. code-block:: yaml
:linenos:
:caption: The `address` variable with the `domainname` type assigned
address:
type: domainname
Assigning a type is convenient for reading, but what else does it bring?
2025-12-01 21:35:27 +01:00
2025-12-02 11:08:54 +01:00
Well, with a correct user data like this one,
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_030/config/01/config.yml
:language: yaml
:caption: A domain name user data setting
2025-12-01 21:35:27 +01:00
..
---
manual:
2025-12-02 11:08:54 +01:00
http_proxy:
address: net.example
:tutorial:`Download this file from the rougail-tutorials git repository <src/tag/v1.1_030/config/01/config.yml>`
if we launch the rougail CLI on it:
.. raw:: html
:url: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_030/config/01/cmd_ro.txt
:class: terminal
..
rougail -m firefox/ -u yaml -yf config/01/config.yml
We have this output:
.. raw:: html
:url: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_030/config/01/output_ro.html
:class: output
..
<pre>╭──────── Caption ────────╮
│ Variable <span style="color: #ffd700">Default value</span> │
│ <span style="color: #00aa00">Modified value</span> │
╰─────────────────────────╯
Variables:
<span style="color: #5c5cff">┣━━ </span>📓 Configure Proxy Access to the Internet: <span style="color: #ffd700">No proxy</span>
<span style="color: #5c5cff">┗━━ </span>📂 Manual proxy configuration
<span style="color: #5c5cff"> </span><span style="color: #5c5cff">┗━━ </span>📂 HTTP Proxy
<span style="color: #5c5cff"> </span><span style="color: #5c5cff"> </span><span style="color: #5c5cff">┗━━ </span>📓 HTTP address: <span style="color: #00aa00">example.net</span> ◀ loaded from the YAML file
<span style="color: #5c5cff"> </span><span style="color: #5c5cff"> </span><span style="color: #5c5cff"> </span>"config/01/config.yml"
</pre>
2025-12-03 15:04:23 +01:00
And we don't really see any change associated with the fact that we have assigned
a type to this variable. But if we assign this (wrong) user data:
2025-12-02 11:08:54 +01:00
2025-12-03 15:04:23 +01:00
.. type-along:: A domain name has no space in it
Let's have a look at an example of user setting that does not fit the
`domainname` type:
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_030/config/03/config.yml
2025-12-02 11:08:54 +01:00
:language: yaml
2025-12-03 15:04:23 +01:00
:caption: An invalid domain name for the :file:`config/03/config.yml` user data setting
2025-12-01 21:35:27 +01:00
2025-12-02 11:08:54 +01:00
..
---
manual:
2025-12-01 21:35:27 +01:00
http_proxy:
2025-12-03 15:04:23 +01:00
address: bla bla
2025-12-01 21:35:27 +01:00
2025-12-03 15:04:23 +01:00
:tutorial:`Download this file from the rougail-tutorials git repository <src/tag/v1.1_030/config/03/config.yml>`
2025-12-02 11:08:54 +01:00
2025-12-03 15:04:23 +01:00
The value is obviously not a domain name, then when we will launch the rougail CLI:
2025-12-02 11:08:54 +01:00
.. raw:: html
2025-12-03 15:04:23 +01:00
:url: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_030/config/03/cmd_invalid.txt
2025-12-02 11:08:54 +01:00
:class: terminal
..
2025-12-03 15:04:23 +01:00
rougail -m firefox/ -u yaml -yf config/03/config.yml --cli.invalid_user_datas_error
2025-12-02 11:08:54 +01:00
we then have this output:
.. raw:: html
2025-12-03 15:04:23 +01:00
:url: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_030/config/03/output_invalid.html
2025-12-02 11:08:54 +01:00
:class: error
..
<pre><span style="font-weight: bold; color: #ff0000">🛑 ERRORS</span>
2025-12-03 15:04:23 +01:00
<span style="color: #ff0000">┗━━ </span>the value "bla bla" is an invalid domain name for
2025-12-02 11:08:54 +01:00
<span style="color: #ff0000"> </span>"manual.http_proxy.address" (HTTP address), must not be an IP, it will be
<span style="color: #ff0000"> </span>ignored when loading from the YAML file "config/02/config.yml"
</pre>
2025-12-03 15:04:23 +01:00
.. type-along:: what if we set an IP address instead of a domain name?
2025-12-02 11:08:54 +01:00
2025-12-03 15:04:23 +01:00
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_030/config/02/config.yml
2025-12-02 11:08:54 +01:00
:language: yaml
2025-12-03 15:04:23 +01:00
:caption: A domain name in the :file:`config/02/config.yml` user data setting with an IP address
2025-12-02 11:08:54 +01:00
..
---
manual:
http_proxy:
2025-12-03 15:04:23 +01:00
address: 19.168.230.51
2025-12-02 11:08:54 +01:00
2025-12-03 15:04:23 +01:00
:tutorial:`Download this file from the rougail-tutorials git repository <src/tag/v1.1_030/config/02/config.yml>`
2025-12-02 11:08:54 +01:00
2025-12-03 15:04:23 +01:00
With a value that *is not a domain name* but an IP address, then when we will launch the rougail CLI
we will see a little problem:
2025-12-02 11:08:54 +01:00
.. raw:: html
2025-12-03 15:04:23 +01:00
:url: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_030/config/02/cmd_invalid.txt
2025-12-02 11:08:54 +01:00
:class: terminal
..
2025-12-03 15:04:23 +01:00
rougail -m firefox/ -u yaml -yf config/02/config.yml --cli.invalid_user_datas_error
2025-12-02 11:08:54 +01:00
we then have this output:
.. raw:: html
2025-12-03 15:04:23 +01:00
:url: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_030/config/02/output_invalid.html
2025-12-02 11:08:54 +01:00
:class: error
..
<pre><span style="font-weight: bold; color: #ff0000">🛑 ERRORS</span>
2025-12-03 15:04:23 +01:00
<span style="color: #ff0000">┗━━ </span>the value "192.168.0.1" is an invalid domain name for
2025-12-02 11:08:54 +01:00
<span style="color: #ff0000"> </span>"manual.http_proxy.address" (HTTP address), must not be an IP, it will be
<span style="color: #ff0000"> </span>ignored when loading from the YAML file "config/02/config.yml"
</pre>
2025-12-03 15:04:23 +01:00
We observe that an error has been raised because an IP address is not a domain name.
Therefore, a type validation is taking place because we declared the type `domainname`.
2025-12-02 11:08:54 +01:00
.. type-along:: A variable with type's parameters
.. questions:: Question
2025-12-03 15:04:23 +01:00
OK I agree with the `domainname` necessary type validation, but what if I want to specify
2025-12-02 11:08:54 +01:00
an IP address as a user value for this `address` variable?
2025-12-02 11:52:21 +01:00
Because it is therefore simply impossible to do so now.
2025-12-02 11:08:54 +01:00
Is there a way for my `address` variable to accept an IP address?
Well, it is possible to configure the type so that it accepts IP addresses.
We need to specify whether our variable accepts to be filled using an IP or a domain name only.
This is where the ability to parameterize our variable comes in.
.. rubric:: Let's add a type parameter.
.. type-along:: For those who follow the tutorial with the help of the git repository
Now you need to checkout the `v1.1_031` version::
git checkout v1.1_031
Let's add a type parameter named `allow_ip`:
2025-12-01 21:35:27 +01:00
2025-12-02 11:08:54 +01:00
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_031/firefox/10-manual.yml
2025-12-01 21:35:27 +01:00
:language: yaml
2025-12-02 11:08:54 +01:00
:caption: The `allow_ip` type parameter set in the :file:`firefox/10-manual.yml` structure file
2025-12-01 21:35:27 +01:00
:linenos:
..
---
manual:
description: Manual proxy configuration
http_proxy:
description: HTTP Proxy
address:
description: HTTP address
type: domainname
params:
allow_ip: true
2025-12-02 11:08:54 +01:00
The params allow the domain name `address` variable to be set with IPs.
2025-12-01 21:35:27 +01:00
.. glossary::
parameter
2025-12-02 11:52:21 +01:00
A parameter is a property of a variable that can refine its behavior.
It is declared by adding the `params` attribute in the variable's
definition.
Now we will test with an IP address as the value for our `address` variable.
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_031/config/02/config.yml
:language: yaml
2025-12-03 15:04:23 +01:00
:caption: An IP address as a value in the :file:`config/02/config.yml` user value
2025-12-02 11:52:21 +01:00
..
---
manual:
http_proxy:
address: 192.168.0.1
:tutorial:`Download this file from the rougail-tutorials git repository <src/tag/v1.1_031/config/02/config.yml>`
if we launch the rougail CLI on it:
.. raw:: html
:url: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_031/config/02/cmd_ro.txt
:class: terminal
..
rougail -m firefox/ -u yaml -yf config/02/config.yml
We have this output:
.. raw:: html
2025-12-03 15:04:23 +01:00
:url: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_031/config/02/output_ro.html
2025-12-02 11:52:21 +01:00
:class: output
We can see that the IP address value has been accepted.
A variable with type `port`
------------------------------
2025-12-03 15:04:23 +01:00
.. type-along:: For those who follow the tutorial with the help of the git repository
2025-12-02 11:52:21 +01:00
2025-12-03 15:04:23 +01:00
Now you need to checkout the `v1.1_032` version::
git checkout v1.1_032
2025-12-02 11:52:21 +01:00
2025-12-03 18:58:41 +01:00
After the `address` variable let's add, according to our use case,
2025-12-02 11:52:21 +01:00
2025-12-03 15:04:23 +01:00
.. image:: images/firefox_port.png
2025-12-01 21:35:27 +01:00
2025-12-03 18:58:41 +01:00
a new variable of type `port`. Our structure file looks like this:
2025-12-01 21:35:27 +01:00
2025-12-03 18:58:41 +01:00
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_032/firefox/10-manual.yml
:language: yaml
:caption: The `port` type variable in the :file:`firefox/10-manual.yml` structure file
:linenos:
..
port:
description: HTTP Port
type: port
default: 8080
:tutorial:`Download this file from the rougail-tutorials git repository <src/tag/v1.1_032/firefox/10-manual.yml>`
Let's assing a value to this port:
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/commit/v1.1_032/config/02/config.yml
:language: yaml
:caption: A user data :file:`config/02/config.yml` setting a value to the port variable
..
proxy_mode: Manual proxy configuration
manual:
http_proxy:
address: example.net
port: 3128
:tutorial:`Download this file from the rougail-tutorials git repository <src/tag/v1.1_032/config/02/config.yml>`
If we launch the rougail CLI:
.. raw:: html
:class: terminal
:url: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/commit/v1.1_032/config/02/cmd_ro.txt
We have this output:
.. raw:: html
:class: output
:url: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/commit/v1.1_032/config/02/output_ro.html
..
<pre>╭─────────────────────────── Caption ────────────────────────────╮
│ Variable <span style="color: #00aa00">Modified value</span> │
│ <span style="color: #ff0000">Undocumented but modified variable</span> (⏳ Original default value) │
╰────────────────────────────────────────────────────────────────╯
Variables:
<span style="color: #5c5cff">┣━━ </span>📓 <span style="color: #ff0000">Configure Proxy Access to the Internet</span>: <span style="color: #00aa00">Manual proxy configuration</span> ◀
<span style="color: #5c5cff">┃ </span>loaded from the YAML file "config/02/config.yml" (⏳ No proxy)
<span style="color: #5c5cff">┗━━ </span>📂 Manual proxy configuration
<span style="color: #5c5cff"> </span><span style="color: #5c5cff">┗━━ </span>📂 HTTP Proxy
<span style="color: #5c5cff"> </span><span style="color: #5c5cff"> </span><span style="color: #5c5cff">┣━━ </span>📓 <span style="color: #ff0000">HTTP address</span>: <span style="color: #00aa00">example.net</span> ◀ loaded from the YAML file
<span style="color: #5c5cff"> </span><span style="color: #5c5cff"> </span><span style="color: #5c5cff">┃ </span>"config/02/config.yml"
<span style="color: #5c5cff"> </span><span style="color: #5c5cff"> </span><span style="color: #5c5cff">┗━━ </span>📓 <span style="color: #ff0000">HTTP Port</span>: <span style="color: #00aa00">3128</span> ◀ loaded from the YAML file
<span style="color: #5c5cff"> </span><span style="color: #5c5cff"> </span><span style="color: #5c5cff"> </span>"config/02/config.yml" (⏳ 8080)
</pre>
How can we know what validations the port type performs on the value assigned to the variable?
There are a number of validations that are carried out with this `port` type:
- well-known ports (1 to 1023) are allowed
- registred ports (1024 to 49151) are allowed
.. - private ports (greater than 49152) are allowed
Now let's assign a value that is outside the allowed ports:
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/commit/v1.1_032/config/03/config.yml
:language: yaml
:caption: A user value in :file:`config/03/config.yml` that is not allowed
:tutorial:`Download this file from the rougail-tutorials git repository <src/tag/v1.1_032/config/03/config.yml>`
Again, we launch the rougail CLI:
.. raw:: html
:class: terminal
:url: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/commit/v1.1_032/config/03/cmd_invalid.txt
.. rougail -m firefox/ -u yaml -yf config/03/config.yml --cli.invalid_user_datas_error
And we have this output:
.. raw:: html
:class: error
:url: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/commit/v1.1_032/config/03/output_invalid.html
..
<pre><span style="font-weight: bold; color: #ff0000">🛑 ERRORS</span>
<span style="color: #ff0000">┗━━ </span>the value "100000" is an invalid port for "manual.http_proxy.port" (HTTP
<span style="color: #ff0000"> </span>Port), must be between 1 and 65535, it will be ignored when loading from the
<span style="color: #ff0000"> </span>YAML file "config/03/config.yml"
</pre>
We observe that, as with the `domainname` type, a number of validations are performed
to ensure that the value assigned to this variable conforms to the `port` type.
2025-12-03 21:13:38 +01:00
A variable with type `boolean`
-----------------------------------
.. type-along:: For those who follow the tutorial with the help of the git repository
Now you need to checkout the `v1.1_033` version::
git checkout v1.1_033
Let's add one more variable in the `manual` family, with a much more basic type: `boolean`.
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_033/firefox/20-manual.yml
:language: yaml
:caption: A new structure file :file:`firefox/20-manual.yml` with one variable
..
%YAML 1.2
---
version: 1.1
manual:
use_for_https: true # Also use this proxy for HTTPS
...
:tutorial:`Download this file from the rougail-tutorials git repository <src/tag/v1.1_033/firefox/20-manual.yml>`
.. note::
- it is not necessary to declare the variable as a boolean type
this type is *inferred* by the `true` default value
- we have decided to create a new structure file :file:`firefox/20-manual.yml`.
This is not necessary but usefull, please have a look at the :ref:`structure file organization and naming conventions <namingconvention>`
2025-12-01 21:35:27 +01:00
.. keypoints:: let's review the key points
2025-12-03 18:58:41 +01:00
- we can assign a `domainname` type to a variable
- we can set a :term:`parameter` to a `domainname` variable to refine their typing behavior
- we can assign a `port` type to a variable