diff --git a/pyinfra/storage/adapters/s3.py b/pyinfra/storage/adapters/s3.py index 3db0488..ef2b1d1 100644 --- a/pyinfra/storage/adapters/s3.py +++ b/pyinfra/storage/adapters/s3.py @@ -1,18 +1,27 @@ import io import logging +import re from itertools import repeat from operator import attrgetter from urllib.parse import urlparse from minio import Minio from retry import retry -from validators import url from pyinfra.config import Config, get_config + CONFIG = get_config() logger = logging.getLogger(CONFIG.logging_level_root) +ALLOWED_CONNECTION_SCHEMES = {"http", "https"} +URL_VALIDATOR = re.compile( + r"^((" + + r"([A-Za-z]{3,9}:(?:\/\/)?)" + + r"(?:[\-;:&=\+\$,\w]+@)?" + r"[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)" + + r"[A-Za-z0-9\.\-]+)" + r"((?:\/[\+~%\/\.\w\-_]*)?" + + r"\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)") + class S3StorageAdapter(object): def __init__(self, client: Minio): @@ -62,8 +71,8 @@ class S3StorageAdapter(object): def _parse_endpoint(endpoint): - if url(endpoint): - parsed_url = urlparse(endpoint) + parsed_url = urlparse(endpoint) + if URL_VALIDATOR.match(endpoint) and parsed_url.netloc and parsed_url.scheme in ALLOWED_CONNECTION_SCHEMES: return {"secure": parsed_url.scheme == "https", "endpoint": parsed_url.netloc} else: raise Exception(f"The configured storage endpoint is not a valid url: {endpoint}") diff --git a/requirements.txt b/requirements.txt index e859054..43409f0 100755 --- a/requirements.txt +++ b/requirements.txt @@ -7,4 +7,3 @@ testcontainers==3.4.2 docker-compose==1.29.2 pytest~=7.0.1 funcy==1.17 -validators==0.18.2