Parser: fix config parser

This commit is contained in:
Akemi Izuko 2024-05-26 22:17:06 -06:00
parent fe2d1cfa14
commit 7293796883
Signed by: akemi
GPG key ID: 8DE0764E1809E9FC
2 changed files with 23 additions and 6 deletions

View file

@ -37,12 +37,29 @@ coronation:
Hostname: coronation.cs.ualberta.ca Hostname: coronation.cs.ualberta.ca
``` ```
## Rules ## Quick Start
```bash
mv ~/.ssh/config ~/.ssh/config_og
python3 src/ssh_config_to_yaml.py ~/.ssh/config_og --out ~/.ssh/config.yaml
# Do some edits on ~/.ssh/config.yaml. The migration script won't compress
# things with for-loops or templates. Then...
python3 ~/.ssh/config.yaml --out ~/.ssh/config
```
As a proof of concept, you can even chain the scripts! The order of hosts will
change, but the config should function identically!
```bash
python3 src/main.py <(python3 src/ssh_config_to_yaml.py ~/.ssh/config)
```
# Rules
The `src/ssh_config_to_yaml.py` script will assist in quickly migrating your The `src/ssh_config_to_yaml.py` script will assist in quickly migrating your
existing config. existing config.
#### SSH Properties ### SSH Properties
Standard SSH config properties go under the `ssh_props` heading for every host. Standard SSH config properties go under the `ssh_props` heading for every host.
For example: For example:
@ -72,7 +89,7 @@ github.com:
Note that yaml does not support duplicate keys, so keys can take a list of Note that yaml does not support duplicate keys, so keys can take a list of
properties instead to mimic repeated keys, as seen above. properties instead to mimic repeated keys, as seen above.
#### Templates ### Templates
Templates are "default" properties inherited from another host. Templates must Templates are "default" properties inherited from another host. Templates must
be declared above the host that uses it. You can make a template-only host by be declared above the host that uses it. You can make a template-only host by
@ -153,7 +170,7 @@ Host ohaton
LocalForward 9000 localhost:9000 LocalForward 9000 localhost:9000
``` ```
#### For loops ### For loops
For loops allow simple substitution of a single variable over a range or set of For loops allow simple substitution of a single variable over a range or set of
values. Ranges must be numerical, but sets can be any arbitrary string. Multiple values. Ranges must be numerical, but sets can be any arbitrary string. Multiple

View file

@ -26,7 +26,7 @@ def parse_sshconfig(lines):
if m_host: if m_host:
if hostname is not None: if hostname is not None:
parse[hostname] = host parse[hostname] = { "ssh_props": host }
hostname = m_host[1] hostname = m_host[1]
host = dict() host = dict()
@ -36,7 +36,7 @@ def parse_sshconfig(lines):
host[m_prop[1]] = [m_prop[2]] host[m_prop[1]] = [m_prop[2]]
if hostname is not None: if hostname is not None:
parse[hostname] = host parse[hostname] = { "ssh_props": host }
return parse return parse