From 8e26e4edd59b6bae119377f9b7a46dca972c07f6 Mon Sep 17 00:00:00 2001 From: Seth Foster Date: Mon, 14 Oct 2019 11:38:20 -0400 Subject: [PATCH] Allow oauth2 settings to be set in the ui and api Oauth2 settings were initialized early in the awx import stage, and those settings were not modifiable. This change allows oauth2 to check for settings in django.conf settings, which are dynamically updated through api calls at runtime. As a result, oauth2 settings will match the values in django.conf settings at any point in time. --- awx/__init__.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/awx/__init__.py b/awx/__init__.py index e7a5a828ec..b97a5694af 100644 --- a/awx/__init__.py +++ b/awx/__init__.py @@ -82,6 +82,16 @@ def find_commands(management_dir): return commands +def oauth2_getattribute(self, attr): + # Custom method to override + # oauth2_provider.settings.OAuth2ProviderSettings.__getattribute__ + from django.conf import settings + val = settings.OAUTH2_PROVIDER.get(attr) + if val is None: + val = object.__getattribute__(self, attr) + return val + + def prepare_env(): # Update the default settings environment variable based on current mode. os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'awx.settings.%s' % MODE) @@ -93,6 +103,12 @@ def prepare_env(): # Monkeypatch Django find_commands to also work with .pyc files. import django.core.management django.core.management.find_commands = find_commands + + # Monkeypatch Oauth2 toolkit settings class to check for settings + # in django.conf settings each time, not just once during import + import oauth2_provider.settings + oauth2_provider.settings.OAuth2ProviderSettings.__getattribute__ = oauth2_getattribute + # Use the AWX_TEST_DATABASE_* environment variables to specify the test # database settings to use when management command is run as an external # program via unit tests.