Example #1
0
    def read_secrets(self) -> dict:
        """Read secrets configuration file.

        Stores API keys, such.
        """
        # Secret configuration diretives
        from websauna.utils.secrets import read_ini_secrets
        from websauna.system.core.interfaces import ISecrets

        settings = self.settings

        secrets_file = settings.get("websauna.secrets_file")
        if not secrets_file:
            return {}

        strict = asbool(settings.get("websauna.secrets_strict", True))

        _secrets = read_ini_secrets(secrets_file, strict=strict)
        self.config.registry.registerUtility(_secrets, ISecrets)
        secret_settings = {
            k.replace('app:main.', ''): v
            for k, v in _secrets.items() if k.startswith('app:main.')
        }
        settings.update(secret_settings)
        self.config.registry.settings.update(secret_settings)
        return _secrets
Example #2
0
    def get_celery_config(self, settings) -> str:
        """Return celery configuration from Websauna (optionally secret-) settings.

        :param settings: Websauna settings (from app:main section).
        :return: Celery configuration, as a string.
        """
        value = None
        secrets_file = settings.get('websauna.secrets_file')
        if secrets_file:
            secrets = read_ini_secrets(secrets_file)
            value = secrets.get('app:main.websauna.celery_config', '')
        value = value or settings.get('websauna.celery_config')
        if not value:
            raise RuntimeError('No Celery configuration found in settings')
        return value
Example #3
0
    def get_celery_config(self, config_file: str) -> str:
        """Return celery configuration, from given config_file.

        :param config_file: Websauna configuration file.
        :return: Celery configuration, as a string.
        """
        value = None
        loader = plaster.get_loader(config_file)
        settings = loader.get_settings('app:main')
        secrets_file = settings.get('websauna.secrets_file')
        if secrets_file:
            secrets = read_ini_secrets(secrets_file)
            value = secrets.get('app:main.websauna.celery_config', '')
        value = value if value else settings.get('websauna.celery_config')
        if not value:
            raise RuntimeError('Could not find websauna.celery_config in {ini_file}'.format(ini_file=ini_file))
        return value
Example #4
0
    def read_secrets(self) -> dict:
        """Read secrets configuration file.

        Stores API keys, such.
        """
        # Secret configuration diretives
        from websauna.utils.secrets import read_ini_secrets
        from websauna.system.core.interfaces import ISecrets

        settings = self.settings

        secrets_file = settings.get("websauna.secrets_file")
        if not secrets_file:
            return {}

        _secrets = read_ini_secrets(secrets_file)
        self.config.registry.registerUtility(_secrets, ISecrets)
        return _secrets
Example #5
0
    def read_secrets(self) -> dict:
        """Read secrets configuration file.

        Stores API keys, such.
        """
        # Secret configuration diretives
        from websauna.utils.secrets import read_ini_secrets
        from websauna.system.core.interfaces import ISecrets

        settings = self.settings

        secrets_file = settings.get("websauna.secrets_file")
        if not secrets_file:
            return {}

        _secrets = read_ini_secrets(secrets_file)
        self.config.registry.registerUtility(_secrets, ISecrets)
        return _secrets
Example #6
0
def test_read_local_secrets():
    """Read file referred by a relative path."""
    data = secrets.read_ini_secrets("test-secrets.ini")
    assert data.get("authomatic.secret") == os.environ["RANDOM_VALUE"]
Example #7
0
def test_file_secrets():
    """Read file referred by absolute path."""
    data = secrets.read_ini_secrets("file://" +
                                    os.path.abspath("test-secrets.ini"))
    assert data.get("authomatic.secret") == os.environ["RANDOM_VALUE"]
Example #8
0
def test_read_local_secrets():
    """Read file referred by a relative path."""
    data = secrets.read_ini_secrets("test-secrets.ini", strict=False)
    assert data.get("authomatic.secret") == "xxx"
Example #9
0
def test_file_secrets():
    """Read file referred by absolute path."""
    data = secrets.read_ini_secrets("file://" + os.path.abspath("test-secrets.ini"), strict=False)
    assert data.get("authomatic.secret") == "xxx"
Example #10
0
def test_read_local_secrets():
    """Read file referred by a relative path."""
    data = secrets.read_ini_secrets("test-secrets.ini", strict=False)
    assert data.get("authomatic.secret") == "xxx"
Example #11
0
def test_file_secrets():
    """Read file referred by absolute path."""
    data = secrets.read_ini_secrets("file://" +
                                    os.path.abspath("test-secrets.ini"),
                                    strict=False)
    assert data.get("authomatic.secret") == "xxx"
Example #12
0
def test_read_local_secrets():
    """Read file referred by a relative path."""
    data = secrets.read_ini_secrets("test-secrets.ini")
    assert data.get("authomatic.secret") == os.environ["RANDOM_VALUE"]
Example #13
0
def test_file_secrets():
    """Read file referred by absolute path."""
    data = secrets.read_ini_secrets("file://" + os.path.abspath("test-secrets.ini"))
    assert data.get("authomatic.secret") == os.environ["RANDOM_VALUE"]