From dc4ce8acc9f35ad9454535aca691c0571317ff54 Mon Sep 17 00:00:00 2001 From: claffin Date: Wed, 26 Feb 2025 06:38:42 +0000 Subject: [PATCH] Add multi-account support for cloud providers - Implement multi-instance configuration for AWS, DigitalOcean, GCP, and Hetzner - Update provider management to support multiple accounts per provider - Add support for instance-specific scaling, region, and display name configurations - Enhance API and UI to handle multiple provider instances - Improve environment variable configuration for additional accounts - Update documentation for multi-account setup and configuration --- README.md | 130 +++++- cloudproxy-ui/src/components/ListProxies.vue | 82 +++- cloudproxy/check.py | 2 +- cloudproxy/main.py | 333 ++++++++++++-- cloudproxy/providers/aws/functions.py | 258 +++++++++-- cloudproxy/providers/aws/main.py | 123 ++++-- .../providers/digitalocean/functions.py | 145 +++++- cloudproxy/providers/digitalocean/main.py | 136 ++++-- cloudproxy/providers/hetzner/functions.py | 131 +++++- cloudproxy/providers/hetzner/main.py | 110 +++-- cloudproxy/providers/manager.py | 89 ++-- cloudproxy/providers/settings.py | 222 ++++++++-- docs/api.md | 143 +++++- docs/aws.md | 102 ++++- docs/digitalocean.md | 58 ++- docs/gcp.md | 115 +++-- docs/hetzner.md | 85 +++- tests/test_api_providers.py | 380 ++++++++++++++++ tests/test_check.py | 2 +- tests/test_check_multi_account.py | 209 +++++++++ tests/test_main.py | 1 + tests/test_main_models.py | 91 +++- tests/test_main_routes.py | 302 ++++++++----- tests/test_providers_aws_functions.py | 413 ++++++++++++++---- tests/test_providers_aws_main.py | 200 ++++++++- .../test_providers_digitalocean_functions.py | 241 +++++++++- tests/test_providers_digitalocean_main.py | 15 +- tests/test_providers_hetzner_functions.py | 298 +++++++++++++ tests/test_providers_manager.py | 183 +++++++- tests/test_providers_manager_functions.py | 194 +++++++- tests/test_proxy_model.py | 184 ++++++++ 31 files changed, 4342 insertions(+), 635 deletions(-) create mode 100644 tests/test_api_providers.py create mode 100644 tests/test_check_multi_account.py create mode 100644 tests/test_providers_hetzner_functions.py create mode 100644 tests/test_proxy_model.py diff --git a/README.md b/README.md index 2ddb170..014489f 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ CloudProxy exposes an API and modern UI for managing your proxy infrastructure. * Modern UI with real-time updates * Interactive API documentation * Multi-provider support +* Multiple accounts per provider * Automatic proxy rotation * Health monitoring * Easy scaling controls @@ -158,6 +159,43 @@ my_request = requests.get("https://api.ipify.org", proxies=proxies) For detailed API documentation, see [API Documentation](docs/api.md). +## Multi-Account Provider Support + +CloudProxy now supports multiple accounts per provider, allowing you to: + +- Use multiple API keys or access tokens for the same provider +- Configure different regions, sizes, and scaling parameters per account +- Organize proxies by account/instance for better management +- Scale each account independently + +Each provider can have multiple "instances", which represent different accounts or configurations. Each instance has its own: + +- Scaling parameters (min/max) +- Region settings +- Size configuration +- API credentials +- IP addresses + +To configure multiple instances, use environment variables with the instance name in the format: +``` +PROVIDERNAME_INSTANCENAME_VARIABLE +``` + +For example, to configure two DigitalOcean accounts: +```shell +# Default DigitalOcean account +DIGITALOCEAN_ENABLED=True +DIGITALOCEAN_ACCESS_TOKEN=your_first_token +DIGITALOCEAN_DEFAULT_REGION=lon1 +DIGITALOCEAN_DEFAULT_MIN_SCALING=2 + +# Second DigitalOcean account +DIGITALOCEAN_SECONDACCOUNT_ENABLED=True +DIGITALOCEAN_SECONDACCOUNT_ACCESS_TOKEN=your_second_token +DIGITALOCEAN_SECONDACCOUNT_REGION=nyc1 +DIGITALOCEAN_SECONDACCOUNT_MIN_SCALING=3 +``` + ## CloudProxy API Examples ### List available proxy servers @@ -287,7 +325,31 @@ For detailed API documentation, see [API Documentation](docs/api.md). "max_scaling": 2 }, "size": "s-1vcpu-1gb", - "region": "lon1" + "region": "lon1", + "instances": { + "default": { + "enabled": true, + "ips": ["192.168.1.1"], + "scaling": { + "min_scaling": 2, + "max_scaling": 2 + }, + "size": "s-1vcpu-1gb", + "region": "lon1", + "display_name": "Default Account" + }, + "secondary": { + "enabled": true, + "ips": ["192.168.1.2"], + "scaling": { + "min_scaling": 1, + "max_scaling": 3 + }, + "size": "s-1vcpu-1gb", + "region": "nyc1", + "display_name": "US Account" + } + } }, "aws": { "enabled": false, @@ -335,6 +397,72 @@ For detailed API documentation, see [API Documentation](docs/api.md). } } ``` + +### Get provider instance +#### Request + +`GET /providers/digitalocean/secondary` + + curl -X 'GET' 'http://localhost:8000/providers/digitalocean/secondary' -H 'accept: application/json' + +#### Response +```json +{ + "metadata": { + "request_id": "123e4567-e89b-12d3-a456-426614174000", + "timestamp": "2024-02-24T08:00:00Z" + }, + "message": "Provider 'digitalocean' instance 'secondary' configuration retrieved successfully", + "provider": "digitalocean", + "instance": "secondary", + "config": { + "enabled": true, + "ips": ["192.168.1.2"], + "scaling": { + "min_scaling": 1, + "max_scaling": 3 + }, + "size": "s-1vcpu-1gb", + "region": "nyc1", + "display_name": "US Account" + } +} +``` + +### Update provider instance scaling +#### Request + +`PATCH /providers/digitalocean/secondary` + + curl -X 'PATCH' 'http://localhost:8000/providers/digitalocean/secondary' \ + -H 'accept: application/json' \ + -H 'Content-Type: application/json' \ + -d '{"min_scaling": 2, "max_scaling": 5}' + +#### Response +```json +{ + "metadata": { + "request_id": "123e4567-e89b-12d3-a456-426614174000", + "timestamp": "2024-02-24T08:00:00Z" + }, + "message": "Provider 'digitalocean' instance 'secondary' scaling configuration updated successfully", + "provider": "digitalocean", + "instance": "secondary", + "config": { + "enabled": true, + "ips": ["192.168.1.2"], + "scaling": { + "min_scaling": 2, + "max_scaling": 5 + }, + "size": "s-1vcpu-1gb", + "region": "nyc1", + "display_name": "US Account" + } +} +``` + CloudProxy runs on a schedule of every 30 seconds, it will check if the minimum scaling has been met, if not then it will deploy the required number of proxies. The new proxy info will appear in IPs once they are deployed and ready to be used. diff --git a/cloudproxy-ui/src/components/ListProxies.vue b/cloudproxy-ui/src/components/ListProxies.vue index 0a8b171..c357ba1 100644 --- a/cloudproxy-ui/src/components/ListProxies.vue +++ b/cloudproxy-ui/src/components/ListProxies.vue @@ -1,8 +1,8 @@