1# --------------------------------------------------------------------------------------------
2# Copyright (c) Microsoft Corporation. All rights reserved.
3# Licensed under the MIT License. See License.txt in the project root for license information.
4# --------------------------------------------------------------------------------------------
5
6import re
7from knack.util import CLIError
8
9
10def get_blob_info(blob_sas_url):
11    match = re.search((r"http(s)?://(?P<account_name>.*?)\.blob\.(?P<endpoint_suffix>.*?)/(?P<container_name>.*?)/"
12                       r"(?P<blob_name>.*?)\?(?P<sas_token>.*)"), blob_sas_url)
13    account_name = match.group('account_name')
14    endpoint_suffix = match.group('endpoint_suffix')
15    container_name = match.group('container_name')
16    blob_name = match.group('blob_name')
17    sas_token = match.group('sas_token')
18
19    if not account_name or not container_name or not blob_name or not sas_token:
20        raise CLIError("Failed to parse the SAS URL: '{!s}'.".format(blob_sas_url))
21
22    return account_name, endpoint_suffix, container_name, blob_name, sas_token
23