5c8fc9e26580b143454adea9b77f07419f215092
添加诊断脚本 test_config.py,用于测试和验证环境变量配置的正确加载。 脚本检查当前工作目录、Python 环境、.env 文件位置、已加载的环境变量, 并测试 python-dotenv 和 pydantic-settings 的集成情况,以协助调试配置问题。
Git Manager
A web-based management platform for Gitea server mirrors and SSH keys, providing centralized control over Git server synchronization and key management.
Features
-
SSH Key Management
- Create, read, update, and delete SSH keys
- AES-256 encryption for stored private keys
- Secure key storage and retrieval
-
Server Management
- Add and manage Gitea server configurations
- Server health monitoring
- Automatic synchronization support
-
Repository Synchronization
- Mirror repositories from Gitea servers
- Sync history and logging
- Scheduled sync operations
-
Web Interface
- Modern Vue.js-based frontend
- Element Plus UI components
- Real-time status monitoring
-
REST API
- Full-featured REST API
- Token-based authentication
- OpenAPI documentation
Quick Start
Prerequisites
- Python 3.8+
- Node.js 16+
- Git
Installation
- Clone the repository:
git clone <repository-url>
cd git
- Install backend dependencies:
cd backend
pip install -r requirements.txt
- Install frontend dependencies:
cd ../frontend
npm install
Initialization
- Create environment configuration:
cp .env.example .env
- Edit
.envwith your configuration:
# Generate a secure encryption key (32 bytes, base64 encoded)
python -c "import base64, os; print(base64.b64encode(os.urandom(32)).decode())"
# Generate a secure API token
python -c "import secrets; print(secrets.token_urlsafe(32))"
- Initialize the database:
cd backend
python init_db.py
Build and Run
Option 1: Using the start script (Linux/Mac)
./start.sh
Option 2: Manual startup
- Build the frontend:
cd frontend
npm run build
- Start the backend server:
cd ../backend
python -m app.main
Or using uvicorn directly:
cd backend
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
- Access the application:
- Web UI: http://localhost:8000
- API Documentation: http://localhost:8000/api/docs
- ReDoc: http://localhost:8000/api/redoc
API Documentation
Authentication
All API endpoints require authentication via the X-API-Token header:
curl -H "X-API-Token: your-api-token" http://localhost:8000/api/servers
Main Endpoints
Status
GET /api/status- Get system status
SSH Keys
GET /api/ssh-keys- List all SSH keysPOST /api/ssh-keys- Create a new SSH keyGET /api/ssh-keys/{key_id}- Get SSH key detailsPUT /api/ssh-keys/{key_id}- Update SSH keyDELETE /api/ssh-keys/{key_id}- Delete SSH key
Servers
GET /api/servers- List all serversPOST /api/servers- Add a new serverGET /api/servers/{server_id}- Get server detailsPUT /api/servers/{server_id}- Update serverDELETE /api/servers/{server_id}- Delete serverPOST /api/servers/{server_id}/sync- Trigger server sync
For detailed API documentation, visit /api/docs when the server is running.
Development Setup
Backend Development
- Install development dependencies:
cd backend
pip install -r requirements.txt
- Run tests:
pytest
- Run with auto-reload:
uvicorn app.main:app --reload
Frontend Development
- Start development server:
cd frontend
npm run dev
- Build for production:
npm run build
- Preview production build:
npm run preview
Project Structure
git/
├── backend/ # FastAPI backend
│ ├── app/
│ │ ├── api/ # API route handlers
│ │ ├── models/ # SQLAlchemy ORM models
│ │ ├── schemas/ # Pydantic schemas
│ │ ├── services/ # Business logic
│ │ ├── config.py # Configuration management
│ │ ├── database.py # Database connection
│ │ ├── security.py # Encryption & auth
│ │ └── main.py # FastAPI application
│ ├── tests/ # Backend tests
│ ├── init_db.py # Database initialization script
│ └── requirements.txt # Python dependencies
├── frontend/ # Vue.js frontend
│ ├── src/
│ │ ├── api/ # API client
│ │ ├── components/ # Vue components
│ │ ├── router/ # Vue Router config
│ │ ├── stores/ # Pinia stores
│ │ └── main.js # App entry point
│ ├── package.json # Node dependencies
│ └── vite.config.js # Vite config
├── data/ # Application data
│ ├── database.db # SQLite database
│ ├── ssh-keys/ # Stored SSH keys
│ └── repos/ # Mirrored repositories
├── docs/ # Documentation
├── tests/ # Integration tests
├── .env.example # Environment template
├── start.sh # Startup script
└── README.md # This file
Configuration
Configuration is managed through environment variables in the .env file:
| Variable | Description | Default |
|---|---|---|
GM_ENCRYPT_KEY |
AES-256 encryption key (base64) | Required |
GM_API_TOKEN |
API authentication token | Required |
GM_DATA_DIR |
Data directory path | ./data |
GM_HOST |
Server host | 0.0.0.0 |
GM_PORT |
Server port | 8000 |
Tech Stack
Backend
- FastAPI - Modern, fast web framework
- SQLAlchemy - ORM for database operations
- Pydantic - Data validation using Python type annotations
- Uvicorn - ASGI server
- APScheduler - Task scheduling
- Paramiko - SSH/SCP operations
- GitPython - Git operations
- Cryptography - AES-256 encryption
Frontend
- Vue.js 3 - Progressive JavaScript framework
- Vite - Build tool and dev server
- Vue Router - Official router
- Pinia - State management
- Element Plus - Vue 3 UI library
- Axios - HTTP client
Database
- SQLite - Lightweight database (easily replaceable with PostgreSQL/MySQL)
Security
- SSH private keys are encrypted using AES-256-GCM
- API authentication via secure tokens
- CORS support for cross-origin requests
- Input validation and sanitization
License
[Your License Here]
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Description
Languages
Python
80.1%
Vue
14.2%
JavaScript
3.4%
Batchfile
1.4%
Shell
0.8%
Other
0.1%