Skip to main content

Command line tool to check fixity for AIPs stored in the Archivematica Storage Service.

Project description

fixity

PyPI version GitHub CI codecov

Table of contents

About

Fixity is a command line tool that assists in checking fixity for AIPs stored in the Archivematica Storage Service.

"Fixity" in digital preservation terms is defined as "the assurance that a digital file has remained unchanged, i.e. fixed." (Bailey, 2014) and more information about that, and the concept of checksums, can be found in the Digital Preservation Coalition's (DPC) Digital Preservation Handbook.

Fixity is a client application that calls the Storage Service's Check Fixity API endpoint for a single AIP or for each AIP in the Storage Service.

Check fixity

The Storage Service's Check Fixity endpoint can be used to trigger a fixity check on an individual package. When the Fixity client calls this endpoint, the checking is done in the Storage Service itself.

Fixity aggregates results and makes it easy to do this across all packages.

To trigger fixity checking for a package, we need to know the AIP UUID and the Storage Service authorization parameters.

The URL is constructed as follows: http://127.0.0.1:62081/api/v2/file/<AIP UUID>/check_fixity/

And we can supply authentication information in a HTTP request using a command line tool such as HTTPie:

http -v --pretty=format \
    GET "http://127.0.0.1:62081/api/v2/file/5e21dd0d-190e-4ffb-b752-76d860bea898/check_fixity/" \
    Authorization:"ApiKey test:test"

This results in the following JSON output showing us that the Fixity check was a 'success', that is, there were no errors:

{
    "failures": {
        "files": {
            "changed": [],
            "missing": [],
            "untracked": []
        }
    },
    "message": "",
    "success": true,
    "timestamp": null
}

This detailed JSON output is recorded in Fixity's internal database. Summary information about errors is printed to the console. The output for package 5e21dd0d-190e-4ffb-b752-76d860bea898 would simply look as follows:

Fixity scan succeeded for AIP: 5e21dd0d-190e-4ffb-b752-76d860bea898

The Check Fixity endpoint updates the Storage Service fixitylog model with details of the last check completed.

Storage Service users can see the last Fixity Date and Fixity Status in the Storage Service Packages panel by going to {storage-service-url}/packages/

Administrators of the Storage Service can query the Storage Service database as follows:

select
   package_id as "AIP UUID",
   datetime_reported as "Fixity Last Checked",
   success,
   error_details
from locations_fixitylog
where package_id = '5e21dd0d-190e-4ffb-b752-76d860bea898'
order by datetime_reported desc
limit 1;

And we can see the details of the check in the SQL output:

+--------------------------------------+----------------------------+---------+---------------+
| AIP UUID                             | Fixity Last Checked        | success | error_details |
+--------------------------------------+----------------------------+---------+---------------+
| 5e21dd0d-190e-4ffb-b752-76d860bea898 | 2018-11-06 11:20:43.634188 |       1 | NULL          |
+--------------------------------------+----------------------------+---------+---------------+

Fixity errors

The Storage Service can detect multiple categories of error. Some are shown as outputs of Fixity below with the corresponding detailed information that can be accessed from Fixity's database:

Information has been deleted from a file

Fixity scan failed for AIP: 5e21dd0d-190e-4ffb-b752-76d860bea898 (Oxum error.
Found 10 files and 126404 bytes on disk; expected 10 files and 126405 bytes.)

Detail:

{
    "failures": {
        "files": {
            "changed": [],
            "missing": [],
            "untracked": []
        }
    },
    "finished": 1541505247,
    "message": "Oxum error.  Found 10 files and 126404 bytes on disk; expected 10 files and 126405 bytes.",
    "started": 1541505247,
    "success": false,
    "timestamp": null
}

A character in a file has been modified

Fixity scan failed for AIP: 5e21dd0d-190e-4ffb-b752-76d860bea898 (invalid bag)

Detail:

