Skip to main content

Reusable filesystem validators for Mr. Kot checks.

Project description

mr-kot-fs-validators

Reusable filesystem validator factories for Mr. Kot checks. This package provides a set of validator factories that you compose inside your own checks using check_all().

Usage

from mr_kot import check, check_all
from mr_kot_fs_validators import (
    Exists, IsFile, HasMode, OwnerIs, GroupIs
)

@check
def hosts_file_state():
    return check_all(
        "/etc/hosts",
        Exists(),
        IsFile(),
        HasMode("0644"),
        OwnerIs("root"),
        GroupIs("root"),
    )

Each validator is a small factory returning a callable: validator(target_path) -> (status, evidence). Statuses follow Mr. Kot conventions: PASS, FAIL, ERROR (and occasionally WARN).

Evidence style

  • PASS: path=/etc/hosts exists
  • FAIL: path=/data mode expected=0755 actual=0775
  • FAIL(recursive): path=/data child=/data/logs/old owner expected=mysql actual=root
  • ERROR: path=/var/log error=PermissionError: [Errno 13] Permission denied

Validators

  • Existence and type: Exists, IsFile, IsDir, IsSymlink, IsSocket, IsBlockDevice, IsCharDevice.
  • Permissions/ownership: HasMode, OwnerIs, GroupIs, IsExecutable, IsReadable, IsWritable.
  • Content/size: Empty, SizeBetween.
  • State/links: SymlinkPointsTo, RecentThan, HasSubdirs, HasFiles.
  • Mounts/devices/capacity: FSTypeIs, MountExists, FreeSpaceAtLeast, DeviceAvailable.
  • I/O smoke: CanReadFile, CanWriteFile.

Notes

  • recursive=True in HasMode, OwnerIs, GroupIs traverses directories with os.walk and fails on the first mismatch.
  • follow_symlinks controls stat-like checks; default False unless stated otherwise.
  • RecentThan() accepts a file path or an epoch timestamp (float or int).
  • FSTypeIs/MountExists parse /proc/self/mountinfo on Linux.
  • I/O smoke tests avoid leaving artifacts; CanWriteFile() always removes the temporary file it creates.

Permissions shortcuts

IsExecutable(by_user=True, by_group=False, by_others=False), IsReadable(...), and IsWritable(...) accept flags to select which bits to require. If all flags are False, they fall back to checking any of the three categories.

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

mr_kot_fs_validators-0.1.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

mr_kot_fs_validators-0.1.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file mr_kot_fs_validators-0.1.0.tar.gz.

File metadata

  • Download URL: mr_kot_fs_validators-0.1.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.14.0-1014-aws

File hashes

Hashes for mr_kot_fs_validators-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cb34a1a24ff795c32a8def9e47757155883016d7d040356b053078ecded84488
MD5 15682d7f8bcd54eb7f4addb2b84a6b51
BLAKE2b-256 91bf5230a516e8b03744685e12ae095d6daa992519f7041e0157fbf80a366ddd

See more details on using hashes here.

File details

Details for the file mr_kot_fs_validators-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mr_kot_fs_validators-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.14.0-1014-aws

File hashes

Hashes for mr_kot_fs_validators-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fcdc3dde1c9554db19e7b3da9274c9b09dff69b235fcb5892f535ce8810cbb9f
MD5 70cdc9dd97b490ae401b40d6c3474c52
BLAKE2b-256 6d7dde9e1ba7a81465920da9796de23f5ad358af70af7cf0183f16810efc3217

See more details on using hashes here.

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