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

Update Administration backup LROs to conform to guidelines #17440

Merged
merged 8 commits into from
Jan 5, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ protected KeyVaultAccessControlClient() { }
public KeyVaultAccessControlClient(System.Uri vaultUri, Azure.Core.TokenCredential credential) { }
public KeyVaultAccessControlClient(System.Uri vaultUri, Azure.Core.TokenCredential credential, Azure.Security.KeyVault.Administration.KeyVaultAdministrationClientOptions options) { }
public virtual System.Uri VaultUri { get { throw null; } }
public virtual Azure.Response<Azure.Security.KeyVault.Administration.KeyVaultRoleAssignment> CreateRoleAssignment(Azure.Security.KeyVault.Administration.KeyVaultRoleScope roleScope, string roleDefinitionId, string principalId, System.Guid? name = default(System.Guid?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Security.KeyVault.Administration.KeyVaultRoleAssignment>> CreateRoleAssignmentAsync(Azure.Security.KeyVault.Administration.KeyVaultRoleScope roleScope, string roleDefinitionId, string principalId, System.Guid? name = default(System.Guid?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Security.KeyVault.Administration.KeyVaultRoleAssignment> CreateRoleAssignment(Azure.Security.KeyVault.Administration.KeyVaultRoleScope roleScope, string roleDefinitionId, string principalId, System.Guid? roleAssignmentName = default(System.Guid?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Security.KeyVault.Administration.KeyVaultRoleAssignment>> CreateRoleAssignmentAsync(Azure.Security.KeyVault.Administration.KeyVaultRoleScope roleScope, string roleDefinitionId, string principalId, System.Guid? roleAssignmentName = default(System.Guid?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Security.KeyVault.Administration.KeyVaultRoleAssignment> DeleteRoleAssignment(Azure.Security.KeyVault.Administration.KeyVaultRoleScope roleScope, string roleAssignmentName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Security.KeyVault.Administration.KeyVaultRoleAssignment>> DeleteRoleAssignmentAsync(Azure.Security.KeyVault.Administration.KeyVaultRoleScope roleScope, string roleAssignmentName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Security.KeyVault.Administration.KeyVaultRoleAssignment> GetRoleAssignment(Azure.Security.KeyVault.Administration.KeyVaultRoleScope roleScope, string roleAssignmentName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down Expand Up @@ -74,18 +74,18 @@ public KeyVaultBackupClient(System.Uri vaultUri, Azure.Core.TokenCredential cred
public partial class KeyVaultPermission
{
public KeyVaultPermission() { }
public System.Collections.Generic.IList<string> AllowActions { get { throw null; } }
public System.Collections.Generic.IList<string> AllowDataActions { get { throw null; } }
public System.Collections.Generic.IList<string> DenyActions { get { throw null; } }
public System.Collections.Generic.IList<string> DenyDataActions { get { throw null; } }
public System.Collections.Generic.IList<string> AllowedActions { get { throw null; } }
public System.Collections.Generic.IList<string> AllowedDataActions { get { throw null; } }
public System.Collections.Generic.IList<string> DeniedActions { get { throw null; } }
public System.Collections.Generic.IList<string> DeniedDataActions { get { throw null; } }
}
public partial class KeyVaultRoleAssignment
{
internal KeyVaultRoleAssignment() { }
public string Id { get { throw null; } }
public string Name { get { throw null; } }
public Azure.Security.KeyVault.Administration.KeyVaultRoleAssignmentPropertiesWithScope Properties { get { throw null; } }
public string RoleAssignmentType { get { throw null; } }
public string Type { get { throw null; } }
}
public partial class KeyVaultRoleAssignmentPropertiesWithScope
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Core.Pipeline;
using Azure.Security.KeyVault.Administration.Models;

namespace Azure.Security.KeyVault.Administration
Expand All @@ -17,11 +18,12 @@ public class BackupOperation : Operation<BackupResult>
/// <summary>
/// The number of seconds recommended by the service to delay before checking on completion status.
/// </summary>
private readonly int? _retryAfterSeconds;
internal int? _retryAfterSeconds;
private readonly KeyVaultBackupClient _client;
private Response _response;
private FullBackupDetailsInternal _value;
private readonly string _id;
private RequestFailedException _requestFailedException;

/// <summary>
/// Creates an instance of a BackupOperation from a previously started operation. <see cref="UpdateStatus(CancellationToken)"/>, <see cref="UpdateStatusAsync(CancellationToken)"/>,
Expand Down Expand Up @@ -97,9 +99,9 @@ public override BackupResult Value
{
throw new InvalidOperationException("The operation is not complete.");
}
if (_value != null && _value.EndTime.HasValue && _value.Error != null)
if (_requestFailedException != null)
{
throw new RequestFailedException($"{_value.Error.Message}\nInnerError: {_value.Error.InnerError}\nCode: {_value.Error.Code}");
throw _requestFailedException;
}
#pragma warning restore CA1065 // Do not raise exceptions in unexpected locations
return new BackupResult(new Uri(_value.AzureStorageBlobContainerUri), _value.StartTime.Value, _value.EndTime.Value);
Expand All @@ -116,26 +118,41 @@ public override BackupResult Value
public override Response GetRawResponse() => _response;

/// <inheritdoc/>
public override Response UpdateStatus(CancellationToken cancellationToken = default)
{
if (!HasCompleted)
{
Response<FullBackupDetailsInternal> response = _client.GetBackupDetails(Id, cancellationToken);
_value = response.Value;
_response = response.GetRawResponse();
}

return GetRawResponse();
}
public override Response UpdateStatus(CancellationToken cancellationToken = default) =>
UpdateStatusAsync(false, cancellationToken).EnsureCompleted();

/// <inheritdoc/>
public override async ValueTask<Response> UpdateStatusAsync(CancellationToken cancellationToken = default)
public override async ValueTask<Response> UpdateStatusAsync(CancellationToken cancellationToken = default) =>
await UpdateStatusAsync(true, cancellationToken).ConfigureAwait(false);

private async ValueTask<Response> UpdateStatusAsync(bool async, CancellationToken cancellationToken = default)
{
if (!HasCompleted)
{
Response<FullBackupDetailsInternal> response = await _client.GetBackupDetailsAsync(Id, cancellationToken).ConfigureAwait(false);
_value = response.Value;
_response = response.GetRawResponse();
try
{
Response<FullBackupDetailsInternal> response = async ?
await _client.GetBackupDetailsAsync(Id, cancellationToken).ConfigureAwait(false)
: _client.GetBackupDetails(Id, cancellationToken);

_value = response.Value;
_response = response.GetRawResponse();
}
catch (RequestFailedException ex)
{
_requestFailedException = ex;
throw;
}
catch (Exception ex)
{
_requestFailedException = new RequestFailedException("Unexpected failure", ex);
throw _requestFailedException;
}
if (_value != null && _value.EndTime.HasValue && _value.Error != null)
{
_requestFailedException = new RequestFailedException($"{_value.Error.Message}\nInnerError: {_value.Error.InnerError}\nCode: {_value.Error.Code}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not already have a utility method in Core, perhaps, that would do this consistently?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which part were you thinking should be consistent? The error payload in this case is specific to the service.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatting itself.

throw _requestFailedException;
}
}

return GetRawResponse();
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,12 @@ public virtual AsyncPageable<KeyVaultRoleAssignment> GetRoleAssignmentsAsync(Key
/// <param name="roleScope">The scope of the role assignment to create.</param>
/// <param name="roleDefinitionId">The role definition ID used in the role assignment.</param>
/// <param name="principalId">The principal ID assigned to the role. This maps to the ID inside the Active Directory. It can point to a user, service principal, or security group.</param>
/// <param name="name">Optional name used to create the role assignment. A new <see cref="Guid"/> will be generated if not specified.</param>
/// <param name="roleAssignmentName">Optional name used to create the role assignment. A new <see cref="Guid"/> will be generated if not specified.</param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
/// <exception cref="ArgumentNullException"><paramref name="roleDefinitionId"/> or <paramref name="principalId"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="roleDefinitionId"/> or <paramref name="principalId"/> is empty.</exception>
public virtual Response<KeyVaultRoleAssignment> CreateRoleAssignment(KeyVaultRoleScope roleScope, string roleDefinitionId, string principalId, Guid? name = null, CancellationToken cancellationToken = default)
public virtual Response<KeyVaultRoleAssignment> CreateRoleAssignment(KeyVaultRoleScope roleScope, string roleDefinitionId, string principalId, Guid? roleAssignmentName = null, CancellationToken cancellationToken = default)
{
Argument.AssertNotNullOrEmpty(roleDefinitionId, nameof(roleDefinitionId));
Argument.AssertNotNullOrEmpty(principalId, nameof(principalId));
Expand All @@ -253,7 +253,7 @@ public virtual Response<KeyVaultRoleAssignment> CreateRoleAssignment(KeyVaultRol
scope.Start();
try
{
var _name = (name ?? Guid.NewGuid()).ToString();
var _name = (roleAssignmentName ?? Guid.NewGuid()).ToString();
var properties = new KeyVaultRoleAssignmentProperties(roleDefinitionId, principalId);

return _assignmentsRestClient.Create(VaultUri.AbsoluteUri, roleScope.ToString(), _name, new RoleAssignmentCreateParameters(properties), cancellationToken);
Expand All @@ -271,12 +271,12 @@ public virtual Response<KeyVaultRoleAssignment> CreateRoleAssignment(KeyVaultRol
/// <param name="roleScope">The scope of the role assignment to create.</param>
/// <param name="roleDefinitionId">The role definition ID used in the role assignment.</param>
/// <param name="principalId">The principal ID assigned to the role. This maps to the ID inside the Active Directory. It can point to a user, service principal, or security group.</param>
/// <param name="name">Optional name used to create the role assignment. A new <see cref="Guid"/> will be generated if not specified.</param>
/// <param name="roleAssignmentName">Optional name used to create the role assignment. A new <see cref="Guid"/> will be generated if not specified.</param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
/// <exception cref="ArgumentNullException"><paramref name="roleDefinitionId"/> or <paramref name="principalId"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="roleDefinitionId"/> or <paramref name="principalId"/> is empty.</exception>
public virtual async Task<Response<KeyVaultRoleAssignment>> CreateRoleAssignmentAsync(KeyVaultRoleScope roleScope, string roleDefinitionId, string principalId, Guid? name = default, CancellationToken cancellationToken = default)
public virtual async Task<Response<KeyVaultRoleAssignment>> CreateRoleAssignmentAsync(KeyVaultRoleScope roleScope, string roleDefinitionId, string principalId, Guid? roleAssignmentName = default, CancellationToken cancellationToken = default)
{
Argument.AssertNotNullOrEmpty(roleDefinitionId, nameof(roleDefinitionId));
Argument.AssertNotNullOrEmpty(principalId, nameof(principalId));
Expand All @@ -285,7 +285,7 @@ public virtual async Task<Response<KeyVaultRoleAssignment>> CreateRoleAssignment
scope.Start();
try
{
var _name = (name ?? Guid.NewGuid()).ToString();
var _name = (roleAssignmentName ?? Guid.NewGuid()).ToString();
var properties = new KeyVaultRoleAssignmentProperties(roleDefinitionId, principalId);

return await _assignmentsRestClient.CreateAsync(VaultUri.AbsoluteUri, roleScope.ToString(), _name, new RoleAssignmentCreateParameters(properties), cancellationToken)
Expand Down
Loading