fix: 08*
This commit is contained in:
parent
38fad60219
commit
fe0488b8d3
4 changed files with 306 additions and 297 deletions
|
|
@ -120,6 +120,9 @@ Rougail et ces composants :
|
|||
### Structurals
|
||||
|
||||
Les fichiers de "Structures" sont des fichiers au format Rougail dans laquelle toutes les informations du cycle de vie sont définies.
|
||||
|
||||
Avoir des données structurées veut dire qu'on peut publier une fois et avoir plusieurs rendus.
|
||||
|
||||
Il est important de tout mettre ces informations au même endroit. Ainsi on connaitre toutes les aspects de la variable en lisant ces fichiers.
|
||||
On y retrouve :
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ Custom type
|
|||
.. objectives:: Objectives
|
||||
|
||||
In this sections we are going to learn how to create custom types with Rougail.
|
||||
In short, a custom type is nothing more than a kind of a template for a family.
|
||||
In short, a custom type is nothing more than a kind of a template for a variable or a family.
|
||||
|
||||
.. prerequisites:: Prerequisites
|
||||
|
||||
|
|
@ -31,10 +31,10 @@ Let's look now at the possibilities for adding types.
|
|||
This feature is essential for having a truly adaptable tool.
|
||||
|
||||
.. note:: It is actually possible to add types,
|
||||
but that involves adding predefined types to the :term:`tiramisu` underlying consistency library itself,
|
||||
but that involves adding predefined types to the :term:`Tiramisu` underlying consistency library itself,
|
||||
and that’s a different matter altogether. There is a simpler way to achieve this with the Rougail type definition feature.
|
||||
|
||||
It is possible in Rougail to create custom types in a very simple way, it is much like defining families.
|
||||
It is possible in Rougail to create custom types in a very simple way, it is much like defining variables or families.
|
||||
|
||||
Our folder structure will be expanded a bit:
|
||||
|
||||
|
|
@ -69,18 +69,16 @@ Let's examine this more closely this :file:`types/proxy/00-type.yml` type defini
|
|||
type: domainname
|
||||
params:
|
||||
allow_ip: true
|
||||
default:
|
||||
variable: __.http_proxy.address
|
||||
|
||||
port:
|
||||
description: Proxy port
|
||||
type: port
|
||||
default:
|
||||
variable: __.http_proxy.port
|
||||
default: 8080
|
||||
...
|
||||
|
||||
The new type named `proxy` is declared the same way we declare a family.
|
||||
It's more or less like a family declaration except it will be used as a type definition.
|
||||
If you remember, it's mostly the content as the family `manual.http_proxy` in `firefox/10-manual.yml` file of this tutorial.
|
||||
|
||||
.. questions:: How do we use a new type?
|
||||
|
||||
|
|
@ -106,30 +104,15 @@ Let's declare that a family is of type `proxy` as follows:
|
|||
http_proxy:
|
||||
description: HTTP Proxy
|
||||
type: proxy
|
||||
|
||||
address:
|
||||
default: null
|
||||
|
||||
port:
|
||||
default: 8080
|
||||
...
|
||||
|
||||
We can see that the type declared for the `http_proxy` family is `type: proxy`.
|
||||
It's perfectly natural in the rougail style.
|
||||
|
||||
Now in the `address` family it is not necessary to specify the `domainname` type nor the `allow_ip` parameter:
|
||||
|
||||
.. code-block:: yaml
|
||||
:caption: We can omit these settings now due to the type definition
|
||||
|
||||
description: HTTP address
|
||||
type: domainname
|
||||
params:
|
||||
allow_ip: true
|
||||
We can see that the type declared for the `http_proxy` family is now `type: proxy`.
|
||||
It's perfectly natural in the Rougail style.
|
||||
|
||||
But in order to use our new type we need to declare it to Rougail otherwise the new type is not available.
|
||||
The Rougail CLI has the `--types` type declaration command line option for this purpose.
|
||||
Let's launch the rougail CLI with this command line parameter:
|
||||
Let's launch the Rougail CLI with this command line parameter:
|
||||
|
||||
.. raw:: html
|
||||
:url: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/commit/v1.1_080/config/01/cmd_ro.txt
|
||||
|
|
@ -145,11 +128,209 @@ We want the same behavior as usual.
|
|||
|
||||
The type definition adds nothing to the structural logic. It's just a very convenient way to save time when writing structure files.
|
||||
|
||||
Now in the `address` variable it is not necessary to be specified and all parameters (the `domainname` type and the `allow_ip` parameter) are available:
|
||||
|
||||
.. code-block:: yaml
|
||||
:caption: We can omit these settings now due to the type definition
|
||||
|
||||
description: HTTP address
|
||||
type: domainname
|
||||
params:
|
||||
allow_ip: true
|
||||
|
||||
HTTPS and SOCKS Proxy with "proxy" type
|
||||
---------------------------------------
|
||||
|
||||
.. type-along:: For those who follow the tutorial with the help of the git repository
|
||||
|
||||
Now you need to checkout the `v1.1_081` version::
|
||||
|
||||
git switch --detach v1.1_081
|
||||
|
||||
With this use of a type, it is possible to define our HTTPS and SOCKS Proxy in a much more conscious way:
|
||||
|
||||
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/commit/v1.1_081/firefox/20-manual.yml
|
||||
:language: yaml
|
||||
:caption: The :file:`firefox/20-manual.yml` structure file with less code due to the `proxy` type definition
|
||||
|
||||
..
|
||||
%YAML 1.2
|
||||
---
|
||||
version: 1.1
|
||||
|
||||
manual:
|
||||
|
||||
use_for_https: true # Also use this proxy for HTTPS
|
||||
|
||||
https_proxy:
|
||||
description: HTTPS Proxy
|
||||
type: proxy
|
||||
hidden:
|
||||
variable: _.use_for_https
|
||||
|
||||
socks_proxy:
|
||||
description: SOCKS Proxy
|
||||
type: proxy
|
||||
...
|
||||
|
||||
Now we have two families with the `proxy` type: `https_proxy` and `socks_proxy`.
|
||||
|
||||
FIXME expliqué qu'on n'a pas encore tout ce qu'on avait avant !
|
||||
|
||||
Add a variable in a family with custom type
|
||||
--------------------------------------------
|
||||
|
||||
.. type-along:: For those who follow the tutorial with the help of the git repository
|
||||
|
||||
Now you need to checkout the `v1.1_082` version::
|
||||
|
||||
git switch --detach v1.1_082
|
||||
|
||||
|
||||
In the `socks_proxy` family definition, we need to added a new variable, the `version` variable:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
version:
|
||||
description: SOCKS host version used by proxy
|
||||
choices:
|
||||
- v4
|
||||
- v5
|
||||
default: v5
|
||||
|
||||
You can see that what we call a type definition in Rougail is very flexible, because it is perfectly possible
|
||||
to add to what has been defined in the type.
|
||||
The type definition here is therefore not only a template but much more an extensible schema.
|
||||
|
||||
Redefine default value in custom type variable
|
||||
-----------------------------------------------
|
||||
|
||||
.. type-along:: For those who follow the tutorial with the help of the git repository
|
||||
|
||||
Now you need to checkout the `v1.1_083` version::
|
||||
|
||||
git switch --detach v1.1_083
|
||||
|
||||
In this section we are going to make an implicit redefinition of variables default values.
|
||||
|
||||
.. glossary::
|
||||
|
||||
redefine
|
||||
|
||||
A redefine is a redefinition of all or part of the attributes of a variable as it was previously defined.
|
||||
There are two types of redefine, an implicit and an explicit.
|
||||
An implicit redefinition is a redefinition which has not been declared with the `redefine` attribute.
|
||||
An explicit redefinition is a redefinition which has been declared with the `redefine: true` attribute.
|
||||
|
||||
Only default values can be implicitly redefined (and only in the type definitions), all other attributes
|
||||
need to be explicitely redefined.
|
||||
|
||||
In the type definition file, we are now setting default values for the `address` and `port` variables:
|
||||
|
||||
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/commit/v1.1_083/types/proxy/00-type.yml
|
||||
:language: yaml
|
||||
:caption: The :file:`types/proxy/00-type.yml` type definition file with the default values for `address` and `port`
|
||||
|
||||
..
|
||||
%YAML 1.2
|
||||
---
|
||||
version: 1.1
|
||||
|
||||
proxy:
|
||||
|
||||
address:
|
||||
description: Proxy address
|
||||
type: domainname
|
||||
params:
|
||||
allow_ip: true
|
||||
default:
|
||||
variable: __.http_proxy.address
|
||||
|
||||
port:
|
||||
description: Proxy port
|
||||
type: port
|
||||
default:
|
||||
variable: __.http_proxy.port
|
||||
...
|
||||
|
||||
But we don't want theses default values for HTTP definition. We can :term:`redefine` these type settings in the structure file:
|
||||
|
||||
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/commit/v1.1_083/firefox/10-manual.yml
|
||||
:language: yaml
|
||||
:caption: The :file:`firefox/10-manual.yml` structure definition file with the **redefined** default values for `address` and `port`
|
||||
|
||||
..
|
||||
%YAML 1.2
|
||||
---
|
||||
version: 1.1
|
||||
|
||||
manual:
|
||||
description: Manual proxy configuration
|
||||
disabled:
|
||||
variable: _.proxy_mode
|
||||
when_not: Manual proxy configuration
|
||||
|
||||
http_proxy:
|
||||
description: HTTP Proxy
|
||||
type: proxy
|
||||
|
||||
address:
|
||||
default: null
|
||||
|
||||
port:
|
||||
default: 8080
|
||||
...
|
||||
|
||||
This means that the default values for these variables will now be those defined
|
||||
in the structure file if the values are defined (and not in the type definitions file).
|
||||
|
||||
Let's have a closer look at the behavior here.
|
||||
|
||||
Let's launch the Rougail CLI:
|
||||
|
||||
.. raw:: html
|
||||
:url: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/commit/v1.1_082/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/commit/v1.1_082/config/01/output_ro.html
|
||||
:class: output
|
||||
|
||||
We can see in the output that
|
||||
|
||||
- the default values of the `port` variable, which is `8080` in the structure file, comes from the strucure file.
|
||||
- the default values of the `address` variable is not set because it is `null` by default in the structure file,
|
||||
so there is not such thing as a default value set for this variable.
|
||||
|
||||
.. questions:: What happens if the default value in the type definition is not suitable for us?
|
||||
|
||||
If we hadn't defined a value in the userdata file, the Rougail CLI would have returned the following error:
|
||||
|
||||
::
|
||||
|
||||
🛑 Caution
|
||||
┗━━ Manual proxy configuration
|
||||
┣━━ HTTP Proxy
|
||||
┃ ┗━━ Proxy address: 🛑 mandatory variable but has no value
|
||||
┗━━ SOCKS Proxy
|
||||
┗━━ Proxy address: 🛑 mandatory variable but has no value
|
||||
|
||||
Therefore, the default value that was taken into account is indeed that of the structure file, and not that of the type definition.
|
||||
|
||||
.. note:: We can see that the Rougail behavior is always very simple, there is no such thing as an MRO
|
||||
(Method Resolution Object) that try fallback to the default value defined in the type definition file.
|
||||
The Rougail behavior is much more simple and transparent.
|
||||
|
||||
.. type-along:: kinematics of setting the `address` value
|
||||
|
||||
Let's take the time to explain how the value of the variable `manual.http_proxy.address` is determined using the type definition.
|
||||
|
||||
The :file:`10-manual.yml` structure file defines the :file:`manual.https_proxy` family
|
||||
The :file:`10-manual.yml` structure file defines the :file:`manual.http_proxy` family
|
||||
which is defined with the help of the `proxy` type:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
|
@ -191,207 +372,23 @@ finally set by the user data file:
|
|||
┃ ┃ file "config/01/config.yml"
|
||||
|
||||
|
||||
|
||||
Add a variable in a family with custom type
|
||||
Redefine other parameter in custom type for HTTP
|
||||
--------------------------------------------------
|
||||
|
||||
.. type-along:: For those who follow the tutorial with the help of the git repository
|
||||
|
||||
Now you need to checkout the `v1.1_081` version::
|
||||
Now you need to checkout the `v1.1_084` version::
|
||||
|
||||
git switch --detach v1.1_081
|
||||
|
||||
With this use of a type, it is possible to define our HTTPS and SOCKS Proxy in a much more conscious way:
|
||||
|
||||
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/commit/v1.1_081/firefox/20-manual.yml
|
||||
:language: yaml
|
||||
:caption: The :file:`firefox/20-manual.yml` structure file with less code due to the `proxy` type definition
|
||||
|
||||
..
|
||||
%YAML 1.2
|
||||
---
|
||||
version: 1.1
|
||||
|
||||
manual:
|
||||
|
||||
use_for_https: true # Also use this proxy for HTTPS
|
||||
|
||||
https_proxy:
|
||||
description: HTTPS Proxy
|
||||
type: proxy
|
||||
hidden:
|
||||
variable: _.use_for_https
|
||||
|
||||
socks_proxy:
|
||||
description: SOCKS Proxy
|
||||
type: proxy
|
||||
|
||||
version:
|
||||
description: SOCKS host version used by proxy
|
||||
choices:
|
||||
- v4
|
||||
- v5
|
||||
default: v5
|
||||
...
|
||||
|
||||
First, now we have two families with the `proxy` type: `type: proxy`, and `socks_proxy`.
|
||||
|
||||
Second, in the `socks_proxy` family definition, we can see that we have added a new variable,
|
||||
the `version` variable:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
version:
|
||||
description: SOCKS host version used by proxy
|
||||
choices:
|
||||
- v4
|
||||
- v5
|
||||
default: v5
|
||||
|
||||
You can see that what we call a type definition in Rougail is very flexible, because it is perfectly possible
|
||||
to add to what has been defined in the type.
|
||||
The type definition here is therefore not only a template but much more an extensible schema.
|
||||
|
||||
Redefine default value in custom type variable
|
||||
--------------------------------------------------
|
||||
|
||||
.. type-along:: For those who follow the tutorial with the help of the git repository
|
||||
|
||||
Now you need to checkout the `v1.1_082` version::
|
||||
|
||||
git switch --detach v1.1_082
|
||||
|
||||
.. glossary::
|
||||
|
||||
redefine
|
||||
|
||||
A redefine is a redefinition of all or part of the attributes of a variable as it was previously defined.
|
||||
There are two types of redefine, an implicit and an explicit.
|
||||
An implicit redefinition is a redefinition which has not been declared with the `redefine` attribute.
|
||||
An explicit redefinition is a redefinition which has been declared with the `redefine: true` attribute.
|
||||
|
||||
Only default values can be implicitly redefined (and only in the type definitions), all other attributes
|
||||
need to be explicitely redefined.
|
||||
|
||||
|
||||
In this section we are going to make an implicit redefinition of variables default values.
|
||||
|
||||
In the type definition file, we have default values defined for the `address` and `port` variables:
|
||||
|
||||
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/commit/v1.1_082/types/proxy/00-type.yml
|
||||
:language: yaml
|
||||
:caption: The :file:`types/proxy/00-type.yml` type definition file with the default values for `address` and `port`
|
||||
|
||||
..
|
||||
%YAML 1.2
|
||||
---
|
||||
version: 1.1
|
||||
|
||||
proxy:
|
||||
|
||||
address:
|
||||
description: Proxy address
|
||||
type: domainname
|
||||
params:
|
||||
allow_ip: true
|
||||
default:
|
||||
variable: __.http_proxy.address
|
||||
|
||||
port:
|
||||
description: Proxy port
|
||||
type: port
|
||||
default:
|
||||
variable: __.http_proxy.port
|
||||
...
|
||||
|
||||
But we don't want theses default values. We can :term:`redefine` these type settings in the structure file:
|
||||
|
||||
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/commit/v1.1_082/firefox/10-manual.yml
|
||||
:language: yaml
|
||||
:caption: The :file:`firefox/10-manual.yml` structure definition file with the **redefined** default values for `address` and `port`
|
||||
|
||||
..
|
||||
%YAML 1.2
|
||||
---
|
||||
version: 1.1
|
||||
|
||||
manual:
|
||||
description: Manual proxy configuration
|
||||
disabled:
|
||||
variable: _.proxy_mode
|
||||
when_not: Manual proxy configuration
|
||||
|
||||
http_proxy:
|
||||
description: HTTP Proxy
|
||||
type: proxy
|
||||
|
||||
address:
|
||||
default: null
|
||||
|
||||
port:
|
||||
default: 8080
|
||||
...
|
||||
|
||||
This means that the default values for these variables will now be those defined
|
||||
in the structure file if the values are defined (and not in the type definitions file).
|
||||
|
||||
Let's have a closer look at the behavior here.
|
||||
|
||||
Let's launch the Rougail CLI:
|
||||
|
||||
.. raw:: html
|
||||
:url: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/commit/v1.1_082/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/commit/v1.1_082/config/01/output_ro.html
|
||||
:class: output
|
||||
|
||||
We can see in the output that
|
||||
|
||||
- the default values of the `port` variable, which is `8080` in the structure file, comes from the strucure file.
|
||||
- the default values of the `address` variable is not set because it is `null` by default in the structure file,
|
||||
so there is not such thing as a default value set for this variable.
|
||||
|
||||
.. questions:: What happens if the default value in the type definition is not suitable for us?
|
||||
|
||||
If we hadn't defined a value in the userdata file, the Rougail CLI would have returned the following error:
|
||||
|
||||
::
|
||||
|
||||
🛑 Caution
|
||||
┗━━ Manual proxy configuration
|
||||
┣━━ HTTP Proxy
|
||||
┃ ┗━━ Proxy address: 🛑 mandatory variable but has no value
|
||||
┗━━ SOCKS Proxy
|
||||
┗━━ Proxy address: 🛑 mandatory variable but has no value
|
||||
|
||||
Therefore, the default value that was taken into account is indeed that of the structure file, and not that of the type definition.
|
||||
|
||||
.. note:: We can see that the Rougail behavior is always very simple, there is no such thing as an MRO
|
||||
(Method Resolution Object) that try fallback to the default value defined in the type definition file.
|
||||
The Rougail behavior is much more simple and transparent.
|
||||
|
||||
Redefine other parameter in custom type
|
||||
------------------------------------------
|
||||
|
||||
.. type-along:: For those who follow the tutorial with the help of the git repository
|
||||
|
||||
Now you need to checkout the `v1.1_083` version::
|
||||
|
||||
git switch --detach v1.1_083
|
||||
git switch --detach v1.1_084
|
||||
|
||||
In this sections we are going to make explicit :term:`redefinitions <redefine>`.
|
||||
|
||||
The type definition didn't change, what we're talking about here is modifiying what has been previously defined
|
||||
in the type definition file:
|
||||
FIXME : en fait si ! on supprime la description, de address et port qui n'a pas de sens dans le type (suivant le type il faut le redéfinir).
|
||||
et on modifie ici le type pour HTTP.
|
||||
|
||||
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/commit/v1.1_083/types/proxy/00-type.yml
|
||||
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/commit/v1.1_084/types/proxy/00-type.yml
|
||||
:language: yaml
|
||||
:caption: The :file:`types/proxy/00-type.yml` type definition file with the default definitions
|
||||
|
||||
|
|
@ -403,7 +400,6 @@ in the type definition file:
|
|||
proxy:
|
||||
|
||||
address:
|
||||
description: Proxy address
|
||||
type: domainname
|
||||
params:
|
||||
allow_ip: true
|
||||
|
|
@ -411,17 +407,16 @@ in the type definition file:
|
|||
variable: __.http_proxy.address
|
||||
|
||||
port:
|
||||
description: Proxy port
|
||||
type: port
|
||||
default:
|
||||
variable: __.http_proxy.port
|
||||
...
|
||||
|
||||
We can see here, for example, that the `address` and `port` variables don't have
|
||||
any `description` atribute. We need to add one, so we need to extend the type
|
||||
defintions.
|
||||
any `description` attribute. We need to add one, so we need to extend the type
|
||||
definitions.
|
||||
|
||||
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/commit/v1.1_083/firefox/10-manual.yml
|
||||
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/commit/v1.1_084/firefox/10-manual.yml
|
||||
:language: yaml
|
||||
:caption: The :file:`firefox/10-manual.yml` structure definition file with explicit redefinitions
|
||||
|
||||
|
|
@ -451,7 +446,6 @@ defintions.
|
|||
description: HTTP proxy port
|
||||
...
|
||||
|
||||
|
||||
.. note:: Transforming an implicit defintion into an explicit redefinition is very simple; you just need to add the `redefine: true` attribute:
|
||||
|
||||
Let's launch the Rougail CLI:
|
||||
|
|
@ -504,3 +498,15 @@ type definition file.
|
|||
- implicit or explicit redefinitions
|
||||
|
||||
We have seen how the definition of type, used effectively, allows for a new expressiveness.
|
||||
|
||||
|
||||
Redefine other parameter in custom type for HTTPS and SOCKS
|
||||
-----------------------------------------------------------
|
||||
|
||||
.. type-along:: For those who follow the tutorial with the help of the git repository
|
||||
|
||||
Now you need to checkout the `v1.1_084` version::
|
||||
|
||||
git switch --detach v1.1_084
|
||||
|
||||
FIXME pareil pour https et socks
|
||||
|
|
|
|||
Loading…
Reference in a new issue