RED-4653: Switched to validating the connection url via a regex since the validators lib parses our endpoints incorrectly
This commit is contained in:
parent
8d0234fcc5
commit
8f1ef0dd55
@ -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}")
|
||||
|
||||
@ -7,4 +7,3 @@ testcontainers==3.4.2
|
||||
docker-compose==1.29.2
|
||||
pytest~=7.0.1
|
||||
funcy==1.17
|
||||
validators==0.18.2
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user