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.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod
16from azure.mgmt.core.exceptions import ARMErrorFormat
17from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling
18
19from ... import models as _models
20
21T = TypeVar('T')
22ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]]
23
24class StorageAccountsOperations:
25    """StorageAccountsOperations async operations.
26
27    You should not instantiate this class directly. Instead, you should create a Client instance that
28    instantiates it for you and attaches it as an attribute.
29
30    :ivar models: Alias to model classes used in this operation group.
31    :type models: ~azure.mgmt.storage.v2019_04_01.models
32    :param client: Client for service requests.
33    :param config: Configuration of service client.
34    :param serializer: An object model serializer.
35    :param deserializer: An object model deserializer.
36    """
37
38    models = _models
39
40    def __init__(self, client, config, serializer, deserializer) -> None:
41        self._client = client
42        self._serialize = serializer
43        self._deserialize = deserializer
44        self._config = config
45
46    async def check_name_availability(
47        self,
48        account_name: "_models.StorageAccountCheckNameAvailabilityParameters",
49        **kwargs: Any
50    ) -> "_models.CheckNameAvailabilityResult":
51        """Checks that the storage account name is valid and is not already in use.
52
53        :param account_name: The name of the storage account within the specified resource group.
54         Storage account names must be between 3 and 24 characters in length and use numbers and
55         lower-case letters only.
56        :type account_name: ~azure.mgmt.storage.v2019_04_01.models.StorageAccountCheckNameAvailabilityParameters
57        :keyword callable cls: A custom type or function that will be passed the direct response
58        :return: CheckNameAvailabilityResult, or the result of cls(response)
59        :rtype: ~azure.mgmt.storage.v2019_04_01.models.CheckNameAvailabilityResult
60        :raises: ~azure.core.exceptions.HttpResponseError
61        """
62        cls = kwargs.pop('cls', None)  # type: ClsType["_models.CheckNameAvailabilityResult"]
63        error_map = {
64            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
65        }
66        error_map.update(kwargs.pop('error_map', {}))
67        api_version = "2019-04-01"
68        content_type = kwargs.pop("content_type", "application/json")
69        accept = "application/json"
70
71        # Construct URL
72        url = self.check_name_availability.metadata['url']  # type: ignore
73        path_format_arguments = {
74            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
75        }
76        url = self._client.format_url(url, **path_format_arguments)
77
78        # Construct parameters
79        query_parameters = {}  # type: Dict[str, Any]
80        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
81
82        # Construct headers
83        header_parameters = {}  # type: Dict[str, Any]
84        header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str')
85        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
86
87        body_content_kwargs = {}  # type: Dict[str, Any]
88        body_content = self._serialize.body(account_name, 'StorageAccountCheckNameAvailabilityParameters')
89        body_content_kwargs['content'] = body_content
90        request = self._client.post(url, query_parameters, header_parameters, **body_content_kwargs)
91        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
92        response = pipeline_response.http_response
93
94        if response.status_code not in [200]:
95            map_error(status_code=response.status_code, response=response, error_map=error_map)
96            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
97
98        deserialized = self._deserialize('CheckNameAvailabilityResult', pipeline_response)
99
100        if cls:
101            return cls(pipeline_response, deserialized, {})
102
103        return deserialized
104    check_name_availability.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.Storage/checkNameAvailability'}  # type: ignore
105
106    async def _create_initial(
107        self,
108        resource_group_name: str,
109        account_name: str,
110        parameters: "_models.StorageAccountCreateParameters",
111        **kwargs: Any
112    ) -> Optional["_models.StorageAccount"]:
113        cls = kwargs.pop('cls', None)  # type: ClsType[Optional["_models.StorageAccount"]]
114        error_map = {
115            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
116        }
117        error_map.update(kwargs.pop('error_map', {}))
118        api_version = "2019-04-01"
119        content_type = kwargs.pop("content_type", "application/json")
120        accept = "application/json"
121
122        # Construct URL
123        url = self._create_initial.metadata['url']  # type: ignore
124        path_format_arguments = {
125            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
126            'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
127            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
128        }
129        url = self._client.format_url(url, **path_format_arguments)
130
131        # Construct parameters
132        query_parameters = {}  # type: Dict[str, Any]
133        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
134
135        # Construct headers
136        header_parameters = {}  # type: Dict[str, Any]
137        header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str')
138        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
139
140        body_content_kwargs = {}  # type: Dict[str, Any]
141        body_content = self._serialize.body(parameters, 'StorageAccountCreateParameters')
142        body_content_kwargs['content'] = body_content
143        request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs)
144        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
145        response = pipeline_response.http_response
146
147        if response.status_code not in [200, 202]:
148            map_error(status_code=response.status_code, response=response, error_map=error_map)
149            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
150
151        deserialized = None
152        if response.status_code == 200:
153            deserialized = self._deserialize('StorageAccount', pipeline_response)
154
155        if cls:
156            return cls(pipeline_response, deserialized, {})
157
158        return deserialized
159    _create_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}'}  # type: ignore
160
161    async def begin_create(
162        self,
163        resource_group_name: str,
164        account_name: str,
165        parameters: "_models.StorageAccountCreateParameters",
166        **kwargs: Any
167    ) -> AsyncLROPoller["_models.StorageAccount"]:
168        """Asynchronously creates a new storage account with the specified parameters. If an account is
169        already created and a subsequent create request is issued with different properties, the
170        account properties will be updated. If an account is already created and a subsequent create or
171        update request is issued with the exact same set of properties, the request will succeed.
172
173        :param resource_group_name: The name of the resource group within the user's subscription. The
174         name is case insensitive.
175        :type resource_group_name: str
176        :param account_name: The name of the storage account within the specified resource group.
177         Storage account names must be between 3 and 24 characters in length and use numbers and
178         lower-case letters only.
179        :type account_name: str
180        :param parameters: The parameters to provide for the created account.
181        :type parameters: ~azure.mgmt.storage.v2019_04_01.models.StorageAccountCreateParameters
182        :keyword callable cls: A custom type or function that will be passed the direct response
183        :keyword str continuation_token: A continuation token to restart a poller from a saved state.
184        :keyword polling: By default, your polling method will be AsyncARMPolling.
185         Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy.
186        :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod
187        :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
188        :return: An instance of AsyncLROPoller that returns either StorageAccount or the result of cls(response)
189        :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.storage.v2019_04_01.models.StorageAccount]
190        :raises ~azure.core.exceptions.HttpResponseError:
191        """
192        polling = kwargs.pop('polling', True)  # type: Union[bool, AsyncPollingMethod]
193        cls = kwargs.pop('cls', None)  # type: ClsType["_models.StorageAccount"]
194        lro_delay = kwargs.pop(
195            'polling_interval',
196            self._config.polling_interval
197        )
198        cont_token = kwargs.pop('continuation_token', None)  # type: Optional[str]
199        if cont_token is None:
200            raw_result = await self._create_initial(
201                resource_group_name=resource_group_name,
202                account_name=account_name,
203                parameters=parameters,
204                cls=lambda x,y,z: x,
205                **kwargs
206            )
207
208        kwargs.pop('error_map', None)
209        kwargs.pop('content_type', None)
210
211        def get_long_running_output(pipeline_response):
212            deserialized = self._deserialize('StorageAccount', pipeline_response)
213
214            if cls:
215                return cls(pipeline_response, deserialized, {})
216            return deserialized
217
218        path_format_arguments = {
219            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
220            'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
221            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
222        }
223
224        if polling is True: polling_method = AsyncARMPolling(lro_delay, path_format_arguments=path_format_arguments,  **kwargs)
225        elif polling is False: polling_method = AsyncNoPolling()
226        else: polling_method = polling
227        if cont_token:
228            return AsyncLROPoller.from_continuation_token(
229                polling_method=polling_method,
230                continuation_token=cont_token,
231                client=self._client,
232                deserialization_callback=get_long_running_output
233            )
234        else:
235            return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method)
236    begin_create.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}'}  # type: ignore
237
238    async def delete(
239        self,
240        resource_group_name: str,
241        account_name: str,
242        **kwargs: Any
243    ) -> None:
244        """Deletes a storage account in Microsoft Azure.
245
246        :param resource_group_name: The name of the resource group within the user's subscription. The
247         name is case insensitive.
248        :type resource_group_name: str
249        :param account_name: The name of the storage account within the specified resource group.
250         Storage account names must be between 3 and 24 characters in length and use numbers and
251         lower-case letters only.
252        :type account_name: str
253        :keyword callable cls: A custom type or function that will be passed the direct response
254        :return: None, or the result of cls(response)
255        :rtype: None
256        :raises: ~azure.core.exceptions.HttpResponseError
257        """
258        cls = kwargs.pop('cls', None)  # type: ClsType[None]
259        error_map = {
260            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
261        }
262        error_map.update(kwargs.pop('error_map', {}))
263        api_version = "2019-04-01"
264
265        # Construct URL
266        url = self.delete.metadata['url']  # type: ignore
267        path_format_arguments = {
268            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
269            'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
270            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
271        }
272        url = self._client.format_url(url, **path_format_arguments)
273
274        # Construct parameters
275        query_parameters = {}  # type: Dict[str, Any]
276        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
277
278        # Construct headers
279        header_parameters = {}  # type: Dict[str, Any]
280
281        request = self._client.delete(url, query_parameters, header_parameters)
282        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
283        response = pipeline_response.http_response
284
285        if response.status_code not in [200, 204]:
286            map_error(status_code=response.status_code, response=response, error_map=error_map)
287            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
288
289        if cls:
290            return cls(pipeline_response, None, {})
291
292    delete.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}'}  # type: ignore
293
294    async def get_properties(
295        self,
296        resource_group_name: str,
297        account_name: str,
298        expand: Optional[str] = "geoReplicationStats",
299        **kwargs: Any
300    ) -> "_models.StorageAccount":
301        """Returns the properties for the specified storage account including but not limited to name, SKU
302        name, location, and account status. The ListKeys operation should be used to retrieve storage
303        keys.
304
305        :param resource_group_name: The name of the resource group within the user's subscription. The
306         name is case insensitive.
307        :type resource_group_name: str
308        :param account_name: The name of the storage account within the specified resource group.
309         Storage account names must be between 3 and 24 characters in length and use numbers and
310         lower-case letters only.
311        :type account_name: str
312        :param expand: May be used to expand the properties within account's properties. By default,
313         data is not included when fetching properties. Currently we only support geoReplicationStats.
314        :type expand: str
315        :keyword callable cls: A custom type or function that will be passed the direct response
316        :return: StorageAccount, or the result of cls(response)
317        :rtype: ~azure.mgmt.storage.v2019_04_01.models.StorageAccount
318        :raises: ~azure.core.exceptions.HttpResponseError
319        """
320        cls = kwargs.pop('cls', None)  # type: ClsType["_models.StorageAccount"]
321        error_map = {
322            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
323        }
324        error_map.update(kwargs.pop('error_map', {}))
325        api_version = "2019-04-01"
326        accept = "application/json"
327
328        # Construct URL
329        url = self.get_properties.metadata['url']  # type: ignore
330        path_format_arguments = {
331            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
332            'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
333            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
334        }
335        url = self._client.format_url(url, **path_format_arguments)
336
337        # Construct parameters
338        query_parameters = {}  # type: Dict[str, Any]
339        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
340        if expand is not None:
341            query_parameters['$expand'] = self._serialize.query("expand", expand, 'str')
342
343        # Construct headers
344        header_parameters = {}  # type: Dict[str, Any]
345        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
346
347        request = self._client.get(url, query_parameters, header_parameters)
348        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
349        response = pipeline_response.http_response
350
351        if response.status_code not in [200]:
352            map_error(status_code=response.status_code, response=response, error_map=error_map)
353            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
354
355        deserialized = self._deserialize('StorageAccount', pipeline_response)
356
357        if cls:
358            return cls(pipeline_response, deserialized, {})
359
360        return deserialized
361    get_properties.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}'}  # type: ignore
362
363    async def update(
364        self,
365        resource_group_name: str,
366        account_name: str,
367        parameters: "_models.StorageAccountUpdateParameters",
368        **kwargs: Any
369    ) -> "_models.StorageAccount":
370        """The update operation can be used to update the SKU, encryption, access tier, or tags for a
371        storage account. It can also be used to map the account to a custom domain. Only one custom
372        domain is supported per storage account; the replacement/change of custom domain is not
373        supported. In order to replace an old custom domain, the old value must be cleared/unregistered
374        before a new value can be set. The update of multiple properties is supported. This call does
375        not change the storage keys for the account. If you want to change the storage account keys,
376        use the regenerate keys operation. The location and name of the storage account cannot be
377        changed after creation.
378
379        :param resource_group_name: The name of the resource group within the user's subscription. The
380         name is case insensitive.
381        :type resource_group_name: str
382        :param account_name: The name of the storage account within the specified resource group.
383         Storage account names must be between 3 and 24 characters in length and use numbers and
384         lower-case letters only.
385        :type account_name: str
386        :param parameters: The parameters to provide for the updated account.
387        :type parameters: ~azure.mgmt.storage.v2019_04_01.models.StorageAccountUpdateParameters
388        :keyword callable cls: A custom type or function that will be passed the direct response
389        :return: StorageAccount, or the result of cls(response)
390        :rtype: ~azure.mgmt.storage.v2019_04_01.models.StorageAccount
391        :raises: ~azure.core.exceptions.HttpResponseError
392        """
393        cls = kwargs.pop('cls', None)  # type: ClsType["_models.StorageAccount"]
394        error_map = {
395            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
396        }
397        error_map.update(kwargs.pop('error_map', {}))
398        api_version = "2019-04-01"
399        content_type = kwargs.pop("content_type", "application/json")
400        accept = "application/json"
401
402        # Construct URL
403        url = self.update.metadata['url']  # type: ignore
404        path_format_arguments = {
405            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
406            'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
407            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
408        }
409        url = self._client.format_url(url, **path_format_arguments)
410
411        # Construct parameters
412        query_parameters = {}  # type: Dict[str, Any]
413        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
414
415        # Construct headers
416        header_parameters = {}  # type: Dict[str, Any]
417        header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str')
418        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
419
420        body_content_kwargs = {}  # type: Dict[str, Any]
421        body_content = self._serialize.body(parameters, 'StorageAccountUpdateParameters')
422        body_content_kwargs['content'] = body_content
423        request = self._client.patch(url, query_parameters, header_parameters, **body_content_kwargs)
424        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
425        response = pipeline_response.http_response
426
427        if response.status_code not in [200]:
428            map_error(status_code=response.status_code, response=response, error_map=error_map)
429            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
430
431        deserialized = self._deserialize('StorageAccount', pipeline_response)
432
433        if cls:
434            return cls(pipeline_response, deserialized, {})
435
436        return deserialized
437    update.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}'}  # type: ignore
438
439    def list(
440        self,
441        **kwargs: Any
442    ) -> AsyncIterable["_models.StorageAccountListResult"]:
443        """Lists all the storage accounts available under the subscription. Note that storage keys are not
444        returned; use the ListKeys operation for this.
445
446        :keyword callable cls: A custom type or function that will be passed the direct response
447        :return: An iterator like instance of either StorageAccountListResult or the result of cls(response)
448        :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.storage.v2019_04_01.models.StorageAccountListResult]
449        :raises: ~azure.core.exceptions.HttpResponseError
450        """
451        cls = kwargs.pop('cls', None)  # type: ClsType["_models.StorageAccountListResult"]
452        error_map = {
453            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
454        }
455        error_map.update(kwargs.pop('error_map', {}))
456        api_version = "2019-04-01"
457        accept = "application/json"
458
459        def prepare_request(next_link=None):
460            # Construct headers
461            header_parameters = {}  # type: Dict[str, Any]
462            header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
463
464            if not next_link:
465                # Construct URL
466                url = self.list.metadata['url']  # type: ignore
467                path_format_arguments = {
468                    'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
469                }
470                url = self._client.format_url(url, **path_format_arguments)
471                # Construct parameters
472                query_parameters = {}  # type: Dict[str, Any]
473                query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
474
475                request = self._client.get(url, query_parameters, header_parameters)
476            else:
477                url = next_link
478                query_parameters = {}  # type: Dict[str, Any]
479                request = self._client.get(url, query_parameters, header_parameters)
480            return request
481
482        async def extract_data(pipeline_response):
483            deserialized = self._deserialize('StorageAccountListResult', pipeline_response)
484            list_of_elem = deserialized.value
485            if cls:
486                list_of_elem = cls(list_of_elem)
487            return deserialized.next_link or None, AsyncList(list_of_elem)
488
489        async def get_next(next_link=None):
490            request = prepare_request(next_link)
491
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            return pipeline_response
500
501        return AsyncItemPaged(
502            get_next, extract_data
503        )
504    list.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.Storage/storageAccounts'}  # type: ignore
505
506    def list_by_resource_group(
507        self,
508        resource_group_name: str,
509        **kwargs: Any
510    ) -> AsyncIterable["_models.StorageAccountListResult"]:
511        """Lists all the storage accounts available under the given resource group. Note that storage keys
512        are not returned; use the ListKeys operation for this.
513
514        :param resource_group_name: The name of the resource group within the user's subscription. The
515         name is case insensitive.
516        :type resource_group_name: str
517        :keyword callable cls: A custom type or function that will be passed the direct response
518        :return: An iterator like instance of either StorageAccountListResult or the result of cls(response)
519        :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.storage.v2019_04_01.models.StorageAccountListResult]
520        :raises: ~azure.core.exceptions.HttpResponseError
521        """
522        cls = kwargs.pop('cls', None)  # type: ClsType["_models.StorageAccountListResult"]
523        error_map = {
524            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
525        }
526        error_map.update(kwargs.pop('error_map', {}))
527        api_version = "2019-04-01"
528        accept = "application/json"
529
530        def prepare_request(next_link=None):
531            # Construct headers
532            header_parameters = {}  # type: Dict[str, Any]
533            header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
534
535            if not next_link:
536                # Construct URL
537                url = self.list_by_resource_group.metadata['url']  # type: ignore
538                path_format_arguments = {
539                    'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
540                    'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
541                }
542                url = self._client.format_url(url, **path_format_arguments)
543                # Construct parameters
544                query_parameters = {}  # type: Dict[str, Any]
545                query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
546
547                request = self._client.get(url, query_parameters, header_parameters)
548            else:
549                url = next_link
550                query_parameters = {}  # type: Dict[str, Any]
551                request = self._client.get(url, query_parameters, header_parameters)
552            return request
553
554        async def extract_data(pipeline_response):
555            deserialized = self._deserialize('StorageAccountListResult', pipeline_response)
556            list_of_elem = deserialized.value
557            if cls:
558                list_of_elem = cls(list_of_elem)
559            return None, AsyncList(list_of_elem)
560
561        async def get_next(next_link=None):
562            request = prepare_request(next_link)
563
564            pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
565            response = pipeline_response.http_response
566
567            if response.status_code not in [200]:
568                map_error(status_code=response.status_code, response=response, error_map=error_map)
569                raise HttpResponseError(response=response, error_format=ARMErrorFormat)
570
571            return pipeline_response
572
573        return AsyncItemPaged(
574            get_next, extract_data
575        )
576    list_by_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts'}  # type: ignore
577
578    async def list_keys(
579        self,
580        resource_group_name: str,
581        account_name: str,
582        expand: Optional[str] = "kerb",
583        **kwargs: Any
584    ) -> "_models.StorageAccountListKeysResult":
585        """Lists the access keys or Kerberos keys (if active directory enabled) for the specified storage
586        account.
587
588        :param resource_group_name: The name of the resource group within the user's subscription. The
589         name is case insensitive.
590        :type resource_group_name: str
591        :param account_name: The name of the storage account within the specified resource group.
592         Storage account names must be between 3 and 24 characters in length and use numbers and
593         lower-case letters only.
594        :type account_name: str
595        :param expand: Specifies type of the key to be listed. Possible value is kerb.
596        :type expand: str
597        :keyword callable cls: A custom type or function that will be passed the direct response
598        :return: StorageAccountListKeysResult, or the result of cls(response)
599        :rtype: ~azure.mgmt.storage.v2019_04_01.models.StorageAccountListKeysResult
600        :raises: ~azure.core.exceptions.HttpResponseError
601        """
602        cls = kwargs.pop('cls', None)  # type: ClsType["_models.StorageAccountListKeysResult"]
603        error_map = {
604            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
605        }
606        error_map.update(kwargs.pop('error_map', {}))
607        api_version = "2019-04-01"
608        accept = "application/json"
609
610        # Construct URL
611        url = self.list_keys.metadata['url']  # type: ignore
612        path_format_arguments = {
613            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
614            'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
615            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
616        }
617        url = self._client.format_url(url, **path_format_arguments)
618
619        # Construct parameters
620        query_parameters = {}  # type: Dict[str, Any]
621        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
622        if expand is not None:
623            query_parameters['$expand'] = self._serialize.query("expand", expand, 'str')
624
625        # Construct headers
626        header_parameters = {}  # type: Dict[str, Any]
627        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
628
629        request = self._client.post(url, query_parameters, header_parameters)
630        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
631        response = pipeline_response.http_response
632
633        if response.status_code not in [200]:
634            map_error(status_code=response.status_code, response=response, error_map=error_map)
635            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
636
637        deserialized = self._deserialize('StorageAccountListKeysResult', pipeline_response)
638
639        if cls:
640            return cls(pipeline_response, deserialized, {})
641
642        return deserialized
643    list_keys.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/listKeys'}  # type: ignore
644
645    async def regenerate_key(
646        self,
647        resource_group_name: str,
648        account_name: str,
649        regenerate_key: "_models.StorageAccountRegenerateKeyParameters",
650        **kwargs: Any
651    ) -> "_models.StorageAccountListKeysResult":
652        """Regenerates one of the access keys or Kerberos keys for the specified storage account.
653
654        :param resource_group_name: The name of the resource group within the user's subscription. The
655         name is case insensitive.
656        :type resource_group_name: str
657        :param account_name: The name of the storage account within the specified resource group.
658         Storage account names must be between 3 and 24 characters in length and use numbers and
659         lower-case letters only.
660        :type account_name: str
661        :param regenerate_key: Specifies name of the key which should be regenerated -- key1, key2,
662         kerb1, kerb2.
663        :type regenerate_key: ~azure.mgmt.storage.v2019_04_01.models.StorageAccountRegenerateKeyParameters
664        :keyword callable cls: A custom type or function that will be passed the direct response
665        :return: StorageAccountListKeysResult, or the result of cls(response)
666        :rtype: ~azure.mgmt.storage.v2019_04_01.models.StorageAccountListKeysResult
667        :raises: ~azure.core.exceptions.HttpResponseError
668        """
669        cls = kwargs.pop('cls', None)  # type: ClsType["_models.StorageAccountListKeysResult"]
670        error_map = {
671            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
672        }
673        error_map.update(kwargs.pop('error_map', {}))
674        api_version = "2019-04-01"
675        content_type = kwargs.pop("content_type", "application/json")
676        accept = "application/json"
677
678        # Construct URL
679        url = self.regenerate_key.metadata['url']  # type: ignore
680        path_format_arguments = {
681            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
682            'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
683            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
684        }
685        url = self._client.format_url(url, **path_format_arguments)
686
687        # Construct parameters
688        query_parameters = {}  # type: Dict[str, Any]
689        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
690
691        # Construct headers
692        header_parameters = {}  # type: Dict[str, Any]
693        header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str')
694        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
695
696        body_content_kwargs = {}  # type: Dict[str, Any]
697        body_content = self._serialize.body(regenerate_key, 'StorageAccountRegenerateKeyParameters')
698        body_content_kwargs['content'] = body_content
699        request = self._client.post(url, query_parameters, header_parameters, **body_content_kwargs)
700        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
701        response = pipeline_response.http_response
702
703        if response.status_code not in [200]:
704            map_error(status_code=response.status_code, response=response, error_map=error_map)
705            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
706
707        deserialized = self._deserialize('StorageAccountListKeysResult', pipeline_response)
708
709        if cls:
710            return cls(pipeline_response, deserialized, {})
711
712        return deserialized
713    regenerate_key.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/regenerateKey'}  # type: ignore
714
715    async def list_account_sas(
716        self,
717        resource_group_name: str,
718        account_name: str,
719        parameters: "_models.AccountSasParameters",
720        **kwargs: Any
721    ) -> "_models.ListAccountSasResponse":
722        """List SAS credentials of a storage account.
723
724        :param resource_group_name: The name of the resource group within the user's subscription. The
725         name is case insensitive.
726        :type resource_group_name: str
727        :param account_name: The name of the storage account within the specified resource group.
728         Storage account names must be between 3 and 24 characters in length and use numbers and
729         lower-case letters only.
730        :type account_name: str
731        :param parameters: The parameters to provide to list SAS credentials for the storage account.
732        :type parameters: ~azure.mgmt.storage.v2019_04_01.models.AccountSasParameters
733        :keyword callable cls: A custom type or function that will be passed the direct response
734        :return: ListAccountSasResponse, or the result of cls(response)
735        :rtype: ~azure.mgmt.storage.v2019_04_01.models.ListAccountSasResponse
736        :raises: ~azure.core.exceptions.HttpResponseError
737        """
738        cls = kwargs.pop('cls', None)  # type: ClsType["_models.ListAccountSasResponse"]
739        error_map = {
740            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
741        }
742        error_map.update(kwargs.pop('error_map', {}))
743        api_version = "2019-04-01"
744        content_type = kwargs.pop("content_type", "application/json")
745        accept = "application/json"
746
747        # Construct URL
748        url = self.list_account_sas.metadata['url']  # type: ignore
749        path_format_arguments = {
750            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
751            'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
752            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
753        }
754        url = self._client.format_url(url, **path_format_arguments)
755
756        # Construct parameters
757        query_parameters = {}  # type: Dict[str, Any]
758        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
759
760        # Construct headers
761        header_parameters = {}  # type: Dict[str, Any]
762        header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str')
763        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
764
765        body_content_kwargs = {}  # type: Dict[str, Any]
766        body_content = self._serialize.body(parameters, 'AccountSasParameters')
767        body_content_kwargs['content'] = body_content
768        request = self._client.post(url, query_parameters, header_parameters, **body_content_kwargs)
769        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
770        response = pipeline_response.http_response
771
772        if response.status_code not in [200]:
773            map_error(status_code=response.status_code, response=response, error_map=error_map)
774            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
775
776        deserialized = self._deserialize('ListAccountSasResponse', pipeline_response)
777
778        if cls:
779            return cls(pipeline_response, deserialized, {})
780
781        return deserialized
782    list_account_sas.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/ListAccountSas'}  # type: ignore
783
784    async def list_service_sas(
785        self,
786        resource_group_name: str,
787        account_name: str,
788        parameters: "_models.ServiceSasParameters",
789        **kwargs: Any
790    ) -> "_models.ListServiceSasResponse":
791        """List service SAS credentials of a specific resource.
792
793        :param resource_group_name: The name of the resource group within the user's subscription. The
794         name is case insensitive.
795        :type resource_group_name: str
796        :param account_name: The name of the storage account within the specified resource group.
797         Storage account names must be between 3 and 24 characters in length and use numbers and
798         lower-case letters only.
799        :type account_name: str
800        :param parameters: The parameters to provide to list service SAS credentials.
801        :type parameters: ~azure.mgmt.storage.v2019_04_01.models.ServiceSasParameters
802        :keyword callable cls: A custom type or function that will be passed the direct response
803        :return: ListServiceSasResponse, or the result of cls(response)
804        :rtype: ~azure.mgmt.storage.v2019_04_01.models.ListServiceSasResponse
805        :raises: ~azure.core.exceptions.HttpResponseError
806        """
807        cls = kwargs.pop('cls', None)  # type: ClsType["_models.ListServiceSasResponse"]
808        error_map = {
809            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
810        }
811        error_map.update(kwargs.pop('error_map', {}))
812        api_version = "2019-04-01"
813        content_type = kwargs.pop("content_type", "application/json")
814        accept = "application/json"
815
816        # Construct URL
817        url = self.list_service_sas.metadata['url']  # type: ignore
818        path_format_arguments = {
819            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
820            'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
821            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
822        }
823        url = self._client.format_url(url, **path_format_arguments)
824
825        # Construct parameters
826        query_parameters = {}  # type: Dict[str, Any]
827        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
828
829        # Construct headers
830        header_parameters = {}  # type: Dict[str, Any]
831        header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str')
832        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
833
834        body_content_kwargs = {}  # type: Dict[str, Any]
835        body_content = self._serialize.body(parameters, 'ServiceSasParameters')
836        body_content_kwargs['content'] = body_content
837        request = self._client.post(url, query_parameters, header_parameters, **body_content_kwargs)
838        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
839        response = pipeline_response.http_response
840
841        if response.status_code not in [200]:
842            map_error(status_code=response.status_code, response=response, error_map=error_map)
843            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
844
845        deserialized = self._deserialize('ListServiceSasResponse', pipeline_response)
846
847        if cls:
848            return cls(pipeline_response, deserialized, {})
849
850        return deserialized
851    list_service_sas.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/ListServiceSas'}  # type: ignore
852
853    async def _failover_initial(
854        self,
855        resource_group_name: str,
856        account_name: str,
857        **kwargs: Any
858    ) -> None:
859        cls = kwargs.pop('cls', None)  # type: ClsType[None]
860        error_map = {
861            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
862        }
863        error_map.update(kwargs.pop('error_map', {}))
864        api_version = "2019-04-01"
865
866        # Construct URL
867        url = self._failover_initial.metadata['url']  # type: ignore
868        path_format_arguments = {
869            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
870            'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
871            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
872        }
873        url = self._client.format_url(url, **path_format_arguments)
874
875        # Construct parameters
876        query_parameters = {}  # type: Dict[str, Any]
877        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
878
879        # Construct headers
880        header_parameters = {}  # type: Dict[str, Any]
881
882        request = self._client.post(url, query_parameters, header_parameters)
883        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
884        response = pipeline_response.http_response
885
886        if response.status_code not in [200, 202]:
887            map_error(status_code=response.status_code, response=response, error_map=error_map)
888            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
889
890        if cls:
891            return cls(pipeline_response, None, {})
892
893    _failover_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/failover'}  # type: ignore
894
895    async def begin_failover(
896        self,
897        resource_group_name: str,
898        account_name: str,
899        **kwargs: Any
900    ) -> AsyncLROPoller[None]:
901        """Failover request can be triggered for a storage account in case of availability issues. The
902        failover occurs from the storage account's primary cluster to secondary cluster for RA-GRS
903        accounts. The secondary cluster will become primary after failover.
904
905        :param resource_group_name: The name of the resource group within the user's subscription. The
906         name is case insensitive.
907        :type resource_group_name: str
908        :param account_name: The name of the storage account within the specified resource group.
909         Storage account names must be between 3 and 24 characters in length and use numbers and
910         lower-case letters only.
911        :type account_name: str
912        :keyword callable cls: A custom type or function that will be passed the direct response
913        :keyword str continuation_token: A continuation token to restart a poller from a saved state.
914        :keyword polling: By default, your polling method will be AsyncARMPolling.
915         Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy.
916        :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod
917        :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
918        :return: An instance of AsyncLROPoller that returns either None or the result of cls(response)
919        :rtype: ~azure.core.polling.AsyncLROPoller[None]
920        :raises ~azure.core.exceptions.HttpResponseError:
921        """
922        polling = kwargs.pop('polling', True)  # type: Union[bool, AsyncPollingMethod]
923        cls = kwargs.pop('cls', None)  # type: ClsType[None]
924        lro_delay = kwargs.pop(
925            'polling_interval',
926            self._config.polling_interval
927        )
928        cont_token = kwargs.pop('continuation_token', None)  # type: Optional[str]
929        if cont_token is None:
930            raw_result = await self._failover_initial(
931                resource_group_name=resource_group_name,
932                account_name=account_name,
933                cls=lambda x,y,z: x,
934                **kwargs
935            )
936
937        kwargs.pop('error_map', None)
938        kwargs.pop('content_type', None)
939
940        def get_long_running_output(pipeline_response):
941            if cls:
942                return cls(pipeline_response, None, {})
943
944        path_format_arguments = {
945            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
946            'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
947            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
948        }
949
950        if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, path_format_arguments=path_format_arguments,  **kwargs)
951        elif polling is False: polling_method = AsyncNoPolling()
952        else: polling_method = polling
953        if cont_token:
954            return AsyncLROPoller.from_continuation_token(
955                polling_method=polling_method,
956                continuation_token=cont_token,
957                client=self._client,
958                deserialization_callback=get_long_running_output
959            )
960        else:
961            return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method)
962    begin_failover.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/failover'}  # type: ignore
963
964    async def revoke_user_delegation_keys(
965        self,
966        resource_group_name: str,
967        account_name: str,
968        **kwargs: Any
969    ) -> None:
970        """Revoke user delegation keys.
971
972        :param resource_group_name: The name of the resource group within the user's subscription. The
973         name is case insensitive.
974        :type resource_group_name: str
975        :param account_name: The name of the storage account within the specified resource group.
976         Storage account names must be between 3 and 24 characters in length and use numbers and
977         lower-case letters only.
978        :type account_name: str
979        :keyword callable cls: A custom type or function that will be passed the direct response
980        :return: None, or the result of cls(response)
981        :rtype: None
982        :raises: ~azure.core.exceptions.HttpResponseError
983        """
984        cls = kwargs.pop('cls', None)  # type: ClsType[None]
985        error_map = {
986            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
987        }
988        error_map.update(kwargs.pop('error_map', {}))
989        api_version = "2019-04-01"
990
991        # Construct URL
992        url = self.revoke_user_delegation_keys.metadata['url']  # type: ignore
993        path_format_arguments = {
994            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
995            'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
996            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
997        }
998        url = self._client.format_url(url, **path_format_arguments)
999
1000        # Construct parameters
1001        query_parameters = {}  # type: Dict[str, Any]
1002        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
1003
1004        # Construct headers
1005        header_parameters = {}  # type: Dict[str, Any]
1006
1007        request = self._client.post(url, query_parameters, header_parameters)
1008        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
1009        response = pipeline_response.http_response
1010
1011        if response.status_code not in [200]:
1012            map_error(status_code=response.status_code, response=response, error_map=error_map)
1013            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
1014
1015        if cls:
1016            return cls(pipeline_response, None, {})
1017
1018    revoke_user_delegation_keys.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/revokeUserDelegationKeys'}  # type: ignore
1019