Skip to content
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

{Keyvault} Fix test failure in az keyvault certificate create #27016

Merged
merged 5 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 7 additions & 29 deletions src/azure-cli/azure/cli/command_modules/keyvault/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from azure.cli.command_modules.keyvault.security_domain.shared_secret import SharedSecret
from azure.cli.command_modules.keyvault.security_domain.sp800_108 import KDF
from azure.cli.command_modules.keyvault.security_domain.utils import Utils
from azure.cli.core import telemetry
from azure.cli.core.azclierror import InvalidArgumentValueError, RequiredArgumentMissingError,\
MutuallyExclusiveArgumentError
from azure.cli.core.profiles import ResourceType, AZURE_API_PROFILES, SDKProfile
Expand Down Expand Up @@ -1548,38 +1547,17 @@ def create_certificate(client, certificate_name, policy,
disabled=False, tags=None):
logger.info("Starting long-running operation 'keyvault certificate create'")

client.begin_create_certificate(
certificate_name=certificate_name, policy=policy, enabled=not disabled, tags=tags)

poller = client.begin_create_certificate(certificate_name=certificate_name,
policy=policy,
enabled=not disabled,
tags=tags)
if policy.issuer_name.lower() == 'unknown':
# return immediately for a pending certificate
return client.get_certificate_operation(certificate_name)

# otherwise loop until the certificate creation is complete
while True:
check = client.get_certificate_operation(certificate_name)
if check.status != 'inProgress':
logger.info(
"Long-running operation 'keyvault certificate create' finished with result %s.",
check)
return check
try:
time.sleep(10)
except KeyboardInterrupt:
logger.info("Long-running operation wait cancelled.")
raise
except Exception as client_exception:
telemetry.set_exception(exception=client_exception, fault_type='cert-create-error',
summary='Unexpected client exception during cert creation')
message = getattr(client_exception, 'message', client_exception)

try:
ex_message = json.loads(client_exception.response.text) # pylint: disable=no-member
message = str(message) + ' ' + ex_message['error']['details'][0]['message']
except: # pylint: disable=bare-except
pass

raise CLIError('{}'.format(message))
# otherwise polling until the certificate creation is complete
poller.result()
return client.get_certificate_operation(certificate_name)


def _asn1_to_iso8601(asn1_date):
Expand Down
Loading