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
5# license information.
6#
7# Code generated by Microsoft (R) AutoRest Code Generator.
8# Changes may cause incorrect behavior and will be lost if the code is
9# regenerated.
10# --------------------------------------------------------------------------
11
12from azure.core.exceptions import map_error
13
14from ... import models
15
16
17class ServiceOperations:
18    """ServiceOperations async operations.
19
20    You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute.
21
22    :param client: Client for service requests.
23    :param config: Configuration of service client.
24    :param serializer: An object model serializer.
25    :param deserializer: An object model deserializer.
26    """
27
28    models = models
29
30    def __init__(self, client, config, serializer, deserializer) -> None:
31
32        self._client = client
33        self._serialize = serializer
34        self._deserialize = deserializer
35
36        self._config = config
37
38    async def set_properties(self, storage_service_properties, timeout=None, request_id=None, *, cls=None, **kwargs):
39        """Sets properties for a storage account's Blob service endpoint,
40        including properties for Storage Analytics and CORS (Cross-Origin
41        Resource Sharing) rules.
42
43        :param storage_service_properties: The StorageService properties.
44        :type storage_service_properties:
45         ~azure.storage.blob.models.StorageServiceProperties
46        :param timeout: The timeout parameter is expressed in seconds. For
47         more information, see <a
48         href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting
49         Timeouts for Blob Service Operations.</a>
50        :type timeout: int
51        :param request_id: Provides a client-generated, opaque value with a 1
52         KB character limit that is recorded in the analytics logs when storage
53         analytics logging is enabled.
54        :type request_id: str
55        :param callable cls: A custom type or function that will be passed the
56         direct response
57        :return: None or the result of cls(response)
58        :rtype: None
59        :raises:
60         :class:`StorageErrorException<azure.storage.blob.models.StorageErrorException>`
61        """
62        error_map = kwargs.pop('error_map', None)
63        restype = "service"
64        comp = "properties"
65
66        # Construct URL
67        url = self.set_properties.metadata['url']
68        path_format_arguments = {
69            'url': self._serialize.url("self._config.url", self._config.url, 'str', skip_quote=True)
70        }
71        url = self._client.format_url(url, **path_format_arguments)
72
73        # Construct parameters
74        query_parameters = {}
75        if timeout is not None:
76            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int', minimum=0)
77        query_parameters['restype'] = self._serialize.query("restype", restype, 'str')
78        query_parameters['comp'] = self._serialize.query("comp", comp, 'str')
79
80        # Construct headers
81        header_parameters = {}
82        header_parameters['Content-Type'] = 'application/xml; charset=utf-8'
83        header_parameters['x-ms-version'] = self._serialize.header("self._config.version", self._config.version, 'str')
84        if request_id is not None:
85            header_parameters['x-ms-client-request-id'] = self._serialize.header("request_id", request_id, 'str')
86
87        # Construct body
88        body_content = self._serialize.body(storage_service_properties, 'StorageServiceProperties')
89
90        # Construct and send request
91        request = self._client.put(url, query_parameters, header_parameters, body_content)
92        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
93        response = pipeline_response.http_response
94
95        if response.status_code not in [202]:
96            map_error(status_code=response.status_code, response=response, error_map=error_map)
97            raise models.StorageErrorException(response, self._deserialize)
98
99        if cls:
100            response_headers = {
101                'x-ms-client-request-id': self._deserialize('str', response.headers.get('x-ms-client-request-id')),
102                'x-ms-request-id': self._deserialize('str', response.headers.get('x-ms-request-id')),
103                'x-ms-version': self._deserialize('str', response.headers.get('x-ms-version')),
104                'x-ms-error-code': self._deserialize('str', response.headers.get('x-ms-error-code')),
105            }
106            return cls(response, None, response_headers)
107    set_properties.metadata = {'url': '/'}
108
109    async def get_properties(self, timeout=None, request_id=None, *, cls=None, **kwargs):
110        """gets the properties of a storage account's Blob service, including
111        properties for Storage Analytics and CORS (Cross-Origin Resource
112        Sharing) rules.
113
114        :param timeout: The timeout parameter is expressed in seconds. For
115         more information, see <a
116         href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting
117         Timeouts for Blob Service Operations.</a>
118        :type timeout: int
119        :param request_id: Provides a client-generated, opaque value with a 1
120         KB character limit that is recorded in the analytics logs when storage
121         analytics logging is enabled.
122        :type request_id: str
123        :param callable cls: A custom type or function that will be passed the
124         direct response
125        :return: StorageServiceProperties or the result of cls(response)
126        :rtype: ~azure.storage.blob.models.StorageServiceProperties
127        :raises:
128         :class:`StorageErrorException<azure.storage.blob.models.StorageErrorException>`
129        """
130        error_map = kwargs.pop('error_map', None)
131        restype = "service"
132        comp = "properties"
133
134        # Construct URL
135        url = self.get_properties.metadata['url']
136        path_format_arguments = {
137            'url': self._serialize.url("self._config.url", self._config.url, 'str', skip_quote=True)
138        }
139        url = self._client.format_url(url, **path_format_arguments)
140
141        # Construct parameters
142        query_parameters = {}
143        if timeout is not None:
144            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int', minimum=0)
145        query_parameters['restype'] = self._serialize.query("restype", restype, 'str')
146        query_parameters['comp'] = self._serialize.query("comp", comp, 'str')
147
148        # Construct headers
149        header_parameters = {}
150        header_parameters['Accept'] = 'application/xml'
151        header_parameters['x-ms-version'] = self._serialize.header("self._config.version", self._config.version, 'str')
152        if request_id is not None:
153            header_parameters['x-ms-client-request-id'] = self._serialize.header("request_id", request_id, 'str')
154
155        # Construct and send request
156        request = self._client.get(url, query_parameters, header_parameters)
157        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
158        response = pipeline_response.http_response
159
160        if response.status_code not in [200]:
161            map_error(status_code=response.status_code, response=response, error_map=error_map)
162            raise models.StorageErrorException(response, self._deserialize)
163
164        header_dict = {}
165        deserialized = None
166        if response.status_code == 200:
167            deserialized = self._deserialize('StorageServiceProperties', response)
168            header_dict = {
169                'x-ms-client-request-id': self._deserialize('str', response.headers.get('x-ms-client-request-id')),
170                'x-ms-request-id': self._deserialize('str', response.headers.get('x-ms-request-id')),
171                'x-ms-version': self._deserialize('str', response.headers.get('x-ms-version')),
172                'x-ms-error-code': self._deserialize('str', response.headers.get('x-ms-error-code')),
173            }
174
175        if cls:
176            return cls(response, deserialized, header_dict)
177
178        return deserialized
179    get_properties.metadata = {'url': '/'}
180
181    async def get_statistics(self, timeout=None, request_id=None, *, cls=None, **kwargs):
182        """Retrieves statistics related to replication for the Blob service. It is
183        only available on the secondary location endpoint when read-access
184        geo-redundant replication is enabled for the storage account.
185
186        :param timeout: The timeout parameter is expressed in seconds. For
187         more information, see <a
188         href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting
189         Timeouts for Blob Service Operations.</a>
190        :type timeout: int
191        :param request_id: Provides a client-generated, opaque value with a 1
192         KB character limit that is recorded in the analytics logs when storage
193         analytics logging is enabled.
194        :type request_id: str
195        :param callable cls: A custom type or function that will be passed the
196         direct response
197        :return: StorageServiceStats or the result of cls(response)
198        :rtype: ~azure.storage.blob.models.StorageServiceStats
199        :raises:
200         :class:`StorageErrorException<azure.storage.blob.models.StorageErrorException>`
201        """
202        error_map = kwargs.pop('error_map', None)
203        restype = "service"
204        comp = "stats"
205
206        # Construct URL
207        url = self.get_statistics.metadata['url']
208        path_format_arguments = {
209            'url': self._serialize.url("self._config.url", self._config.url, 'str', skip_quote=True)
210        }
211        url = self._client.format_url(url, **path_format_arguments)
212
213        # Construct parameters
214        query_parameters = {}
215        if timeout is not None:
216            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int', minimum=0)
217        query_parameters['restype'] = self._serialize.query("restype", restype, 'str')
218        query_parameters['comp'] = self._serialize.query("comp", comp, 'str')
219
220        # Construct headers
221        header_parameters = {}
222        header_parameters['Accept'] = 'application/xml'
223        header_parameters['x-ms-version'] = self._serialize.header("self._config.version", self._config.version, 'str')
224        if request_id is not None:
225            header_parameters['x-ms-client-request-id'] = self._serialize.header("request_id", request_id, 'str')
226
227        # Construct and send request
228        request = self._client.get(url, query_parameters, header_parameters)
229        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
230        response = pipeline_response.http_response
231
232        if response.status_code not in [200]:
233            map_error(status_code=response.status_code, response=response, error_map=error_map)
234            raise models.StorageErrorException(response, self._deserialize)
235
236        header_dict = {}
237        deserialized = None
238        if response.status_code == 200:
239            deserialized = self._deserialize('StorageServiceStats', response)
240            header_dict = {
241                'x-ms-client-request-id': self._deserialize('str', response.headers.get('x-ms-client-request-id')),
242                'x-ms-request-id': self._deserialize('str', response.headers.get('x-ms-request-id')),
243                'x-ms-version': self._deserialize('str', response.headers.get('x-ms-version')),
244                'Date': self._deserialize('rfc-1123', response.headers.get('Date')),
245                'x-ms-error-code': self._deserialize('str', response.headers.get('x-ms-error-code')),
246            }
247
248        if cls:
249            return cls(response, deserialized, header_dict)
250
251        return deserialized
252    get_statistics.metadata = {'url': '/'}
253
254    async def list_containers_segment(self, prefix=None, marker=None, maxresults=None, include=None, timeout=None, request_id=None, *, cls=None, **kwargs):
255        """The List Containers Segment operation returns a list of the containers
256        under the specified account.
257
258        :param prefix: Filters the results to return only containers whose
259         name begins with the specified prefix.
260        :type prefix: str
261        :param marker: A string value that identifies the portion of the list
262         of containers to be returned with the next listing operation. The
263         operation returns the NextMarker value within the response body if the
264         listing operation did not return all containers remaining to be listed
265         with the current page. The NextMarker value can be used as the value
266         for the marker parameter in a subsequent call to request the next page
267         of list items. The marker value is opaque to the client.
268        :type marker: str
269        :param maxresults: Specifies the maximum number of containers to
270         return. If the request does not specify maxresults, or specifies a
271         value greater than 5000, the server will return up to 5000 items. Note
272         that if the listing operation crosses a partition boundary, then the
273         service will return a continuation token for retrieving the remainder
274         of the results. For this reason, it is possible that the service will
275         return fewer results than specified by maxresults, or than the default
276         of 5000.
277        :type maxresults: int
278        :param include: Include this parameter to specify that the container's
279         metadata be returned as part of the response body. Possible values
280         include: 'metadata'
281        :type include: str or
282         ~azure.storage.blob.models.ListContainersIncludeType
283        :param timeout: The timeout parameter is expressed in seconds. For
284         more information, see <a
285         href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting
286         Timeouts for Blob Service Operations.</a>
287        :type timeout: int
288        :param request_id: Provides a client-generated, opaque value with a 1
289         KB character limit that is recorded in the analytics logs when storage
290         analytics logging is enabled.
291        :type request_id: str
292        :param callable cls: A custom type or function that will be passed the
293         direct response
294        :return: ListContainersSegmentResponse or the result of cls(response)
295        :rtype: ~azure.storage.blob.models.ListContainersSegmentResponse
296        :raises:
297         :class:`StorageErrorException<azure.storage.blob.models.StorageErrorException>`
298        """
299        error_map = kwargs.pop('error_map', None)
300        comp = "list"
301
302        # Construct URL
303        url = self.list_containers_segment.metadata['url']
304        path_format_arguments = {
305            'url': self._serialize.url("self._config.url", self._config.url, 'str', skip_quote=True)
306        }
307        url = self._client.format_url(url, **path_format_arguments)
308
309        # Construct parameters
310        query_parameters = {}
311        if prefix is not None:
312            query_parameters['prefix'] = self._serialize.query("prefix", prefix, 'str')
313        if marker is not None:
314            query_parameters['marker'] = self._serialize.query("marker", marker, 'str')
315        if maxresults is not None:
316            query_parameters['maxresults'] = self._serialize.query("maxresults", maxresults, 'int', minimum=1)
317        if include is not None:
318            query_parameters['include'] = self._serialize.query("include", include, 'ListContainersIncludeType')
319        if timeout is not None:
320            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int', minimum=0)
321        query_parameters['comp'] = self._serialize.query("comp", comp, 'str')
322
323        # Construct headers
324        header_parameters = {}
325        header_parameters['Accept'] = 'application/xml'
326        header_parameters['x-ms-version'] = self._serialize.header("self._config.version", self._config.version, 'str')
327        if request_id is not None:
328            header_parameters['x-ms-client-request-id'] = self._serialize.header("request_id", request_id, 'str')
329
330        # Construct and send request
331        request = self._client.get(url, query_parameters, header_parameters)
332        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
333        response = pipeline_response.http_response
334
335        if response.status_code not in [200]:
336            map_error(status_code=response.status_code, response=response, error_map=error_map)
337            raise models.StorageErrorException(response, self._deserialize)
338
339        header_dict = {}
340        deserialized = None
341        if response.status_code == 200:
342            deserialized = self._deserialize('ListContainersSegmentResponse', response)
343            header_dict = {
344                'x-ms-client-request-id': self._deserialize('str', response.headers.get('x-ms-client-request-id')),
345                'x-ms-request-id': self._deserialize('str', response.headers.get('x-ms-request-id')),
346                'x-ms-version': self._deserialize('str', response.headers.get('x-ms-version')),
347                'x-ms-error-code': self._deserialize('str', response.headers.get('x-ms-error-code')),
348            }
349
350        if cls:
351            return cls(response, deserialized, header_dict)
352
353        return deserialized
354    list_containers_segment.metadata = {'url': '/'}
355
356    async def get_user_delegation_key(self, key_info, timeout=None, request_id=None, *, cls=None, **kwargs):
357        """Retrieves a user delegation key for the Blob service. This is only a
358        valid operation when using bearer token authentication.
359
360        :param key_info:
361        :type key_info: ~azure.storage.blob.models.KeyInfo
362        :param timeout: The timeout parameter is expressed in seconds. For
363         more information, see <a
364         href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting
365         Timeouts for Blob Service Operations.</a>
366        :type timeout: int
367        :param request_id: Provides a client-generated, opaque value with a 1
368         KB character limit that is recorded in the analytics logs when storage
369         analytics logging is enabled.
370        :type request_id: str
371        :param callable cls: A custom type or function that will be passed the
372         direct response
373        :return: UserDelegationKey or the result of cls(response)
374        :rtype: ~azure.storage.blob.models.UserDelegationKey
375        :raises:
376         :class:`StorageErrorException<azure.storage.blob.models.StorageErrorException>`
377        """
378        error_map = kwargs.pop('error_map', None)
379        restype = "service"
380        comp = "userdelegationkey"
381
382        # Construct URL
383        url = self.get_user_delegation_key.metadata['url']
384        path_format_arguments = {
385            'url': self._serialize.url("self._config.url", self._config.url, 'str', skip_quote=True)
386        }
387        url = self._client.format_url(url, **path_format_arguments)
388
389        # Construct parameters
390        query_parameters = {}
391        if timeout is not None:
392            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int', minimum=0)
393        query_parameters['restype'] = self._serialize.query("restype", restype, 'str')
394        query_parameters['comp'] = self._serialize.query("comp", comp, 'str')
395
396        # Construct headers
397        header_parameters = {}
398        header_parameters['Accept'] = 'application/xml'
399        header_parameters['Content-Type'] = 'application/xml; charset=utf-8'
400        header_parameters['x-ms-version'] = self._serialize.header("self._config.version", self._config.version, 'str')
401        if request_id is not None:
402            header_parameters['x-ms-client-request-id'] = self._serialize.header("request_id", request_id, 'str')
403
404        # Construct body
405        body_content = self._serialize.body(key_info, 'KeyInfo')
406
407        # Construct and send request
408        request = self._client.post(url, query_parameters, header_parameters, body_content)
409        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
410        response = pipeline_response.http_response
411
412        if response.status_code not in [200]:
413            map_error(status_code=response.status_code, response=response, error_map=error_map)
414            raise models.StorageErrorException(response, self._deserialize)
415
416        header_dict = {}
417        deserialized = None
418        if response.status_code == 200:
419            deserialized = self._deserialize('UserDelegationKey', response)
420            header_dict = {
421                'x-ms-client-request-id': self._deserialize('str', response.headers.get('x-ms-client-request-id')),
422                'x-ms-request-id': self._deserialize('str', response.headers.get('x-ms-request-id')),
423                'x-ms-version': self._deserialize('str', response.headers.get('x-ms-version')),
424                'Date': self._deserialize('rfc-1123', response.headers.get('Date')),
425                'x-ms-error-code': self._deserialize('str', response.headers.get('x-ms-error-code')),
426            }
427
428        if cls:
429            return cls(response, deserialized, header_dict)
430
431        return deserialized
432    get_user_delegation_key.metadata = {'url': '/'}
433
434    async def get_account_info(self, *, cls=None, **kwargs):
435        """Returns the sku name and account kind .
436
437        :param callable cls: A custom type or function that will be passed the
438         direct response
439        :return: None or the result of cls(response)
440        :rtype: None
441        :raises:
442         :class:`StorageErrorException<azure.storage.blob.models.StorageErrorException>`
443        """
444        error_map = kwargs.pop('error_map', None)
445        restype = "account"
446        comp = "properties"
447
448        # Construct URL
449        url = self.get_account_info.metadata['url']
450        path_format_arguments = {
451            'url': self._serialize.url("self._config.url", self._config.url, 'str', skip_quote=True)
452        }
453        url = self._client.format_url(url, **path_format_arguments)
454
455        # Construct parameters
456        query_parameters = {}
457        query_parameters['restype'] = self._serialize.query("restype", restype, 'str')
458        query_parameters['comp'] = self._serialize.query("comp", comp, 'str')
459
460        # Construct headers
461        header_parameters = {}
462        header_parameters['x-ms-version'] = self._serialize.header("self._config.version", self._config.version, 'str')
463
464        # Construct and send request
465        request = self._client.get(url, query_parameters, header_parameters)
466        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
467        response = pipeline_response.http_response
468
469        if response.status_code not in [200]:
470            map_error(status_code=response.status_code, response=response, error_map=error_map)
471            raise models.StorageErrorException(response, self._deserialize)
472
473        if cls:
474            response_headers = {
475                'x-ms-client-request-id': self._deserialize('str', response.headers.get('x-ms-client-request-id')),
476                'x-ms-request-id': self._deserialize('str', response.headers.get('x-ms-request-id')),
477                'x-ms-version': self._deserialize('str', response.headers.get('x-ms-version')),
478                'Date': self._deserialize('rfc-1123', response.headers.get('Date')),
479                'x-ms-sku-name': self._deserialize(models.SkuName, response.headers.get('x-ms-sku-name')),
480                'x-ms-account-kind': self._deserialize(models.AccountKind, response.headers.get('x-ms-account-kind')),
481                'x-ms-error-code': self._deserialize('str', response.headers.get('x-ms-error-code')),
482            }
483            return cls(response, None, response_headers)
484    get_account_info.metadata = {'url': '/'}
485
486    async def submit_batch(self, body, content_length, multipart_content_type, timeout=None, request_id=None, *, cls=None, **kwargs):
487        """The Batch operation allows multiple API calls to be embedded into a
488        single HTTP request.
489
490        :param body: Initial data
491        :type body: Generator
492        :param content_length: The length of the request.
493        :type content_length: long
494        :param multipart_content_type: Required. The value of this header must
495         be multipart/mixed with a batch boundary. Example header value:
496         multipart/mixed; boundary=batch_<GUID>
497        :type multipart_content_type: str
498        :param timeout: The timeout parameter is expressed in seconds. For
499         more information, see <a
500         href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting
501         Timeouts for Blob Service Operations.</a>
502        :type timeout: int
503        :param request_id: Provides a client-generated, opaque value with a 1
504         KB character limit that is recorded in the analytics logs when storage
505         analytics logging is enabled.
506        :type request_id: str
507        :param callable cls: A custom type or function that will be passed the
508         direct response
509        :return: object or the result of cls(response)
510        :rtype: Generator
511        :raises:
512         :class:`StorageErrorException<azure.storage.blob.models.StorageErrorException>`
513        """
514        error_map = kwargs.pop('error_map', None)
515        comp = "batch"
516
517        # Construct URL
518        url = self.submit_batch.metadata['url']
519        path_format_arguments = {
520            'url': self._serialize.url("self._config.url", self._config.url, 'str', skip_quote=True)
521        }
522        url = self._client.format_url(url, **path_format_arguments)
523
524        # Construct parameters
525        query_parameters = {}
526        if timeout is not None:
527            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int', minimum=0)
528        query_parameters['comp'] = self._serialize.query("comp", comp, 'str')
529
530        # Construct headers
531        header_parameters = {}
532        header_parameters['Accept'] = 'application/xml'
533        header_parameters['Content-Type'] = 'application/xml; charset=utf-8'
534        header_parameters['Content-Length'] = self._serialize.header("content_length", content_length, 'long')
535        header_parameters['Content-Type'] = self._serialize.header("multipart_content_type", multipart_content_type, 'str')
536        header_parameters['x-ms-version'] = self._serialize.header("self._config.version", self._config.version, 'str')
537        if request_id is not None:
538            header_parameters['x-ms-client-request-id'] = self._serialize.header("request_id", request_id, 'str')
539
540        # Construct body
541
542        # Construct and send request
543        request = self._client.post(url, query_parameters, header_parameters, stream_content=body)
544        pipeline_response = await self._client._pipeline.run(request, stream=True, **kwargs)
545        response = pipeline_response.http_response
546
547        if response.status_code not in [200]:
548            await response.load_body()
549            map_error(status_code=response.status_code, response=response, error_map=error_map)
550            raise models.StorageErrorException(response, self._deserialize)
551
552        header_dict = {}
553        deserialized = None
554        if response.status_code == 200:
555            deserialized = response.stream_download(self._client._pipeline)
556            header_dict = {
557                'Content-Type': self._deserialize('str', response.headers.get('Content-Type')),
558                'x-ms-request-id': self._deserialize('str', response.headers.get('x-ms-request-id')),
559                'x-ms-version': self._deserialize('str', response.headers.get('x-ms-version')),
560                'x-ms-error-code': self._deserialize('str', response.headers.get('x-ms-error-code')),
561            }
562
563        if cls:
564            return cls(response, deserialized, header_dict)
565
566        return deserialized
567    submit_batch.metadata = {'url': '/'}
568