in curator/helpers/utils.py [0:0]
def multitarget_fix(pattern: str) -> str:
"""
If pattern only has '-' prefixed entries (excludes)
prepend a wildcard to pattern
:param pattern: The Elasticsearch multi-target syntax pattern
:type pattern: str
:returns: The pattern, possibly with a wildcard prepended
:rtype: str
"""
# Split pattern into elements
elements = pattern.split(',')
if len(elements) == 1 and elements[0] == '':
return '*'
# Initialize positive and negative lists
positives = []
negatives = []
# Loop through elements and sort them into positive and negative lists
for element in elements:
if element.startswith('-'):
negatives.append(element)
else:
positives.append(element)
# If there are no positive elements, but there are negative elements,
# add a wildcard to the beginning of the pattern
if len(positives) == 0 and len(negatives) > 0:
logger.debug(
"Only negative elements in pattern. Adding '*' so there's something "
" to remove"
)
return '*,' + pattern
# Otherwise, return the original pattern
return pattern