1# coding=utf-8
2# --------------------------------------------------------------------------
3# Copyright (c) Microsoft Corporation. All rights reserved.
4# Licensed under the MIT License. See License.txt in the project root for license information.
5# Code generated by Microsoft (R) AutoRest Code Generator.
6# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7# --------------------------------------------------------------------------
8from typing import Any, AsyncIterable, Callable, Dict, Generic, Optional, TypeVar, Union
9import warnings
10
11from azure.core.async_paging import AsyncItemPaged, AsyncList
12from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
13from azure.core.pipeline import PipelineResponse
14from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest
15from azure.mgmt.core.exceptions import ARMErrorFormat
16
17from ... import models as _models
18
19T = TypeVar('T')
20ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]]
21
22class BlobContainersOperations:
23    """BlobContainersOperations async operations.
24
25    You should not instantiate this class directly. Instead, you should create a Client instance that
26    instantiates it for you and attaches it as an attribute.
27
28    :ivar models: Alias to model classes used in this operation group.
29    :type models: ~azure.mgmt.storage.v2020_08_01_preview.models
30    :param client: Client for service requests.
31    :param config: Configuration of service client.
32    :param serializer: An object model serializer.
33    :param deserializer: An object model deserializer.
34    """
35
36    models = _models
37
38    def __init__(self, client, config, serializer, deserializer) -> None:
39        self._client = client
40        self._serialize = serializer
41        self._deserialize = deserializer
42        self._config = config
43
44    def list(
45        self,
46        resource_group_name: str,
47        account_name: str,
48        maxpagesize: Optional[str] = None,
49        filter: Optional[str] = None,
50        include: Optional[Union[str, "_models.ListContainersInclude"]] = None,
51        **kwargs: Any
52    ) -> AsyncIterable["_models.ListContainerItems"]:
53        """Lists all containers and does not support a prefix like data plane. Also SRP today does not
54        return continuation token.
55
56        :param resource_group_name: The name of the resource group within the user's subscription. The
57         name is case insensitive.
58        :type resource_group_name: str
59        :param account_name: The name of the storage account within the specified resource group.
60         Storage account names must be between 3 and 24 characters in length and use numbers and
61         lower-case letters only.
62        :type account_name: str
63        :param maxpagesize: Optional. Specified maximum number of containers that can be included in
64         the list.
65        :type maxpagesize: str
66        :param filter: Optional. When specified, only container names starting with the filter will be
67         listed.
68        :type filter: str
69        :param include: Optional, used to include the properties for soft deleted blob containers.
70        :type include: str or ~azure.mgmt.storage.v2020_08_01_preview.models.ListContainersInclude
71        :keyword callable cls: A custom type or function that will be passed the direct response
72        :return: An iterator like instance of either ListContainerItems or the result of cls(response)
73        :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.storage.v2020_08_01_preview.models.ListContainerItems]
74        :raises: ~azure.core.exceptions.HttpResponseError
75        """
76        cls = kwargs.pop('cls', None)  # type: ClsType["_models.ListContainerItems"]
77        error_map = {
78            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
79        }
80        error_map.update(kwargs.pop('error_map', {}))
81        api_version = "2020-08-01-preview"
82        accept = "application/json"
83
84        def prepare_request(next_link=None):
85            # Construct headers
86            header_parameters = {}  # type: Dict[str, Any]
87            header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
88
89            if not next_link:
90                # Construct URL
91                url = self.list.metadata['url']  # type: ignore
92                path_format_arguments = {
93                    'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
94                    'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
95                    'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
96                }
97                url = self._client.format_url(url, **path_format_arguments)
98                # Construct parameters
99                query_parameters = {}  # type: Dict[str, Any]
100                query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
101                if maxpagesize is not None:
102                    query_parameters['$maxpagesize'] = self._serialize.query("maxpagesize", maxpagesize, 'str')
103                if filter is not None:
104                    query_parameters['$filter'] = self._serialize.query("filter", filter, 'str')
105                if include is not None:
106                    query_parameters['$include'] = self._serialize.query("include", include, 'str')
107
108                request = self._client.get(url, query_parameters, header_parameters)
109            else:
110                url = next_link
111                query_parameters = {}  # type: Dict[str, Any]
112                request = self._client.get(url, query_parameters, header_parameters)
113            return request
114
115        async def extract_data(pipeline_response):
116            deserialized = self._deserialize('ListContainerItems', pipeline_response)
117            list_of_elem = deserialized.value
118            if cls:
119                list_of_elem = cls(list_of_elem)
120            return deserialized.next_link or None, AsyncList(list_of_elem)
121
122        async def get_next(next_link=None):
123            request = prepare_request(next_link)
124
125            pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
126            response = pipeline_response.http_response
127
128            if response.status_code not in [200]:
129                map_error(status_code=response.status_code, response=response, error_map=error_map)
130                raise HttpResponseError(response=response, error_format=ARMErrorFormat)
131
132            return pipeline_response
133
134        return AsyncItemPaged(
135            get_next, extract_data
136        )
137    list.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/blobServices/default/containers'}  # type: ignore
138
139    async def create(
140        self,
141        resource_group_name: str,
142        account_name: str,
143        container_name: str,
144        blob_container: "_models.BlobContainer",
145        **kwargs: Any
146    ) -> "_models.BlobContainer":
147        """Creates a new container under the specified account as described by request body. The container
148        resource includes metadata and properties for that container. It does not include a list of the
149        blobs contained by the container.
150
151        :param resource_group_name: The name of the resource group within the user's subscription. The
152         name is case insensitive.
153        :type resource_group_name: str
154        :param account_name: The name of the storage account within the specified resource group.
155         Storage account names must be between 3 and 24 characters in length and use numbers and
156         lower-case letters only.
157        :type account_name: str
158        :param container_name: The name of the blob container within the specified storage account.
159         Blob container names must be between 3 and 63 characters in length and use numbers, lower-case
160         letters and dash (-) only. Every dash (-) character must be immediately preceded and followed
161         by a letter or number.
162        :type container_name: str
163        :param blob_container: Properties of the blob container to create.
164        :type blob_container: ~azure.mgmt.storage.v2020_08_01_preview.models.BlobContainer
165        :keyword callable cls: A custom type or function that will be passed the direct response
166        :return: BlobContainer, or the result of cls(response)
167        :rtype: ~azure.mgmt.storage.v2020_08_01_preview.models.BlobContainer
168        :raises: ~azure.core.exceptions.HttpResponseError
169        """
170        cls = kwargs.pop('cls', None)  # type: ClsType["_models.BlobContainer"]
171        error_map = {
172            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
173        }
174        error_map.update(kwargs.pop('error_map', {}))
175        api_version = "2020-08-01-preview"
176        content_type = kwargs.pop("content_type", "application/json")
177        accept = "application/json"
178
179        # Construct URL
180        url = self.create.metadata['url']  # type: ignore
181        path_format_arguments = {
182            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
183            'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
184            'containerName': self._serialize.url("container_name", container_name, 'str', max_length=63, min_length=3),
185            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
186        }
187        url = self._client.format_url(url, **path_format_arguments)
188
189        # Construct parameters
190        query_parameters = {}  # type: Dict[str, Any]
191        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
192
193        # Construct headers
194        header_parameters = {}  # type: Dict[str, Any]
195        header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str')
196        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
197
198        body_content_kwargs = {}  # type: Dict[str, Any]
199        body_content = self._serialize.body(blob_container, 'BlobContainer')
200        body_content_kwargs['content'] = body_content
201        request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs)
202        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
203        response = pipeline_response.http_response
204
205        if response.status_code not in [200, 201]:
206            map_error(status_code=response.status_code, response=response, error_map=error_map)
207            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
208
209        if response.status_code == 200:
210            deserialized = self._deserialize('BlobContainer', pipeline_response)
211
212        if response.status_code == 201:
213            deserialized = self._deserialize('BlobContainer', pipeline_response)
214
215        if cls:
216            return cls(pipeline_response, deserialized, {})
217
218        return deserialized
219    create.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/blobServices/default/containers/{containerName}'}  # type: ignore
220
221    async def update(
222        self,
223        resource_group_name: str,
224        account_name: str,
225        container_name: str,
226        blob_container: "_models.BlobContainer",
227        **kwargs: Any
228    ) -> "_models.BlobContainer":
229        """Updates container properties as specified in request body. Properties not mentioned in the
230        request will be unchanged. Update fails if the specified container doesn't already exist.
231
232        :param resource_group_name: The name of the resource group within the user's subscription. The
233         name is case insensitive.
234        :type resource_group_name: str
235        :param account_name: The name of the storage account within the specified resource group.
236         Storage account names must be between 3 and 24 characters in length and use numbers and
237         lower-case letters only.
238        :type account_name: str
239        :param container_name: The name of the blob container within the specified storage account.
240         Blob container names must be between 3 and 63 characters in length and use numbers, lower-case
241         letters and dash (-) only. Every dash (-) character must be immediately preceded and followed
242         by a letter or number.
243        :type container_name: str
244        :param blob_container: Properties to update for the blob container.
245        :type blob_container: ~azure.mgmt.storage.v2020_08_01_preview.models.BlobContainer
246        :keyword callable cls: A custom type or function that will be passed the direct response
247        :return: BlobContainer, or the result of cls(response)
248        :rtype: ~azure.mgmt.storage.v2020_08_01_preview.models.BlobContainer
249        :raises: ~azure.core.exceptions.HttpResponseError
250        """
251        cls = kwargs.pop('cls', None)  # type: ClsType["_models.BlobContainer"]
252        error_map = {
253            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
254        }
255        error_map.update(kwargs.pop('error_map', {}))
256        api_version = "2020-08-01-preview"
257        content_type = kwargs.pop("content_type", "application/json")
258        accept = "application/json"
259
260        # Construct URL
261        url = self.update.metadata['url']  # type: ignore
262        path_format_arguments = {
263            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
264            'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
265            'containerName': self._serialize.url("container_name", container_name, 'str', max_length=63, min_length=3),
266            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
267        }
268        url = self._client.format_url(url, **path_format_arguments)
269
270        # Construct parameters
271        query_parameters = {}  # type: Dict[str, Any]
272        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
273
274        # Construct headers
275        header_parameters = {}  # type: Dict[str, Any]
276        header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str')
277        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
278
279        body_content_kwargs = {}  # type: Dict[str, Any]
280        body_content = self._serialize.body(blob_container, 'BlobContainer')
281        body_content_kwargs['content'] = body_content
282        request = self._client.patch(url, query_parameters, header_parameters, **body_content_kwargs)
283        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
284        response = pipeline_response.http_response
285
286        if response.status_code not in [200]:
287            map_error(status_code=response.status_code, response=response, error_map=error_map)
288            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
289
290        deserialized = self._deserialize('BlobContainer', pipeline_response)
291
292        if cls:
293            return cls(pipeline_response, deserialized, {})
294
295        return deserialized
296    update.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/blobServices/default/containers/{containerName}'}  # type: ignore
297
298    async def get(
299        self,
300        resource_group_name: str,
301        account_name: str,
302        container_name: str,
303        **kwargs: Any
304    ) -> "_models.BlobContainer":
305        """Gets properties of a specified container.
306
307        :param resource_group_name: The name of the resource group within the user's subscription. The
308         name is case insensitive.
309        :type resource_group_name: str
310        :param account_name: The name of the storage account within the specified resource group.
311         Storage account names must be between 3 and 24 characters in length and use numbers and
312         lower-case letters only.
313        :type account_name: str
314        :param container_name: The name of the blob container within the specified storage account.
315         Blob container names must be between 3 and 63 characters in length and use numbers, lower-case
316         letters and dash (-) only. Every dash (-) character must be immediately preceded and followed
317         by a letter or number.
318        :type container_name: str
319        :keyword callable cls: A custom type or function that will be passed the direct response
320        :return: BlobContainer, or the result of cls(response)
321        :rtype: ~azure.mgmt.storage.v2020_08_01_preview.models.BlobContainer
322        :raises: ~azure.core.exceptions.HttpResponseError
323        """
324        cls = kwargs.pop('cls', None)  # type: ClsType["_models.BlobContainer"]
325        error_map = {
326            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
327        }
328        error_map.update(kwargs.pop('error_map', {}))
329        api_version = "2020-08-01-preview"
330        accept = "application/json"
331
332        # Construct URL
333        url = self.get.metadata['url']  # type: ignore
334        path_format_arguments = {
335            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
336            'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
337            'containerName': self._serialize.url("container_name", container_name, 'str', max_length=63, min_length=3),
338            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
339        }
340        url = self._client.format_url(url, **path_format_arguments)
341
342        # Construct parameters
343        query_parameters = {}  # type: Dict[str, Any]
344        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
345
346        # Construct headers
347        header_parameters = {}  # type: Dict[str, Any]
348        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
349
350        request = self._client.get(url, query_parameters, header_parameters)
351        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
352        response = pipeline_response.http_response
353
354        if response.status_code not in [200]:
355            map_error(status_code=response.status_code, response=response, error_map=error_map)
356            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
357
358        deserialized = self._deserialize('BlobContainer', pipeline_response)
359
360        if cls:
361            return cls(pipeline_response, deserialized, {})
362
363        return deserialized
364    get.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/blobServices/default/containers/{containerName}'}  # type: ignore
365
366    async def delete(
367        self,
368        resource_group_name: str,
369        account_name: str,
370        container_name: str,
371        **kwargs: Any
372    ) -> None:
373        """Deletes specified container under its account.
374
375        :param resource_group_name: The name of the resource group within the user's subscription. The
376         name is case insensitive.
377        :type resource_group_name: str
378        :param account_name: The name of the storage account within the specified resource group.
379         Storage account names must be between 3 and 24 characters in length and use numbers and
380         lower-case letters only.
381        :type account_name: str
382        :param container_name: The name of the blob container within the specified storage account.
383         Blob container names must be between 3 and 63 characters in length and use numbers, lower-case
384         letters and dash (-) only. Every dash (-) character must be immediately preceded and followed
385         by a letter or number.
386        :type container_name: str
387        :keyword callable cls: A custom type or function that will be passed the direct response
388        :return: None, or the result of cls(response)
389        :rtype: None
390        :raises: ~azure.core.exceptions.HttpResponseError
391        """
392        cls = kwargs.pop('cls', None)  # type: ClsType[None]
393        error_map = {
394            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
395        }
396        error_map.update(kwargs.pop('error_map', {}))
397        api_version = "2020-08-01-preview"
398
399        # Construct URL
400        url = self.delete.metadata['url']  # type: ignore
401        path_format_arguments = {
402            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
403            'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
404            'containerName': self._serialize.url("container_name", container_name, 'str', max_length=63, min_length=3),
405            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
406        }
407        url = self._client.format_url(url, **path_format_arguments)
408
409        # Construct parameters
410        query_parameters = {}  # type: Dict[str, Any]
411        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
412
413        # Construct headers
414        header_parameters = {}  # type: Dict[str, Any]
415
416        request = self._client.delete(url, query_parameters, header_parameters)
417        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
418        response = pipeline_response.http_response
419
420        if response.status_code not in [200, 204]:
421            map_error(status_code=response.status_code, response=response, error_map=error_map)
422            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
423
424        if cls:
425            return cls(pipeline_response, None, {})
426
427    delete.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/blobServices/default/containers/{containerName}'}  # type: ignore
428
429    async def set_legal_hold(
430        self,
431        resource_group_name: str,
432        account_name: str,
433        container_name: str,
434        legal_hold: "_models.LegalHold",
435        **kwargs: Any
436    ) -> "_models.LegalHold":
437        """Sets legal hold tags. Setting the same tag results in an idempotent operation. SetLegalHold
438        follows an append pattern and does not clear out the existing tags that are not specified in
439        the request.
440
441        :param resource_group_name: The name of the resource group within the user's subscription. The
442         name is case insensitive.
443        :type resource_group_name: str
444        :param account_name: The name of the storage account within the specified resource group.
445         Storage account names must be between 3 and 24 characters in length and use numbers and
446         lower-case letters only.
447        :type account_name: str
448        :param container_name: The name of the blob container within the specified storage account.
449         Blob container names must be between 3 and 63 characters in length and use numbers, lower-case
450         letters and dash (-) only. Every dash (-) character must be immediately preceded and followed
451         by a letter or number.
452        :type container_name: str
453        :param legal_hold: The LegalHold property that will be set to a blob container.
454        :type legal_hold: ~azure.mgmt.storage.v2020_08_01_preview.models.LegalHold
455        :keyword callable cls: A custom type or function that will be passed the direct response
456        :return: LegalHold, or the result of cls(response)
457        :rtype: ~azure.mgmt.storage.v2020_08_01_preview.models.LegalHold
458        :raises: ~azure.core.exceptions.HttpResponseError
459        """
460        cls = kwargs.pop('cls', None)  # type: ClsType["_models.LegalHold"]
461        error_map = {
462            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
463        }
464        error_map.update(kwargs.pop('error_map', {}))
465        api_version = "2020-08-01-preview"
466        content_type = kwargs.pop("content_type", "application/json")
467        accept = "application/json"
468
469        # Construct URL
470        url = self.set_legal_hold.metadata['url']  # type: ignore
471        path_format_arguments = {
472            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
473            'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
474            'containerName': self._serialize.url("container_name", container_name, 'str', max_length=63, min_length=3),
475            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
476        }
477        url = self._client.format_url(url, **path_format_arguments)
478
479        # Construct parameters
480        query_parameters = {}  # type: Dict[str, Any]
481        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
482
483        # Construct headers
484        header_parameters = {}  # type: Dict[str, Any]
485        header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str')
486        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
487
488        body_content_kwargs = {}  # type: Dict[str, Any]
489        body_content = self._serialize.body(legal_hold, 'LegalHold')
490        body_content_kwargs['content'] = body_content
491        request = self._client.post(url, query_parameters, header_parameters, **body_content_kwargs)
492        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
493        response = pipeline_response.http_response
494
495        if response.status_code not in [200]:
496            map_error(status_code=response.status_code, response=response, error_map=error_map)
497            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
498
499        deserialized = self._deserialize('LegalHold', pipeline_response)
500
501        if cls:
502            return cls(pipeline_response, deserialized, {})
503
504        return deserialized
505    set_legal_hold.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/blobServices/default/containers/{containerName}/setLegalHold'}  # type: ignore
506
507    async def clear_legal_hold(
508        self,
509        resource_group_name: str,
510        account_name: str,
511        container_name: str,
512        legal_hold: "_models.LegalHold",
513        **kwargs: Any
514    ) -> "_models.LegalHold":
515        """Clears legal hold tags. Clearing the same or non-existent tag results in an idempotent
516        operation. ClearLegalHold clears out only the specified tags in the request.
517
518        :param resource_group_name: The name of the resource group within the user's subscription. The
519         name is case insensitive.
520        :type resource_group_name: str
521        :param account_name: The name of the storage account within the specified resource group.
522         Storage account names must be between 3 and 24 characters in length and use numbers and
523         lower-case letters only.
524        :type account_name: str
525        :param container_name: The name of the blob container within the specified storage account.
526         Blob container names must be between 3 and 63 characters in length and use numbers, lower-case
527         letters and dash (-) only. Every dash (-) character must be immediately preceded and followed
528         by a letter or number.
529        :type container_name: str
530        :param legal_hold: The LegalHold property that will be clear from a blob container.
531        :type legal_hold: ~azure.mgmt.storage.v2020_08_01_preview.models.LegalHold
532        :keyword callable cls: A custom type or function that will be passed the direct response
533        :return: LegalHold, or the result of cls(response)
534        :rtype: ~azure.mgmt.storage.v2020_08_01_preview.models.LegalHold
535        :raises: ~azure.core.exceptions.HttpResponseError
536        """
537        cls = kwargs.pop('cls', None)  # type: ClsType["_models.LegalHold"]
538        error_map = {
539            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
540        }
541        error_map.update(kwargs.pop('error_map', {}))
542        api_version = "2020-08-01-preview"
543        content_type = kwargs.pop("content_type", "application/json")
544        accept = "application/json"
545
546        # Construct URL
547        url = self.clear_legal_hold.metadata['url']  # type: ignore
548        path_format_arguments = {
549            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
550            'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
551            'containerName': self._serialize.url("container_name", container_name, 'str', max_length=63, min_length=3),
552            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
553        }
554        url = self._client.format_url(url, **path_format_arguments)
555
556        # Construct parameters
557        query_parameters = {}  # type: Dict[str, Any]
558        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
559
560        # Construct headers
561        header_parameters = {}  # type: Dict[str, Any]
562        header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str')
563        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
564
565        body_content_kwargs = {}  # type: Dict[str, Any]
566        body_content = self._serialize.body(legal_hold, 'LegalHold')
567        body_content_kwargs['content'] = body_content
568        request = self._client.post(url, query_parameters, header_parameters, **body_content_kwargs)
569        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
570        response = pipeline_response.http_response
571
572        if response.status_code not in [200]:
573            map_error(status_code=response.status_code, response=response, error_map=error_map)
574            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
575
576        deserialized = self._deserialize('LegalHold', pipeline_response)
577
578        if cls:
579            return cls(pipeline_response, deserialized, {})
580
581        return deserialized
582    clear_legal_hold.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/blobServices/default/containers/{containerName}/clearLegalHold'}  # type: ignore
583
584    async def create_or_update_immutability_policy(
585        self,
586        resource_group_name: str,
587        account_name: str,
588        container_name: str,
589        if_match: Optional[str] = None,
590        parameters: Optional["_models.ImmutabilityPolicy"] = None,
591        **kwargs: Any
592    ) -> "_models.ImmutabilityPolicy":
593        """Creates or updates an unlocked immutability policy. ETag in If-Match is honored if given but
594        not required for this operation.
595
596        :param resource_group_name: The name of the resource group within the user's subscription. The
597         name is case insensitive.
598        :type resource_group_name: str
599        :param account_name: The name of the storage account within the specified resource group.
600         Storage account names must be between 3 and 24 characters in length and use numbers and
601         lower-case letters only.
602        :type account_name: str
603        :param container_name: The name of the blob container within the specified storage account.
604         Blob container names must be between 3 and 63 characters in length and use numbers, lower-case
605         letters and dash (-) only. Every dash (-) character must be immediately preceded and followed
606         by a letter or number.
607        :type container_name: str
608        :param if_match: The entity state (ETag) version of the immutability policy to update. A value
609         of "*" can be used to apply the operation only if the immutability policy already exists. If
610         omitted, this operation will always be applied.
611        :type if_match: str
612        :param parameters: The ImmutabilityPolicy Properties that will be created or updated to a blob
613         container.
614        :type parameters: ~azure.mgmt.storage.v2020_08_01_preview.models.ImmutabilityPolicy
615        :keyword callable cls: A custom type or function that will be passed the direct response
616        :return: ImmutabilityPolicy, or the result of cls(response)
617        :rtype: ~azure.mgmt.storage.v2020_08_01_preview.models.ImmutabilityPolicy
618        :raises: ~azure.core.exceptions.HttpResponseError
619        """
620        cls = kwargs.pop('cls', None)  # type: ClsType["_models.ImmutabilityPolicy"]
621        error_map = {
622            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
623        }
624        error_map.update(kwargs.pop('error_map', {}))
625        immutability_policy_name = "default"
626        api_version = "2020-08-01-preview"
627        content_type = kwargs.pop("content_type", "application/json")
628        accept = "application/json"
629
630        # Construct URL
631        url = self.create_or_update_immutability_policy.metadata['url']  # type: ignore
632        path_format_arguments = {
633            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
634            'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
635            'containerName': self._serialize.url("container_name", container_name, 'str', max_length=63, min_length=3),
636            'immutabilityPolicyName': self._serialize.url("immutability_policy_name", immutability_policy_name, 'str'),
637            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
638        }
639        url = self._client.format_url(url, **path_format_arguments)
640
641        # Construct parameters
642        query_parameters = {}  # type: Dict[str, Any]
643        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
644
645        # Construct headers
646        header_parameters = {}  # type: Dict[str, Any]
647        if if_match is not None:
648            header_parameters['If-Match'] = self._serialize.header("if_match", if_match, 'str')
649        header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str')
650        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
651
652        body_content_kwargs = {}  # type: Dict[str, Any]
653        if parameters is not None:
654            body_content = self._serialize.body(parameters, 'ImmutabilityPolicy')
655        else:
656            body_content = None
657        body_content_kwargs['content'] = body_content
658        request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs)
659        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
660        response = pipeline_response.http_response
661
662        if response.status_code not in [200]:
663            map_error(status_code=response.status_code, response=response, error_map=error_map)
664            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
665
666        response_headers = {}
667        response_headers['ETag']=self._deserialize('str', response.headers.get('ETag'))
668        deserialized = self._deserialize('ImmutabilityPolicy', pipeline_response)
669
670        if cls:
671            return cls(pipeline_response, deserialized, response_headers)
672
673        return deserialized
674    create_or_update_immutability_policy.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/blobServices/default/containers/{containerName}/immutabilityPolicies/{immutabilityPolicyName}'}  # type: ignore
675
676    async def get_immutability_policy(
677        self,
678        resource_group_name: str,
679        account_name: str,
680        container_name: str,
681        if_match: Optional[str] = None,
682        **kwargs: Any
683    ) -> "_models.ImmutabilityPolicy":
684        """Gets the existing immutability policy along with the corresponding ETag in response headers and
685        body.
686
687        :param resource_group_name: The name of the resource group within the user's subscription. The
688         name is case insensitive.
689        :type resource_group_name: str
690        :param account_name: The name of the storage account within the specified resource group.
691         Storage account names must be between 3 and 24 characters in length and use numbers and
692         lower-case letters only.
693        :type account_name: str
694        :param container_name: The name of the blob container within the specified storage account.
695         Blob container names must be between 3 and 63 characters in length and use numbers, lower-case
696         letters and dash (-) only. Every dash (-) character must be immediately preceded and followed
697         by a letter or number.
698        :type container_name: str
699        :param if_match: The entity state (ETag) version of the immutability policy to update. A value
700         of "*" can be used to apply the operation only if the immutability policy already exists. If
701         omitted, this operation will always be applied.
702        :type if_match: str
703        :keyword callable cls: A custom type or function that will be passed the direct response
704        :return: ImmutabilityPolicy, or the result of cls(response)
705        :rtype: ~azure.mgmt.storage.v2020_08_01_preview.models.ImmutabilityPolicy
706        :raises: ~azure.core.exceptions.HttpResponseError
707        """
708        cls = kwargs.pop('cls', None)  # type: ClsType["_models.ImmutabilityPolicy"]
709        error_map = {
710            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
711        }
712        error_map.update(kwargs.pop('error_map', {}))
713        immutability_policy_name = "default"
714        api_version = "2020-08-01-preview"
715        accept = "application/json"
716
717        # Construct URL
718        url = self.get_immutability_policy.metadata['url']  # type: ignore
719        path_format_arguments = {
720            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
721            'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
722            'containerName': self._serialize.url("container_name", container_name, 'str', max_length=63, min_length=3),
723            'immutabilityPolicyName': self._serialize.url("immutability_policy_name", immutability_policy_name, 'str'),
724            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
725        }
726        url = self._client.format_url(url, **path_format_arguments)
727
728        # Construct parameters
729        query_parameters = {}  # type: Dict[str, Any]
730        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
731
732        # Construct headers
733        header_parameters = {}  # type: Dict[str, Any]
734        if if_match is not None:
735            header_parameters['If-Match'] = self._serialize.header("if_match", if_match, 'str')
736        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
737
738        request = self._client.get(url, query_parameters, header_parameters)
739        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
740        response = pipeline_response.http_response
741
742        if response.status_code not in [200]:
743            map_error(status_code=response.status_code, response=response, error_map=error_map)
744            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
745
746        response_headers = {}
747        response_headers['ETag']=self._deserialize('str', response.headers.get('ETag'))
748        deserialized = self._deserialize('ImmutabilityPolicy', pipeline_response)
749
750        if cls:
751            return cls(pipeline_response, deserialized, response_headers)
752
753        return deserialized
754    get_immutability_policy.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/blobServices/default/containers/{containerName}/immutabilityPolicies/{immutabilityPolicyName}'}  # type: ignore
755
756    async def delete_immutability_policy(
757        self,
758        resource_group_name: str,
759        account_name: str,
760        container_name: str,
761        if_match: str,
762        **kwargs: Any
763    ) -> "_models.ImmutabilityPolicy":
764        """Aborts an unlocked immutability policy. The response of delete has
765        immutabilityPeriodSinceCreationInDays set to 0. ETag in If-Match is required for this
766        operation. Deleting a locked immutability policy is not allowed, the only way is to delete the
767        container after deleting all expired blobs inside the policy locked container.
768
769        :param resource_group_name: The name of the resource group within the user's subscription. The
770         name is case insensitive.
771        :type resource_group_name: str
772        :param account_name: The name of the storage account within the specified resource group.
773         Storage account names must be between 3 and 24 characters in length and use numbers and
774         lower-case letters only.
775        :type account_name: str
776        :param container_name: The name of the blob container within the specified storage account.
777         Blob container names must be between 3 and 63 characters in length and use numbers, lower-case
778         letters and dash (-) only. Every dash (-) character must be immediately preceded and followed
779         by a letter or number.
780        :type container_name: str
781        :param if_match: The entity state (ETag) version of the immutability policy to update. A value
782         of "*" can be used to apply the operation only if the immutability policy already exists. If
783         omitted, this operation will always be applied.
784        :type if_match: str
785        :keyword callable cls: A custom type or function that will be passed the direct response
786        :return: ImmutabilityPolicy, or the result of cls(response)
787        :rtype: ~azure.mgmt.storage.v2020_08_01_preview.models.ImmutabilityPolicy
788        :raises: ~azure.core.exceptions.HttpResponseError
789        """
790        cls = kwargs.pop('cls', None)  # type: ClsType["_models.ImmutabilityPolicy"]
791        error_map = {
792            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
793        }
794        error_map.update(kwargs.pop('error_map', {}))
795        immutability_policy_name = "default"
796        api_version = "2020-08-01-preview"
797        accept = "application/json"
798
799        # Construct URL
800        url = self.delete_immutability_policy.metadata['url']  # type: ignore
801        path_format_arguments = {
802            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
803            'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
804            'containerName': self._serialize.url("container_name", container_name, 'str', max_length=63, min_length=3),
805            'immutabilityPolicyName': self._serialize.url("immutability_policy_name", immutability_policy_name, 'str'),
806            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
807        }
808        url = self._client.format_url(url, **path_format_arguments)
809
810        # Construct parameters
811        query_parameters = {}  # type: Dict[str, Any]
812        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
813
814        # Construct headers
815        header_parameters = {}  # type: Dict[str, Any]
816        header_parameters['If-Match'] = self._serialize.header("if_match", if_match, 'str')
817        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
818
819        request = self._client.delete(url, query_parameters, header_parameters)
820        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
821        response = pipeline_response.http_response
822
823        if response.status_code not in [200]:
824            map_error(status_code=response.status_code, response=response, error_map=error_map)
825            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
826
827        response_headers = {}
828        response_headers['ETag']=self._deserialize('str', response.headers.get('ETag'))
829        deserialized = self._deserialize('ImmutabilityPolicy', pipeline_response)
830
831        if cls:
832            return cls(pipeline_response, deserialized, response_headers)
833
834        return deserialized
835    delete_immutability_policy.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/blobServices/default/containers/{containerName}/immutabilityPolicies/{immutabilityPolicyName}'}  # type: ignore
836
837    async def lock_immutability_policy(
838        self,
839        resource_group_name: str,
840        account_name: str,
841        container_name: str,
842        if_match: str,
843        **kwargs: Any
844    ) -> "_models.ImmutabilityPolicy":
845        """Sets the ImmutabilityPolicy to Locked state. The only action allowed on a Locked policy is
846        ExtendImmutabilityPolicy action. ETag in If-Match is required for this operation.
847
848        :param resource_group_name: The name of the resource group within the user's subscription. The
849         name is case insensitive.
850        :type resource_group_name: str
851        :param account_name: The name of the storage account within the specified resource group.
852         Storage account names must be between 3 and 24 characters in length and use numbers and
853         lower-case letters only.
854        :type account_name: str
855        :param container_name: The name of the blob container within the specified storage account.
856         Blob container names must be between 3 and 63 characters in length and use numbers, lower-case
857         letters and dash (-) only. Every dash (-) character must be immediately preceded and followed
858         by a letter or number.
859        :type container_name: str
860        :param if_match: The entity state (ETag) version of the immutability policy to update. A value
861         of "*" can be used to apply the operation only if the immutability policy already exists. If
862         omitted, this operation will always be applied.
863        :type if_match: str
864        :keyword callable cls: A custom type or function that will be passed the direct response
865        :return: ImmutabilityPolicy, or the result of cls(response)
866        :rtype: ~azure.mgmt.storage.v2020_08_01_preview.models.ImmutabilityPolicy
867        :raises: ~azure.core.exceptions.HttpResponseError
868        """
869        cls = kwargs.pop('cls', None)  # type: ClsType["_models.ImmutabilityPolicy"]
870        error_map = {
871            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
872        }
873        error_map.update(kwargs.pop('error_map', {}))
874        api_version = "2020-08-01-preview"
875        accept = "application/json"
876
877        # Construct URL
878        url = self.lock_immutability_policy.metadata['url']  # type: ignore
879        path_format_arguments = {
880            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
881            'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
882            'containerName': self._serialize.url("container_name", container_name, 'str', max_length=63, min_length=3),
883            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
884        }
885        url = self._client.format_url(url, **path_format_arguments)
886
887        # Construct parameters
888        query_parameters = {}  # type: Dict[str, Any]
889        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
890
891        # Construct headers
892        header_parameters = {}  # type: Dict[str, Any]
893        header_parameters['If-Match'] = self._serialize.header("if_match", if_match, 'str')
894        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
895
896        request = self._client.post(url, query_parameters, header_parameters)
897        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
898        response = pipeline_response.http_response
899
900        if response.status_code not in [200]:
901            map_error(status_code=response.status_code, response=response, error_map=error_map)
902            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
903
904        response_headers = {}
905        response_headers['ETag']=self._deserialize('str', response.headers.get('ETag'))
906        deserialized = self._deserialize('ImmutabilityPolicy', pipeline_response)
907
908        if cls:
909            return cls(pipeline_response, deserialized, response_headers)
910
911        return deserialized
912    lock_immutability_policy.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/blobServices/default/containers/{containerName}/immutabilityPolicies/default/lock'}  # type: ignore
913
914    async def extend_immutability_policy(
915        self,
916        resource_group_name: str,
917        account_name: str,
918        container_name: str,
919        if_match: str,
920        parameters: Optional["_models.ImmutabilityPolicy"] = None,
921        **kwargs: Any
922    ) -> "_models.ImmutabilityPolicy":
923        """Extends the immutabilityPeriodSinceCreationInDays of a locked immutabilityPolicy. The only
924        action allowed on a Locked policy will be this action. ETag in If-Match is required for this
925        operation.
926
927        :param resource_group_name: The name of the resource group within the user's subscription. The
928         name is case insensitive.
929        :type resource_group_name: str
930        :param account_name: The name of the storage account within the specified resource group.
931         Storage account names must be between 3 and 24 characters in length and use numbers and
932         lower-case letters only.
933        :type account_name: str
934        :param container_name: The name of the blob container within the specified storage account.
935         Blob container names must be between 3 and 63 characters in length and use numbers, lower-case
936         letters and dash (-) only. Every dash (-) character must be immediately preceded and followed
937         by a letter or number.
938        :type container_name: str
939        :param if_match: The entity state (ETag) version of the immutability policy to update. A value
940         of "*" can be used to apply the operation only if the immutability policy already exists. If
941         omitted, this operation will always be applied.
942        :type if_match: str
943        :param parameters: The ImmutabilityPolicy Properties that will be extended for a blob
944         container.
945        :type parameters: ~azure.mgmt.storage.v2020_08_01_preview.models.ImmutabilityPolicy
946        :keyword callable cls: A custom type or function that will be passed the direct response
947        :return: ImmutabilityPolicy, or the result of cls(response)
948        :rtype: ~azure.mgmt.storage.v2020_08_01_preview.models.ImmutabilityPolicy
949        :raises: ~azure.core.exceptions.HttpResponseError
950        """
951        cls = kwargs.pop('cls', None)  # type: ClsType["_models.ImmutabilityPolicy"]
952        error_map = {
953            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
954        }
955        error_map.update(kwargs.pop('error_map', {}))
956        api_version = "2020-08-01-preview"
957        content_type = kwargs.pop("content_type", "application/json")
958        accept = "application/json"
959
960        # Construct URL
961        url = self.extend_immutability_policy.metadata['url']  # type: ignore
962        path_format_arguments = {
963            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
964            'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
965            'containerName': self._serialize.url("container_name", container_name, 'str', max_length=63, min_length=3),
966            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
967        }
968        url = self._client.format_url(url, **path_format_arguments)
969
970        # Construct parameters
971        query_parameters = {}  # type: Dict[str, Any]
972        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
973
974        # Construct headers
975        header_parameters = {}  # type: Dict[str, Any]
976        header_parameters['If-Match'] = self._serialize.header("if_match", if_match, 'str')
977        header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str')
978        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
979
980        body_content_kwargs = {}  # type: Dict[str, Any]
981        if parameters is not None:
982            body_content = self._serialize.body(parameters, 'ImmutabilityPolicy')
983        else:
984            body_content = None
985        body_content_kwargs['content'] = body_content
986        request = self._client.post(url, query_parameters, header_parameters, **body_content_kwargs)
987        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
988        response = pipeline_response.http_response
989
990        if response.status_code not in [200]:
991            map_error(status_code=response.status_code, response=response, error_map=error_map)
992            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
993
994        response_headers = {}
995        response_headers['ETag']=self._deserialize('str', response.headers.get('ETag'))
996        deserialized = self._deserialize('ImmutabilityPolicy', pipeline_response)
997
998        if cls:
999            return cls(pipeline_response, deserialized, response_headers)
1000
1001        return deserialized
1002    extend_immutability_policy.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/blobServices/default/containers/{containerName}/immutabilityPolicies/default/extend'}  # type: ignore
1003
1004    async def lease(
1005        self,
1006        resource_group_name: str,
1007        account_name: str,
1008        container_name: str,
1009        parameters: Optional["_models.LeaseContainerRequest"] = None,
1010        **kwargs: Any
1011    ) -> "_models.LeaseContainerResponse":
1012        """The Lease Container operation establishes and manages a lock on a container for delete
1013        operations. The lock duration can be 15 to 60 seconds, or can be infinite.
1014
1015        :param resource_group_name: The name of the resource group within the user's subscription. The
1016         name is case insensitive.
1017        :type resource_group_name: str
1018        :param account_name: The name of the storage account within the specified resource group.
1019         Storage account names must be between 3 and 24 characters in length and use numbers and
1020         lower-case letters only.
1021        :type account_name: str
1022        :param container_name: The name of the blob container within the specified storage account.
1023         Blob container names must be between 3 and 63 characters in length and use numbers, lower-case
1024         letters and dash (-) only. Every dash (-) character must be immediately preceded and followed
1025         by a letter or number.
1026        :type container_name: str
1027        :param parameters: Lease Container request body.
1028        :type parameters: ~azure.mgmt.storage.v2020_08_01_preview.models.LeaseContainerRequest
1029        :keyword callable cls: A custom type or function that will be passed the direct response
1030        :return: LeaseContainerResponse, or the result of cls(response)
1031        :rtype: ~azure.mgmt.storage.v2020_08_01_preview.models.LeaseContainerResponse
1032        :raises: ~azure.core.exceptions.HttpResponseError
1033        """
1034        cls = kwargs.pop('cls', None)  # type: ClsType["_models.LeaseContainerResponse"]
1035        error_map = {
1036            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
1037        }
1038        error_map.update(kwargs.pop('error_map', {}))
1039        api_version = "2020-08-01-preview"
1040        content_type = kwargs.pop("content_type", "application/json")
1041        accept = "application/json"
1042
1043        # Construct URL
1044        url = self.lease.metadata['url']  # type: ignore
1045        path_format_arguments = {
1046            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
1047            'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
1048            'containerName': self._serialize.url("container_name", container_name, 'str', max_length=63, min_length=3),
1049            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
1050        }
1051        url = self._client.format_url(url, **path_format_arguments)
1052
1053        # Construct parameters
1054        query_parameters = {}  # type: Dict[str, Any]
1055        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
1056
1057        # Construct headers
1058        header_parameters = {}  # type: Dict[str, Any]
1059        header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str')
1060        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
1061
1062        body_content_kwargs = {}  # type: Dict[str, Any]
1063        if parameters is not None:
1064            body_content = self._serialize.body(parameters, 'LeaseContainerRequest')
1065        else:
1066            body_content = None
1067        body_content_kwargs['content'] = body_content
1068        request = self._client.post(url, query_parameters, header_parameters, **body_content_kwargs)
1069        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
1070        response = pipeline_response.http_response
1071
1072        if response.status_code not in [200]:
1073            map_error(status_code=response.status_code, response=response, error_map=error_map)
1074            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
1075
1076        deserialized = self._deserialize('LeaseContainerResponse', pipeline_response)
1077
1078        if cls:
1079            return cls(pipeline_response, deserialized, {})
1080
1081        return deserialized
1082    lease.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/blobServices/default/containers/{containerName}/lease'}  # type: ignore
1083