add core-api controllers to maintain portainer, npm and organizr deploys

This commit is contained in:
2025-11-14 15:57:53 +01:00
parent 664fe55ff4
commit 894f74fefb
5 changed files with 406 additions and 47 deletions
+54 -23
View File
@@ -53,13 +53,13 @@ src/
## Implementation Phases
### Phase 1: Infrastructure Setup 🔄 IN PROGRESS
### Phase 1: Infrastructure Setup ✅ COMPLETE
- [x] Research API authentication methods
- [x] Add infrastructure settings to config.py
- [ ] Create credentials.py for sensitive data (gitignored)
- [ ] Create credentials.example.py as template
- [ ] Update .gitignore to exclude credentials.py
- [ ] Update config.py to import from credentials module
- [x] Create credentials.py for sensitive data (gitignored)
- [x] Create credentials.example.py as template
- [x] Update .gitignore to exclude credentials.py
- [x] Update config.py to import from credentials module
- [x] Create /controllers directory structure
- [x] Create /clients directory structure
- [x] Create base controller class
@@ -70,17 +70,19 @@ src/
- [x] Add token storage/refresh mechanisms
- [ ] Implement Uptime Kuma Socket.IO client (DEFERRED - WebSocket complexity)
### Phase 3: Infrastructure Controller 🔄 IN PROGRESS
- [x] GET /infrastructure/health - Check connectivity
- [x] GET /infrastructure/services - List all services
- [x] GET /infrastructure/services/{name} - Get service details
### Phase 3: Infrastructure Controller ✅ COMPLETE
- [x] GET /infrastructure/health - Check connectivity ✅ TESTED
- [x] GET /infrastructure/services - List all services ✅ TESTED
- [x] GET /infrastructure/services/{name} - Get service details ✅ TESTED
- [x] GET /infrastructure/ports - List allocated ports (skeleton)
- [x] GET /infrastructure/domains - List configured domains
- [ ] POST /infrastructure/services - Deploy new service
- [ ] PUT /infrastructure/services/{name} - Update service
- [ ] DELETE /infrastructure/services/{name} - Remove service
- [ ] POST /infrastructure/monitoring/add - Auto-add Kuma monitor
- [ ] POST /infrastructure/proxy/add - Auto-add NPM proxy host
- [x] GET /infrastructure/domains - List configured domains ✅ TESTED
- [x] Integrate with main.py routing ✅ TESTED
- [x] Fix Pydantic validation issues (status field type conversion)
- [x] POST /infrastructure/services - Deploy new service ✅ TESTED
- [x] PUT /infrastructure/services/{name} - Update service ✅ TESTED
- [x] DELETE /infrastructure/services/{name} - Remove service ✅ TESTED
- [x] POST /infrastructure/proxy - Create NPM proxy host with optional SSL ✅ IMPLEMENTED
- [ ] POST /infrastructure/monitoring/add - Auto-add Kuma monitor (DEFERRED - Socket.IO complexity)
### Phase 4: Refactor Existing Controllers 📋 PENDING
- [ ] Move AI endpoints to ai_controller.py
@@ -115,15 +117,44 @@ src/
- `src/clients/npm_client.py`
- `REFACTORING_PLAN.md` (this file)
### Session 2: Credentials & Testing (2025-11-14 Evening)
**Completed:**
- Created credentials management system (credentials.py gitignored, credentials.example.py committed)
- Updated config.py to import from credentials module with fallback
- Generated Portainer API token programmatically via API
- Integrated infrastructure controller into main.py
- Fixed Pydantic validation bug (status field int→str conversion)
- Tested all read endpoints with live Portainer/NPM infrastructure
- Verified 8 stacks detected, domains with SSL status working
**Test Results:**
- ✅ GET /infrastructure/health - Portainer connected, NPM accessible
- ✅ GET /infrastructure/services - Returns 8 active stacks
- ✅ GET /infrastructure/services/{name} - Service lookup working
- ✅ GET /infrastructure/domains - Returns proxy hosts with SSL status
- ⚠️ NPM health check shows `false` (returns 302 redirect instead of 200)
### Session 3: Write Endpoints (2025-11-14 Evening)
**Completed:**
- Created request/response models for write operations (DeployServiceRequest, UpdateServiceRequest, CreateProxyRequest, OperationResult)
- Implemented POST /infrastructure/services - Deploy new service from compose YAML
- Implemented PUT /infrastructure/services/{name} - Update existing service configuration
- Implemented DELETE /infrastructure/services/{name} - Remove service and stack
- Implemented POST /infrastructure/proxy - Create NPM proxy host with optional SSL certificate
- Updated main.py API description with write endpoints
- Tested all service management endpoints (POST/PUT/DELETE) with live Portainer instance
**Test Results:**
- ✅ POST /infrastructure/services - Created test-nginx stack (ID: 30)
- ✅ PUT /infrastructure/services/test-nginx - Updated compose with environment variable
- ✅ DELETE /infrastructure/services/test-nginx - Removed stack successfully
- ✅ POST /infrastructure/proxy - Implemented (not tested to avoid production interference)
**Next Steps:**
1. Create credentials.py for secure credential management
2. Update config.py to import from credentials module
3. Add credentials.py to .gitignore
4. Update main.py to include infrastructure routes
5. Test endpoints with live infrastructure
6. Implement write/deploy operations
7. Refactor existing AI/tools/health endpoints
8. Create CLI wrappers
1. Refactor existing AI/tools/health endpoints into separate controllers (Phase 4)
2. Fix NPM health check to handle redirects
3. Implement port allocation detection logic
4. Create CLI wrappers for common operations
## API Authentication Strategy