Skip to content

Commit 996c680

Browse files
authored
[Tables] Make credential parameter keyword-only (Azure#19117)
* Make credential keyword-only * Updated tests
1 parent 0e79a8c commit 996c680

29 files changed

+142
-140
lines changed

sdk/tables/azure-data-tables/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Storage service configuration models have now been prefixed with `Table`, including
99
`TableAccessPolicy`, `TableMetrics`, `TableRetentionPolicy`, `TableCorsRule`
1010
* All parameters for `TableServiceClient.set_service_properties` are now keyword-only.
11+
* The `credential` parameter for all Clients is now keyword-only.
1112

1213
**Fixes**
1314
* Fixed support for Cosmos emulator endpoint, via URL/credential or connection string.

sdk/tables/azure-data-tables/azure/data/tables/_base_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# license information.
55
# --------------------------------------------------------------------------
66

7-
from typing import Dict, Optional, Any, List, Mapping, Union
7+
from typing import Dict, Optional, Any, List, Mapping
88
from uuid import uuid4
99
try:
1010
from urllib.parse import parse_qs, quote, urlparse
@@ -200,13 +200,13 @@ def api_version(self):
200200

201201
class TablesBaseClient(AccountHostsMixin):
202202

203-
def __init__(
203+
def __init__( # pylint: disable=missing-client-constructor-parameter-credential
204204
self,
205205
endpoint, # type: str
206-
credential=None, # type: Union[AzureNamedKeyCredential, AzureSasCredential]
207206
**kwargs # type: Any
208207
):
209208
# type: (...) -> None
209+
credential = kwargs.pop('credential', None)
210210
super(TablesBaseClient, self).__init__(endpoint, credential=credential, **kwargs)
211211
self._client = AzureTable(
212212
self.url,

sdk/tables/azure-data-tables/azure/data/tables/_table_client.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,22 @@ class TableClient(TablesBaseClient):
5959
:ivar str url: The full URL to the Tables account.
6060
"""
6161

62-
def __init__(
62+
def __init__( # pylint: disable=missing-client-constructor-parameter-credential
6363
self,
6464
endpoint, # type: str
6565
table_name, # type: str
66-
credential=None, # type: Union[AzureNamedKeyCredential, AzureSasCredential]
6766
**kwargs # type: Any
6867
):
6968
# type: (...) -> None
7069
"""Create TableClient from a Credential.
7170
7271
:param str endpoint: A URL to an Azure Tables account.
7372
:param str table_name: The table name.
74-
:param credential:
73+
:keyword credential:
7574
The credentials with which to authenticate. This is optional if the
76-
account URL already has a SAS token, or the connection string already has shared
77-
access key values. The value can be a SAS token string or an account shared access
78-
key.
79-
:type credential:
75+
account URL already has a SAS token. The value can be one of AzureNamedKeyCredential
76+
or AzureSasCredential from azure-core.
77+
:paramtype credential:
8078
:class:`~azure.core.credentials.AzureNamedKeyCredential` or
8179
:class:`~azure.core.credentials.AzureSasCredential`
8280
:returns: None
@@ -85,7 +83,7 @@ def __init__(
8583
raise ValueError("Please specify a table name.")
8684
_validate_table_name(table_name)
8785
self.table_name = table_name
88-
super(TableClient, self).__init__(endpoint, credential=credential, **kwargs)
86+
super(TableClient, self).__init__(endpoint, **kwargs)
8987

9088
def _format_url(self, hostname):
9189
"""Format the endpoint URL according to the current location
@@ -123,16 +121,18 @@ def from_connection_string(
123121
return cls(endpoint, table_name=table_name, credential=credential, **kwargs)
124122

125123
@classmethod
126-
def from_table_url(cls, table_url, credential=None, **kwargs):
127-
# type: (str, Optional[Any], Any) -> TableClient
124+
def from_table_url(cls, table_url, **kwargs):
125+
# type: (str, Any) -> TableClient
128126
"""A client to interact with a specific Table.
129127
130128
:param str table_url: The full URI to the table, including SAS token if used.
131-
:param credential:
129+
:keyword credential:
132130
The credentials with which to authenticate. This is optional if the
133-
account URL already has a SAS token. The value can be a SAS token string, an account
134-
shared access key.
135-
:type credential: str
131+
account URL already has a SAS token. The value can be one of AzureNamedKeyCredential
132+
or AzureSasCredential from azure-core.
133+
:paramtype credential:
134+
:class:`~azure.core.credentials.AzureNamedKeyCredential` or
135+
:class:`~azure.core.credentials.AzureSasCredential`
136136
:returns: A table client.
137137
:rtype: :class:`~azure.data.tables.TableClient`
138138
"""
@@ -163,7 +163,7 @@ def from_table_url(cls, table_url, credential=None, **kwargs):
163163
raise ValueError(
164164
"Invalid URL. Please provide a URL with a valid table name"
165165
)
166-
return cls(endpoint, table_name=table_name, credential=credential, **kwargs)
166+
return cls(endpoint, table_name=table_name, **kwargs)
167167

168168
@distributed_trace
169169
def get_table_access_policy(

sdk/tables/azure-data-tables/azure/data/tables/_table_service_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ class TableServiceClient(TablesBaseClient):
4242
The URL to the table service endpoint. Any other entities included
4343
in the URL path (e.g. table) will be discarded. This URL can be optionally
4444
authenticated with a SAS token.
45-
:param credential:
45+
:keyword credential:
4646
The credentials with which to authenticate. This is optional if the
4747
account URL already has a SAS token. The value can be one of AzureNamedKeyCredential
4848
or AzureSasCredential from azure-core.
49-
:type credential:
49+
:paramtype credential:
5050
:class:`~azure.core.credentials.AzureNamedKeyCredential` or
5151
:class:`~azure.core.credentials.AzureSasCredential`
5252
:keyword str api_version:

sdk/tables/azure-data-tables/azure/data/tables/aio/_base_client_async.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@
3838

3939
class AsyncTablesBaseClient(AccountHostsMixin):
4040

41-
def __init__(
41+
def __init__( # pylint: disable=missing-client-constructor-parameter-credential
4242
self,
4343
endpoint: str,
44+
*,
4445
credential: Optional[Union[AzureSasCredential, AzureNamedKeyCredential]] = None,
4546
**kwargs: Any
4647
) -> None:

sdk/tables/azure-data-tables/azure/data/tables/aio/_table_client_async.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,23 @@ class TableClient(AsyncTablesBaseClient):
4747
:ivar str url: The full URL to the Tables account.
4848
"""
4949

50-
def __init__(
50+
def __init__( # pylint: disable=missing-client-constructor-parameter-credential
5151
self,
5252
endpoint: str,
5353
table_name: str,
54+
*,
5455
credential: Optional[Union[AzureSasCredential, AzureNamedKeyCredential]] = None,
5556
**kwargs
5657
) -> None:
5758
"""Create TableClient from a Credential.
5859
5960
:param str endpoint: A URL to an Azure Tables account.
6061
:param str table_name: The table name.
61-
:param credential:
62+
:keyword credential:
6263
The credentials with which to authenticate. This is optional if the
63-
account URL already has a SAS token, or the connection string already has shared
64-
access key values. The value can be a SAS token string or an account shared access
65-
key.
66-
:type credential:
64+
account URL already has a SAS token. The value can be one of AzureNamedKeyCredential
65+
or AzureSasCredential from azure-core.
66+
:paramtype credential:
6767
:class:`~azure.core.credentials.AzureNamedKeyCredential` or
6868
:class:`~azure.core.credentials.AzureSasCredential`
6969
@@ -113,17 +113,16 @@ def from_connection_string(
113113
def from_table_url(
114114
cls,
115115
table_url: str,
116-
credential: Optional[Union[AzureSasCredential, AzureNamedKeyCredential]] = None,
117116
**kwargs
118117
) -> 'TableClient':
119118
"""A client to interact with a specific Table.
120119
121120
:param str table_url: The full URI to the table, including SAS token if used.
122-
:param credential:
121+
:keyword credential:
123122
The credentials with which to authenticate. This is optional if the
124-
account URL already has a SAS token. The value can be a SAS token string, an account
125-
shared access key.
126-
:type credential:
123+
table URL already has a SAS token. The value can be one of AzureNamedKeyCredential
124+
or AzureSasCredential from azure-core.
125+
:paramtype credential:
127126
:class:`~azure.core.credentials.AzureNamedKeyCredential` or
128127
:class:`~azure.core.credentials.AzureSasCredential`
129128
:returns: A table client.
@@ -156,7 +155,7 @@ def from_table_url(
156155
raise ValueError(
157156
"Invalid URL. Please provide a URL with a valid table name"
158157
)
159-
return cls(endpoint, table_name=table_name, credential=credential, **kwargs)
158+
return cls(endpoint, table_name=table_name, **kwargs)
160159

161160
@distributed_trace_async
162161
async def get_table_access_policy(self, **kwargs) -> Mapping[str, TableAccessPolicy]:

sdk/tables/azure-data-tables/azure/data/tables/aio/_table_service_client_async.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ class TableServiceClient(AsyncTablesBaseClient):
4545
The URL to the table service endpoint. Any other entities included
4646
in the URL path (e.g. table) will be discarded. This URL can be optionally
4747
authenticated with a SAS token.
48-
:param str credential:
48+
:keyword credential:
4949
The credentials with which to authenticate. This is optional if the
50-
account URL already has a SAS token. The value can be a SAS token string, an account
51-
shared access key.
50+
account URL already has a SAS token. The value can be one of AzureNamedKeyCredential
51+
or AzureSasCredential from azure-core.
52+
:paramtype credential:
53+
:class:`~azure.core.credentials.AzureNamedKeyCredential` or
54+
:class:`~azure.core.credentials.AzureSasCredential`
5255
:keyword str api_version:
5356
The Storage API version to use for requests. Default value is '2019-02-02'.
5457
Setting to an older version may result in reduced feature compatibility.

sdk/tables/azure-data-tables/samples/async_samples/sample_insert_delete_entities_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async def delete_entity(self):
6565
from azure.core.credentials import AzureNamedKeyCredential
6666

6767
credential = AzureNamedKeyCredential(self.account_name, self.access_key)
68-
table_client = TableClient(endpoint=self.endpoint, credential=credential, table_name=self.table_name)
68+
table_client = TableClient(endpoint=self.endpoint, table_name=self.table_name, credential=credential)
6969

7070
# [START delete_entity]
7171
async with table_client:

sdk/tables/azure-data-tables/samples/sample_insert_delete_entities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def delete_entity(self):
7272
from azure.core.credentials import AzureNamedKeyCredential
7373

7474
credential = AzureNamedKeyCredential(self.account_name, self.access_key)
75-
with TableClient(endpoint=self.endpoint, credential=credential, table_name=self.table_name) as table_client:
75+
with TableClient(endpoint=self.endpoint, table_name=self.table_name, credential=credential) as table_client:
7676

7777
# Create entity to delete (to showcase etag)
7878
try:

sdk/tables/azure-data-tables/tests/_shared/asynctestcase.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ async def _create_table(self, ts, prefix=TEST_TABLE_PREFIX, table_list=None):
5656
return table
5757

5858
async def _delete_all_tables(self, account_name, key):
59-
client = TableServiceClient(self.account_url(account_name, "cosmos"), key)
59+
client = TableServiceClient(self.account_url(account_name, "cosmos"), credential=key)
6060
async for table in client.list_tables():
6161
await client.delete_table(table.name)
6262

@@ -118,7 +118,7 @@ async def _insert_random_entity(self, pk=None, rk=None):
118118

119119
async def _set_up(self, account_name, account_key, url="table"):
120120
account_url = self.account_url(account_name, url)
121-
self.ts = TableServiceClient(account_url, account_key)
121+
self.ts = TableServiceClient(account_url, credential=account_key)
122122
self.table_name = self.get_resource_name("uttable")
123123
self.table = self.ts.get_table_client(self.table_name)
124124
if self.is_live:

0 commit comments

Comments
 (0)