183 lines
8.8 KiB
Python
183 lines
8.8 KiB
Python
#!/usr/bin/env python3
|
|||
|
|
"""Generates docs/SETTINGS-REFERENCE.md: every setting, what it does, its values, and where it is set.
|
||
|
|
|
||
|
|
Sources (edit those, then run this; SettingsReferenceTest fails when the document is stale):
|
||
|
|
runway-app/src/main/resources/kernel-settings.yml console-managed kernel settings (schema)
|
||
|
|
runway-app/src/main/resources/i18n/operator-messages.properties their English labels and help
|
||
|
|
scripts/dev/settings-homes.yml settings on other screens, and server-only ones with reasons
|
||
|
|
runway-plugin-protection/plugin.yml + i18n/messages.properties the essential plugin's settings
|
||
|
|
|
||
|
|
Run from the repository root: python3 scripts/dev/gen-settings-reference.py
|
||
|
|
"""
|
||
|
|
import os
|
||
|
|
import yaml
|
||
|
|
|
||
|
|
ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||
|
|
|
||
|
|
|
||
|
|
def props(path):
|
||
|
|
out = {}
|
||
|
|
key = None
|
||
|
|
for line in open(path, encoding='utf-8'):
|
||
|
|
line = line.rstrip('\n')
|
||
|
|
if not line or line.startswith('#') or '=' not in line:
|
||
|
|
continue
|
||
|
|
k, v = line.split('=', 1)
|
||
|
|
out[k.strip()] = v.strip()
|
||
|
|
return out
|
||
|
|
|
||
|
|
|
||
|
|
def cell(text):
|
||
|
|
return (text or '').replace('|', '\\|').replace('\n', ' ')
|
||
|
|
|
||
|
|
|
||
|
|
def values(s):
|
||
|
|
t = s.get('type', 'string')
|
||
|
|
parts = []
|
||
|
|
if t == 'enum' and s.get('range'):
|
||
|
|
parts.append('one of ' + ', '.join(f'`{x.strip()}`' for x in str(s['range']).split(',')))
|
||
|
|
elif t == 'boolean':
|
||
|
|
parts.append('`true` or `false`')
|
||
|
|
elif t in ('int', 'decimal') and s.get('range'):
|
||
|
|
lo, hi = str(s['range']).split('..')
|
||
|
|
parts.append(f'{"whole number" if t == "int" else "number"} from {lo} to {hi}')
|
||
|
|
elif t == 'list':
|
||
|
|
parts.append('comma-separated list')
|
||
|
|
elif t == 'secret':
|
||
|
|
parts.append('secret (stored encrypted, never shown)')
|
||
|
|
else:
|
||
|
|
parts.append('text')
|
||
|
|
default = s.get('default')
|
||
|
|
if isinstance(default, bool):
|
||
|
|
default = str(default).lower() # YAML booleans print as true/false, not Python's True/False
|
||
|
|
parts.append('default ' + (f'`{default}`' if default not in (None, '') else 'empty'))
|
||
|
|
return '; '.join(parts)
|
||
|
|
|
||
|
|
|
||
|
|
SCREENS = [
|
||
|
|
('server', 'Settings → Server settings', '/__app/config/server'),
|
||
|
|
('backups', 'Backups → Settings (backup policy)', '/__app/config/backups'),
|
||
|
|
('bandwidth', 'Bandwidth → Settings (metering and quota)', '/__app/config/bandwidth'),
|
||
|
|
('activity', 'Activity → Logs → Settings (activity log retention)', '/__app/config/activity'),
|
||
|
|
('plugins', 'Plugins → Settings (plugin limits)', '/__app/config/plugins'),
|
||
|
|
]
|
||
|
|
|
||
|
|
|
||
|
|
def main():
|
||
|
|
ks = yaml.safe_load(open(f'{ROOT}/runway-app/src/main/resources/kernel-settings.yml', encoding='utf-8'))
|
||
|
|
msg = props(f'{ROOT}/runway-app/src/main/resources/i18n/operator-messages.properties')
|
||
|
|
homes = yaml.safe_load(open(f'{ROOT}/scripts/dev/settings-homes.yml', encoding='utf-8'))
|
||
|
|
prot = yaml.safe_load(open(f'{ROOT}/runway-plugin-protection/plugin.yml', encoding='utf-8'))
|
||
|
|
pmsg = props(f'{ROOT}/runway-plugin-protection/i18n/messages.properties')
|
||
|
|
|
||
|
|
out = []
|
||
|
|
w = out.append
|
||
|
|
w('# Settings reference')
|
||
|
|
w('')
|
||
|
|
w('<!-- GENERATED by scripts/dev/gen-settings-reference.py — do not edit; edit its sources and run it again. -->')
|
||
|
|
w('')
|
||
|
|
w('Every setting the Runway kernel and its essential protection plugin read: what it does, the values it takes, '
|
||
|
|
'and where you set it. Per-site settings are made on the site console\'s screens (SITE-MANAGER-GUIDE.md); '
|
||
|
|
'optional plugins document their own settings.')
|
||
|
|
w('')
|
||
|
|
w('## How settings are layered')
|
||
|
|
w('')
|
||
|
|
w('- **The console** keeps what you set on its screens in `external/platform.yml` (platform) and in each '
|
||
|
|
'site\'s folder (that site). Only values that differ from the default are stored. A blank field restores '
|
||
|
|
'the default; a blank token field keeps the stored token.')
|
||
|
|
w('- **The server** can set any key in `external/application.yml`, an environment variable '
|
||
|
|
'(`RUNWAY_CSP_MODE` for `runway.csp.mode`) or a command-line argument. **A value set there wins**, and the '
|
||
|
|
'console shows that field disabled with where it is set, and what removing it there would do. To move a key '
|
||
|
|
'to the console in one restart, click **Use the file\'s value** on its row first (it copies the value the '
|
||
|
|
'server runs with), then remove the line and restart: nothing changes (ADMINISTRATION.md §8).')
|
||
|
|
w(' Two exceptions. *Password strength* (`runway.security.password-strength`): the value chosen on Platform '
|
||
|
|
'settings wins over every server source, and the field is never locked. *The protection plugin\'s settings* '
|
||
|
|
'(section 2): `external/plugin-settings/protection.yml`, which its settings screen writes, wins over '
|
||
|
|
'`external/application.yml`, and the form shows no lock; an environment variable or a command-line argument '
|
||
|
|
'still wins over both.')
|
||
|
|
w('- **When a change applies:** the settings in section 1 apply after the next restart (the form says which '
|
||
|
|
'are pending). Settings on the other screens in section 2 say when they apply.')
|
||
|
|
w('- **Kept out of the console on purpose:** the settings in section 3, each with the reason.')
|
||
|
|
w('')
|
||
|
|
|
||
|
|
w('## 1. Console settings: Server settings and the policy cards')
|
||
|
|
w('')
|
||
|
|
groups = {g['id']: g for g in ks['settingGroups']}
|
||
|
|
for prefix, title, path in SCREENS:
|
||
|
|
w(f'### {title}')
|
||
|
|
w('')
|
||
|
|
w(f'Screen: `{path}` (platform administrators). Applies after a restart.')
|
||
|
|
w('')
|
||
|
|
for gid, g in groups.items():
|
||
|
|
if not gid.startswith(prefix + '.'):
|
||
|
|
continue
|
||
|
|
rows = [s for s in ks['settings'] if s['group'] == gid]
|
||
|
|
if not rows:
|
||
|
|
continue
|
||
|
|
w(f'#### {msg.get(g["label"], gid)}')
|
||
|
|
w('')
|
||
|
|
if msg.get(g['help']):
|
||
|
|
w(msg[g['help']])
|
||
|
|
w('')
|
||
|
|
w('| Setting | Key | What it does | Values |')
|
||
|
|
w('|---|---|---|---|')
|
||
|
|
for s in rows:
|
||
|
|
label = msg.get(s['label'], s['key'])
|
||
|
|
adv = ' *(Advanced)*' if s.get('advanced') else ''
|
||
|
|
w(f'| {cell(label)}{adv} | `{s["key"]}` | {cell(msg.get(s["help"], ""))} | {cell(values(s))} |')
|
||
|
|
w('')
|
||
|
|
|
||
|
|
w('## 2. Settings edited on other console screens')
|
||
|
|
w('')
|
||
|
|
w('| Key | Where |')
|
||
|
|
w('|---|---|')
|
||
|
|
for key, where in homes['elsewhere'].items():
|
||
|
|
w(f'| `{key}` | {cell(where)} |')
|
||
|
|
w('')
|
||
|
|
w('Log levels (`logging.level.<logger>`) are set on **Activity → Logs → Log levels** (`/__app/logs/levels`): '
|
||
|
|
'they apply at once and are kept in `platform.yml`; a level set in `application.yml` wins and shows locked.')
|
||
|
|
w('')
|
||
|
|
w('The essential protection plugin\'s settings are on **Plugins → Essential Protection → Settings** '
|
||
|
|
'(`/__app/plugins/protection/settings`). They are stored in `external/plugin-settings/protection.yml` and '
|
||
|
|
'bound as `runway.plugin.protection.<key>`; they apply after a restart. Its login protection (honeypot, '
|
||
|
|
'lockout, CAPTCHA) is the panel below that form and applies at once; each site has its own on '
|
||
|
|
'`/__admin/protection`.')
|
||
|
|
w('')
|
||
|
|
pgroups = {g['id']: g for g in prot.get('settingGroups', [])}
|
||
|
|
for gid, g in pgroups.items():
|
||
|
|
rows = [s for s in prot['settings'] if s.get('group') == gid]
|
||
|
|
if not rows:
|
||
|
|
continue
|
||
|
|
w(f'#### {pmsg.get(g["label"], gid)}')
|
||
|
|
w('')
|
||
|
|
w('| Setting | Key | What it does | Values |')
|
||
|
|
w('|---|---|---|---|')
|
||
|
|
for s in rows:
|
||
|
|
w(f'| {cell(pmsg.get(s["label"], s["key"]))} | `runway.plugin.protection.{s["key"]}` | '
|
||
|
|
f'{cell(pmsg.get(s.get("help", ""), ""))} | {cell(values(s))} |')
|
||
|
|
w('')
|
||
|
|
|
||
|
|
w('## 3. Server-only settings, and why')
|
||
|
|
w('')
|
||
|
|
w('Set these in `external/application.yml` (or the environment). They stay out of the console because the '
|
||
|
|
'console cannot change them safely, or cannot exist until they are known.')
|
||
|
|
w('')
|
||
|
|
by_reason = {}
|
||
|
|
for key, reason in homes['host-only'].items():
|
||
|
|
by_reason.setdefault(reason.strip(), []).append(key)
|
||
|
|
w('| Keys | Why not in the console |')
|
||
|
|
w('|---|---|')
|
||
|
|
for reason, keys in by_reason.items():
|
||
|
|
w(f'| {"<br>".join(f"`{k}`" for k in keys)} | {cell(reason)} |')
|
||
|
|
w('')
|
||
|
|
w('Spring Boot keys Runway pins in its shipped `application.yml` (for example '
|
||
|
|
'`server.forward-headers-strategy`, `spring.web.resources.add-mappings`, `spring.security.filter.order`) are '
|
||
|
|
'part of how the platform works, not preferences: do not change them. ADMINISTRATION.md §8 lists them.')
|
||
|
|
w('')
|
||
|
|
open(f'{ROOT}/docs/SETTINGS-REFERENCE.md', 'w', encoding='utf-8').write('\n'.join(out))
|
||
|
|
n = len(ks['settings']) + len(homes['elsewhere']) + len(homes['host-only']) + len(prot['settings'])
|
||
|
|
print(f'docs/SETTINGS-REFERENCE.md: {n} settings')
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == '__main__':
|
||
|
|
main()
|