Skip to content

Commit

Permalink
Add descriptions for plugin names (#15643)
Browse files Browse the repository at this point in the history
* Add descriptions for plugin names

* Update serializers to display plugin and plugin description

* Add function to extract plugin name descriptions

* Add description for scm

* Conditionalize scm and file descriptions
  • Loading branch information
djyasin authored Nov 25, 2024
1 parent 790875c commit 4bbcb34
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
5 changes: 4 additions & 1 deletion awx/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2325,8 +2325,11 @@ class Meta:

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

if 'source' in self.fields:
self.fields['source'].choices = load_combined_inventory_source_options()
source_options = load_combined_inventory_source_options()

self.fields['source'].choices = [(plugin, description) for plugin, description in source_options.items()]

def get_related(self, obj):
res = super(InventorySourceOptionsSerializer, self).get_related(obj)
Expand Down
30 changes: 29 additions & 1 deletion awx/main/utils/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ def compute_cloud_inventory_sources() -> dict[str, str]:
return dict(zip(plugins, plugins), scm='scm', constructed='constructed')


@cache
def discover_available_cloud_provider_descriptions() -> dict[str, str]:
"""
Return a dictionary of cloud provider plugin descriptions
available.
:returns: Dictionary of plugin cloud descriptions.
:rtype: dict[str, str]
"""
from awx.main.models.inventory import InventorySourceOptions

plugin_description_list = [(plugin_name, plugin.plugin_description) for plugin_name, plugin in InventorySourceOptions.injectors.items()]

plugin_description = dict(plugin_description_list)

return plugin_description


@cache
def load_combined_inventory_source_options() -> dict[str, str]:
"""
Expand All @@ -56,4 +74,14 @@ def load_combined_inventory_source_options() -> dict[str, str]:

plugins = compute_cloud_inventory_sources()

return dict(zip(plugins, plugins), file='file')
plugin_description = discover_available_cloud_provider_descriptions()

if 'scm' in plugins:
plugin_description['scm'] = 'Sourced from a Project'

if 'file' in plugins:
plugin_description['file'] = 'File-based inventory source'

result = {plugin: plugin_description.get(plugin, plugin) for plugin in plugins}

return result

0 comments on commit 4bbcb34

Please sign in to comment.