{
    "failures": {
        "files": {
            "changed": [
                {
                    "actual": "6ea7859a4edb8406aae0dfdf5abda9db97eeb8b416922b7356082ab55c9e4161",
                    "expected": "9fd57a8c09e0443de485cf51b68ad8ef54486454434daed499d2f686b7efc2b4",
                    "hash_type": "sha256",
                    "message": "data/objects/one_file/one_file.txt checksum validation failed (alg=sha256 expected=9fd57a8c09e0443de485cf51b68ad8ef54486454434daed499d2f686b7efc2b4 found=6ea7859a4edb8406aae0dfdf5abda9db97eeb8b416922b7356082ab55c9e4161)",
                    "path": "data/objects/one_file/one_file.txt"
                }
            ],
            "missing": [],
            "untracked": []
        }
    },
    "finished": 1541505387,
    "message": "invalid bag",
    "started": 1541505386,
    "success": false,
    "timestamp": null
}

A file has been removed from the package

Fixity scan failed for AIP: 5e21dd0d-190e-4ffb-b752-76d860bea898 (Oxum error.
Found 9 files and 126386 bytes on disk; expected 10 files and 126405 bytes.)

Detail:

{
    "failures": {
        "files": {
            "changed": [],
            "missing": [],
            "untracked": []
        }
    },
    "finished": 1541505645,
    "message": "Oxum error.  Found 9 files and 126386 bytes on disk; expected 10 files and 126405 bytes.",
    "started": 1541505645,
    "success": false,
    "timestamp": null
}

A file has been added to the package

Fixity scan failed for AIP: 5e21dd0d-190e-4ffb-b752-76d860bea898 (Oxum error.
Found 11 files and 126405 bytes on disk; expected 10 files and 126405 bytes.)

Detail:

{
    "failures": {
        "files": {
            "changed": [],
            "missing": [],
            "untracked": []
        }
    },
    "finished": 1541505549,
    "message": "Oxum error.  Found 11 files and 126405 bytes on disk; expected 10 files and 126405 bytes.",
    "started": 1541505549,
    "success": false,
    "timestamp": null
}

A manifest has been removed from the package

Fixity scan failed for AIP: 5e21dd0d-190e-4ffb-b752-76d860bea898 (Missing
manifest file)

Detail:

{
    "failures": {
        "files": {
            "changed": [],
            "missing": [],
            "untracked": []
        }
    },
    "finished": 1541505815,
    "message": "Missing manifest file",
    "started": 1541505815,
    "success": false,
    "timestamp": null
}

How this looks in the Storage Service

For any error in the Fixity check the Storage Service database maintains a summary log, see for example when data in a file has been modified:

+--------------------------------------+----------------------------+---------+---------------+
| AIP UUID                             | Fixity Last Checked        | success | error_details |
+--------------------------------------+----------------------------+---------+---------------+
| 5e21dd0d-190e-4ffb-b752-76d860bea898 | 2018-11-06 12:10:22.981609 |       0 | invalid bag   |
+--------------------------------------+----------------------------+---------+---------------+

Installation

