From 99c6b171e4578f2ecb04925719c677142d51e551 Mon Sep 17 00:00:00 2001 From: Khushboo Vashi Date: Fri, 11 Mar 2022 14:33:30 +0530 Subject: [PATCH] Fixed the default Public IP range in AWS deployment. --- web/pgacloud/utils/misc.py | 10 ++++++++++ web/pgadmin/misc/cloud/utils/__init__.py | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/web/pgacloud/utils/misc.py b/web/pgacloud/utils/misc.py index ddbbf04cb..586bf09c1 100644 --- a/web/pgacloud/utils/misc.py +++ b/web/pgacloud/utils/misc.py @@ -10,6 +10,7 @@ import random import string import urllib3 +import ipaddress def get_my_ip(): @@ -23,6 +24,15 @@ def get_my_ip(): except Exception: external_ip = '127.0.0.1' + if type(external_ip) == bytes: + external_ip = external_ip.decode('utf-8') + + ip = ipaddress.ip_address(external_ip) + if isinstance(ip, ipaddress.IPv4Address): + return '{}/{}'.format(external_ip, 32) + elif isinstance(ip, ipaddress.IPv6Address): + return '{}/{}'.format(external_ip, 128) + return '{}/{}'.format(external_ip, 32) diff --git a/web/pgadmin/misc/cloud/utils/__init__.py b/web/pgadmin/misc/cloud/utils/__init__.py index ba4b73331..4cded810f 100644 --- a/web/pgadmin/misc/cloud/utils/__init__.py +++ b/web/pgadmin/misc/cloud/utils/__init__.py @@ -8,6 +8,7 @@ # ########################################################################## import urllib3 +import ipaddress def get_my_ip(): @@ -21,4 +22,13 @@ def get_my_ip(): except Exception: external_ip = '127.0.0.1' + if type(external_ip) == bytes: + external_ip = external_ip.decode('utf-8') + + ip = ipaddress.ip_address(external_ip) + if isinstance(ip, ipaddress.IPv4Address): + return '{}/{}'.format(external_ip, 32) + elif isinstance(ip, ipaddress.IPv6Address): + return '{}/{}'.format(external_ip, 128) + return '{}/{}'.format(external_ip, 32)