INNER CODE UNIT · Python
edit_config_many
kejilion/sh · site_access_config.py:10
def edit_config_many(directory: str, name: str, expected_sha256: str, server_indices: list[int],
scope: str, location: str, modifier: str, realm: str, user_file: str,
*, validate, reload_config, assert_context=None) -> str:
if not server_indices or len(server_indices) > 64 or len(set(server_indices)) != len(server_indices):
raise ConfigError('invalid server list')
def transform(content):
try:
source = content.decode('utf-8')
except UnicodeDecodeError as exc:
raise ConfigError('site configuration is not UTF-8') from exc
tree = parse(source)
targets = [select_context(tree, index, scope, location, modifier) for index in server_indices]
for target in targets:
if any(d.words[0] in ('auth_basic', 'auth_basic_user_file') for d in target.directives):
raise ConfigError('a password rule already exists in this context')
for target in sorted(targets, key=lambda block: block.start, reverse=True):
source = replace_auth(source, target, realm, user_file, enforce_satisfy_all=True)