-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[KeyVault] Add --no-wait for command az keyvault security-domain download and --target-operation for command az keyvault security-domain wait
#17263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
435a1ad
Merge branch 'release' into dev
houk-ms f0be844
Merge remote-tracking branch 'origin/dev' into dev
houk-ms 0b9d92c
Merge remote-tracking branch 'origin/dev' into dev
houk-ms 5b775d0
Merge remote-tracking branch 'origin/dev' into dev
houk-ms 22fffd0
Merge remote-tracking branch 'origin/dev' into dev
houk-ms c1205ff
Merge remote-tracking branch 'origin/dev' into dev
houk-ms 000d07e
Merge remote-tracking branch 'origin/dev' into dev
houk-ms 96553de
Merge remote-tracking branch 'origin/dev' into dev
houk-ms f9ad8d5
Merge remote-tracking branch 'origin/dev' into dev
houk-ms c17cd75
security-domain sync to async support
houk-ms 2fce0ba
security-domain download async
houk-ms 8a042c1
fix polling bug
houk-ms 0d9c337
raise error when file operation fails
houk-ms d6e55fa
Merge remote-tracking branch 'origin/dev' into security-domain
houk-ms f186f43
support --id to specify url and fix test
houk-ms 15cd31b
wait before polling
houk-ms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| # pylint: skip-file | ||
| # flake8: noqa | ||
| import json | ||
| import time | ||
|
|
||
| from msrest.service_client import SDKClient | ||
| from msrest import Serializer, Deserializer | ||
|
|
@@ -114,20 +115,101 @@ def download(self, vault_base_url, certificates, custom_headers=None, raw=False, | |
| response = self._client.send( | ||
| request, header_parameters, body_content, stream=False, **operation_config) | ||
|
|
||
| # v7.2-preview and v7.2 will introduce a breaking change to make the operation change from Sync to Async | ||
| # 200: for compatability of response before the change (Sync Operation) | ||
| # 202: for the support of new response after the change (Async Operation) | ||
| if response.status_code not in [200, 202]: | ||
| raise models.KeyVaultErrorException(self._deserialize, response) | ||
|
|
||
| deserialized = None | ||
|
|
||
| # for both old response, and new response | ||
| deserialized = self._deserialize('SecurityDomainObject', response) | ||
|
|
||
| # for new response | ||
| if response.status_code == 202: | ||
| polling_interval = int(response.headers.get('retry-after', 1)) | ||
| status = 'InProgress' | ||
|
|
||
| # keep polling if status is 'InProgress' | ||
| while status == 'InProgress': | ||
| # flush | ||
| time.sleep(0.5*polling_interval) | ||
| print('\r - Running .. ', end='') | ||
| time.sleep(0.5*polling_interval) | ||
| print('\r ', end='') | ||
|
|
||
| # polling | ||
| operation_status = self.download_pending( | ||
| vault_base_url, | ||
| custom_headers=custom_headers, | ||
| raw=False, | ||
| **operation_config | ||
| ) | ||
| status = operation_status.status | ||
|
|
||
| # Response won't be returned if the deployment fails | ||
| if status != 'Success': | ||
| raise models.KeyVaultErrorException(self._deserialize, response) | ||
|
|
||
| if raw: | ||
| client_raw_response = ClientRawResponse(deserialized, response) | ||
| return client_raw_response | ||
|
|
||
| return deserialized | ||
| download.metadata = {'url': '/securitydomain/download'} | ||
|
|
||
| def download_pending(self, vault_base_url, custom_headers=None, raw=False, **operation_config): | ||
| """Get Security domain upload operation status. | ||
| :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. | ||
| :type vault_base_url: str | ||
| :keyword callable cls: A custom type or function that will be passed the direct response | ||
| :return: SecurityDomainOperationStatus, or the result of cls(response) | ||
| :rtype: ~key_vault_client.models.SecurityDomainOperationStatus | ||
| :raises: ~azure.core.exceptions.HttpResponseError | ||
| """ | ||
|
|
||
| # Construct URL | ||
| url = self.upload_pending.metadata['url'] | ||
| path_format_arguments = { | ||
| 'vaultBaseUrl': self._serialize.url("vault_base_url", vault_base_url, 'str', skip_quote=True) | ||
| } | ||
| url = self._client.format_url(url, **path_format_arguments) | ||
|
|
||
| # Construct parameters | ||
| query_parameters = {} | ||
| query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') | ||
|
|
||
| # Construct headers | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [thumb up]! |
||
| header_parameters = {} | ||
| header_parameters['Content-Type'] = 'application/json; charset=utf-8' | ||
| if self.config.generate_client_request_id: | ||
| header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) | ||
| if custom_headers: | ||
| header_parameters.update(custom_headers) | ||
| if self.config.accept_language is not None: | ||
| header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", | ||
| self.config.accept_language, 'str') | ||
|
|
||
| # Construct and send request | ||
| request = self._client.get(url, query_parameters) | ||
| response = self._client.send( | ||
| request, header_parameters, stream=False, **operation_config) | ||
|
|
||
| if response.status_code not in [200]: | ||
| raise models.KeyVaultErrorException(self._deserialize, response) | ||
|
|
||
| deserialized = None | ||
|
|
||
| if response.status_code == 200: | ||
| deserialized = self._deserialize('SecurityDomainObject', response) | ||
| deserialized = self._deserialize('SecurityDomainOperationStatus', response) | ||
|
|
||
| if raw: | ||
| client_raw_response = ClientRawResponse(deserialized, response) | ||
| return client_raw_response | ||
|
|
||
| return deserialized | ||
| download.metadata = {'url': '/securitydomain/download'} | ||
| download_pending.metadata = {'url': '/securitydomain/download/pending'} | ||
|
|
||
| def transfer_key(self, vault_base_url, custom_headers=None, raw=False, **operation_config): | ||
| """Retrieve security domain transfer key. | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set a timeout for Inprogress polling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does that mean CLI user will wait till operation finished. For aync operation, shouldn't the polling be done in --wait ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right. Implementation is updated now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reused the existing codes which supports
max_retrynow, although i think we should not set it