Skip to content

feature: prefix deletion for integrity.Typed #24

@bigbes

Description

@bigbes

Description

Add prefix deletion support to integrity.Typed while maintaining backward compatibility. The task has two parts:

  1. Verify current behavior: Ensure Delete without options only deletes exact keys, not prefixes
  2. Add prefix deletion option: New WithPrefixDelete() option that deletes all keys under a prefix, including hashes and signatures

Implementation Steps

Part 1: Verify Current Behavior

  1. Add tests confirming Delete("prefix") doesn't affect "prefix/child"
  2. Check that namer.GenerateNames rejects names ending with /
  3. Verify storage drivers perform exact key matches, not prefix deletions
  4. Add defensive check in Delete method to ensure keys don't end with /

Part 2: Add Prefix Deletion Option

  1. Create deleteOptions struct in integrity package
  2. Add WithPrefixDelete() option function
  3. Update Typed.Delete to handle prefix deletion:
    • Use namer.Prefix(name, true) for prefix-based key generation
    • Generate all possible key patterns for value/hash/signature keys under prefix
    • Use operation.Get with prefix to find existing keys, then delete them
  4. Ensure proper handling of nested keys with hashes and signatures
  5. Update namer to support prefix-based key enumeration

Examples

Current Behavior (Exact Match)

// Deletes only "/test/key", "/test/key/hash/sha256", "/test/key/sig/rsa"
err := typed.Delete(ctx, "key")

New Prefix Deletion

// Deletes all keys under "/test/prefix/" including nested values and 
err := typed.Delete(ctx, "prefix/", integrity.WithPrefixDelete())

Mixed Usage

// Store structure:
// - /test/users/alice
// - /test/hash/sha256/users/alice/
// - /test/users/bob
// - /test/hash/sha256/users/bob/

// Deletes only alice's keys
typed.Delete(ctx, "users/alice")

// Deletes all users (alice, bob, and their hashes/signatures)
typed.Delete(ctx, "users/", integrity.WithPrefixDelete())

Tests

  • Exact deletion tests
  • Prefix deletion tests
  • Integration tests

Checklist

  • Old behaviour verification
  • New behaviour (with prefix) implementation
  • Testing
  • Documentation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions