Skip to content

Commit 2fb4547

Browse files
authored
[Key Vault] Respond to review feedback for 7.6 support packages (#41541)
1 parent d4c68ac commit 2fb4547

File tree

18 files changed

+116
-210
lines changed

18 files changed

+116
-210
lines changed

sdk/keyvault/azure-keyvault-administration/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
- Key Vault API version `7.6` is now the default
1616
- (From 4.6.0b1) Updated minimum `typing-extensions` version to 4.6.0
1717

18+
### Breaking Changes
19+
20+
> These changes do not impact the API of stable versions such as 4.5.0. Only code written against a beta version such as 4.6.0b1 may be affected.
21+
22+
- Changed the return types of `KeyVaultBackupClient.begin_pre_backup` and `KeyVaultBackupClient.begin_pre_restore` to be
23+
pollers returning `None`
24+
1825
## 4.6.0b1 (2025-03-20)
1926

2027
### Features Added

sdk/keyvault/azure-keyvault-administration/README.md

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ create, manage, and deploy public and private SSL/TLS certificates
2424
## _Disclaimer_
2525

2626
_Azure SDK Python packages support for Python 2.7 has ended 01 January 2022. For more information and questions, please refer to https://github.com/Azure/azure-sdk-for-python/issues/20691._
27-
_Python 3.8 or later is required to use this package. For more details, please refer to [Azure SDK for Python version support policy](https://github.com/Azure/azure-sdk-for-python/wiki/Azure-SDKs-Python-version-support-policy)._
27+
_Python 3.9 or later is required to use this package. For more details, please refer to [Azure SDK for Python version support policy](https://github.com/Azure/azure-sdk-for-python/wiki/Azure-SDKs-Python-version-support-policy)._
2828

2929
## Getting started
3030
### Install packages
@@ -38,7 +38,7 @@ authentication as demonstrated below.
3838

3939
### Prerequisites
4040
* An [Azure subscription][azure_sub]
41-
* Python 3.8 or later
41+
* Python 3.9 or later
4242
* An existing [Key Vault Managed HSM][managed_hsm]. If you need to create one, you can do so using the Azure CLI by following the steps in [this document][managed_hsm_cli].
4343

4444
### Authenticate the client
@@ -303,17 +303,16 @@ to the library's [credential documentation][sas_docs]. Alternatively, it is poss
303303
```python
304304
CONTAINER_URL = os.environ["CONTAINER_URL"]
305305

306-
check_result: KeyVaultBackupOperation = client.begin_pre_backup(CONTAINER_URL, use_managed_identity=True).result()
306+
try:
307+
client.begin_pre_backup(CONTAINER_URL, use_managed_identity=True).wait()
308+
except HttpResponseError as e:
309+
print(f"A backup cannot be performed: {str(e)}")
307310

308-
if check_result.error:
309-
print(f"Reason the backup cannot be performed: {check_result.error}")
310-
else:
311-
print("A full key backup can be successfully performed.")
311+
print("A full key backup can be successfully performed.")
312312
```
313313

314-
Note that the `begin_pre_backup` method returns a poller. Calling `result()` on this poller returns a
315-
`KeyVaultBackupOperation` -- this object will have a string `error` attribute if the check failed, and otherwise the
316-
check will have succeeded.
314+
Note that the `begin_pre_backup` method returns a poller. Calling `wait()` on this poller waits for the check to
315+
complete. An error will raise if the check failed; otherwise the check will have succeeded.
317316

318317
### Perform a full key backup
319318
To actually perform the key backup, you can use `KeyVaultBackupClient.begin_backup`.
@@ -350,19 +349,16 @@ to the library's [credential documentation][sas_docs]. Alternatively, it is poss
350349
[generate a SAS token in Storage Explorer][storage_explorer].
351350

352351
```python
353-
check_result: KeyVaultRestoreOperation = client.begin_pre_restore(
354-
backup_result.folder_url, use_managed_identity=True
355-
).result()
356-
357-
if check_result.error:
358-
print(f"Reason the backup cannot be performed: {check_result.error}")
359-
else:
360-
print("A full key restore can be successfully performed.")
352+
try:
353+
client.begin_pre_restore(backup_result.folder_url, use_managed_identity=True).wait()
354+
except HttpResponseError as e:
355+
print(f"A full restore cannot be performed: {str(e)}")
356+
357+
print("A full key restore can be successfully performed.")
361358
```
362359

363-
Note that the `begin_pre_restore` method returns a poller. Calling `result()` on this poller returns a
364-
`KeyVaultRestoreOperation` -- this object will have a string `error` attribute if the check failed, and otherwise the
365-
`error` will be None if the check succeeded.
360+
Note that the `begin_pre_restore` method returns a poller. Calling `wait()` on this poller waits for the check to
361+
complete. An error will raise if the check failed; otherwise the check will have succeeded.
366362

367363
### Perform a full key restore
368364
To actually restore your entire collection of keys, you can use `KeyVaultBackupClient.begin_restore`.

sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
from ._enums import KeyVaultRoleScope, KeyVaultDataAction, KeyVaultSettingType
88
from ._internal.client_base import ApiVersion
99
from ._models import (
10-
KeyVaultBackupOperation,
1110
KeyVaultBackupResult,
1211
KeyVaultPermission,
13-
KeyVaultRestoreOperation,
1412
KeyVaultRoleAssignment,
1513
KeyVaultRoleAssignmentProperties,
1614
KeyVaultRoleDefinition,
@@ -21,13 +19,11 @@
2119

2220
__all__ = [
2321
"ApiVersion",
24-
"KeyVaultBackupOperation",
2522
"KeyVaultBackupResult",
2623
"KeyVaultAccessControlClient",
2724
"KeyVaultBackupClient",
2825
"KeyVaultDataAction",
2926
"KeyVaultPermission",
30-
"KeyVaultRestoreOperation",
3127
"KeyVaultRoleAssignment",
3228
"KeyVaultRoleAssignmentProperties",
3329
"KeyVaultRoleDefinition",

sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_backup_client.py

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from azure.core.tracing.decorator import distributed_trace
1515

1616
from ._generated.models import PreBackupOperationParameters, PreRestoreOperationParameters, SASTokenParameter
17-
from ._models import KeyVaultBackupOperation, KeyVaultBackupResult, KeyVaultRestoreOperation
17+
from ._models import KeyVaultBackupResult
1818
from ._internal import KeyVaultClientBase, parse_folder_url
1919
from ._internal.polling import KeyVaultBackupClientPolling, KeyVaultBackupClientPollingMethod
2020

@@ -250,7 +250,7 @@ def begin_pre_backup(
250250
use_managed_identity: Literal[True],
251251
continuation_token: Optional[str] = None,
252252
**kwargs: Any,
253-
) -> LROPoller[KeyVaultBackupOperation]:
253+
) -> LROPoller[None]:
254254
...
255255

256256
@overload
@@ -261,19 +261,17 @@ def begin_pre_backup(
261261
sas_token: str,
262262
continuation_token: Optional[str] = None,
263263
**kwargs: Any,
264-
) -> LROPoller[KeyVaultBackupOperation]:
264+
) -> LROPoller[None]:
265265
...
266266

267267
@distributed_trace
268268
def begin_pre_backup( # pylint: disable=docstring-keyword-should-match-keyword-only
269269
self, blob_storage_url: str, **kwargs: Any
270-
) -> LROPoller[KeyVaultBackupOperation]:
270+
) -> LROPoller[None]:
271271
"""Initiates a pre-backup check of whether a full Key Vault backup can be performed.
272272
273-
A :class:`KeyVaultBackupOperation` instance will be returned by the poller's `result()` method. If the
274-
pre-backup check is successful, the object will have a string `folder_url` attribute, pointing to the blob
275-
storage container where the backup will be stored. If the check fails, the object will have a string `error`
276-
attribute.
273+
If the pre-backup check fails, calling `wait()` on the returned poller will raise an error. Otherwise, a full
274+
backup can be performed.
277275
278276
:param str blob_storage_url: URL of the blob storage container in which the backup will be stored, for example
279277
https://<account>.blob.core.windows.net/backup.
@@ -286,11 +284,9 @@ def begin_pre_backup( # pylint: disable=docstring-keyword-should-match-keyword-
286284
:paramtype use_managed_identity: bool
287285
:keyword str continuation_token: A continuation token to restart polling from a saved state.
288286
289-
:returns: An :class:`~azure.core.polling.LROPoller` instance. Call `result()` on this object to wait for the
290-
operation to complete and get a :class:`KeyVaultBackupOperation`. If the pre-backup check is successful, the
291-
object will have a string `folder_url` attribute, pointing to the blob storage container where the backup
292-
will be stored. If the check fails, the object will have a string `error` attribute.
293-
:rtype: ~azure.core.polling.LROPoller[~azure.keyvault.administration.KeyVaultBackupOperation]
287+
:returns: An :class:`~azure.core.polling.LROPoller` instance. Call `wait()` on this object to wait for the
288+
operation to complete. If the check fails, an error will be raised.
289+
:rtype: ~azure.core.polling.LROPoller[None]
294290
"""
295291
polling_interval: int = kwargs.pop("_polling_interval", 5)
296292
continuation_token: Optional[str] = kwargs.pop("continuation_token", None)
@@ -306,7 +302,7 @@ def begin_pre_backup( # pylint: disable=docstring-keyword-should-match-keyword-
306302

307303
return self._client.begin_pre_full_backup(
308304
pre_backup_operation_parameters=parameters,
309-
cls=KeyVaultBackupOperation._from_generated, # pylint: disable=protected-access
305+
cls=lambda *_: None, # poller.result() returns None
310306
polling=KeyVaultBackupClientPollingMethod(
311307
lro_algorithms=[KeyVaultBackupClientPolling()], timeout=polling_interval, **kwargs
312308
),
@@ -322,7 +318,7 @@ def begin_pre_restore(
322318
use_managed_identity: Literal[True],
323319
continuation_token: Optional[str] = None,
324320
**kwargs: Any,
325-
) -> LROPoller[KeyVaultRestoreOperation]:
321+
) -> LROPoller[None]:
326322
...
327323

328324
@overload
@@ -333,17 +329,17 @@ def begin_pre_restore(
333329
sas_token: str,
334330
continuation_token: Optional[str] = None,
335331
**kwargs: Any,
336-
) -> LROPoller[KeyVaultRestoreOperation]:
332+
) -> LROPoller[None]:
337333
...
338334

339335
@distributed_trace
340336
def begin_pre_restore( # pylint: disable=docstring-keyword-should-match-keyword-only
341337
self, folder_url: str, **kwargs: Any
342-
) -> LROPoller[KeyVaultRestoreOperation]:
338+
) -> LROPoller[None]:
343339
"""Initiates a pre-restore check of whether a full Key Vault restore can be performed.
344340
345-
A :class:`KeyVaultRestoreOperation` instance will be returned by the poller's `result()` method. If the
346-
pre-restore check fails, the object will have a string `error` attribute.
341+
If the pre-restore check fails, calling `wait()` on the returned poller will raise an error. Otherwise, a full
342+
restore can be performed.
347343
348344
:param str folder_url: URL of the blob holding the backup. This would be the `folder_url` of a
349345
:class:`KeyVaultBackupResult` returned by :func:`begin_backup`, for example
@@ -357,10 +353,9 @@ def begin_pre_restore( # pylint: disable=docstring-keyword-should-match-keyword
357353
:paramtype use_managed_identity: bool
358354
:keyword str continuation_token: A continuation token to restart polling from a saved state.
359355
360-
:returns: An :class:`~azure.core.polling.LROPoller` instance. Call `result()` on this object to wait for the
361-
operation to complete and get a :class:`KeyVaultRestoreOperation`. If the pre-restore check fails, the
362-
object will have a string `error` attribute.
363-
:rtype: ~azure.core.polling.LROPoller[~azure.keyvault.administration.KeyVaultRestoreOperation]
356+
:returns: An :class:`~azure.core.polling.LROPoller` instance. Call `wait()` on this object to wait for the
357+
operation to complete. If the check fails, an error will be raised.
358+
:rtype: ~azure.core.polling.LROPoller[None]
364359
"""
365360
polling_interval: int = kwargs.pop("_polling_interval", 5)
366361
continuation_token: Optional[str] = kwargs.pop("continuation_token", None)
@@ -380,7 +375,7 @@ def begin_pre_restore( # pylint: disable=docstring-keyword-should-match-keyword
380375

381376
return self._client.begin_pre_full_restore_operation(
382377
pre_restore_operation_parameters=parameters,
383-
cls=KeyVaultRestoreOperation._from_generated, # pylint: disable=protected-access
378+
cls=lambda *_: None, # poller.result() returns None
384379
polling=KeyVaultBackupClientPollingMethod(
385380
lro_algorithms=[KeyVaultBackupClientPolling()], timeout=polling_interval, **kwargs
386381
),

sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_models.py

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5-
from datetime import datetime
65
from typing import Any, Dict, Optional, Union
76

87
from azure.core.rest import HttpResponse
@@ -11,7 +10,6 @@
1110
from ._generated.models import (
1211
FullBackupOperation,
1312
Permission,
14-
RestoreOperation,
1513
RoleAssignment,
1614
RoleAssignmentProperties,
1715
RoleAssignmentPropertiesWithScope,
@@ -155,50 +153,6 @@ def _from_generated(cls, definition: RoleDefinition) -> "KeyVaultRoleDefinition"
155153
)
156154

157155

158-
class KeyVaultBackupOperation:
159-
"""The details of a Key Vault backup operation.
160-
161-
:ivar str status: The status of the backup operation.
162-
:ivar str status_details: The status details of the backup operation.
163-
:ivar str error: The error details of the backup operation.
164-
:ivar start_time: The start time of the backup operation in UTC.
165-
:vartype start_time: ~datetime.datetime or None
166-
:ivar end_time: The end time of the backup operation in UTC.
167-
:vartype end_time: ~datetime.datetime or None
168-
:ivar str job_id: The job identifier of the backup operation.
169-
:ivar str folder_url: The URL of the Azure Blob Storage container where the backup is stored.
170-
"""
171-
172-
# pylint:disable=unused-argument
173-
174-
def __init__(self, **kwargs: Any) -> None:
175-
self.status: Optional[str] = kwargs.get("status")
176-
self.status_details: Optional[str] = kwargs.get("status_details")
177-
self.error: Optional[str] = kwargs.get("error")
178-
self.start_time: Optional[datetime] = kwargs.get("start_time")
179-
self.end_time: Optional[datetime] = kwargs.get("end_time")
180-
self.job_id: Optional[str] = kwargs.get("job_id")
181-
self.folder_url: Optional[str] = kwargs.get("folder_url")
182-
183-
@classmethod
184-
def _from_generated(
185-
cls, response: HttpResponse, deserialized_operation: FullBackupOperation, response_headers: Dict
186-
) -> "KeyVaultBackupOperation":
187-
error = deserialized_operation.error
188-
error_message: Optional[str] = None
189-
if error and error.message:
190-
error_message = f"{error.code}: {error.message}"
191-
return cls(
192-
status=deserialized_operation.status,
193-
status_details=deserialized_operation.status_details,
194-
error=error_message,
195-
start_time=deserialized_operation.start_time,
196-
end_time=deserialized_operation.end_time,
197-
job_id=deserialized_operation.job_id,
198-
folder_url=deserialized_operation.azure_storage_blob_container_uri,
199-
)
200-
201-
202156
class KeyVaultBackupResult(object):
203157
"""A Key Vault full backup operation result
204158
@@ -217,47 +171,6 @@ def _from_generated(
217171
return cls(folder_url=deserialized_operation.azure_storage_blob_container_uri)
218172

219173

220-
class KeyVaultRestoreOperation:
221-
"""The details of a Key Vault restore operation.
222-
223-
:ivar str status: The status of the restore operation.
224-
:ivar str status_details: The status details of the restore operation.
225-
:ivar str error: The error details of the restore operation.
226-
:ivar start_time: The start time of the restore operation in UTC.
227-
:vartype start_time: ~datetime.datetime or None
228-
:ivar end_time: The end time of the restore operation in UTC.
229-
:vartype end_time: ~datetime.datetime or None
230-
:ivar str job_id: The job identifier of the restore operation.
231-
"""
232-
233-
# pylint:disable=unused-argument
234-
235-
def __init__(self, **kwargs: Any) -> None:
236-
self.status: Optional[str] = kwargs.get("status")
237-
self.status_details: Optional[str] = kwargs.get("status_details")
238-
self.error: Optional[str] = kwargs.get("error")
239-
self.start_time: Optional[datetime] = kwargs.get("start_time")
240-
self.end_time: Optional[datetime] = kwargs.get("end_time")
241-
self.job_id: Optional[str] = kwargs.get("job_id")
242-
243-
@classmethod
244-
def _from_generated(
245-
cls, response: HttpResponse, deserialized_operation: RestoreOperation, response_headers: Dict
246-
) -> "KeyVaultRestoreOperation":
247-
error = deserialized_operation.error
248-
error_message: Optional[str] = None
249-
if error and error.message:
250-
error_message = f"{error.code}: {error.message}"
251-
return cls(
252-
status=deserialized_operation.status,
253-
status_details=deserialized_operation.status_details,
254-
error=error_message,
255-
start_time=deserialized_operation.start_time,
256-
end_time=deserialized_operation.end_time,
257-
job_id=deserialized_operation.job_id,
258-
)
259-
260-
261174
class KeyVaultSetting(object):
262175
"""A Key Vault setting.
263176

0 commit comments

Comments
 (0)