INNER CODE UNIT · Python

edit_config

kejilion/sh · site_access_config.py:35

def edit_config(directory: str, name: str, expected_sha256: str, server_index: int,
                scope: str, location: str, modifier: str, action: str,
                *, realm: str = '', user_file: str = '', validate, reload_config, assert_context=None) -> str:
    if action not in ('set', 'delete'):
        raise ConfigError('invalid configuration action')
    if action == 'delete' and (realm or user_file):
        raise ConfigError('unexpected deletion arguments')

    def transform(content):
        try:
            source = content.decode('utf-8')
        except UnicodeDecodeError as exc:
            raise ConfigError('site configuration is not UTF-8') from exc
        block = select_context(parse(source), server_index, scope, location, modifier)
        direct_auth = [item for item in block.directives
                       if item.words[0] in ('auth_basic', 'auth_basic_user_file')]
        if action == 'delete' and not direct_auth:
            raise ConfigError('no direct authentication rule exists in this context')

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…