3
3
# Licensed under the MIT License. See License.txt in the project root for
4
4
# license information.
5
5
# --------------------------------------------------------------------------
6
- from typing import Union
6
+ from typing import Union , Any
7
7
8
8
from ._models import AccountSasPermissions
9
9
from ._common_conversion import _sign_string
17
17
18
18
19
19
def generate_account_sas (
20
- account_name , # type:str
21
- account_key , # type:str
20
+ credential , # type: AzureNamedKeyCredential
22
21
resource_types , # type:ResourceTypes
23
22
permission , # type:Union[str,AccountSasPermissions]
24
23
expiry , # type:Union[datetime,str]
@@ -29,10 +28,8 @@ def generate_account_sas(
29
28
Generates a shared access signature for the table service.
30
29
Use the returned signature with the sas_token parameter of TableService.
31
30
32
- :param account_name: Account name
33
- :type account_name: str
34
- :param account_key: Account key
35
- :type account_key: str
31
+ :param credential: Credential for the Azure account
32
+ :type credential: :class:`~azure.core.credentials.AzureNamedKeyCredential`
36
33
:param resource_types:
37
34
Specifies the resource types that are accessible with the account SAS.
38
35
:type resource_types: ResourceTypes
@@ -70,11 +67,11 @@ def generate_account_sas(
70
67
:return: A Shared Access Signature (sas) token.
71
68
:rtype: str
72
69
"""
73
- _validate_not_none ("account_name" , account_name )
74
- _validate_not_none ("account_key" , account_key )
70
+ _validate_not_none ("account_name" , credential . named_key . name )
71
+ _validate_not_none ("account_key" , credential . named_key . key )
75
72
if permission is str :
76
73
permission = AccountSasPermissions .from_string (permission = permission )
77
- sas = TableSharedAccessSignature (account_name , account_key )
74
+ sas = TableSharedAccessSignature (credential )
78
75
return sas .generate_account (
79
76
"t" ,
80
77
resource_types ,
@@ -87,8 +84,7 @@ def generate_account_sas(
87
84
88
85
89
86
def generate_table_sas (
90
- account_name , # type: str
91
- account_key , # type: str
87
+ credential , # type: AzureNamedKeyCredential
92
88
table_name , # type: str
93
89
** kwargs # type: Any
94
90
): # type: (...) -> str
@@ -143,7 +139,7 @@ def generate_table_sas(
143
139
:rtype: str
144
140
"""
145
141
146
- sas = TableSharedAccessSignature (account_name , account_key )
142
+ sas = TableSharedAccessSignature (credential )
147
143
return sas .generate_table (
148
144
table_name = table_name ,
149
145
permission = kwargs .pop ("permission" , None ),
@@ -168,17 +164,13 @@ class TableSharedAccessSignature(SharedAccessSignature):
168
164
generate_*_shared_access_signature method directly.
169
165
"""
170
166
171
- def __init__ (self , account_name , account_key ):
167
+ def __init__ (self , credential ):
172
168
"""
173
- :param account_name:
174
- The storage account name used to generate the shared access signatures.
175
- :type account_name: str
176
- :param account_key:
177
- The access key to generate the shares access signatures.
178
- :type account_key: str
169
+ :param credential: The credential used for authenticating requests
170
+ :type credential: :class:`~azure.core.credentials.NamedKeyCredential`
179
171
"""
180
172
super (TableSharedAccessSignature , self ).__init__ (
181
- account_name , account_key , x_ms_version = X_MS_VERSION
173
+ credential , x_ms_version = X_MS_VERSION
182
174
)
183
175
184
176
def generate_table (
0 commit comments