Redefine variable
Objectives
When we said that a variable is immutable when an integrator defined it in structured data, we said that it had to be done explicitly. Let’s see how that works.
Prerequisites
We assume that Rougail’s library is installed on your computer.
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-tutorialsgit 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.
If you want to follow this tutorial with the help of the corresponding rougail-tutorials git repository, this workshop page corresponds to the tags v1.1_240 to v1.1_241
git clone https://forge.cloud.silique.fr/stove/rougail-tutorials.git
git switch --detach v1.1_240
Username is mandatory if a password is set
We now have two new variables following the same pattern as the previous three one:
A variable with the new type
unix_usernameusername, this variable is accessible in type HTTP, HTTPS/SSL, SOCKS4 or SOCKS5A variable with the new type
secretpassword, this variable is accessible in type HTTP, HTTPS/SSL, SOCKS4 or SOCKS5
Nothing really new from now. But we haven’t said everything! In fact, we have to deal with a new situation. We have three coherence configuration choices:
either we fill in the username/password pair
we fill only the username
or leave it blank
Defining only a password makes no sense.
There are several ways to solve this case.
Let’s assume that if the operator sets a password, they must also enter a username. The password can be null.
In Rougail format, we would say that the password is nullable and that the username has a variable calculation to determine if it is nullable. If the password is empty, the username is nullable; otherwise, it is not.
Here’s how to do it:
foxyproxy/00-foxyproxy.yml%YAML 1.2
---
version: 1.1
proxies:
description: Proxy configuration
_type: sequence
title:
description: Title or Description
mandatory: false
type:
description: Proxy Type
choices:
- HTTP
- HTTPS/SSL
- SOCKS4
- SOCKS5
- PAC URL
- WPAD
- System (use system settings)
- Direct (no proxy)
default: Direct (no proxy)
color:
description: Color
regexp: ^#(?:[0-9a-f]{3}){1,2}$
default:
jinja: >-
#{%- for i in range(6) -%}{{- '0123456789abcdef' | random -}}{%- endfor -%}
description: random color value
auto_save: true
address:
description: IP address, DNS name, server name
type: domainname
params:
allow_ip: true
allow_without_dot: true
default:
description: copy HTTP address if proxy is not "Manual"
variable: firefox.manual.http_proxy.address
propertyerror: false
disabled:
jinja: |-
{{ _.type not in ['HTTP', 'HTTPS/SSL', 'SOCKS4', 'SOCKS5'] }}
return_type: boolean
description: |-
if type not in:
- HTTP
- HTTPS/SSL
- SOCKS4
- SOCKS5
port:
description: Port
type: port
default:
description: copy HTTP port if proxy is not "Manual"
variable: firefox.manual.http_proxy.port
propertyerror: false
disabled:
jinja: |-
{{ _.type not in ['HTTP', 'HTTPS/SSL', 'SOCKS4', 'SOCKS5'] }}
return_type: boolean
description: |-
if type not in:
- HTTP
- HTTPS/SSL
- SOCKS4
- SOCKS5
username:
description: Username
type: unix_user
mandatory:
variable: _.password
when_not: null
disabled:
jinja: |-
{{ _.type not in ['HTTP', 'HTTPS/SSL', 'SOCKS4', 'SOCKS5'] }}
return_type: boolean
description: |-
if type not in:
- HTTP
- HTTPS/SSL
- SOCKS4
- SOCKS5
password:
description: Password
type: secret
mandatory: false
disabled:
jinja: |-
{{ _.type not in ['HTTP', 'HTTPS/SSL', 'SOCKS4', 'SOCKS5'] }}
return_type: boolean
description: |-
if type not in:
- HTTP
- HTTPS/SSL
- SOCKS4
- SOCKS5
url:
description: URL
type: web_address
default:
description: copy HTTP address if proxy is "Auto"
variable: firefox.auto
propertyerror: false
disabled:
jinja: |-
{{ _.type not in ['PAC URL', 'WPAD'] }}
return_type: boolean
description: |-
if type is not in:
- PAC URL
- WPAD
...
Now let’s test with the following user data file:
config/02/config.yml user data 1---
2foxyproxy:
3 proxies:
4 - title: My company
5 type: HTTP
6 color: '#66cc66'
7 address: proxy.company.net
8 port: 8080
9 username: one_user
10 password: P4ssW0rD
11 - title: An other company
12 type: HTTP
13 address: proxy.company.net
14 port: 8080
If we launch the Rougail CLI:
We have this output:
╭────────────── Caption ───────────────╮ │ Variable Default value │ │ Modified value │ │ (⏳ Original default value) │ ╰──────────────────────────────────────╯ Variables: ┣━━ 📂 firefox (Firefox) ┃ ┣━━ 📓 proxy_mode (Configure Proxy Access to the Internet): No proxy ┃ ┗━━ 📂 dns_over_https (DNS over HTTPS) ┃ ┗━━ 📓 enable_dns_over_https (Enable DNS over HTTPS): false ┗━━ 📂 foxyproxy (FoxyProxy) ┗━━ 📂 proxies (Proxy configuration) ┣━━ 📂 title (Title or Description) ┃ ┣━━ 📓 title (Title or Description): My company ◀ loaded from the ┃ ┃ YAML file "config/02/config.yml" ┃ ┣━━ 📓 type (Proxy Type): HTTP ◀ loaded from the YAML file ┃ ┃ "config/02/config.yml" (⏳ Direct (no proxy)) ┃ ┣━━ 📓 color (Color): #66cc66 ◀ loaded from the YAML file ┃ ┃ "config/02/config.yml" ┃ ┣━━ 📓 address (IP address, DNS name, server name): ┃ ┃ proxy.company.net ◀ loaded from the YAML file ┃ ┃ "config/02/config.yml" ┃ ┣━━ 📓 port (Port): 8080 ◀ loaded from the YAML file ┃ ┃ "config/02/config.yml" ┃ ┣━━ 📓 username (Username): one_user ◀ loaded from the YAML file ┃ ┃ "config/02/config.yml" ┃ ┗━━ 📓 password (Password): ********** ◀ loaded from the YAML file ┃ "config/02/config.yml" ┗━━ 📂 title (Title or Description) ┣━━ 📓 title (Title or Description): An other company ◀ loaded from ┃ the YAML file "config/02/config.yml" ┣━━ 📓 type (Proxy Type): HTTP ◀ loaded from the YAML file ┃ "config/02/config.yml" (⏳ Direct (no proxy)) ┣━━ 📓 color (Color): #100796 ┣━━ 📓 address (IP address, DNS name, server name): ┃ proxy.company.net ◀ loaded from the YAML file ┃ "config/02/config.yml" ┣━━ 📓 port (Port): 8080 ◀ loaded from the YAML file ┃ "config/02/config.yml" ┣━━ 📓 username (Username): null ┗━━ 📓 password (Password): null
Note
The value of a variable of type secret is replaced by asterisks (*) when it is displayed.