def get_key(key, config, msg=None, delete=False):
    """Returns a value given a dictionary key, throwing if not available."""
    if isinstance(key, list):
        if len(key) <= 1:
            if msg is not None:
                raise AssertionError(msg)
            else:
                raise AssertionError(
                    'must provide at least two valid keys to test')
        for k in key:
            if k in config:
                val = config[k]
                if delete:
                    del config[k]
                return val
        if msg is not None:
            raise AssertionError(msg)
        else:
            raise AssertionError(
                "config dictionary missing a field named as one of '%s'" %
                str(key))
    elif key not in config:
        if msg is not None:
            raise AssertionError(msg)
        else:
            raise AssertionError("config dictionary missing '%s' field" % key)
    else:
        val = config[key]
        if delete:
            del config[key]
        return val
