mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00:00
Error if a module is found to shadow a reserved keyword (#34649)
* Error if a module is found to shadow a reserved keyword * Add test for shadowed module * Bring in functools.wraps for the decorator * Drop the decorator, make _find_plugin the real function, find_plugin now holds the shadow logic * Swap order of functions for bottom to top execution order * Only error for modules * Add test for loading a lookup plugin that shadows a keyword
This commit is contained in:
@@ -232,7 +232,7 @@ class PluginLoader:
|
||||
self._paths = None
|
||||
display.debug('Added %s to loader search path' % (directory))
|
||||
|
||||
def find_plugin(self, name, mod_type='', ignore_deprecated=False, check_aliases=False):
|
||||
def _find_plugin(self, name, mod_type='', ignore_deprecated=False, check_aliases=False):
|
||||
''' Find a plugin named name '''
|
||||
|
||||
global _PLUGIN_FILTERS
|
||||
@@ -322,6 +322,20 @@ class PluginLoader:
|
||||
|
||||
return None
|
||||
|
||||
def find_plugin(self, name, mod_type='', ignore_deprecated=False, check_aliases=False):
|
||||
''' Find a plugin named name '''
|
||||
|
||||
# Import here to avoid circular import
|
||||
from ansible.vars.reserved import is_reserved_name
|
||||
|
||||
plugin = self._find_plugin(name, mod_type=mod_type, ignore_deprecated=ignore_deprecated, check_aliases=check_aliases)
|
||||
if plugin and self.package == 'ansible.modules' and is_reserved_name(name):
|
||||
raise AnsibleError(
|
||||
'Module "%s" shadows the name of a reserved keyword. Please rename or remove this module. Found at %s' % (name, plugin)
|
||||
)
|
||||
|
||||
return plugin
|
||||
|
||||
def has_plugin(self, name):
|
||||
''' Checks if a plugin named name exists '''
|
||||
|
||||
|
||||
@@ -77,4 +77,8 @@ def warn_if_reserved(myvars):
|
||||
display.warning('Found variable using reserved name: %s' % varname)
|
||||
|
||||
|
||||
def is_reserved_name(name):
|
||||
return name in _RESERVED_NAMES
|
||||
|
||||
|
||||
_RESERVED_NAMES = frozenset(get_reserved_names())
|
||||
|
||||
Reference in New Issue
Block a user