Skip to content

Commit

Permalink
Update swagger reference and fixup changes (Azure#13259)
Browse files Browse the repository at this point in the history
* Update swagger reference and fixup changes

* pr comments

* refactor _value usage in operations

* throw InvalidOperationException on in-progress operation
  • Loading branch information
christothes authored Jul 7, 2020
1 parent 311b330 commit b422813
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,9 @@
<Compile Include="$(MSBuildThisFileDirectory)\..\..\Azure.Security.KeyVault.Shared\src\IJsonSerializable.cs" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(AzureCoreSharedSources)NoBodyResponse{T}.cs" Link="Shared\Core\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)ForwardsClientCallsAttribute.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(AzureCoreSharedSources)Argument.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)ArrayBufferWriter.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)AzureKeyCredentialPolicy.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)AzureResourceProviderNamespaceAttribute.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)ClientDiagnostics.cs" Link="Shared\Core\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)ContentTypeUtilities.cs" Link="Shared\Core\%(RecursiveDir)\%(Filename)%(Extension)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class BackupOperation : Operation<Uri>
private readonly KeyVaultBackupClient _client;
private Response _response;
private FullBackupDetailsInternal _value;
private readonly string _id;

/// <summary>
/// Creates an instance of a BackupOperation from a previously started operation. <see cref="UpdateStatus(CancellationToken)"/>, <see cref="UpdateStatusAsync(CancellationToken)"/>,
Expand All @@ -36,20 +37,20 @@ public BackupOperation(string id, KeyVaultBackupClient client)
Argument.AssertNotNull(client, nameof(client));

_client = client;
_value = new FullBackupDetailsInternal(string.Empty, string.Empty, null, null, null, id, string.Empty);
_id = id;
}

/// <summary>
/// Initializes a new instance of a BackupOperation.
/// </summary>
/// <param name="client">An instance of <see cref="KeyVaultBackupClient" />.</param>
/// <param name="response">The <see cref="ResponseWithHeaders{T, THeaders}" /> returned from <see cref="KeyVaultBackupClient.StartBackup(Uri, string, CancellationToken)"/> or <see cref="KeyVaultBackupClient.StartBackupAsync(Uri, string, CancellationToken)"/>.</param>
internal BackupOperation(KeyVaultBackupClient client, ResponseWithHeaders<FullBackupDetailsInternal, ServiceFullBackupHeaders> response)
internal BackupOperation(KeyVaultBackupClient client, ResponseWithHeaders<ServiceFullBackupHeaders> response)
{
_client = client;
_response = response;
_retryAfterSeconds = response.Headers.RetryAfter;
_value = response.Value ?? throw new InvalidOperationException("The response does not contain a value.");
_id = response.Headers.JobId() ?? throw new InvalidOperationException("The response does not contain an Id");
}

/// <summary>
Expand All @@ -66,21 +67,22 @@ internal BackupOperation(FullBackupDetailsInternal value, Response response, Key

_response = response;
_value = value;
_id = value.JobId;
_client = client;
}

/// <summary>
/// The start time of the restore operation.
/// </summary>
public DateTimeOffset? StartTime => _value.StartTime;
public DateTimeOffset? StartTime => _value?.StartTime;

/// <summary>
/// The end time of the restore operation.
/// </summary>
public DateTimeOffset? EndTime => _value.EndTime;
public DateTimeOffset? EndTime => _value?.EndTime;

/// <inheritdoc/>
public override string Id => _value.JobId;
public override string Id => _id;

/// <summary>
/// Gets the <see cref="FullBackupDetailsInternal"/> of the backup operation.
Expand All @@ -91,6 +93,10 @@ public override Uri Value
get
{
#pragma warning disable CA1065 // Do not raise exceptions in unexpected locations
if (!HasCompleted)
{
throw new InvalidOperationException("The operation is not complete.");
}
if (EndTime.HasValue && _value.Error != null)
{
throw new RequestFailedException($"{_value.Error.Message}\nInnerError: {_value.Error.InnerError}\nCode: {_value.Error.Code}");
Expand All @@ -101,10 +107,10 @@ public override Uri Value
}

/// <inheritdoc/>
public override bool HasCompleted => _value.EndTime.HasValue;
public override bool HasCompleted => EndTime.HasValue;

/// <inheritdoc/>
public override bool HasValue => _response != null && _value.Error == null && HasCompleted;
public override bool HasValue => _response != null && _value?.Error == null && HasCompleted;

/// <inheritdoc/>
public override Response GetRawResponse() => _response;
Expand Down
Loading

0 comments on commit b422813

Please sign in to comment.