ansible_sign.checksum package

Subpackages

Submodules

ansible_sign.checksum.base module

class ansible_sign.checksum.base.ChecksumFile(root, differ=None)[source]

Bases: object

Slurp a checksum file and be able to check and compare its contents to a given root directory. Also: be able to write out a checksum file.

We only allow sha256 for now, though supporting 512, etc. would be easy.

calculate_checksum(path)[source]
calculate_checksums_from_root(verifying)[source]

Using the root of the project and the differ class passed to the constructor, iterate over all files in the project and calculate their checksums. Return a dictionary of the result, keyed on the filename.

Just calling this is not enough in many cases- you want to ensure that the files in the checksum list are the same ones present in reality. diff() above does just that. Use that in combination with this method, or use verify() which does it for you.

diff(paths)[source]

Given a collection of paths, use the differ to figure out which files (in reality) have been added/removed from the project root (or latest SCM tree).

property differ_warnings

A differ can store a set of warnings (as strings) in the_differ.warnings which we can propagate up here. This allows calling code to display any warnings found during diffing time.

generate_gnu_style()[source]

Using the root directory and ‘differ’ class given to the constructor, generate a GNU-style checksum manifest file. This is always generated from scratch by finding the list of relevant files in the root directory (by asking the differ), and calculating the checksum for each of them.

The resulting list is always sorted by filename.

parse(checksum_file_contents)[source]

Given a complete checksum manifest as a string, parse it and return a dict with the result, keyed on each filename or path.

verify(parsed_manifest_dct, diff=True)[source]

Takes a parsed manifest file (e.g. using parse(), with paths as keys and checksums as values).

Then calculates the current list of files in the project root. If paths have been added or removed, ChecksumMismatch is raised.

Otherwise, each the checksum of file in the project root (and subdirs) is calculated and that result is checked to be equal to the parsed checksums passed in.

property warnings

Right now this is just the same as differ_warnings. In the future it might include warnings that we differ in methods in this class as well.

exception ansible_sign.checksum.base.ChecksumMismatch[source]

Bases: Exception

exception ansible_sign.checksum.base.InvalidChecksumLine[source]

Bases: Exception

exception ansible_sign.checksum.base.NoDifferException[source]

Bases: Exception

Module contents

This package handles checksum validation for Ansible content.