Skip to content

Commit

Permalink
Add selective bulk fetcher execution (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
alfinkel authored Nov 20, 2020
1 parent 3312a59 commit 8595dbb
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# [1.8.0](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v1.8.0)

- [ADDED] Selective fetcher bulk `--include` and `--exclude` execution is now possible.

# [1.7.2](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v1.7.2)

- [FIXED] LazyLoader namedtuple defaults removed; Framework compatible with Python 3.6 again.
Expand Down
2 changes: 1 addition & 1 deletion compliance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
# limitations under the License.
"""Compliance automation package."""

__version__ = '1.7.2'
__version__ = '1.8.0'
14 changes: 13 additions & 1 deletion compliance/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""Compliance automation flow management module."""

import inspect
import json
import os
import re
import sys
Expand Down Expand Up @@ -180,7 +181,18 @@ def get_fetchers(self):
self.load_errors.add(load_err)
except AttributeError:
pass
return fetchers
if not (self.opts.include or self.opts.exclude):
return fetchers
include = {f'{f.__module__}.{f.__name__}' for f in fetchers}
if self.opts.include:
include = set(json.loads(open(self.opts.include).read()))
exclude = set()
if self.opts.exclude:
exclude = set(json.loads(open(self.opts.exclude).read()))
return filter(
lambda f: f'{f.__module__}.{f.__name__}' in include - exclude,
fetchers
)

def run_fetchers(self, reruns=None):
"""
Expand Down
16 changes: 16 additions & 0 deletions compliance/scripts/compliance_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ def _init_arguments(self):
action='append',
default=[]
)
self.add_argument(
'--include',
help='Specifies the path/name of the fetcher include JSON file.',
metavar='fetchers.json',
default=None
)
self.add_argument(
'--exclude',
help='Specifies the path/name of the fetcher exclude JSON file.',
metavar='fetchers.json',
default=None
)

def _validate_arguments(self, args):
if 'stdout' not in args.notify:
Expand All @@ -117,6 +129,10 @@ def _validate_arguments(self, args):
)
if not args.fetch and not args.check:
self.parser.error('--fetch or --check option is expected.')
if not args.fetch and (args.include or args.exclude):
self.parser.error(
'--include/--exclude options only valid with --fetch.'
)
if not args.check and args.fix != 'off':
self.parser.error('--fix option only valid with --check.')

Expand Down
17 changes: 14 additions & 3 deletions doc-source/design-principles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,20 @@ due to an unavailable evidence dependency.
Fetcher Execution
=================

The Auditree framework will run all fetchers (tests prefixed by ``fetch_``)
that it can find.

By default the Auditree framework will run all fetchers (tests prefixed by
``fetch_``) that it can find. However, it is possible to limit fetcher
execution in bulk by using the ``--include`` and/or ``exclude`` CLI options
while providing a file path/name to a JSON config file containing a list of
fetchers to include/exclude. The format of the JSON config file is a list of
fetcher classes. Where a fetcher class is represented as a string dot notation
path to the fetcher class.

Fetcher include/exclude JSON config file example::

[
"fetcher_pkg.path_to_my_checks.checks.fetch_module_foo.FooFetcherClass",
"fetcher_pkg.path_to_my_checks.checks.fetch_module_bar.BarFetcherClass"
]

Compliance Checks
~~~~~~~~~~~~~~~~~
Expand Down

0 comments on commit 8595dbb

Please sign in to comment.