def load_from_files()

in src/alerter/rabbitmq_admin.py [0:0]


    def load_from_files(filepath: str, want_ssl: bool):
        """
        Initialises RabbitMQ config from text files in a directory.  This is intended to be used from Kubernetes,
        where we can mount a secrets manifest as a directory path and read its contents from files.
        :param filepath: directory to load the files from. An IOError will be raised if any of the expected files do not exist here.
        :param want_ssl: if this is set, then use HTTPS for accessing the management port (recommended!)
        :return: a RabbitMQConfig object. Raises an exception if there is an error.
        """
        with open(filepath + "/rabbitmq_client_uri", "r") as f:
            content = f.read()
            parsed_url = urlparse(content)

        if parsed_url.scheme != "amqp":
            logger.error("Expected rabbitmq uri scheme to be 'amqp' but got {0}".format(parsed_url.scheme))
            raise ValueError("scheme is incorrect")
        if parsed_url.path == "":
            logger.error("Expected a virtualhost in the rabbitmq uri at {0}".format(filepath))
            raise ValueError("no virtualhost for rabbitmq")

        # we don't use the port from the parsed url as that is for the AMQP port not the management port
        return RabbitMQConfig(parsed_url.hostname, None, parsed_url.path.lstrip("/ "),
                              want_ssl,
                              requests.auth.HTTPBasicAuth(parsed_url.username, parsed_url.password)
                              )