This repository was archived by the owner on Oct 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathtablestorageaccount.py
More file actions
62 lines (55 loc) · 2.64 KB
/
Copy pathtablestorageaccount.py
File metadata and controls
62 lines (55 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#-------------------------------------------------------------------------
# Microsoft Developer & Platform Evangelism
#
# Copyright (c) Microsoft Corporation. All rights reserved.
#
# THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
#----------------------------------------------------------------------------------
# The example companies, organizations, products, domain names,
# e-mail addresses, logos, people, places, and events depicted
# herein are fictitious. No association with any real company,
# organization, product, domain name, email address, logo, person,
# places, or events is intended or should be inferred.
#--------------------------------------------------------------------------
from azure.storage import SharedAccessSignature
from azure.storage.table import TableService, Entity
class TableStorageAccount(object):
"""
Provides a factory for creating table
with a common account name and connection_string.
"""
def __init__(self, account_name=None, connection_string=None, sas_token=None, endpoint_suffix = 'cosmosdb.windows.net', is_emulated=None):
'''
:param str account_name:
Storage account account name.
:param str connection_string:
Storage account connection string.
:param str sas_token:
Storage account sas token.
:param str enpoint_suffix:
Storage account endpoint_suffix.
:param bool is_emulated:
Whether to use the emulator. Defaults to False. If specified, will
override all other parameters.
'''
self.account_name = account_name
self.connection_string = connection_string
self.sas_token = sas_token
self.endpoint_suffix = endpoint_suffix
self.is_emulated = is_emulated
def create_table_service(self):
'''
Creates a TableService object with the settings specified in the
TableStorageAccount.
:return: A service object.
:rtype: :class:`~azure.storage.table.tableservice.TableService`
'''
return TableService(account_name = self.account_name,
sas_token=self.sas_token,
endpoint_suffix=self.endpoint_suffix,
connection_string= self.connection_string,
is_emulated=self.is_emulated)
def is_azure_cosmosdb_table(self):
return self.connection_string != None and "table.cosmosdb" in self.connection_string