feat: implement Python storage cleaner with Appwrite integration
What does this PR do?
This PR implements a Python translation of the existing Node.js AppwriteService for cleaning storage buckets by removing files older than a retention period. It also provides a Python version of the serverless handler function that validates environment variables, authenticates the API key from request headers, and triggers the bucket cleanup process.
Test Plan
The changes were verified by running the Python service locally with mock environment variables and headers to ensure the cleanup function executes without error and correctly deletes files as intended. Additionally, error handling was tested by providing invalid or missing API keys to confirm appropriate error responses are returned.
Related PRs and Issues
#310
Have you read the Contributing Guidelines on issues?
Yes, I have read and followed the contributing guidelines.
Summary by CodeRabbit
- New Features
- Python Storage Cleaner function that deletes files older than a configurable retention period from a specified bucket; supports GET invocation and cron scheduling, validates inputs, and returns success or error responses.
- Documentation
- Added README describing usage, configuration, environment variables, runtime, permissions, cron, and timeout.
- Chores
- Added Python .gitignore and introduced the Appwrite SDK runtime dependency.
Walkthrough
Adds a Python storage-cleaner function under python/storage-cleaner: a Python-specific .gitignore, README.md, and requirements.txt (adds appwrite>=13.1.0,<14.0.0). New source files: src/utils.py (get_expiry_date computes UTC expiry from RETENTION_PERIOD_DAYS; throw_if_missing validates keys), src/appwrite.py (AppwriteService initializes Client from APPWRITE_FUNCTION_API_ENDPOINT, APPWRITE_FUNCTION_PROJECT_ID and provided API key; clean_bucket lists files with createdAt < expiry in batches (limit 25), deletes them, and aggregates failures), and src/main.py (entrypoint main(context) validating env vars, checking x-appwrite-key header, invoking clean_bucket, and returning HTTP responses).
Pre-merge checks and finishing touches
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title Check | ✅ Passed | The title concisely describes the primary feature added by the pull request, namely the implementation of a Python storage cleaner integrated with Appwrite, aligning closely with the objectives and scope of the changes. |
✨ Finishing touches
- [ ] 📝 Generate Docstrings
🧪 Generate unit tests
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🧪 Early access (Sonnet 4.5): enabled
We are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.
Note:
- Public repositories are always opted into early access features.
- You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
Comment @coderabbitai help to get the list of available commands and usage tips.