# 🔐 Admin Panel Documentation

## Overview

The Admin Panel provides a comprehensive interface for managing services, providers, and environments in the Multi-Cloud Orchestration Portal.

## Features

### ✅ Implemented

1. **Service Management**
   - View all services
   - Enable/disable services
   - Track service configuration changes

2. **Provider Management**
   - View all cloud providers
   - Enable/disable providers
   - Track provider configuration changes

3. **Environment Management**
   - View all environments
   - Enable/disable environments
   - Updates `environments.yaml` file

4. **Audit Logging**
   - View all admin actions
   - Track who made changes
   - IP address logging
   - Timestamp tracking

5. **Authentication**
   - Simple token-based authentication
   - Session management
   - Secure admin routes

## Access

**URL**: `http://localhost:5000/admin` (or `/admin` in the Vue app)

**Default Credentials**:
- Username: `admin`
- Password: `admin` (or set `ADMIN_PASSWORD` environment variable)

## API Endpoints

### Authentication
- `POST /api/admin/login` - Login and get admin token

### Services
- `GET /api/admin/services` - Get all services
- `GET /api/admin/services/:name` - Get specific service
- `PUT /api/admin/services/:name` - Update service (enable/disable)

### Providers
- `GET /api/admin/providers` - Get all providers
- `GET /api/admin/providers/:name` - Get specific provider
- `PUT /api/admin/providers/:name` - Update provider (enable/disable)

### Environments
- `PUT /api/admin/environments/:name/toggle` - Toggle environment enabled/disabled

### Audit Logs
- `GET /api/admin/audit-logs?limit=100` - Get audit logs

## Database Schema

### service_config
- `id` - Primary key
- `service_name` - Unique service identifier
- `enabled` - Boolean flag
- `config_json` - JSON configuration
- `updated_at` - Timestamp
- `updated_by` - Admin username

### provider_config
- `id` - Primary key
- `provider_name` - Unique provider identifier
- `enabled` - Boolean flag
- `config_json` - JSON configuration
- `updated_at` - Timestamp
- `updated_by` - Admin username

### admin_audit_log
- `id` - Primary key
- `admin_user` - Username who made the change
- `action` - Action performed
- `resource_type` - Type of resource (service, provider, environment)
- `resource_id` - Resource identifier
- `details` - JSON details
- `ip_address` - IP address of admin
- `timestamp` - When the action occurred

## Usage

### Enabling/Disabling Services

1. Navigate to Admin Panel
2. Click on "Services" tab
3. Toggle the switch for any service
4. Changes are saved immediately
5. Audit log entry is created

### Enabling/Disabling Providers

1. Navigate to Admin Panel
2. Click on "Providers" tab
3. Toggle the switch for any provider
4. Changes are saved immediately
5. Audit log entry is created

### Enabling/Disabling Environments

1. Navigate to Admin Panel
2. Click on "Environments" tab
3. Toggle the switch for any environment
4. Changes update `environments.yaml` file
5. Audit log entry is created

## Security

- All admin routes require authentication token
- Token is stored in localStorage
- Token expires after 24 hours
- All actions are logged in audit log
- IP addresses are tracked

## Future Enhancements

- [ ] Role-based access control (RBAC)
- [ ] Multi-user support
- [ ] Password hashing (bcrypt)
- [ ] JWT tokens instead of simple tokens
- [ ] Two-factor authentication (2FA)
- [ ] Email notifications for admin actions
- [ ] Advanced filtering in audit logs
- [ ] Export audit logs to CSV/PDF

## Troubleshooting

### Can't login
- Check username is `admin`
- Check password (default: `admin` or `ADMIN_PASSWORD` env var)
- Check browser console for errors

### Changes not saving
- Check authentication token is valid
- Check browser console for API errors
- Check server logs for errors

### Audit logs not showing
- Check database is initialized
- Check admin_audit_log table exists
- Check authentication token is valid

---

**Last Updated**: 2024-11-19
**Version**: 1.0.0

