def _age_elements()

in curator/defaults/filtertypes.py [0:0]


def _age_elements(action, config):
    """
    Sort which filter types that have ``use_age`` are suitable for
    :py:class:`~.curator.IndexList` and which are acceptable in
    :py:class:`~.curator.SnapshotList`, which are required, and which are not.

    :param action: The name of an action
    :type action: str
    :param config: The configuration block for one filter of ``action``
    :type config: dict

    :returns: A :py:class:`list` containing one or more
        :py:class:`~.voluptuous.schema_builder.Optional` or
        :py:class:`~.voluptuous.schema_builder.Required` options from
        :py:mod:`~.curator.defaults.filter_elements`, defining acceptable values
        for each for the given ``action``
    :rtype: list
    """
    retval = []
    is_req = True
    if config['filtertype'] in ['count', 'space']:
        # is_req = True if 'use_age' in config and config['use_age'] else False
        is_req = bool('use_age' in config and config['use_age'])
    retval.append(filter_elements.source(action=action, required=is_req))
    if action in settings.index_actions():
        retval.append(filter_elements.stats_result())
    # This is a silly thing here, because the absence of 'source' will
    # show up in the actual schema check, but it keeps code from breaking here
    ts_req = False
    if 'source' in config:
        if config['source'] == 'name':
            ts_req = True
        elif action in settings.index_actions():
            # field_stats must _only_ exist for Index actions (not Snapshot)
            if config['source'] == 'field_stats':
                retval.append(filter_elements.field(required=True))
            else:
                retval.append(filter_elements.field(required=False))
        retval.append(filter_elements.timestring(required=ts_req))
    else:
        # If source isn't in the config, then the other elements are not
        # required, but should be Optional to prevent false positives
        retval.append(filter_elements.field(required=False))
        retval.append(filter_elements.timestring(required=ts_req))
    return retval