Installation of Fixity can be completed with the following steps:

  1. Checkout or link the code to /usr/lib/archivematica/fixity

    1. Go to /usr/lib/archivematica/

      user@root:~$ cd /usr/lib/archivematica/
      
    2. Clone the code:

      user@root:/usr/lib/archivematica/$ git clone https://github.com/artefactual/fixity.git
      

      Once this is complete, the directory /usr/lib/archivematica/fixity should exist. cd back to the home directory

      user@root:/usr/lib/archivematica/$ cd
      
  2. Create a virtualenv in /usr/share/python/fixity, and install fixity and dependencies in it

    1. Switch to root

      user@root:~$ sudo -i
      
    2. Run:

      root@host:~# virtualenv /usr/share/python/fixity
      root@host:~# source /usr/share/python/fixity/bin/activate
      (fixity)root@host:~# cd /usr/lib/archivematica/fixity
      (fixity)root@host:/usr/lib/archivematica/fixity# pip install -r requirements.txt
      (fixity)root@host:/usr/lib/archivematica/fixity# pip install -e .
      
  3. Create a symlink from the executable to /usr/local/bin. You must still be root.

    (fixity)root@host:/usr/lib/archivematica/fixity# ln -s /usr/share/python/fixity/bin/fixity /usr/local/bin/fixity
    
  4. Export required environment variables. For ease of use later, creating /etc/profile.d/fixity.sh is recommended:

    1. To create the file:

      (fixity)root@host:/usr/lib/archivematica/fixity# touch /etc/profile.d/fixity.sh
      (fixity)root@host:/usr/lib/archivematica/fixity# nano /etc/profile.d/fixity.sh
      
    2. You are now editing the environment variables file. You should use the URL of your Storage Service, and the username and API key of one Storage Service user. Replace the URL, user and key with your data.

      #!/bin/bash
      export STORAGE_SERVICE_URL=http://localhost:8000
      export STORAGE_SERVICE_USER=myuser
      export STORAGE_SERVICE_KEY=myapikey
      
    3. Optionally, if you are using Fixity with a reporting service, you can also add:

      export REPORT_URL=http://myurl.com
      export REPORT_USERNAME=myuser
      export REPORT_PASSWORD=mypassword
      
    4. Load the variables from the file.

      (fixity)root@host:/usr/lib/archivematica/fixity# source /etc/profile.d/fixity.sh
      
  5. Run the tool with sudo or as root the first time. Subsequent runs can be with any user.

    (fixity)root@host:/usr/lib/archivematica/fixity# fixity scanall
    
  6. To exit the virtualenv:

    (fixity)root@host:/usr/lib/archivematica/fixity# deactivate
    root@host:/usr/lib/archivematica/fixity#
    

    And to exit the root user:

    root@host:/usr/lib/archivematica/fixity# exit
    user@host:~$
    
  7. After the initial install, to run fixity you only need to load the variables you defined earlier and run fixity.

    user@host:~$ source /etc/profile.d/fixity.sh
    user@host:~$ fixity scanall
    

Usage

For more information on usage, consult the manpage.

Development

To set up this repository for local development:

  1. Clone this repository:

    git clone git@github.com:artefactual/fixity
    
  2. Enter the repository directory:

    cd fixity
    
  3. Create a virtual environment with a recent version of Python:

    python3 -m venv .venv
    
  4. Activate the virtual environment:

    source .venv/bin/activate
    
  5. Install the project in editable mode passing the development extra:

    pip install -e .[dev]
    

Tests

This project uses tox to manage and run tests with pytest. You can find the configuration details in the [tool.tox] section of the pyproject.toml file.

You can install tox in your virtual environment:

pip install tox

Run all the tests this way:

tox -e py

You can pass options to pytest:

tox -e py -- -vvv -k "test_fixity"

Security

If you have a security concern about Archivematica or any of its companion repositories, please see the Archivematica security policy for information on how to safely report a vulnerability.

Copyright

Fixity is copyright 2014-2018 Artefactual Systems Inc.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fixity-0.8.0.tar.gz (57.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fixity-0.8.0-py3-none-any.whl (38.3 kB view details)

Uploaded Python 3

File details

Details for the file fixity-0.8.0.tar.gz.

File metadata

  • Download URL: fixity-0.8.0.tar.gz
  • Upload date:
  • Size: 57.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for fixity-0.8.0.tar.gz
Algorithm Hash digest
SHA256 bed5835874bf66f404dcb9d8b84449c4537818a5f516c7c62c8d6a35c55a9dc2
MD5 d8a4e33e3a84c93ba286ecda350396e1
BLAKE2b-256 dc1a6e209c76f7b814018267a166d9f750a84ade05d562f54b3c3a814d6c75e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for fixity-0.8.0.tar.gz:

Publisher: release.yml on artefactual/fixity

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fixity-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: fixity-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 38.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for fixity-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9bbaf2a0e0555ca2c8e32d0016a1ad8009dc72024618fadd540d75619d3366e9
MD5 1928f33709805f82954d73c37d39c64b
BLAKE2b-256 790ac10ed80550909ea02b7a73ce1c4917dd10304231dad98ea96f5286606a76

See more details on using hashes here.

Provenance

The following attestation bundles were made for fixity-0.8.0-py3-none-any.whl:

Publisher: release.yml on artefactual/fixity

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page