Coverage for curator/defaults/filter_elements.py: 98%
87 statements
« prev ^ index » next coverage.py v7.3.0, created at 2023-08-16 15:27 -0600
« prev ^ index » next coverage.py v7.3.0, created at 2023-08-16 15:27 -0600
1"""Filter element schema definitions"""
2from six import string_types
3from voluptuous import All, Any, Boolean, Coerce, Optional, Range, Required
4from curator.defaults import settings
6# pylint: disable=missing-docstring
8### Schema information ###
10def aliases(**kwargs):
11 # This setting is used by the alias filtertype and is required
12 return {Required('aliases'): Any(list, *string_types)}
14def allocation_type(**kwargs):
15 return {Optional('allocation_type', default='require'): All(
16 Any(*string_types), Any('require', 'include', 'exclude'))}
18def count(**kwargs):
19 # This setting is only used with the count filtertype and is required
20 return {Required('count'): All(Coerce(int), Range(min=1))}
22def date_from(**kwargs):
23 # This setting is only used with the period filtertype.
24 return {Optional('date_from'): Any(*string_types)}
26def date_from_format(**kwargs):
27 # This setting is only used with the period filtertype.
28 return {Optional('date_from_format'): Any(*string_types)}
30def date_to(**kwargs):
31 # This setting is only used with the period filtertype.
32 return {Optional('date_to'): Any(*string_types)}
34def date_to_format(**kwargs):
35 # This setting is only used with the period filtertype.
36 return {Optional('date_to_format'): Any(*string_types)}
38def direction(**kwargs):
39 # This setting is only used with the age filtertype.
40 return {Required('direction'): Any('older', 'younger')}
42def disk_space(**kwargs):
43 # This setting is only used with the space filtertype and is required
44 return {Required('disk_space'): Any(Coerce(float))}
46def epoch(**kwargs):
47 # This setting is only used with the age filtertype.
48 return {Optional('epoch', default=None): Any(Coerce(int), None)}
50def exclude(**kwargs):
51 # pylint: disable=E1120
52 # This setting is available in all filter types.
53 if 'exclude' in kwargs and kwargs['exclude']:
54 val = True
55 else: # False by default
56 val = False
57 return {Optional('exclude', default=val): Any(bool, All(Any(*string_types), Boolean()))}
59def field(**kwargs):
60 # This setting is only used with the age filtertype.
61 if 'required' in kwargs and kwargs['required']:
62 return {Required('field'): Any(*string_types)}
63 else:
64 return {Optional('field'): Any(*string_types)}
66def intersect(**kwargs):
67 # pylint: disable=E1120
68 # This setting is only used with the period filtertype when using field_stats
69 # i.e. indices only.
70 return {Optional('intersect', default=False): Any(bool, All(Any(*string_types), Boolean()))}
72def key(**kwargs):
73 # This setting is only used with the allocated filtertype.
74 return {Required('key'): Any(*string_types)}
76def kind(**kwargs):
77 # This setting is only used with the pattern filtertype and is required
78 return {
79 Required('kind'): Any('prefix', 'suffix', 'timestring', 'regex')
80 }
82def max_num_segments(**kwargs):
83 return {
84 Required('max_num_segments'): All(Coerce(int), Range(min=1))
85 }
87def number_of_shards(**kwargs):
88 return {
89 Required('number_of_shards'): All(Coerce(int), Range(min=1))
90 }
92def pattern(**kwargs):
93 return {
94 Optional('pattern'): Any(*string_types)
95 }
97def period_type(**kwargs):
98 # This setting is only used with the period filtertype.
99 return {Optional('period_type', default='relative'): Any('relative', 'absolute')}
101def range_from(**kwargs):
102 return {Optional('range_from'): Coerce(int)}
104def range_to(**kwargs):
105 return {Optional('range_to'): Coerce(int)}
107def reverse(**kwargs):
108 # pylint: disable=E1120
109 # Only used with space filtertype
110 # Should be ignored if `use_age` is True
111 return {Optional('reverse', default=True): Any(bool, All(Any(*string_types), Boolean()))}
113def shard_filter_behavior(**kwargs):
114 # This setting is only used with the shards filtertype and defaults to 'greater_than'.
115 return {
116 Optional('shard_filter_behavior', default='greater_than'):
117 Any('greater_than', 'less_than', 'greater_than_or_equal', 'less_than_or_equal', 'equal')
118 }
120def source(**kwargs):
121 # This setting is only used with the age filtertype, or with the space
122 # filtertype when use_age is set to True.
123 if 'action' in kwargs and kwargs['action'] in settings.snapshot_actions():
124 valuelist = Any('name', 'creation_date')
125 else:
126 valuelist = Any('name', 'creation_date', 'field_stats')
128 if 'required' in kwargs and kwargs['required']:
129 return {Required('source'): valuelist}
130 else:
131 return {Optional('source'): valuelist}
133def state(**kwargs):
134 # This setting is only used with the state filtertype.
135 return {Optional('state', default='SUCCESS'): Any(
136 'SUCCESS', 'PARTIAL', 'FAILED', 'IN_PROGRESS')}
138def stats_result(**kwargs):
139 # This setting is only used with the age filtertype.
140 return {
141 Optional('stats_result', default='min_value'): Any(
142 'min_value', 'max_value')
143 }
145def timestring(**kwargs):
146 # This setting is only used with the age filtertype, or with the space
147 # filtertype if use_age is set to True.
148 if 'required' in kwargs and kwargs['required']:
149 return {Required('timestring'): Any(*string_types)}
150 else:
151 return {Optional('timestring', default=None): Any(None, *string_types)}
153def threshold_behavior(**kwargs):
154 # This setting is only used with the space and size filtertype and defaults to 'greater_than'.
155 return {
156 Optional('threshold_behavior', default='greater_than'): Any('greater_than', 'less_than')
157 }
159def unit(**kwargs):
160 # This setting is only used with the age filtertype, or with the space
161 # filtertype if use_age is set to True.
162 return {
163 Required('unit'): Any(
164 'seconds', 'minutes', 'hours', 'days', 'weeks', 'months', 'years'
165 )
166 }
168def unit_count(**kwargs):
169 # This setting is only used with the age filtertype, or with the space
170 # filtertype if use_age is set to True.
171 return {Required('unit_count'): Coerce(int)}
173def unit_count_pattern(**kwargs):
174 # This setting is used with the age filtertype to define, whether
175 # the unit_count value is taken from the configuration or read from
176 # the index name via a regular expression
177 return {Optional('unit_count_pattern'): Any(*string_types)}
179def use_age(**kwargs):
180 # pylint: disable=E1120
181 # Use of this setting requires the additional setting, source.
182 return {Optional('use_age', default=False): Any(bool, All(Any(*string_types), Boolean()))}
184def value(**kwargs):
185 # This setting is only used with the pattern filtertype and is a required
186 # setting. There is a separate value option associated with the allocation
187 # action, and the allocated filtertype.
188 return {Required('value'): Any(*string_types)}
190def week_starts_on(**kwargs):
191 return {
192 Optional('week_starts_on', default='sunday'): Any(
193 'Sunday', 'sunday', 'SUNDAY', 'Monday', 'monday', 'MONDAY', None
194 )
195 }
197def size_threshold(**kwargs):
198 # This setting is only used with the size filtertype and is required
199 return { Required('size_threshold'): Any(Coerce(float)) }
201def size_behavior(**kwargs):
202 # This setting is only used with the size filtertype and defaults to 'primary'.
203 return {
204 Optional('size_behavior', default='primary'): Any('primary', 'total')
205 }