compliance.utils package

Subpackages

Submodules

compliance.utils.credentials module

Compliance credentials configuration.

class compliance.utils.credentials.Config(cfg_file='~/.credentials')[source]

Bases: object

Handle credentials configuration.

get(section, key=None, account=None, default=<object object>)[source]

Retrieve sections and keys by account.

Parameters:
  • section – the section from which to retrieve keys.

  • account – if provided, fetches the value for the specific account. assumes the account is prefixed to the key and separated by _.

  • default – if provided, returns this value if a value cannot be found; otherwise raises an exception.

Parm key:

the key in the section whose value you want to retrieve. if not specified, returns the whole section as a dictionary.

compliance.utils.data_parse module

Compliance automation data and formatting utilities module.

compliance.utils.data_parse.deep_merge(a, b, path=None, append=False)[source]

Merge two dicts, taking into account any sub (or sub-sub-*) dicts.

If append is True then list values from b will be appended to a’s. Modified from: https://stackoverflow.com/a/7205107/566346

compliance.utils.data_parse.format_json(data, **addl_kwargs)[source]

Provide a JSON string formatted to the standards of the library.

This function ensures that the JSON is sorted, indented, and uses the appropriate separators for all instances of JSON generated by this library.

Parameters:
  • data – The data structure to be formatted.

  • add_kwargs – Additional json.dumps options

Returns:

A formatted JSON string.

compliance.utils.data_parse.get_sha256_hash(key, size=None)[source]

Provide a SHA256 hash based on the supplied key values.

Parameters:
  • key – An iterable of key values.

  • size – The size of the returned hash. Defaults to full hash. If size provided is greater than the hash size the full hash is returned.

Returns:

a SHA256 hash for the key values supplied.

compliance.utils.data_parse.parse_dot_key(data, key)[source]

Provide the element from the data dictionary defined by the key.

The key may be a key path depicted by dot notation.

Parameters:
  • data – A dictionary

  • key – A dictionary key string that may be a key path depicted by dot notation. For example “foo.bar”.

Returns:

The dictionary value from data associated to the key.

compliance.utils.exceptions module

Compliance automation custom exceptions module.

exception compliance.utils.exceptions.DependencyFetcherNotFoundError[source]

Bases: ValueError

Dependency fetcher not found exception class.

exception compliance.utils.exceptions.DependencyUnavailableError[source]

Bases: ValueError

Missing dependent evidence exception class.

exception compliance.utils.exceptions.EvidenceNotFoundError[source]

Bases: ValueError

Missing evidence exception class.

exception compliance.utils.exceptions.HistoricalEvidenceNotFoundError[source]

Bases: ValueError

Missing historical evidence exception class.

exception compliance.utils.exceptions.LockerPushError(push_info=None)[source]

Bases: Exception

Locker push exception class.

exception compliance.utils.exceptions.StaleEvidenceError[source]

Bases: Exception

Stale evidence exception class.

exception compliance.utils.exceptions.UnverifiedEvidenceError[source]

Bases: Exception

Unverified evidence exception class.

compliance.utils.http module

Compliance HTTP helpers.

class compliance.utils.http.BaseSession(baseurl)[source]

Bases: Session

Subclass of requests.Session to support a base URL.

prepare_request(request)[source]

Prefix with self.baseurl if request.url does not include it.

compliance.utils.path module

Compliance automation path formatting utilities module.

compliance.utils.path.get_module_path(path)[source]

Provide the full module dot notation path based on the file path provided.

Parameters:

path – absolute or relative path to a file or directory.

Returns:

the module path in dot notation.

compliance.utils.path.get_toplevel_dirpath(path)[source]

Provide the top level directory for the given path.

The top level directory contains the controls.json file. This function returns None if a top level path can not be found.

Parameters:

path – absolute or relative path to a file or directory.

Returns:

the absolute path to the top level directory.

compliance.utils.path.load_evidences_modules(path)[source]

Load all evidences modules found within the path directory structure.

Parameters:

path – absolute path to a top level directory.

compliance.utils.path.substitute_config(path_tmpl)[source]

Substitute the config values on the given path template.

Parameters:

path_tmpl – a string template of a path

compliance.utils.test module

Compliance automation underlying test framework utilities module.

compliance.utils.test.parse_test_id(test_id)[source]

Parse a test ID into useful parts.

Takes a test ID and parses out useful parts of it:

> parse_test_id('foo.bar.baz.test_mod.MyTestClass.test_method')
{
    'scope': 'foo',
    'type': 'bar',
    'accreditation': 'baz',
    'file': 'test_mod',
    'class': 'MyTestClass',
    'method': 'test_method',
    'class_path': 'foo.bar.baz.test_mod.MyTestClass.test_method'
}

Note: scope/type/accreditation might not be returned if your path structure is different from the suggested one.

Module contents

Compliance automation utilities package.