compliance package¶
Subpackages¶
Submodules¶
compliance.agent module¶
Compliance check automation module.
- class compliance.agent.ComplianceAgent(name=None, use_agent_dir=True)[source]¶
Bases:
object
Compliance agent class.
- AGENTS_DIR = 'agents'¶
- PUBLIC_KEYS_EVIDENCE_PATH = 'raw/auditree/agent_public_keys.json'¶
- get_path(path)[source]¶
Get the full evidence path.
- Parameters:
path – The relative evidence path as a string.
- Returns:
The full evidence path as a string.
- hash_and_sign(data_bytes)[source]¶
Hash and sign evidence using the agent private key.
- Parameters:
data_bytes – The data to sign as bytes.
- Returns:
A tuple containing the hexadecimal digest string and the base64 encoded signature string. Returns tuple (None, None) if the agent is not configured to sign evidence.
- load_public_key_from_locker(locker)[source]¶
Load agent public key from locker.
- Parameters:
locker – A locker of type
compliance.locker.Locker
.
- property name¶
Get agent name.
- property private_key¶
Get agent private key.
- property public_key¶
Get agent public key.
compliance.check module¶
Compliance check automation module.
- class compliance.check.ComplianceCheck(*args, **kwargs)[source]¶
Bases:
TestCase
Compliance check automation TestCase class.
- add_evidence_metadata(evidence_path, evidence_dt=None, evidence_locker=None)[source]¶
Add evidence metadata to the evidence_metadata property of each check.
- Parameters:
evidence_path – the evidence path.
evidence_dt – the evidence date.
evidence_locker – the locker the evidence was retrieved from. Use when historical evidence is found in a secondary locker.
- add_failures(section_key, section_value)[source]¶
Add failures for each check.
- Param:
section_key: key for the failures.
- Param:
section_value: all the failures for that key.
- add_issue_if_diff(actual, expected, msg, as_warning=False)[source]¶
Add failures/warnings if differences exist between actual and expected.
- Parameters:
actual – the “actual” set items.
expected – the “expected” set items.
msg – the section key used if differences are found.
as_warning – warn if True, fail if False.
- add_successes(section_key, section_value)[source]¶
Add successes for each check.
- Param:
section_key: key for the successes.
- Param:
section_value: all the successes for that key.
- add_warnings(section_key, section_value)[source]¶
Add warnings for each check.
- Param:
section_key: key for the warnings.
- Param:
section_value: all the warnings for that key.
- assertEquals(first, second, msg=None)¶
Fail if the two objects are unequal as determined by the ‘==’ operator.
- property evidence_metadata¶
Metadata of all evidence used by each check as a property.
- evidences_for_check(results)[source]¶
Provide evidences used by all tests in the check.
- Parameters:
results – contains all the test results.
- property failures¶
Failures as a property for each check.
- failures_for_check(results)[source]¶
Provide failures associated with all tests in the check.
- Parameters:
results – contains all the test results.
- failures_for_check_count(results)[source]¶
Count failures for all tests in check.
- Parameters:
results – contains all the test results.
- property fixed_failure_count¶
Count of failures fixed by the fix routine.
- get_historical_evidence(evidence_path, evidence_dt)[source]¶
Retrieve historical evidence from the locker and track as metadata.
- Parameters:
evidence_path – the evidence path.
evidence_dt – the evidence date.
- property reports¶
List of the check reports.
- run(result=None)[source]¶
Override the unittest.TestCase.run method.
Decorates
test_
methods by adding common functionality (e.g. failures count check).
- property runbook_url¶
Runbook URL associated with the check.
If runbook links are enabled in the configuration, the value returned is based on the runbook base URL and the check’s class name. It is assumed that the runbook exists and is in HTML format.
- property successes¶
Successes as a property for each check.
- successes_for_check(results)[source]¶
Provide successes associated with all tests in the check.
- Parameters:
results – contains all the test results.
- successes_for_check_count(results)[source]¶
Count successes for all tests in check.
- Parameters:
results – contains all the test results.
- property title¶
Check title, normally used in check reports.
- total_issues_count(results)[source]¶
Total number of issues as property for the check.
- Parameters:
results – contains all the test results.
- property warnings¶
Warnings as a property for each check.
compliance.config module¶
Compliance configuration automation module.
- class compliance.config.ComplianceConfig[source]¶
Bases:
object
The configuration for a compliance run.
Credentials and a cache of known evidences are included.
- DEFAULTS = {'locker': {'dirname': 'compliance', 'repo_url': 'https://github.com/YOUR_ORG/YOUR_PROJECT'}, 'notify': {'gh_issues': {}, 'ghe_issues': {}, 'pagerduty': {}, 'slack': {}}, 'org': {'name': 'YOUR_ORG', 'settings': {}}, 'runbooks': {'base_url': 'https://example.com/runbooks', 'enabled': False}}¶
- add_evidences(evidence_list)[source]¶
Add a list of evidence objects to the evidence cache.
- Parameters:
evidence_list – a list of evidence objects.
- property creds¶
Credentials used for locker management and running fetchers.
- property evidences¶
All evidence objects currently in the evidence cache.
- get(config_path, default=None)[source]¶
Provide the configuration value for the supplied
config_path
.Returns the default if
config_path
cannot be retrieved.- Parameters:
config_path – dot notation path with the following format
'key[.subkey]
. For instance,locker.dirname
.
- get_evidence(evidence_path)[source]¶
Provide an evidence object from the evidence cache.
- Parameters:
path – the path to the evidence within the Locker. For example,
raw/source1/evidence.json
- get_template_dir(test_obj=None)[source]¶
Provide absolute path to the template directory for the test object.
The associated path will be the first directory found named
templates
in the test object absolute path traversed in reverse. Iftest_obj
isNone
, then current directory'.'
is assumed as initial path.- Parameters:
test_obj – a
compliance.ComplianceTest
object from where the template directory search will start from.
- load(config_file=None)[source]¶
Load configuration from a JSON file.
- Parameters:
config_file – the path to the JSON config file. If
None
, theDEFAULT
configuration is used.
- property raw_config¶
Raw configuration settings as a dictionary.
compliance.controls module¶
Compliance check controls automation module.
- class compliance.controls.ControlDescriptor(dirs=None)[source]¶
Bases:
object
Class abstraction for controls.json content.
Used when processing controls.json content.
- property accred_checks¶
Provide all checks by accreditation (key) as a dictionary.
- property as_dict¶
Provide control descriptor content as a modifiable dictionary.
- get_accreditations(test_path)[source]¶
Provide the accreditation list for a given test_path.
This works for original and simplified controls formats.
Original: {‘test_path’: {‘key’: {‘sub-key: [‘accred1’, ‘accred2’]}}} Simplified: {‘test_path’: [‘accred1’, ‘accred2’]}
- Parameters:
test_path – the Python path to the test. For example:
package.category.checks.module.TestClass
- is_test_included(test_path, accreditations)[source]¶
Provide boolean result of whether a check is part of accreditations.
- Parameters:
test_path – the Python path to the test. For instance:
package.accr1.TestClass
orpackage.accr2.test_function
accreditations – list of accreditations names where
test_path
may be included.
- property paths¶
All absolute paths to
controls.json
file(s).
compliance.evidence module¶
Compliance evidence management automation module.
- class compliance.evidence.DerivedEvidence(name, category, ttl=86400, description='', **kwargs)[source]¶
Bases:
_BaseEvidence
The derived evidence class.
- EVIDENCE_TYPE = 'derived'¶
- class compliance.evidence.ExternalEvidence(name, category, ttl=31536000, description='', **kwargs)[source]¶
Bases:
_BaseEvidence
The external evidence class.
- EVIDENCE_TYPE = 'external'¶
- class compliance.evidence.LazyLoader(path, ev_class)¶
Bases:
tuple
- ev_class¶
Alias for field number 1
- path¶
Alias for field number 0
- class compliance.evidence.RawEvidence(*args, **kwargs)[source]¶
Bases:
_BaseEvidence
The raw evidence class.
Raw evidence is partition-able if the content is JSON and by providing a list of partition fields along with an optional partition root. The evidence partitioning can be defined in configuration JSON or directly upon construction of a RawEvidence object. The constructor route overrides the configuration settings, if both are provided.
- EVIDENCE_TYPE = 'raw'¶
- get_partition(key)[source]¶
Provide a slice of content based on the supplied partition key.
Return a JSON document that is a slice of the original evidence content based on the list of key values provided. Key values are expected to match the key fields provided during evidence instantiation and are relative to the root partition provided during evidence instantiation.
- Parameters:
key – A list of key values to partition by
- Returns:
A JSON document filtered by the key values provided
- property is_partitioned¶
Raw evidence partitioned status.
- property partition_keys¶
All partition keys for this evidence object.
Return all key values based on evidence content and the key fields provided during evidence instantiation. Key values are relative to the root partition provided during evidence instantiation.
- Returns:
A list of key values where the key values are lists as well.
- class compliance.evidence.ReportEvidence(name, category, ttl=86400, description='', **kwargs)[source]¶
Bases:
_BaseEvidence
The report evidence class.
- EVIDENCE_TYPE = 'reports'¶
- class compliance.evidence.TmpEvidence(name, category, ttl=86400, description='', **kwargs)[source]¶
Bases:
_BaseEvidence
The temporary evidence class.
- EVIDENCE_TYPE = 'tmp'¶
- class compliance.evidence.derived_evidence(locker, sources, target)[source]¶
Bases:
object
Helper context manager for a typical
fetch_
method implementation.Use when retrieving derived evidence by a fetcher and the name of the evidence is dynamic. When the evidence name is static/known use the @store_derived_evidence decorator instead.
If TTL has expired on the derived evidence, the context manager yields a dictionary containing all of the source evidences as well as the derived evidence objects specified in the
sources
andtarget
arguments.If TTL has not expired on the derived evidence, the context manager yields
None
and expects the callingwith
block to exit gracefully immediately.Inside the
with
block:If
sources
are provided as a list then the source evidence is accessible through the source path as the key for the yielded dictionary of evidence.If
sources
are provided as a dictionary where evidence short names are keys and evidence source paths are the values then the evidence is accessible through the evidence short name as the key for the yielded dictionary of evidence.If a single evidence source path is provided as a string then the source evidence is accessible by using ‘source’ as the key for the yielded dictionary of evidence.
The derived evidence object is always accessible by using ‘derived’ as the key for the yielded dictionary of evidence.
The context manager expects the derived evidence content to be generated and set via
set_content
by the callingwith
block.
- class compliance.evidence.evidences(obj, from_evidences)[source]¶
Bases:
object
Helper context manager for a typical
test_
method implementation.Use when processing evidence by a check and the name(s) of the evidence is/are dynamic. When the evidence names are static/known use the @with_*_evidences decorators instead.
Inside the
with
block:If
evidence_paths
are provided as a list then the evidence is accessible through the evidence path as the key for the yielded dictionary of evidence.If
evidence_paths
are provided as a dictionary where evidence short names are keys and evidence paths are the values then the evidence is accessible through the evidence short name as the key for the yielded dictionary of evidence.If a single evidence path is provided as a string then the evidence object is yielded by this context manager.
- compliance.evidence.get_evidence_base_classes()[source]¶
Provide a list of all valid base evidence class objects.
- compliance.evidence.get_evidence_by_path(path, locker=None)[source]¶
Provide an evidence object specified by the given path.
The following strategy is used:
Return evidence if it is present in the evidence cache populating content if necessary and possible.
If evidence is not in the evidence cache but a locker is provided, then the evidence will be retrieved from the locker.
Otherwise, an evidence object is built with the default parameters.
- Parameters:
path – relative path to the evidence within the Locker. For example,
raw/source1/evidence.json
.- Returns:
the evidence object.
- compliance.evidence.get_evidence_class(evidence_type)[source]¶
Provide the appropriate evidence class based on the supplied type.
Returns the corresponding evidence class object based on the category provided. If no match
None
is returned.- Parameters:
evidence_type – the type of evidence class desired as a string. Valid values are
tmp
,reports
,derived
,raw
,external
.- Returns:
the appropriate evidence class.
- compliance.evidence.get_evidence_dependency(path, locker, fetcher=None)[source]¶
Provide evidence to fetchers that depend on that other evidence to fetch.
Use when a fetcher needs evidence fetched by another fetcher in order to complete its fetch process. The premise is that if the evidence is in the evidence cache then return that because it was placed there by another fetcher. If not then get the evidence directly from the locker without putting that evidence into the evidence cache. When an evidence dependency is not found the fetcher is queued up as a dependency rerun for subsequent processing.
- Parameters:
path – relative path to the evidence within the Locker. For example,
raw/source1/evidence.json
.locker – evidence Locker object.
fetcher – optional Python notation path to fetcher method. If provided, this defines the fetcher that is added to the re-run list. Otherwise the execution stack is traversed to find the fetcher caller.
- Returns:
the evidence object.
- class compliance.evidence.raw_evidence(locker, evidence_path)[source]¶
Bases:
_EvidenceContextManager
Helper context manager for a typical
fetch_
method implementation.Use when retrieving raw evidence by a fetcher and the name of the evidence is dynamic. When the evidence name is static/known use the @store_raw_evidence decorator instead.
If TTL has expired, the context manager yields the evidence object specified by the
evidence_path
. The context manager expects the evidence content to be retrieved and set viaset_content
by the callingwith
block.If TTL has not expired, the context manager yields
None
and expects the callingwith
block to exit gracefully immediately.
- compliance.evidence.store_derived_evidence(evidences, target)[source]¶
Decorate a typical
fetcher_
method fetching derived evidence.Use when retrieving derived evidence by a fetcher and the name of the evidence is static/known. When the evidence name is dynamic use the derived_evidence context manager instead.
The decorator expects that the decorated method returns the content to be stored in the locker. The storing of the evidence is also handled by this decorator.
- Parameters:
evidences – a list of relative paths to the evidences needed by the fetcher. They will be passed to the method call. For example,
[raw/src/foo.json, derived/src/bar.json]
.target – relative path to the evidence to be stored in the Locker. For example,
src/evidence.json
.
- compliance.evidence.store_raw_evidence(evidence_path)[source]¶
Decorate a typical
fetcher_
method fetching raw evidence.Use when retrieving raw evidence by a fetcher and the name of the evidence is static/known. When the evidence name is dynamic use the raw_evidence context manager instead.
The decorator expects that the decorated method returns the content to be stored in the locker. The storing of the evidence is also handled by this decorator.
- Parameters:
path – relative path to the evidence within the Locker. For example,
source1/evidence.json
.
- compliance.evidence.store_tmp_evidence(evidence_path)[source]¶
Decorate a typical
fetcher_
method fetching temporary evidence.Use when retrieving temporary evidence by a fetcher and the name of the evidence is static/known. When the evidence name is dynamic use the tmp_evidence context manager instead.
- Parameters:
path – relative path to the evidence within the Locker. For example,
source1/evidence.json
.
- class compliance.evidence.tmp_evidence(locker, evidence_path)[source]¶
Bases:
_EvidenceContextManager
Helper context manager for a typical
fetch_
method implementation.Use when retrieving temporary evidence by a fetcher and the name of the evidence is dynamic. When the evidence name is static/known use the @store_tmp_evidence decorator instead.
If the evidence is not present, the context manager yields the evidence object specified by the
evidence_path
. The context manager expects the evidence content to be retrieved and set viaset_content
by the callingwith
block.If the evidence is present, the context manager yields
None
and expects the callingwith
block to exit gracefully immediately.
- compliance.evidence.with_derived_evidences(*from_evidences)[source]¶
Decorate a typical
test_
check method processing derived evidences.Use when processing derived evidence by a check and the name(s) of the evidence is/are static/known. When the evidence names are dynamic use the
evidences
context manager instead.- Parameters:
from_evidences – relative paths to evidences as strings or LazyLoader namedtuples that contain relative paths to evidences and evidence classes required by the check.
- compliance.evidence.with_external_evidences(*from_evidences)[source]¶
Decorate a typical
test_
check method processing external evidences.Use when processing external evidence by a check and the name(s) of the evidence is/are static/known. When the evidence names are dynamic use the
evidences
context manager instead.- Parameters:
from_evidences – relative paths to evidences as strings or LazyLoader namedtuples that contain relative paths to evidences and evidence classes required by the check.
- compliance.evidence.with_raw_evidences(*from_evidences)[source]¶
Decorate a typical
test_
check method processing raw evidences.Use when processing raw evidence by a check and the name(s) of the evidence is/are static/known. When the evidence names are dynamic use the
evidences
context manager instead.- Parameters:
from_evidences – relative paths to evidences as strings or LazyLoader namedtuples that contain relative paths to evidences and evidence classes required by the check.
- compliance.evidence.with_tmp_evidences(*from_evidences)[source]¶
Decorate a typical
test_
check method processing temporary evidences.Use when processing temporary evidence by a check and the name(s) of the evidence is/are static/known. When the evidence names are dynamic use the
evidences
context manager instead.- Parameters:
from_evidences – relative paths to evidences as strings or LazyLoader namedtuples that contain relative paths to evidences and evidence classes required by the check.
compliance.fetch module¶
Compliance fetcher automation module.
- class compliance.fetch.ComplianceFetcher(*args, **kwargs)[source]¶
Bases:
TestCase
Compliance fetcher automation TestCase class.
- fetchCloudantDoc(db_url, params=None)[source]¶
Retrieve a Cloudant document.
Helper/Convenience method.
- Parameters:
db_url – the URL to the Cloudant doc to retrieve.
params – optional parameters to include in the GET request.
- Returns:
the Cloudant document content.
- fetchLocalCommands(commands, cwd=None, env=None, show_exit_status=False, show_timestamp=False, timeout=20, user=None)[source]¶
Retrieve the output from locally executed commands.
Helper/Convenience method.
- Parameters:
commands – A list of string commands to be executed.
cwd – Override the current working directory. Defaults to None.
env – Override environment variables. Defaults to None.
show_exit_status – Show the exit status for each command. Defaults to False.
show_timestamp – Show a timestamp denoting when each command was executed. Defaults to False.
timeout – Terminate after timeout seconds. Defaults to 20.
user – Execute commands as specified user. Defaults to current user.
- Returns:
Command output as a string.
- fetchURL(url, params=None, creds=None)[source]¶
Retrieve remote content through an HTTP GET request.
Helper/Convenience method.
- Parameters:
url – the URL of the file.
params – optional parameters to include in the GET request.
creds – optional tuple with (user, password) to be used.
- Returns:
the remote content.
- classmethod session(url=None, creds=None, **headers)[source]¶
Provide a requests session object with User-Agent header.
- Parameters:
url – optional base URL for the session requests to use. A url argument triggers a new session object to be created whereas no url argument will return the current session object if one exists.
creds – optional authentication credentials.
headers – optional kwargs to add to session headers.
- Returns:
a requests Session object.
compliance.fix module¶
Compliance fixer automation module.
- class compliance.fix.Fixer(results, dry_run=True, out=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]¶
Bases:
object
This class attempts to resolve check failures.
- execute_fix(test_obj, fct, args=None)[source]¶
Execute the fix routine for a given check test object.
This method gets called by fix_* methods in checks. It gets passed a function (method) that must be called in order to fix one specific issue. The method’s fix will either get executed, or if in dry-run mode, will print out the method’s docstring, injecting any arguments if needed. The check’s fixed_failure_count is incremented if the fix was successful.
- Parameters:
test_obj – instance of subclass of
compliance.utils.check.ComplianceCheck
on which to execute the fixfct – a callback function that will actually perform the fix. this function will be passed a reference to this fixer, along with a reference to a compliance.utils.credentials.Config object. this callback will also need to have a docstring, which is what will be displayed in dry-run mode. the docstring will get formatted with the arguments passed to the fix function.
args – dictionary of named arguments to pass to the fix function fct.
- fix()[source]¶
Perform all fix routines found in executed checks.
Iterate through all compliance checks and looks for fix_* methods with corresponding test_* methods. These are executed, and results are recorded if fixes are made.
Note: Instead of individual fix_* methods, you can instead define a single fix_failures method which handles all fixes for the class.
compliance.locker module¶
Compliance locker management automation module.
- class compliance.locker.Locker(name=None, repo_url=None, branch=None, creds=None, do_push=False, ttl_tolerance=0, gitconfig=None, local_path=None, use_extra_lockers=True)[source]¶
Bases:
object
The locker (context manager) class.
The evidence locker maintains a git repository of evidence and places new evidence into it. It can validate a piece of evidence against a time to live. The Locker is a context manager. On instantiation it will retrieve the configured git repository.
- add_content_to_locker(content, folder='', filename=None)[source]¶
Add non-evidence text content to the local locker.
- Parameters:
content – the content to add to the local locker.
folder – the folder in the local locker to add the content to.
filename – the name of the file in the local locker.
- add_evidence(evidence, checks=None, evidence_used=None)[source]¶
Add the evidence to the locker.
The locker will generate the file internally and add it to the local git repository.
- Parameters:
evidence – the evidence to add. Note that evidence content attribute must be populated.
checks – A list of checks used to generate report content. Only applicable for check generated ReportEvidence.
evidence_used – metadata for evidence used by a check. Only applicable for check generated ReportEvidence.
- checkin(message=None)[source]¶
Commit changed files to the local git repository.
- Parameters:
message – the message to apply on the commit.
- property clone_depth¶
Provide the commit depth used when cloning the repository.
- Returns:
the clone depth.
- property clone_shallow_since_days¶
Provide the maximum commit age to fetch when cloning the repository.
- Returns:
the shallow since days.
- create_tombstone_metadata(candidate, metadata, reason)[source]¶
Create tombstones for evidence being removed from the locker.
- Parameters:
candidate – either the name of the evidence file or an iterable of partition hashes.
metadata – the evidence metadata dictionary.
reason – the reason evidence is being removed.
- Returns:
a list of tombstones.
- get_abandoned_evidences(threshold=None)[source]¶
Provide a set of evidence where the update
threshold
has passed.- Parameters:
threshold (int) – the time in seconds after TTL expires that evidence can remain un-updated before it is considered abandoned. The abandoned evidence threshold defaults to 30 days if none is provided.
- Returns:
a set of abandoned evidence file relative paths.
- get_content_from_locker(folder='', filename=None)[source]¶
Read non-evidence text content from the local locker.
- Parameters:
folder – the folder in the local locker to get the content from.
filename – the name of the file in the local locker.
- get_dependency_reruns()[source]¶
Provide dot notation path to fetcher methods to be re-executed.
Fetchers will only be considered for re-execution if they initially failed to execute due to a dependency error.
- Returns:
a list of fetcher methods to re-execute.
- get_empty_evidences()[source]¶
Provide a list of evidence paths to empty evidence files.
Evidence content is considered empty based on an evidence object’s is_empty property. This information is stored in evidence metadata.
- Returns:
a list of empty evidence file relative paths.
- get_evidence(evidence_path, ignore_ttl=False, evidence_dt=None)[source]¶
Provide the evidence from the locker.
The evidence may or may not exist in the locker. If the evidence is historical but not found in the immediate locker and a previous locker URL is provided in the configuration then an attempt to get the historical version of the evidence will be made from the previous locker.
- Parameters:
evidence_path – string path of the evidence within the locker. For example, raw/service1/output.json.
ignore_ttl – boolean value to ignore evidence time to live. Defaults to False.
evidence_dt – datetime of the evidence file version to retrieve. Defaults to None which translates to “now”.
- Returns:
the populated evidence object.
- get_evidence_metadata(evidence_path, evidence_dt=None)[source]¶
Provide evidence metadata from package index file.
- Parameters:
evidence_path – the evidence relative path.
evidence_dt – the upper bound evidence commit date.
- Returns:
the metadata for the evidence specified.
- get_file(filename)[source]¶
Provide the path for a file in the locker.
The file may or may not exist in the locker.
- Parameters:
filename – the name of a file in the locker.
- Returns:
the path to the filename provided.
- get_index_file(evidence)[source]¶
Provide the full path to the index file of the given evidence.
- Parameters:
evidence – the evidence object to be used.
- get_index_file_by_path(evidence_path)[source]¶
Provide the full path to the supplied evidence’s index file.
- Parameters:
evidence_path – the path to the evidence within the evidence locker.
- Returns:
the full path to the evidence’s index file.
- get_large_files(size=50000000)[source]¶
Provide a dictionary of “large” evidence locker files.
A “large” file is one whose size is > the
size
argument provided.- Parameters:
size (int) – file size threshold.
- Returns:
a dictionary of file paths and sizes of “large” files.
- get_latest_commit(path, dt=None)[source]¶
Provide the most recent commit for the file and date specified.
- Parameters:
path – the relative path to the file.
dt – the upper bound commit date.
- Returns:
the latest commit containing the file specified.
- get_locker_repo(locker='evidence locker')[source]¶
Pull (clone) the remote repository to the local git repository.
- Parameters:
locker – the locker “name” used in logging
- get_remote_location(filename, include_commit=True, sha=None, locker_url=None)[source]¶
Provide the path for a file/commit SHA in the locker.
The file may or may not exist in the locker.
- Parameters:
filename – the name of a file in the locker.
include_commit – if the latest commit SHA should be included.
sha – use this commit SHA; requires include_commit to be False.
locker_url – use this locker_url instead of self.repo_url.
- Returns:
the remote repository path to the filename provided.
- get_reports_metadata()[source]¶
Provide all metadata related to reports as a dictionary.
- Returns:
reports metadata.
- property head_commit_hexsha¶
Get SHA of repository head commit.
- Returns:
40 byte hexadecimal version of 20 byte binary SHA.
- index(evidence, checks=None, evidence_used=None)[source]¶
Add an evidence to the git index.
- Parameters:
evidence – the evidence object.
checks – A list of checks used to generate report content. Only applicable for check generated ReportEvidence.
evidence_used – metadata for evidence used by a check. Only applicable for check generated ReportEvidence.
- init()[source]¶
Initialize the local git repository.
If repo_url was provided to the locker object, the repository will be cloned. If not, a fresh new git repository will be created locally.
- load_content(evidence, ignore_ttl=False, evidence_dt=None)[source]¶
Populate the content of the evidence from the locker.
- Parameters:
evidence – an evidence object.
ignore_ttl – Boolean for TTL validation. Defaults to False.
evidence_dt – The date of the evidence content to load.
- Returns:
The evidence object with content.
- lock = <unlocked _thread.lock object>¶
- remove_partitions(evidence, hashes)[source]¶
Remove partition files for the specified evidence hash keys.
Used when switching from partitioned evidence to unpartitioned evidence and when partitioned file content is no longer part of the overall evidence content.
- Parameters:
evidence – the evidence object.
hashes – an iterable with evidence partition hashes.
- property touched_files¶
Provide paths to files that have been touched in the local locker.
Files are considered “touched” if they have been added/updated in the locker.
- Returns:
a list of touched files.
compliance.notify module¶
Compliance notification management automation module.
- class compliance.notify.FDNotifier(results, controls, fd=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, push_error=False)[source]¶
Bases:
_BaseNotifier
File descriptor notifier class.
Notifications are written to the file descriptor specified. Defaults to STDOUT.
- class compliance.notify.GHIssuesNotifier(results, controls, push_error=False)[source]¶
Bases:
_BaseMDNotifier
Github notifier class.
Notifications are sent to Github as repository issues. This notifier is configurable via
compliance.config.ComplianceConfig
.
- class compliance.notify.LockerNotifier(results, controls, locker, push_error=False)[source]¶
Bases:
_BaseMDNotifier
Evidence Locker notifier class.
Notifications are written to the evidence locker.
- Parameters:
results – dictionary generated by
compliance.runners.CheckMode
at the end of the execution.controls – dictionary of checks and the accreditations and controls that they belong to.
- class compliance.notify.PagerDutyNotifier(results, controls, push_error=False)[source]¶
Bases:
_BaseNotifier
PagerDuty notifier class.
- class compliance.notify.SlackNotifier(results, controls, push_error=False)[source]¶
Bases:
_BaseNotifier
Slack notifier class.
Notifications are sent to Slack channel(s). This notifier is configurable via
compliance.config.ComplianceConfig
.- MESSAGE_COLORS = {'error': '#9932CC', 'fail': '#D00000', 'pass': '#00D000', 'warn': '#FFD300'}¶
- compliance.notify.get_notifiers()[source]¶
Provide a dictionary of all notifier class objects.
This dictionary contains all valid notifier choices for the
--notify
option in the CLI as keys and their corresponding notifier classes as values.NOTE: When adding/removing a notifier, update this dictionary accordingly.
compliance.report module¶
Compliance report build automation module.
- class compliance.report.ReportBuilder(locker, results, controls)[source]¶
Bases:
object
This class builds all the required reports for the tests.
- generate_check_results(rpt_metadata)[source]¶
Combine the check execution results with associated reports metadata.
This method combines check results with details about associated reports and evidences used, found in the report metadata. It returns a dictionary keyed by check class dot path.
- Parameters:
rpt_metadata – Metadata from all report evidence index.json files
- generate_toc(rpt_metadata)[source]¶
Generate a check reports table of contents.
This method generates a TOC based on all report evidence metadata and appends that TOC to the bottom of an evidence locker’s README.md file.
- Parameters:
rpt_metadata – Metadata from all report evidence index.json files
- get_template_for(test_obj, evidence)[source]¶
Provide the file path of the template associated to the given evidence.
- Parameters:
test_report_obj – the test object that needs to create report.
evidence – the ReportEvidence object expected.
- render_evidence_with_template(evidence, test_obj)[source]¶
Render content based on a template.
If template system was selected, this method renders the content using the template for the given evidence.
- Parameters:
evidence – the evidence object to be rendered using its template.
test_obj – test object which has all the tests for check.
compliance.runners module¶
Compliance automation flow management module.
- class compliance.runners.CheckMode(opts, extra_opts)[source]¶
Bases:
_BaseRunner
The check process flow.
- class compliance.runners.ComplianceBaseResult(stream, descriptions, verbosity)[source]¶
Bases:
TextTestResult
Base Compliance result class.
- class compliance.runners.ComplianceCheckResult(*args, **kwargs)[source]¶
Bases:
ComplianceBaseResult
Compliance check result class.
- addError(test, err)[source]¶
Add test errors to check results.
- Parameters:
test – a
unittest.TestCase
object.err – a tuple of the form returned by sys.exc_info()
- addFailure(test, err)[source]¶
Add test failures to check results.
- Parameters:
test – a
unittest.TestCase
object.err – a tuple of the form returned by sys.exc_info()
- class compliance.runners.ComplianceTestWrapper(test)[source]¶
Bases:
object
TestCase wrapper class.
Wraps the TestCase test object as an attribute to ensure backwards compatibility with checks, reporting, and notifiers.
Module contents¶
Compliance automation package.