/// <summary> /// Initializes a new instance of the <see cref="CertificateOperation"/> class. /// You must call <see cref="UpdateStatus(CancellationToken)"/> or <see cref="UpdateStatusAsync(CancellationToken)"/> before you can get the <see cref="Value"/>. /// </summary> /// <param name="client">A <see cref="CertificateClient"/> for the Key Vault where the operation was started.</param> /// <param name="name">The name of the certificate being created.</param> public CertificateOperation(CertificateClient client, string name) { Argument.AssertNotNull(client, nameof(client)); Argument.AssertNotNullOrEmpty(name, nameof(name)); Properties = new CertificateOperationProperties(client.VaultUri, name); Id = Properties.Id.ToString(); _client = client; }
/// <summary> /// Updates the status of the certificate operation /// </summary> /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> /// <returns>The raw response of the poll operation</returns> public override async ValueTask <Response> UpdateStatusAsync(CancellationToken cancellationToken = default) { if (!_completed) { Response <CertificateOperationProperties> pollResponse = await _client.GetPendingCertificateAsync(Properties.Name, cancellationToken).ConfigureAwait(false); SetRawResponse(pollResponse.GetRawResponse()); Properties = pollResponse; } if (Properties.Status == "completed") { Response <CertificateWithPolicy> getResponse = await _client.GetCertificateWithPolicyAsync(Properties.Name, cancellationToken).ConfigureAwait(false); SetRawResponse(getResponse.GetRawResponse()); Value = getResponse.Value; _completed = true; _hasValue = true; } else if (Properties.Status == "cancelled") { _completed = true; throw new OperationCanceledException("The certificate opertation has been canceled"); } else if (Properties.Error != null) { _completed = true; throw new InvalidOperationException("The certificate operation failed, see Properties.Error for more details"); } return(GetRawResponse()); }
/// <summary> /// Updates the status of the certificate operation /// </summary> /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> /// <returns>The raw response of the poll operation</returns> public override Response UpdateStatus(CancellationToken cancellationToken = default) { if (!_completed) { Response <CertificateOperationProperties> pollResponse = _client.GetPendingCertificate(Properties.Name, cancellationToken); SetRawResponse(pollResponse.GetRawResponse()); Properties = pollResponse; } if (Properties.Status == "completed") { Response <CertificateWithPolicy> getResponse = _client.GetCertificateWithPolicy(Properties.Name, cancellationToken); SetRawResponse(getResponse.GetRawResponse()); Value = getResponse.Value; _completed = true; _hasValue = true; } else if (Properties.Status == "cancelled") { _completed = true; throw new OperationCanceledException("The certificate opertation has been canceled"); } else if (Properties.Error != null) { _completed = true; throw new InvalidOperationException("The certificate operation failed"); } return(GetRawResponse()); }
public void EndUpdateStatus(CertificateOperationProperties properties) => EndUpdateStatus(properties?.Id.AbsoluteUri, properties?.Status, properties?.Error?.Message);
public void EndUpdateStatus(CertificateOperationProperties properties) => EndUpdateStatus(properties?.Id.ToString(), properties?.Status, properties?.Error?.Message);