From 58c9ff0de2a9da5f53a984b412b60497ac203d32 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Fri, 22 May 2020 20:36:04 +0300 Subject: [PATCH] azure: drop obsoleted url format (#3856) --- dvc/remote/azure.py | 39 +++++++-------------------------- tests/unit/remote/test_azure.py | 12 +++++----- 2 files changed, 13 insertions(+), 38 deletions(-) diff --git a/dvc/remote/azure.py b/dvc/remote/azure.py index e39ba2a06..90d76dbf8 100644 --- a/dvc/remote/azure.py +++ b/dvc/remote/azure.py @@ -1,10 +1,8 @@ import logging import os import posixpath -import re import threading from datetime import datetime, timedelta -from urllib.parse import urlparse from funcy import cached_property, wrap_prop @@ -19,12 +17,6 @@ logger = logging.getLogger(__name__) class AzureRemote(BaseRemote): scheme = Schemes.AZURE path_cls = CloudURLInfo - REGEX = ( - r"azure://((?P[^=;]*)?|(" - # backward compatibility - r"(ContainerName=(?P[^;]+);?)?" - r"(?P.+)?)?)$" - ) REQUIRES = {"azure-storage-blob": "azure.storage.blob"} PARAM_CHECKSUM = "etag" COPY_POLL_SECONDS = 5 @@ -34,31 +26,16 @@ class AzureRemote(BaseRemote): super().__init__(repo, config) url = config.get("url", "azure://") + self.path_info = self.path_cls(url) - match = re.match(self.REGEX, url) # backward compatibility - path = match.group("path") - bucket = ( - urlparse(url if path else "").netloc - or match.group("container_name") # backward compatibility - or os.getenv("AZURE_STORAGE_CONTAINER_NAME") - ) + if not self.path_info.bucket: + self.path_info = self.path_cls.from_parts( + scheme=self.scheme, + netloc=os.getenv("AZURE_STORAGE_CONTAINER_NAME"), + ) - self.connection_string = ( - config.get("connection_string") - or match.group("connection_string") # backward compatibility - or os.getenv("AZURE_STORAGE_CONNECTION_STRING") - ) - - if not bucket: - raise ValueError("azure storage container name missing") - - if not self.connection_string: - raise ValueError("azure storage connection string missing") - - self.path_info = ( - self.path_cls(url) - if path - else self.path_cls.from_parts(scheme=self.scheme, netloc=bucket) + self.connection_string = config.get("connection_string") or os.getenv( + "AZURE_STORAGE_CONNECTION_STRING" ) @wrap_prop(threading.Lock()) diff --git a/tests/unit/remote/test_azure.py b/tests/unit/remote/test_azure.py index b3fa97948..24f9bd27f 100644 --- a/tests/unit/remote/test_azure.py +++ b/tests/unit/remote/test_azure.py @@ -9,13 +9,11 @@ connection_string = ( ) -def test_init_compat(dvc): - url = ( - "azure://ContainerName={container_name};{connection_string}" - ).format( - container_name=container_name, connection_string=connection_string, - ) - config = {"url": url} +def test_init_env_var(monkeypatch, dvc): + monkeypatch.setenv("AZURE_STORAGE_CONTAINER_NAME", container_name) + monkeypatch.setenv("AZURE_STORAGE_CONNECTION_STRING", connection_string) + + config = {"url": "azure://"} remote = AzureRemote(dvc, config) assert remote.path_info == "azure://" + container_name assert remote.connection_string == connection_string