Skip to main content

Helpful context managers for managing decryption and mounts of storage devices

Project description

Code style: black Imports: isort Checked with mypy License: GPL v3

Storage Device Managers - Helpful context managers for managing decryption and mounts of storage devices

Overview

The storage_device_managers module provides a set of utilities to manage encrypted storage devices, handle BtrFS mounts, and perform file system operations in a secure and structured way. It is designed to support common storage-related tasks such as:

  • Decrypting and mounting encrypted devices
  • Managing BtrFS compression settings
  • Creating and removing symbolic links with root privileges
  • Formatting and encrypting devices
  • Changing file ownership securely

Features

  • Device Decryption & Encryption: Easily decrypt and encrypt storage devices using cryptsetup.
  • BtrFS Mount Management: Mount and unmount BtrFS file systems with optional compression settings.
  • Symbolic Link Handling: Create and remove symbolic links with elevated permissions.
  • File System Operations: Format devices with BtrFS, manage ownership, and check mount status.
  • Secure Passphrase Handling: Automatically generate safe passwords for encryption.

Usage

Decrypting and Mounting a Device

from pathlib import Path
from storage_device_managers import decrypted_device, mounted_device

# Decrypt and mount a device
with decrypted_device(Path("/dev/sdb1"), "cat /path/to/password-file") as dev:
    with mounted_device(dev) as mount_point:
        print(f"Device mounted at {mount_point}")

Encrypting a Device

from pathlib import Path
from storage_device_managers import encrypt_device

uuid = encrypt_device(Path("/dev/sdb1"), "cat /path/to/password-file")
print(f"Device encrypted with UUID: {uuid}")

Creating a Symbolic Link

from pathlib import Path
from storage_device_managers import symbolic_link

src = Path("/path/to/source")
dest = Path("/path/to/destination")

with symbolic_link(src, dest) as link:
    print(f"Symbolic link created at {link}")

API Reference

Context Managers

  • decrypted_device(device: Path, pass_cmd: str) -> Iterator[Path]
    • Decrypts a device using cryptsetup and returns a context-managed path.
  • mounted_device(device: Path, compression: Optional[ValidCompressions] = None) -> Iterator[Path]
    • Mounts a BtrFS device with optional compression settings.
  • symbolic_link(src: Path, dest: Path) -> Iterator[Path]
    • Creates and removes a symbolic link with root privileges.

Utility Functions

  • mount_btrfs_device(device: Path, mount_dir: Path, compression: Optional[ValidCompressions] = None) -> None
  • is_mounted(device: Path) -> bool
  • get_mounted_devices() -> Mapping[str, Mapping[Path, frozenset[str]]]
  • unmount_device(device: Path) -> None
  • open_encrypted_device(device: Path, pass_cmd: str) -> Path
  • close_decrypted_device(device: Path) -> None
  • encrypt_device(device: Path, password_cmd: str) -> UUID
  • mkfs_btrfs(device: Path) -> None
  • generate_passcmd() -> str
  • chown(file_or_folder: Path, user: Union[int, str], group: Optional[Union[int, str]] = None, *, recursive: bool) -> None

Contributing

Contributions are welcome! Please submit issues and pull requests via GitHub.

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

storage_device_managers-1.0.2.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

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

storage_device_managers-1.0.2-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

Details for the file storage_device_managers-1.0.2.tar.gz.

File metadata

  • Download URL: storage_device_managers-1.0.2.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for storage_device_managers-1.0.2.tar.gz
Algorithm Hash digest
SHA256 9284f00d6787168e8a1da75798cddc233ff178b412c7447290ba72f3a9658dbd
MD5 4196f0b2d166faf53676d748c74707b0
BLAKE2b-256 e471ba5fa0f430f798d71e7e694f2f3a379e0c1f1b21014f79484cbc7ee6417b

See more details on using hashes here.

Provenance

The following attestation bundles were made for storage_device_managers-1.0.2.tar.gz:

Publisher: python-publish.yml on MaxG87/storage-device-managers

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

File details

Details for the file storage_device_managers-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for storage_device_managers-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 562295c8c2f7bb8edd5420d07ee03fc0928a7437847d08f5250eab5ac3983678
MD5 b43a5f50daa198a03cf667dc1665ecaa
BLAKE2b-256 afb8024f95dadeb006a354d207b56f5cc603009cf43e90eee29e2fa58e82d945

See more details on using hashes here.

Provenance

The following attestation bundles were made for storage_device_managers-1.0.2-py3-none-any.whl:

Publisher: python-publish.yml on MaxG87/storage-device-managers

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