-
Notifications
You must be signed in to change notification settings - Fork 438
[Tooling] Add --exclude flag to Generator to support field removal testing #1411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
76ab51e
commit with example test files, to be removed at a later date
a407d11
Merge branch 'master' into exclude_set
2cc6523
tbc changelog message
b530f5b
update PR
071bb63
fixed regression
b3f5bf7
reorder imports
c23266c
make comments more consistent
1174813
make comments more consistent
8c9eb53
refactor add exclude_filter.py
7305ea2
simplified console messages
853b0c3
simplify console messages
b787790
Merge branch 'master' into exclude_set
djptek 8d91616
separated calls to subsetfulter exclude_filter for clarity
14e05a7
added trailing newlines to test files
6cdbcd0
removed fake test files
fead411
refactor - move shared defs from subset to loader
cbd45c3
refactor - move warn to loader
30f88b5
moved test_eval_globs to loader unit tests
d17e7b1
moved test_eval_globs to loader unit tests
20bc1a5
add test_schema_exclude_filter
8764112
test_load_exclude_definitions_raises_when_no_exclude_found
29b56b6
added test_exclude_field
f32b83c
added test_exclude_fields
17c62ef
added test_exclude_non_existing_field_set
c8c1c70
added test_exclude_non_existing_field
90f0b5f
added test_exclude_field_deep_path
c5a7a2a
adding test_exclude_non_existing_field_deep_path
a196562
WIP - test_exclude_field_deep_path is failing
9128f6e
resolved test_exclude_field_deep_path
ed1e18b
Merge branch 'master' into exclude_set
djptek 2dab2af
remove print statement
c0a97c7
Merge branch 'master' into exclude_set
3e65530
Merge branch 'master' into exclude_set
djptek fa1a9e7
Merge branch 'exclude_set' of https://github.com/djptek/ecs into excl…
e52c94f
Merge branch 'master' into exclude_set
2e5abb0
normalize use of 3xdouble quote in comments
8488069
removed exclude-set.yml
3972bea
update USAGE and add dot paths
6782f67
add test_exclude_field_dot_path test_exclude_field_base_always_persists
a17bc29
update tests to reflect delete vestigial parent
c1a57c6
fix #1426 thanks @ebeahan
da24cc5
fix comment
847a0bc
remove unused imports
b66d63e
remove unused imports part 2
f1750a7
removed unused imports the gift that just keeps giving
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from schema import loader | ||
|
||
# This script should be run downstream of the subset filters - it takes | ||
# all ECS and custom fields already loaded by the latter and explicitly | ||
# removes a subset, for example, to simulate impact of future removals | ||
|
||
|
||
def exclude(fields, exclude_file_globs): | ||
excludes = load_exclude_definitions(exclude_file_globs) | ||
|
||
if excludes: | ||
fields = exclude_fields(fields, excludes) | ||
|
||
return fields | ||
|
||
|
||
def long_path(path_as_list): | ||
return '.'.join([e for e in path_as_list]) | ||
|
||
|
||
def pop_field(fields, node_path, path, removed): | ||
"""pops a field from yaml derived dict using path derived from ordered list of nodes""" | ||
if node_path[0] in fields: | ||
if len(node_path) == 1: | ||
flat_name = long_path(path) | ||
fields.pop(node_path[0]) | ||
return flat_name | ||
else: | ||
inner_field = node_path.pop(0) | ||
if 'fields' in fields[inner_field]: | ||
popped = pop_field(fields[inner_field]['fields'], node_path, path, removed) | ||
# if object field with no remaining fields and not 'base', pop it | ||
if fields[inner_field]['fields'] == {} and inner_field != 'base': | ||
fields.pop(inner_field) | ||
return popped | ||
else: | ||
raise ValueError( | ||
'--exclude specified, but no path to field {} found'.format(long_path(path))) | ||
else: | ||
this_long_path = long_path(path) | ||
# Check in case already removed parent | ||
if not any([this_long_path.startswith(long_path) for long_path in removed if long_path != None]): | ||
raise ValueError('--exclude specified, but no field {} found'.format(this_long_path)) | ||
|
||
|
||
def exclude_trace_path(fields, item, path, removed): | ||
"""traverses paths to one or more nodes in a yaml derived dict""" | ||
for list_item in item: | ||
node_path = path.copy() | ||
# cater for name.with.dots | ||
for name in list_item['name'].split('.'): | ||
node_path.append(name) | ||
if not 'fields' in list_item: | ||
parent = node_path[0] | ||
removed.append(pop_field(fields, node_path, node_path.copy(), removed)) | ||
# if parent field has no remaining fields and not 'base', pop it | ||
if parent != 'base' and parent in fields and len(fields[parent]['fields']) == 0: | ||
fields.pop(parent) | ||
else: | ||
raise ValueError('--exclude specified, can\'t parse fields in file {}'.format(item)) | ||
|
||
|
||
def exclude_fields(fields, excludes): | ||
"""Traverses fields and eliminates any field which matches the excludes""" | ||
if excludes: | ||
for ex_list in excludes: | ||
for item in ex_list: | ||
exclude_trace_path(fields, item['fields'], [item['name']], []) | ||
return fields | ||
|
||
|
||
def load_exclude_definitions(file_globs): | ||
if not file_globs: | ||
return [] | ||
excludes = loader.load_definitions(file_globs) | ||
if not excludes: | ||
raise ValueError('--exclude specified, but no exclusions found in {}'.format(file_globs)) | ||
return excludes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.