Add scripts for Harbor user and project management: - register.py: Bulk user registration from Excel - delete_users.py: Complete user deletion with resource cleanup - delete_projects.py: Targeted deletion of student projects (stu01-stu49) - CLAUDE.md: Project documentation and API guidance - requirements.txt: Python dependencies 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
3.3 KiB
3.3 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
This is a Harbor container registry user management tool written in Python. It provides functionality to:
- Register/create Harbor users from Excel data (
register.py
) - Delete Harbor users individually or in batches (
delete_users.py
,delete_users_fixed.py
)
The application interacts with Harbor's REST API v2.0 at https://harbor.seahi.me
.
Setup and Environment
Dependencies Installation
pip install -r requirements.txt
Virtual Environment Setup
# Activate existing virtual environment
source venv/bin/activate # On Unix/macOS
# or
venv\Scripts\activate # On Windows
Core Architecture
Data Flow
- Input: Excel file (
users.xlsx
) with user data (username, realname, password, email) - Authentication: HTTP Basic Auth with Harbor admin credentials
- API Operations: REST API calls to Harbor's
/api/v2.0/users
endpoint - Error Handling: Comprehensive exception handling with Chinese language user feedback
Key Components
- Authentication:
get_admin_credentials()
- Interactive credential collection with getpass - User Operations:
create_harbor_user()
- User creation via POST (register.py:20)delete_harbor_user()
- User deletion via DELETE (requires user ID lookup)get_user_id_by_username()
- User ID resolution from username
- Excel Processing:
pd.read_excel()
withskiprows=1
to handle header row - Connection Testing:
test_api_connection()
validates API connectivity and auth (delete_users_fixed.py:20) - Interactive Modes:
delete_users_fixed.py
provides menu-driven user interaction
File Structure
register.py
- User registration from Exceldelete_users.py
- Basic user deletion tooldelete_users_fixed.py
- Enhanced deletion tool with better error handling and interactive modesusers.xlsx
- Excel data source (not in version control)requirements.txt
- Python dependencies
Common Commands
Environment Setup
# Activate virtual environment (required before running scripts)
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
Run Scripts
# Register users from Excel file
python register.py
# Delete users (recommended enhanced version)
python delete_users_fixed.py
# Delete users (basic version)
python delete_users.py
Development
# Check Python syntax
python -m py_compile register.py
python -m py_compile delete_users_fixed.py
# Run with verbose output for debugging
python -v register.py
API Configuration
- Harbor URL:
https://harbor.seahi.me
- API Version: v2.0
- Authentication: HTTP Basic Auth
- SSL Verification: Disabled (
verify=False
) - HTTPS Warnings: Suppressed via urllib3
Excel File Format
Expected structure for users.xlsx
:
- Row 1: Headers (skipped)
- Column 0: Username
- Column 1: Real name
- Column 2: Password
- Column 4: Email address
Error Handling Patterns
- HTTP 409: User already exists (treated as success for registration)
- HTTP 401: Authentication failure
- HTTP 404: User not found
- HTTP 412: User has dependencies (cannot delete)
- Connection timeouts and network errors are handled gracefully