Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
from_container_url
  • Loading branch information
rakshith91 committed Oct 3, 2019
commit 156196382901e5b2aef5d1ce7492a2a2c8b2dee7
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class ContainerClient(AsyncStorageAccountHostsMixin, ContainerClientBase):
:caption: Creating the container client directly.
"""
def __init__(
self, container_url, # type: str
self, account_url, # type: str
container_name=None, # type: str
credential=None, # type: Optional[Any]
loop=None, # type: Any
Expand All @@ -107,7 +107,7 @@ def __init__(
# type: (...) -> None
kwargs['retry_policy'] = kwargs.get('retry_policy') or ExponentialRetry(**kwargs)
super(ContainerClient, self).__init__(
container_url,
account_url,
container_name=container_name,
credential=credential,
loop=loop,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,33 +107,50 @@ class ContainerClient(StorageAccountHostsMixin):
:caption: Creating the container client directly.
"""
def __init__(
self, container_url, # type: str
container_name=None, # type: Optional[str]
self, account_url, # type: str
container_name, # type: str
credential=None, # type: Optional[Any]
**kwargs # type: Any
):
# type: (...) -> None
try:
if not container_url.lower().startswith('http'):
container_url = "https://" + container_url
if not account_url.lower().startswith('http'):
account_url = "https://" + account_url
except AttributeError:
raise ValueError("Container URL must be a string.")
parsed_url = urlparse(container_url.rstrip('/'))
parsed_url = urlparse(account_url.rstrip('/'))

if not parsed_url.path and not container_name:
if not container_name:
raise ValueError("Please specify a container name.")
if not parsed_url.netloc:
raise ValueError("Invalid URL: {}".format(container_url))
raise ValueError("Invalid URL: {}".format(account_url))

path_container = ""
if parsed_url.path:
path_container = parsed_url.path.lstrip('/').partition('/')[0]
_, sas_token = parse_query(parsed_url.query)
self.container_name = container_name or unquote(path_container) # type: ignore
self.container_name = container_name
self._query_str, credential = self._format_query_string(sas_token, credential)
super(ContainerClient, self).__init__(parsed_url, service='blob', credential=credential, **kwargs)
self._client = AzureBlobStorage(self.url, pipeline=self._pipeline)

@classmethod
def from_container_url(cls, container_url, credential=None, **kwargs):
try:
if not container_url.lower().startswith('http'):
container_url = "https://" + container_url
except AttributeError:
raise ValueError("Container URL must be a string.")
parsed_url = urlparse(container_url.rstrip('/'))

if not parsed_url.netloc:
raise ValueError("Invalid URL: {}".format(container_url))
account_url = parsed_url.netloc.rstrip('/') + "?" + parsed_url.query
container_name = unquote(parsed_url.path.lstrip('/').partition('/')[0])
if not container_name:
raise ValueError("Invalid URL. Please provide a url with a valid container_name")

return cls(
account_url, container_name=container_name, credential=credential, **kwargs
)

def _format_url(self, hostname):
container_name = self.container_name
if isinstance(container_name, six.text_type):
Expand Down