Skip to content

Commit

Permalink
Age limit featured for proxies added.
Browse files Browse the repository at this point in the history
  • Loading branch information
claffin committed May 7, 2021
1 parent 4232890 commit 7c1bc9c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ All you need is:

### Installation

#### Environment variables:

##### Required
`` USERNAME`` - set the username for the forward proxy.

`` PASSWORD`` - set the password for the forward proxy.

##### Optional

`` AGE_LIMIT`` - set the age limit for your forward proxies in seconds. Once the age limit is reached, the proxy is replaced. A value of 0 disables the feature. Default value: 0.

See individual provider pages for environment variables required in above providers supported section.

#### Docker (recommended)
Expand Down
14 changes: 10 additions & 4 deletions cloudproxy/providers/aws/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,21 @@ def aws_check_alive():
ip_ready = []
for instance in list_instances():
try:
if check_alive(instance["Instances"][0]["PublicIpAddress"]):
elapsed = datetime.datetime.now(
datetime.timezone.utc
) - dateparser.parse(instance["Instances"][0]["LaunchTime"])
if config["age_limit"] > 0:
if elapsed > datetime.timedelta(seconds=config["age_limit"]):
delete_proxy(instance["Instances"][0]["InstanceId"])
logger.info(
"Recycling droplet, reached age limit -> " + instance["Instances"][0]["PublicIpAddress"]
)
elif check_alive(instance["Instances"][0]["PublicIpAddress"]):
logger.info(
"Alive: AWS -> " + instance["Instances"][0]["PublicIpAddress"]
)
ip_ready.append(instance["Instances"][0]["PublicIpAddress"])
else:
elapsed = datetime.datetime.now(
datetime.timezone.utc
) - dateparser.parse(instance["Instances"][0]["LaunchTime"])
if elapsed > datetime.timedelta(minutes=10):
delete_proxy(instance["Instances"][0]["InstanceId"])
logger.info(
Expand Down
16 changes: 11 additions & 5 deletions cloudproxy/providers/digitalocean/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
delete_proxy,
)
from cloudproxy.providers import settings
from cloudproxy.providers.settings import delete_queue
from cloudproxy.providers.settings import delete_queue, config


def do_deployment(min_scaling):
Expand All @@ -38,13 +38,19 @@ def do_check_alive():
ip_ready = []
for droplet in list_droplets():
try:
if check_alive(droplet.ip_address):
elapsed = datetime.datetime.now(
datetime.timezone.utc
) - dateparser.parse(droplet.created_at)
if config["age_limit"] > 0:
if elapsed > datetime.timedelta(seconds=config["age_limit"]):
delete_proxy(droplet)
logger.info(
"Recycling droplet, reached age limit -> " + str(droplet.ip_address)
)
elif check_alive(droplet.ip_address):
logger.info("Alive: DO -> " + str(droplet.ip_address))
ip_ready.append(droplet.ip_address)
else:
elapsed = datetime.datetime.now(
datetime.timezone.utc
) - dateparser.parse(droplet.created_at)
if elapsed > datetime.timedelta(minutes=10):
delete_proxy(droplet)
logger.info(
Expand Down
2 changes: 2 additions & 0 deletions cloudproxy/providers/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

config = {
"auth": {"username": "", "password": ""},
"age_limit": 0,
"providers": {
"digitalocean": {
"enabled": False,
Expand Down Expand Up @@ -30,6 +31,7 @@
# Set proxy authentication
config["auth"]["username"] = os.environ.get("USERNAME", "changeme")
config["auth"]["password"] = os.environ.get("PASSWORD", "changeme")
config["age_limit"] = int(os.environ.get('AGE_LIMIT', 0))

# Set DigitalOceana config
config["providers"]["digitalocean"]["enabled"] = os.environ.get(
Expand Down

0 comments on commit 7c1bc9c

Please sign in to comment.