Skip to content

Commit

Permalink
Add shared utility, also skip auth class thing
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCoding committed Sep 4, 2024
1 parent 08b1c1c commit 469e59c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions ansible_base/resource_registry/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import ansible_base.lib.checks # noqa: F401 - register checks
from ansible_base.lib.utils.db import ensure_transaction, migrations_are_complete
from ansible_base.resource_registry.utils.settings import resource_server_defined

logger = logging.getLogger('ansible_base.resource_registry.apps')

Expand Down Expand Up @@ -101,11 +102,10 @@ def proxies_of_model(cls):

def _should_reverse_sync():
enabled = getattr(settings, 'RESOURCE_SERVER_SYNC_ENABLED', False)
resource_server_defined = bool(getattr(settings, 'RESOURCE_SERVER', {}).get('URL', ''))
if enabled and (not resource_server_defined):
if enabled and (not resource_server_defined()):
logger.error("RESOURCE_SERVER is not configured. Reverse sync will not be enabled.")
enabled = False
if enabled and resource_server_defined and ('SECRET_KEY' not in settings.RESOURCE_SERVER or not settings.RESOURCE_SERVER['SECRET_KEY']):
if enabled and resource_server_defined() and ('SECRET_KEY' not in settings.RESOURCE_SERVER or not settings.RESOURCE_SERVER['SECRET_KEY']):
logger.error("RESOURCE_SERVER['SECRET_KEY'] is not configured. Reverse sync will not be enabled.")
enabled = False
return enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from ansible_base.resource_registry.resource_server import get_resource_server_config
from ansible_base.resource_registry.utils.auth_code import get_user_auth_code
from ansible_base.resource_registry.utils.settings import resource_server_defined


def redirect_to_resource_server(*args, social=None, user=None, **kwargs):
Expand All @@ -11,7 +12,9 @@ def redirect_to_resource_server(*args, social=None, user=None, **kwargs):
"""

# Allow for disabling this pipeline without removing it from the settings.
if not getattr(settings, 'ENABLE_SERVICE_BACKED_SSO', False):
# If resource server is defined, also silently quit
# for ease of connected vs disconnected configs
if (not getattr(settings, 'ENABLE_SERVICE_BACKED_SSO', False)) or (not resource_server_defined()):
return None

oidc_alt_key = None
Expand Down
5 changes: 5 additions & 0 deletions ansible_base/resource_registry/utils/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.conf import settings


def resource_server_defined() -> bool:
return bool(getattr(settings, 'RESOURCE_SERVER', {}).get('URL', ''))

0 comments on commit 469e59c

Please sign in to comment.