From 3081036c2c2b2ea3a28f0ef507a3969f7472d13f Mon Sep 17 00:00:00 2001 From: benshalev849 <87974262+benshalev849@users.noreply.github.com> Date: Fri, 5 Nov 2021 18:22:38 +0200 Subject: [PATCH] Env oauth url (#1030) Overriding settings in DB using environment variable in docker --- configs/docker_config.py | 3 +++ powerdnsadmin/models/setting.py | 15 +++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/configs/docker_config.py b/configs/docker_config.py index d06f220..6666fc2 100644 --- a/configs/docker_config.py +++ b/configs/docker_config.py @@ -5,6 +5,9 @@ SQLALCHEMY_DATABASE_URI = 'sqlite:////data/powerdns-admin.db' legal_envvars = ( 'SECRET_KEY', + 'OIDC_OAUTH_API_URL', + 'OIDC_OAUTH_TOKEN_URL', + 'OIDC_OAUTH_AUTHORIZE_URL', 'BIND_ADDRESS', 'PORT', 'LOG_LEVEL', diff --git a/powerdnsadmin/models/setting.py b/powerdnsadmin/models/setting.py index e864a28..4a49a40 100644 --- a/powerdnsadmin/models/setting.py +++ b/powerdnsadmin/models/setting.py @@ -268,16 +268,23 @@ class Setting(db.Model): def get(self, setting): if setting in self.defaults: - result = self.query.filter(Setting.name == setting).first() + + if setting.upper() in current_app.config: + result = current_app.config[setting.upper()] + else: + result = self.query.filter(Setting.name == setting).first() + if result is not None: - return strtobool(result.value) if result.value in [ + if hasattr(result,'value'): + result = result.value + return strtobool(result) if result in [ 'True', 'False' - ] else result.value + ] else result else: return self.defaults[setting] else: current_app.logger.error('Unknown setting queried: {0}'.format(setting)) - + def get_records_allow_to_edit(self): return list( set(self.get_forward_records_allow_to_edit() +