From 4b3d32f0950e1cac9dab5ae1d1f29f5a020a05bb Mon Sep 17 00:00:00 2001 From: Lila Date: Tue, 22 Oct 2024 11:33:30 -0400 Subject: [PATCH] Create third dictionary to preserve current functionality and add file there --- awx/api/serializers.py | 4 ++-- awx/main/utils/plugins.py | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 238e2fb06e6a..8a91f2c124d2 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -120,7 +120,7 @@ ) from awx.main.utils.filters import SmartFilter -from awx.main.utils.plugins import compute_cloud_inventory_sources +from awx.main.utils.plugins import return_inventory_source_options from awx.main.utils.named_url_graph import reset_counters from awx.main.scheduler.task_manager_models import TaskManagerModels from awx.main.redact import UriCleaner, REPLACE_STR @@ -2326,7 +2326,7 @@ class Meta: def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) if 'source' in self.fields: - self.fields['source'].choices = compute_cloud_inventory_sources() or {} + self.fields['source'].choices = return_inventory_source_options() or {} def get_related(self, obj): res = super(InventorySourceOptionsSerializer, self).get_related(obj) diff --git a/awx/main/utils/plugins.py b/awx/main/utils/plugins.py index be10b13d3741..6ceb0fc45938 100644 --- a/awx/main/utils/plugins.py +++ b/awx/main/utils/plugins.py @@ -30,7 +30,7 @@ def discover_available_cloud_provider_plugin_names() -> list[str]: @cache def compute_cloud_inventory_sources() -> dict[str, str]: """Return a dictionary of cloud provider plugin names - available plus source control management. + available plus source control management and constructed. :returns: Dictionary of plugin cloud names plus source control. :rtype: dict[str, str] @@ -38,4 +38,18 @@ def compute_cloud_inventory_sources() -> dict[str, str]: plugins = discover_available_cloud_provider_plugin_names() - return dict(zip(plugins, plugins), file='file', scm='scm', constructed='constructed') + return dict(zip(plugins, plugins), scm='scm', constructed='constructed') + + +@cache +def return_inventory_source_options() -> dict[str, str]: + """Return a dictionary of cloud provider plugin names + plus file. File needed to be separate since it is needs to be consumed directly + by the serializer. + + :returns: Dictionary of plugin cloud names plus source control. + :rtype: dict[str, str] + """ + plugins = compute_cloud_inventory_sources() + + return dict(zip(plugins, plugins)) | dict(file='file')