From ea94db261a6063bcd6b21ea900887d579482ae50 Mon Sep 17 00:00:00 2001 From: Brian McLaughlin Date: Thu, 22 Feb 2024 13:21:42 -0500 Subject: [PATCH 01/10] Add management command to dump auth config data to a file https://issues.redhat.com/browse/AAP-19981 No-Issue --- .../management/commands/dump_auth_config.py | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 galaxy_ng/app/management/commands/dump_auth_config.py diff --git a/galaxy_ng/app/management/commands/dump_auth_config.py b/galaxy_ng/app/management/commands/dump_auth_config.py new file mode 100644 index 0000000000..8323b2f403 --- /dev/null +++ b/galaxy_ng/app/management/commands/dump_auth_config.py @@ -0,0 +1,83 @@ +import json +import os +from django.core.management.base import BaseCommand +from galaxy_ng.app.models.config import Setting +from django.conf import settings +from dynaconf.utils import upperfy + +class Command(BaseCommand): + KEYCLOAK_AUTH_KEYS = [ + "SOCIAL_AUTH_KEYCLOAK_ACCESS_TOKEN_URL", + "SOCIAL_AUTH_KEYCLOAK_AUTHORIZATION_URL", + "SOCIAL_AUTH_KEYCLOAK_KEY", + "SOCIAL_AUTH_KEYCLOAK_PUBLIC_KEY", + "SOCIAL_AUTH_KEYCLOAK_SECRET", + "KEYCLOAK_PROTOCOL", + "KEYCLOAK_HOST", + "KEYCLOAK_PORT", + "KEYCLOAK_REALM", + ] + + LDAP_AUTH_KEYS = [ + "AUTH_LDAP_SERVER_URI", + "AUTH_LDAP_BIND_DN", + "AUTH_LDAP_BIND_PASSWORD", + "AUTH_LDAP_USER_SEARCH_BASE_DN", + "AUTH_LDAP_USER_SEARCH_SCOPE", + "AUTH_LDAP_USER_SEARCH_FILTER", + "AUTH_LDAP_GROUP_SEARCH_BASE_DN", + "AUTH_LDAP_GROUP_SEARCH_SCOPE", + "AUTH_LDAP_GROUP_SEARCH_FILTER", + "AUTH_LDAP_USER_ATTR_MAP", + ] + + help = "Dump auth config data from database to a JSON file" + + def add_arguments(self, parser): + parser.add_argument( + "output_file", + nargs="?", + type=str, + default="/auth_config.json", + help="Output JSON file path", + ) + + def format_config_data(self, type, keys, prefix): + config = { + "type": type, + "configuration": {} + } + for key in keys: + k = key + if prefix in key: + k = key[len(prefix):] + v = settings.get(upperfy(key), default=None) + config["configuration"].update({k: v}) + return config + + + def handle(self, *args, **options): + try: + data = [] + + # Add Keycloak auth config + data.append(self.format_config_data("keycloak", self.KEYCLOAK_AUTH_KEYS, "SOCIAL_AUTH_KEYCLOAK_")) + + # Add LDAP auth config + data.append(self.format_config_data("ldap", self.LDAP_AUTH_KEYS, "AUTH_LDAP_")) + + # Define the path for the output JSON file + output_file = options["output_file"] + + # Ensure the directory exists + os.makedirs(os.path.dirname(output_file), exist_ok=True) + + # Write data to the JSON file + with open(output_file, "w") as f: + json.dump(data, f, indent=4) + + self.stdout.write( + self.style.SUCCESS(f"Auth config data dumped to {output_file}") + ) + except Exception as e: + self.stdout.write(self.style.ERROR(f"An error occurred: {str(e)}")) From 5cac88e1f9c5eceae2d95d5b141095f57d4e1158 Mon Sep 17 00:00:00 2001 From: Brian McLaughlin Date: Thu, 22 Feb 2024 13:33:53 -0500 Subject: [PATCH 02/10] Lint No-Issue --- galaxy_ng/app/management/commands/dump_auth_config.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/galaxy_ng/app/management/commands/dump_auth_config.py b/galaxy_ng/app/management/commands/dump_auth_config.py index 8323b2f403..3cdf1da858 100644 --- a/galaxy_ng/app/management/commands/dump_auth_config.py +++ b/galaxy_ng/app/management/commands/dump_auth_config.py @@ -1,10 +1,10 @@ import json import os from django.core.management.base import BaseCommand -from galaxy_ng.app.models.config import Setting from django.conf import settings from dynaconf.utils import upperfy + class Command(BaseCommand): KEYCLOAK_AUTH_KEYS = [ "SOCIAL_AUTH_KEYCLOAK_ACCESS_TOKEN_URL", @@ -55,13 +55,17 @@ def format_config_data(self, type, keys, prefix): config["configuration"].update({k: v}) return config - def handle(self, *args, **options): try: data = [] # Add Keycloak auth config - data.append(self.format_config_data("keycloak", self.KEYCLOAK_AUTH_KEYS, "SOCIAL_AUTH_KEYCLOAK_")) + data.append( + self.format_config_data( + "keycloak", + self.KEYCLOAK_AUTH_KEYS, + "SOCIAL_AUTH_KEYCLOAK_"), + ) # Add LDAP auth config data.append(self.format_config_data("ldap", self.LDAP_AUTH_KEYS, "AUTH_LDAP_")) From d24074d284f4720b0986d3c316faf064bb7b4671 Mon Sep 17 00:00:00 2001 From: Brian McLaughlin Date: Thu, 22 Feb 2024 13:55:52 -0500 Subject: [PATCH 03/10] Remove upperfy call No-Issue --- galaxy_ng/app/management/commands/dump_auth_config.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/galaxy_ng/app/management/commands/dump_auth_config.py b/galaxy_ng/app/management/commands/dump_auth_config.py index 3cdf1da858..52155fd431 100644 --- a/galaxy_ng/app/management/commands/dump_auth_config.py +++ b/galaxy_ng/app/management/commands/dump_auth_config.py @@ -2,7 +2,6 @@ import os from django.core.management.base import BaseCommand from django.conf import settings -from dynaconf.utils import upperfy class Command(BaseCommand): @@ -51,7 +50,7 @@ def format_config_data(self, type, keys, prefix): k = key if prefix in key: k = key[len(prefix):] - v = settings.get(upperfy(key), default=None) + v = settings.get(key, default=None) config["configuration"].update({k: v}) return config From 57aa65fdf03668ecefccbdc3521eda854395dd35 Mon Sep 17 00:00:00 2001 From: Brian McLaughlin Date: Thu, 22 Feb 2024 15:56:34 -0500 Subject: [PATCH 04/10] Update fields to match requirements on authenticators No-Issue --- .../management/commands/dump_auth_config.py | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/galaxy_ng/app/management/commands/dump_auth_config.py b/galaxy_ng/app/management/commands/dump_auth_config.py index 52155fd431..2c478f9cb8 100644 --- a/galaxy_ng/app/management/commands/dump_auth_config.py +++ b/galaxy_ng/app/management/commands/dump_auth_config.py @@ -11,22 +11,23 @@ class Command(BaseCommand): "SOCIAL_AUTH_KEYCLOAK_KEY", "SOCIAL_AUTH_KEYCLOAK_PUBLIC_KEY", "SOCIAL_AUTH_KEYCLOAK_SECRET", - "KEYCLOAK_PROTOCOL", - "KEYCLOAK_HOST", - "KEYCLOAK_PORT", - "KEYCLOAK_REALM", ] LDAP_AUTH_KEYS = [ "AUTH_LDAP_SERVER_URI", "AUTH_LDAP_BIND_DN", "AUTH_LDAP_BIND_PASSWORD", + "AUTH_LDAP_USER_DN_TEMPLATE", + "AUTH_LDAP_USER_SEARCH", "AUTH_LDAP_USER_SEARCH_BASE_DN", "AUTH_LDAP_USER_SEARCH_SCOPE", "AUTH_LDAP_USER_SEARCH_FILTER", + "AUTH_LDAP_GROUP_SEARCH", "AUTH_LDAP_GROUP_SEARCH_BASE_DN", "AUTH_LDAP_GROUP_SEARCH_SCOPE", "AUTH_LDAP_GROUP_SEARCH_FILTER", + "AUTH_LDAP_GROUP_TYPE", + "AUTH_LDAP_GROUP_TYPE_PARAMS", "AUTH_LDAP_USER_ATTR_MAP", ] @@ -41,10 +42,17 @@ def add_arguments(self, parser): help="Output JSON file path", ) + def is_enabled(self, keys): + values = [] + for key in keys: + values.append(settings.get(key, default=None)) + return all(values) + def format_config_data(self, type, keys, prefix): config = { - "type": type, - "configuration": {} + "type": f"galaxy.authentication.authenticator_plugins.{type}", + "enabled": self.is_enabled(keys), + "configuration": {}, } for key in keys: k = key From 72f2ce68f7d4bdb90315875d12e19c702b2d67f6 Mon Sep 17 00:00:00 2001 From: Brian McLaughlin Date: Tue, 27 Feb 2024 16:54:51 -0500 Subject: [PATCH 05/10] Add config for USER_SEARCH, GROUP_SEARCH and GROUP_TYPE No-Issue --- .../management/commands/dump_auth_config.py | 48 ++++++++++++++++--- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/galaxy_ng/app/management/commands/dump_auth_config.py b/galaxy_ng/app/management/commands/dump_auth_config.py index 2c478f9cb8..5d1ffefc58 100644 --- a/galaxy_ng/app/management/commands/dump_auth_config.py +++ b/galaxy_ng/app/management/commands/dump_auth_config.py @@ -5,7 +5,7 @@ class Command(BaseCommand): - KEYCLOAK_AUTH_KEYS = [ + KEYCLOAK_KEYS = [ "SOCIAL_AUTH_KEYCLOAK_ACCESS_TOKEN_URL", "SOCIAL_AUTH_KEYCLOAK_AUTHORIZATION_URL", "SOCIAL_AUTH_KEYCLOAK_KEY", @@ -13,22 +13,21 @@ class Command(BaseCommand): "SOCIAL_AUTH_KEYCLOAK_SECRET", ] - LDAP_AUTH_KEYS = [ + LDAP_KEYS = [ "AUTH_LDAP_SERVER_URI", "AUTH_LDAP_BIND_DN", "AUTH_LDAP_BIND_PASSWORD", "AUTH_LDAP_USER_DN_TEMPLATE", - "AUTH_LDAP_USER_SEARCH", "AUTH_LDAP_USER_SEARCH_BASE_DN", "AUTH_LDAP_USER_SEARCH_SCOPE", "AUTH_LDAP_USER_SEARCH_FILTER", - "AUTH_LDAP_GROUP_SEARCH", "AUTH_LDAP_GROUP_SEARCH_BASE_DN", "AUTH_LDAP_GROUP_SEARCH_SCOPE", "AUTH_LDAP_GROUP_SEARCH_FILTER", - "AUTH_LDAP_GROUP_TYPE", "AUTH_LDAP_GROUP_TYPE_PARAMS", "AUTH_LDAP_USER_ATTR_MAP", + "AUTH_LDAP_CONNECTION_OPTIONS", + "AUTH_LDAP_START_TLS", ] help = "Dump auth config data from database to a JSON file" @@ -48,6 +47,36 @@ def is_enabled(self, keys): values.append(settings.get(key, default=None)) return all(values) + def post_config_ldap(self): + post_config = {} + # Configure USER_SEARCH and GROUP_SEARCH + AUTH_LDAP_USER_SEARCH_BASE_DN = settings.get("AUTH_LDAP_USER_SEARCH_BASE_DN", default=None) + AUTH_LDAP_USER_SEARCH_SCOPE = settings.get("AUTH_LDAP_USER_SEARCH_SCOPE", default=None) + AUTH_LDAP_USER_SEARCH_FILTER = settings.get("AUTH_LDAP_USER_SEARCH_FILTER", default=None) + AUTH_LDAP_GROUP_SEARCH_BASE_DN = settings.get("AUTH_LDAP_GROUP_SEARCH_BASE_DN", default=None) + AUTH_LDAP_GROUP_SEARCH_SCOPE = settings.get("AUTH_LDAP_GROUP_SEARCH_SCOPE", default=None) + AUTH_LDAP_GROUP_SEARCH_FILTER = settings.get("AUTH_LDAP_GROUP_SEARCH_FILTER", default=None) + + post_config["USER_SEARCH"] = [ + AUTH_LDAP_USER_SEARCH_BASE_DN, + AUTH_LDAP_USER_SEARCH_SCOPE, + AUTH_LDAP_USER_SEARCH_FILTER, + ] + + post_config["GROUP_SEARCH"] = [ + AUTH_LDAP_GROUP_SEARCH_BASE_DN, + AUTH_LDAP_GROUP_SEARCH_SCOPE, + AUTH_LDAP_GROUP_SEARCH_FILTER, + ] + + # Configure GROUP_TYPE + post_config["GROUP_TYPE"] = None + AUTH_LDAP_GROUP_TYPE = settings.get("AUTH_LDAP_GROUP_TYPE") + if AUTH_LDAP_GROUP_TYPE: + post_config["GROUP_TYPE"] = type(AUTH_LDAP_GROUP_TYPE).__name__ + + return post_config + def format_config_data(self, type, keys, prefix): config = { "type": f"galaxy.authentication.authenticator_plugins.{type}", @@ -60,6 +89,11 @@ def format_config_data(self, type, keys, prefix): k = key[len(prefix):] v = settings.get(key, default=None) config["configuration"].update({k: v}) + + # handle post configuration for ldap: + if type == "ldap": + config["configuration"].update(self.post_config_ldap()) + return config def handle(self, *args, **options): @@ -70,12 +104,12 @@ def handle(self, *args, **options): data.append( self.format_config_data( "keycloak", - self.KEYCLOAK_AUTH_KEYS, + self.KEYCLOAK_KEYS, "SOCIAL_AUTH_KEYCLOAK_"), ) # Add LDAP auth config - data.append(self.format_config_data("ldap", self.LDAP_AUTH_KEYS, "AUTH_LDAP_")) + data.append(self.format_config_data("ldap", self.LDAP_KEYS, "AUTH_LDAP_")) # Define the path for the output JSON file output_file = options["output_file"] From 925b7b14341766b24b77e2641ab02b0ce333b062 Mon Sep 17 00:00:00 2001 From: Brian McLaughlin Date: Wed, 28 Feb 2024 08:05:29 -0500 Subject: [PATCH 06/10] Lint No-Issue --- .../management/commands/dump_auth_config.py | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/galaxy_ng/app/management/commands/dump_auth_config.py b/galaxy_ng/app/management/commands/dump_auth_config.py index 5d1ffefc58..65d388328d 100644 --- a/galaxy_ng/app/management/commands/dump_auth_config.py +++ b/galaxy_ng/app/management/commands/dump_auth_config.py @@ -53,21 +53,24 @@ def post_config_ldap(self): AUTH_LDAP_USER_SEARCH_BASE_DN = settings.get("AUTH_LDAP_USER_SEARCH_BASE_DN", default=None) AUTH_LDAP_USER_SEARCH_SCOPE = settings.get("AUTH_LDAP_USER_SEARCH_SCOPE", default=None) AUTH_LDAP_USER_SEARCH_FILTER = settings.get("AUTH_LDAP_USER_SEARCH_FILTER", default=None) - AUTH_LDAP_GROUP_SEARCH_BASE_DN = settings.get("AUTH_LDAP_GROUP_SEARCH_BASE_DN", default=None) + AUTH_LDAP_GROUP_SEARCH_BASE_DN = settings.get( + "AUTH_LDAP_GROUP_SEARCH_BASE_DN", + default=None + ) AUTH_LDAP_GROUP_SEARCH_SCOPE = settings.get("AUTH_LDAP_GROUP_SEARCH_SCOPE", default=None) AUTH_LDAP_GROUP_SEARCH_FILTER = settings.get("AUTH_LDAP_GROUP_SEARCH_FILTER", default=None) post_config["USER_SEARCH"] = [ - AUTH_LDAP_USER_SEARCH_BASE_DN, - AUTH_LDAP_USER_SEARCH_SCOPE, - AUTH_LDAP_USER_SEARCH_FILTER, - ] + AUTH_LDAP_USER_SEARCH_BASE_DN, + AUTH_LDAP_USER_SEARCH_SCOPE, + AUTH_LDAP_USER_SEARCH_FILTER, + ] post_config["GROUP_SEARCH"] = [ - AUTH_LDAP_GROUP_SEARCH_BASE_DN, - AUTH_LDAP_GROUP_SEARCH_SCOPE, - AUTH_LDAP_GROUP_SEARCH_FILTER, - ] + AUTH_LDAP_GROUP_SEARCH_BASE_DN, + AUTH_LDAP_GROUP_SEARCH_SCOPE, + AUTH_LDAP_GROUP_SEARCH_FILTER, + ] # Configure GROUP_TYPE post_config["GROUP_TYPE"] = None From d344face213c919233a0e85cbe7712a06d4bb132 Mon Sep 17 00:00:00 2001 From: Brian McLaughlin Date: Fri, 1 Mar 2024 10:20:43 -0500 Subject: [PATCH 07/10] Update command to output to stdout by default, output file if param supplied Added test to verify output No-Issue --- .../management/commands/dump_auth_config.py | 41 +++++---- .../commands/test_dump_auth_config.py | 89 +++++++++++++++++++ 2 files changed, 114 insertions(+), 16 deletions(-) create mode 100644 galaxy_ng/tests/unit/app/management/commands/test_dump_auth_config.py diff --git a/galaxy_ng/app/management/commands/dump_auth_config.py b/galaxy_ng/app/management/commands/dump_auth_config.py index 65d388328d..7c566875e2 100644 --- a/galaxy_ng/app/management/commands/dump_auth_config.py +++ b/galaxy_ng/app/management/commands/dump_auth_config.py @@ -1,5 +1,6 @@ import json import os +import sys from django.core.management.base import BaseCommand from django.conf import settings @@ -17,17 +18,12 @@ class Command(BaseCommand): "AUTH_LDAP_SERVER_URI", "AUTH_LDAP_BIND_DN", "AUTH_LDAP_BIND_PASSWORD", - "AUTH_LDAP_USER_DN_TEMPLATE", "AUTH_LDAP_USER_SEARCH_BASE_DN", "AUTH_LDAP_USER_SEARCH_SCOPE", "AUTH_LDAP_USER_SEARCH_FILTER", "AUTH_LDAP_GROUP_SEARCH_BASE_DN", "AUTH_LDAP_GROUP_SEARCH_SCOPE", "AUTH_LDAP_GROUP_SEARCH_FILTER", - "AUTH_LDAP_GROUP_TYPE_PARAMS", - "AUTH_LDAP_USER_ATTR_MAP", - "AUTH_LDAP_CONNECTION_OPTIONS", - "AUTH_LDAP_START_TLS", ] help = "Dump auth config data from database to a JSON file" @@ -37,7 +33,7 @@ def add_arguments(self, parser): "output_file", nargs="?", type=str, - default="/auth_config.json", + default=None, help="Output JSON file path", ) @@ -49,6 +45,13 @@ def is_enabled(self, keys): def post_config_ldap(self): post_config = {} + # Other required platform params + post_config["USER_ATTR_MAP"] = settings.get("AUTH_LDAP_USER_ATTR_MAP") + post_config["USER_DN_TEMPLATE"] = settings.get("AUTH_LDAP_USER_DN_TEMPLATE") + post_config["GROUP_TYPE_PARAMS"] = settings.get("AUTH_LDAP_GROUP_TYPE_PARAMS") + post_config["CONNECTION_OPTIONS"] = settings.get("AUTH_LDAP_CONNECTION_OPTIONS") + post_config["START_TLS"] = settings.get("AUTH_LDAP_START_TLS") + # Configure USER_SEARCH and GROUP_SEARCH AUTH_LDAP_USER_SEARCH_BASE_DN = settings.get("AUTH_LDAP_USER_SEARCH_BASE_DN", default=None) AUTH_LDAP_USER_SEARCH_SCOPE = settings.get("AUTH_LDAP_USER_SEARCH_SCOPE", default=None) @@ -114,18 +117,24 @@ def handle(self, *args, **options): # Add LDAP auth config data.append(self.format_config_data("ldap", self.LDAP_KEYS, "AUTH_LDAP_")) - # Define the path for the output JSON file - output_file = options["output_file"] + # write to file if requested + if options["output_file"]: + # Define the path for the output JSON file + output_file = options["output_file"] - # Ensure the directory exists - os.makedirs(os.path.dirname(output_file), exist_ok=True) + # Ensure the directory exists + os.makedirs(os.path.dirname(output_file), exist_ok=True) - # Write data to the JSON file - with open(output_file, "w") as f: - json.dump(data, f, indent=4) + # Write data to the JSON file + with open(output_file, "w") as f: + json.dump(data, f, indent=4) + + self.stdout.write( + self.style.SUCCESS(f"Auth config data dumped to {output_file}") + ) + else: + self.stdout.write(json.dumps(data)) - self.stdout.write( - self.style.SUCCESS(f"Auth config data dumped to {output_file}") - ) except Exception as e: self.stdout.write(self.style.ERROR(f"An error occurred: {str(e)}")) + sys.exit(1) diff --git a/galaxy_ng/tests/unit/app/management/commands/test_dump_auth_config.py b/galaxy_ng/tests/unit/app/management/commands/test_dump_auth_config.py new file mode 100644 index 0000000000..2847680f81 --- /dev/null +++ b/galaxy_ng/tests/unit/app/management/commands/test_dump_auth_config.py @@ -0,0 +1,89 @@ +from io import StringIO +import json +import os +from django.core.management import call_command +from django.test import TestCase, modify_settings, override_settings + +@override_settings(SOCIAL_AUTH_KEYCLOAK_ACCESS_TOKEN_URL="ACCESS_TOKEN_URL") +@override_settings(SOCIAL_AUTH_KEYCLOAK_AUTHORIZATION_URL="AUTHORIZATION_URL") +@override_settings(SOCIAL_AUTH_KEYCLOAK_KEY="KEY") +@override_settings(SOCIAL_AUTH_KEYCLOAK_PUBLIC_KEY="PUBLIC_KEY") +@override_settings(SOCIAL_AUTH_KEYCLOAK_SECRET="SECRET") +@override_settings(AUTH_LDAP_SERVER_URI="SERVER_URI") +@override_settings(AUTH_LDAP_BIND_DN="BIND_DN") +@override_settings(AUTH_LDAP_BIND_PASSWORD="BIND_PASSWORD") +@override_settings(AUTH_LDAP_USER_DN_TEMPLATE="USER_DN_TEMPLATE") +@override_settings(AUTH_LDAP_USER_SEARCH_BASE_DN="USER_SEARCH_BASE_DN") +@override_settings(AUTH_LDAP_USER_SEARCH_SCOPE="USER_SEARCH_SCOPE") +@override_settings(AUTH_LDAP_USER_SEARCH_FILTER="USER_SEARCH_FILTER") +@override_settings(AUTH_LDAP_GROUP_SEARCH_BASE_DN="GROUP_SEARCH_BASE_DN") +@override_settings(AUTH_LDAP_GROUP_SEARCH_SCOPE="GROUP_SEARCH_SCOPE") +@override_settings(AUTH_LDAP_GROUP_SEARCH_FILTER="GROUP_SEARCH_FILTER") +@override_settings(AUTH_LDAP_GROUP_TYPE_PARAMS="GROUP_TYPE_PARAMS") +@override_settings(AUTH_LDAP_USER_ATTR_MAP={ + "email": "email", + "last_name": "last_name", + "first_name": "first_name", +}) +@override_settings(AUTH_LDAP_CONNECTION_OPTIONS={}) +@override_settings(AUTH_LDAP_START_TLS=None) +@override_settings(AUTH_LDAP_GROUP_TYPE="string object") +class TestDumpAuthConfigCommand(TestCase): + def setUp(self): + super().setUp() + self.expected_config = [ + { + "type": "galaxy.authentication.authenticator_plugins.keycloak", + "enabled": True, + "configuration": { + "ACCESS_TOKEN_URL": "ACCESS_TOKEN_URL", + "AUTHORIZATION_URL": "AUTHORIZATION_URL", + "KEY": "KEY", + "PUBLIC_KEY": "PUBLIC_KEY", + "SECRET": "SECRET" + } + }, + { + "type": "galaxy.authentication.authenticator_plugins.ldap", + "enabled": True, + "configuration": { + "SERVER_URI": "SERVER_URI", + "BIND_DN": "BIND_DN", + "BIND_PASSWORD": "BIND_PASSWORD", + "USER_SEARCH_BASE_DN": "USER_SEARCH_BASE_DN", + "USER_SEARCH_SCOPE": "USER_SEARCH_SCOPE", + "USER_SEARCH_FILTER": "USER_SEARCH_FILTER", + "GROUP_SEARCH_BASE_DN": "GROUP_SEARCH_BASE_DN", + "GROUP_SEARCH_SCOPE": "GROUP_SEARCH_SCOPE", + "GROUP_SEARCH_FILTER": "GROUP_SEARCH_FILTER", + "USER_ATTR_MAP": { + "email": "email", + "last_name": "last_name", + "first_name": "first_name" + }, + "USER_DN_TEMPLATE": "USER_DN_TEMPLATE", + "GROUP_TYPE_PARAMS": "GROUP_TYPE_PARAMS", + "CONNECTION_OPTIONS": {}, + "START_TLS": None, + "USER_SEARCH": [ + "USER_SEARCH_BASE_DN", + "USER_SEARCH_SCOPE", + "USER_SEARCH_FILTER" + ], + "GROUP_SEARCH": [ + "GROUP_SEARCH_BASE_DN", + "GROUP_SEARCH_SCOPE", + "GROUP_SEARCH_FILTER" + ], + "GROUP_TYPE": "str" + } + } + ] + def test_json_returned_from_cmd(self): + output = StringIO() + call_command("dump_auth_config", stdout=output) + + print(f"expected_config json dumped:\n{json.dumps(self.expected_config)}") + print(f"output.getvalue():\n{output.getvalue().rstrip()}") + + assert output.getvalue().rstrip() == json.dumps(self.expected_config) From ee41a88ad9b8627984b3b80514aa27a26c58d525 Mon Sep 17 00:00:00 2001 From: Brian McLaughlin Date: Fri, 1 Mar 2024 10:23:09 -0500 Subject: [PATCH 08/10] Rename management command (_ to -) for consistency No-Issue --- .../commands/{dump_auth_config.py => dump-auth-config.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename galaxy_ng/app/management/commands/{dump_auth_config.py => dump-auth-config.py} (100%) diff --git a/galaxy_ng/app/management/commands/dump_auth_config.py b/galaxy_ng/app/management/commands/dump-auth-config.py similarity index 100% rename from galaxy_ng/app/management/commands/dump_auth_config.py rename to galaxy_ng/app/management/commands/dump-auth-config.py From e0c0b73cc879fd2af0cb130515d28b372d1cdbfa Mon Sep 17 00:00:00 2001 From: Brian McLaughlin Date: Fri, 1 Mar 2024 10:28:48 -0500 Subject: [PATCH 09/10] Update call to renamed management command Remove print statements No-Issue --- .../unit/app/management/commands/test_dump_auth_config.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/galaxy_ng/tests/unit/app/management/commands/test_dump_auth_config.py b/galaxy_ng/tests/unit/app/management/commands/test_dump_auth_config.py index 2847680f81..9b3a966ace 100644 --- a/galaxy_ng/tests/unit/app/management/commands/test_dump_auth_config.py +++ b/galaxy_ng/tests/unit/app/management/commands/test_dump_auth_config.py @@ -81,9 +81,5 @@ def setUp(self): ] def test_json_returned_from_cmd(self): output = StringIO() - call_command("dump_auth_config", stdout=output) - - print(f"expected_config json dumped:\n{json.dumps(self.expected_config)}") - print(f"output.getvalue():\n{output.getvalue().rstrip()}") - + call_command("dump-auth-config", stdout=output) assert output.getvalue().rstrip() == json.dumps(self.expected_config) From eae172c66b06584c46df2f5d88d46e45887c20dc Mon Sep 17 00:00:00 2001 From: Brian McLaughlin Date: Fri, 1 Mar 2024 11:15:44 -0500 Subject: [PATCH 10/10] Lint No-Issue --- .../unit/app/management/commands/test_dump_auth_config.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/galaxy_ng/tests/unit/app/management/commands/test_dump_auth_config.py b/galaxy_ng/tests/unit/app/management/commands/test_dump_auth_config.py index 9b3a966ace..d865f9a51a 100644 --- a/galaxy_ng/tests/unit/app/management/commands/test_dump_auth_config.py +++ b/galaxy_ng/tests/unit/app/management/commands/test_dump_auth_config.py @@ -1,8 +1,8 @@ from io import StringIO import json -import os from django.core.management import call_command -from django.test import TestCase, modify_settings, override_settings +from django.test import TestCase, override_settings + @override_settings(SOCIAL_AUTH_KEYCLOAK_ACCESS_TOKEN_URL="ACCESS_TOKEN_URL") @override_settings(SOCIAL_AUTH_KEYCLOAK_AUTHORIZATION_URL="AUTHORIZATION_URL") @@ -79,6 +79,7 @@ def setUp(self): } } ] + def test_json_returned_from_cmd(self): output = StringIO() call_command("dump-auth-config", stdout=output)