feat: Add increment/decrement methods to AdminAPIService

- Add increment_domain_count() method
- Add decrement_domain_count() method
- Update deploy script to preserve .env settings
This commit is contained in:
oguz ozturk 2026-01-12 17:13:59 +03:00
parent 6e29df1945
commit 0b2920e43f
2 changed files with 117 additions and 4 deletions

View File

@ -118,3 +118,92 @@ class AdminAPIService:
'error': f'Admin API error: {str(e)}'
}
def increment_domain_count(self, account_id: int) -> Dict:
"""
Increment domain count for CF account in Admin Panel
Called after successfully creating a domain
Args:
account_id: CF account ID
Returns:
{
"status": "success" | "error",
"message": str,
"new_count": int,
"available_capacity": int,
"error": str (if error)
}
"""
try:
url = f"{self.base_url}/api/cf-accounts/internal/{account_id}/increment"
response = requests.post(url, headers=self.headers, timeout=10)
if response.status_code == 200:
return response.json()
else:
return {
'status': 'error',
'error': f'Admin API returned {response.status_code}: {response.text}'
}
except requests.exceptions.Timeout:
return {
'status': 'error',
'error': 'Admin API request timeout'
}
except requests.exceptions.ConnectionError:
return {
'status': 'error',
'error': 'Cannot connect to Admin API'
}
except Exception as e:
return {
'status': 'error',
'error': f'Admin API error: {str(e)}'
}
def decrement_domain_count(self, account_id: int) -> Dict:
"""
Decrement domain count for CF account in Admin Panel
Called after successfully deleting a domain
Args:
account_id: CF account ID
Returns:
{
"status": "success" | "error",
"message": str,
"new_count": int,
"available_capacity": int,
"error": str (if error)
}
"""
try:
url = f"{self.base_url}/api/cf-accounts/internal/{account_id}/decrement"
response = requests.post(url, headers=self.headers, timeout=10)
if response.status_code == 200:
return response.json()
else:
return {
'status': 'error',
'error': f'Admin API returned {response.status_code}: {response.text}'
}
except requests.exceptions.Timeout:
return {
'status': 'error',
'error': 'Admin API request timeout'
}
except requests.exceptions.ConnectionError:
return {
'status': 'error',
'error': 'Cannot connect to Admin API'
}
except Exception as e:
return {
'status': 'error',
'error': f'Admin API error: {str(e)}'
}

View File

@ -13,13 +13,37 @@ echo "║ 🚀 Hosting Platform Deployment Script 🚀 ║"
echo "╚══════════════════════════════════════════════════════════════╝"
echo ""
# 1. Git Pull
echo "📥 [1/6] Pulling latest code from Gitea..."
# 1. Backup and Git Pull
echo "📥 [1/6] Backing up .env and pulling latest code..."
ssh -i $SSH_KEY $HOST << 'ENDSSH'
# Backup .env file
mkdir -p /opt/backups/hosting-platform
if [ -f /opt/hosting-platform/backend/.env ]; then
cp /opt/hosting-platform/backend/.env /opt/backups/hosting-platform/.env.backup.$(date +%Y%m%d_%H%M%S)
fi
# Pull latest code
cd /opt/hosting-platform
git pull origin main
git fetch origin
git reset --hard origin/main
# Restore .env file
LATEST_BACKUP=$(ls -t /opt/backups/hosting-platform/.env.backup.* 2>/dev/null | head -1)
if [ -n "$LATEST_BACKUP" ]; then
cp "$LATEST_BACKUP" /opt/hosting-platform/backend/.env
fi
# Ensure ADMIN_API config exists
if ! grep -q "ADMIN_API_URL" /opt/hosting-platform/backend/.env; then
cat >> /opt/hosting-platform/backend/.env << 'EOF'
# Admin Panel API (for fetching CF accounts)
ADMIN_API_URL=http://localhost:5001
ADMIN_API_INTERNAL_KEY=internal-api-key-1c2f72e80d1bc5f9bfee7e3726319ac7
EOF
fi
ENDSSH
echo "✅ Git pull complete"
echo "✅ Git pull complete and .env restored"
echo ""
# 2. Backend Dependencies