Skip to content

Commit 1a95f19

Browse files
authored
Update Administration backup LROs to conform to guidelines (Azure#17440)
* fixup LROs to conform to guidelines, add tests
1 parent fcc2766 commit 1a95f19

24 files changed

+614
-127
lines changed

sdk/keyvault/Azure.Security.KeyVault.Administration/api/Azure.Security.KeyVault.Administration.netstandard2.0.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ protected KeyVaultAccessControlClient() { }
2828
public KeyVaultAccessControlClient(System.Uri vaultUri, Azure.Core.TokenCredential credential) { }
2929
public KeyVaultAccessControlClient(System.Uri vaultUri, Azure.Core.TokenCredential credential, Azure.Security.KeyVault.Administration.KeyVaultAdministrationClientOptions options) { }
3030
public virtual System.Uri VaultUri { get { throw null; } }
31-
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; }
32-
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; }
31+
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; }
32+
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; }
3333
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; }
3434
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; }
3535
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; }
@@ -74,18 +74,18 @@ public KeyVaultBackupClient(System.Uri vaultUri, Azure.Core.TokenCredential cred
7474
public partial class KeyVaultPermission
7575
{
7676
public KeyVaultPermission() { }
77-
public System.Collections.Generic.IList<string> AllowActions { get { throw null; } }
78-
public System.Collections.Generic.IList<string> AllowDataActions { get { throw null; } }
79-
public System.Collections.Generic.IList<string> DenyActions { get { throw null; } }
80-
public System.Collections.Generic.IList<string> DenyDataActions { get { throw null; } }
77+
public System.Collections.Generic.IList<string> AllowedActions { get { throw null; } }
78+
public System.Collections.Generic.IList<string> AllowedDataActions { get { throw null; } }
79+
public System.Collections.Generic.IList<string> DeniedActions { get { throw null; } }
80+
public System.Collections.Generic.IList<string> DeniedDataActions { get { throw null; } }
8181
}
8282
public partial class KeyVaultRoleAssignment
8383
{
8484
internal KeyVaultRoleAssignment() { }
8585
public string Id { get { throw null; } }
8686
public string Name { get { throw null; } }
8787
public Azure.Security.KeyVault.Administration.KeyVaultRoleAssignmentPropertiesWithScope Properties { get { throw null; } }
88-
public string RoleAssignmentType { get { throw null; } }
88+
public string Type { get { throw null; } }
8989
}
9090
public partial class KeyVaultRoleAssignmentPropertiesWithScope
9191
{

sdk/keyvault/Azure.Security.KeyVault.Administration/src/BackupOperation.cs

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading;
66
using System.Threading.Tasks;
77
using Azure.Core;
8+
using Azure.Core.Pipeline;
89
using Azure.Security.KeyVault.Administration.Models;
910

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

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

118120
/// <inheritdoc/>
119-
public override Response UpdateStatus(CancellationToken cancellationToken = default)
120-
{
121-
if (!HasCompleted)
122-
{
123-
Response<FullBackupDetailsInternal> response = _client.GetBackupDetails(Id, cancellationToken);
124-
_value = response.Value;
125-
_response = response.GetRawResponse();
126-
}
127-
128-
return GetRawResponse();
129-
}
121+
public override Response UpdateStatus(CancellationToken cancellationToken = default) =>
122+
UpdateStatusAsync(false, cancellationToken).EnsureCompleted();
130123

131124
/// <inheritdoc/>
132-
public override async ValueTask<Response> UpdateStatusAsync(CancellationToken cancellationToken = default)
125+
public override async ValueTask<Response> UpdateStatusAsync(CancellationToken cancellationToken = default) =>
126+
await UpdateStatusAsync(true, cancellationToken).ConfigureAwait(false);
127+
128+
private async ValueTask<Response> UpdateStatusAsync(bool async, CancellationToken cancellationToken = default)
133129
{
134130
if (!HasCompleted)
135131
{
136-
Response<FullBackupDetailsInternal> response = await _client.GetBackupDetailsAsync(Id, cancellationToken).ConfigureAwait(false);
137-
_value = response.Value;
138-
_response = response.GetRawResponse();
132+
try
133+
{
134+
Response<FullBackupDetailsInternal> response = async ?
135+
await _client.GetBackupDetailsAsync(Id, cancellationToken).ConfigureAwait(false)
136+
: _client.GetBackupDetails(Id, cancellationToken);
137+
138+
_value = response.Value;
139+
_response = response.GetRawResponse();
140+
}
141+
catch (RequestFailedException ex)
142+
{
143+
_requestFailedException = ex;
144+
throw;
145+
}
146+
catch (Exception ex)
147+
{
148+
_requestFailedException = new RequestFailedException("Unexpected failure", ex);
149+
throw _requestFailedException;
150+
}
151+
if (_value != null && _value.EndTime.HasValue && _value.Error != null)
152+
{
153+
_requestFailedException = new RequestFailedException($"{_value.Error.Message}\nInnerError: {_value.Error.InnerError}\nCode: {_value.Error.Code}");
154+
throw _requestFailedException;
155+
}
139156
}
140157

141158
return GetRawResponse();

sdk/keyvault/Azure.Security.KeyVault.Administration/src/Generated/Models/KeyVaultPermission.Serialization.cs

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/keyvault/Azure.Security.KeyVault.Administration/src/Generated/Models/KeyVaultPermission.cs

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/keyvault/Azure.Security.KeyVault.Administration/src/Generated/Models/KeyVaultRoleAssignment.cs

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/keyvault/Azure.Security.KeyVault.Administration/src/KeyVaultAccessControlClient.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,12 @@ public virtual AsyncPageable<KeyVaultRoleAssignment> GetRoleAssignmentsAsync(Key
239239
/// <param name="roleScope">The scope of the role assignment to create.</param>
240240
/// <param name="roleDefinitionId">The role definition ID used in the role assignment.</param>
241241
/// <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>
242-
/// <param name="name">Optional name used to create the role assignment. A new <see cref="Guid"/> will be generated if not specified.</param>
242+
/// <param name="roleAssignmentName">Optional name used to create the role assignment. A new <see cref="Guid"/> will be generated if not specified.</param>
243243
/// <param name="cancellationToken"> The cancellation token to use. </param>
244244
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
245245
/// <exception cref="ArgumentNullException"><paramref name="roleDefinitionId"/> or <paramref name="principalId"/> is null.</exception>
246246
/// <exception cref="ArgumentException"><paramref name="roleDefinitionId"/> or <paramref name="principalId"/> is empty.</exception>
247-
public virtual Response<KeyVaultRoleAssignment> CreateRoleAssignment(KeyVaultRoleScope roleScope, string roleDefinitionId, string principalId, Guid? name = null, CancellationToken cancellationToken = default)
247+
public virtual Response<KeyVaultRoleAssignment> CreateRoleAssignment(KeyVaultRoleScope roleScope, string roleDefinitionId, string principalId, Guid? roleAssignmentName = null, CancellationToken cancellationToken = default)
248248
{
249249
Argument.AssertNotNullOrEmpty(roleDefinitionId, nameof(roleDefinitionId));
250250
Argument.AssertNotNullOrEmpty(principalId, nameof(principalId));
@@ -253,7 +253,7 @@ public virtual Response<KeyVaultRoleAssignment> CreateRoleAssignment(KeyVaultRol
253253
scope.Start();
254254
try
255255
{
256-
var _name = (name ?? Guid.NewGuid()).ToString();
256+
var _name = (roleAssignmentName ?? Guid.NewGuid()).ToString();
257257
var properties = new KeyVaultRoleAssignmentProperties(roleDefinitionId, principalId);
258258

259259
return _assignmentsRestClient.Create(VaultUri.AbsoluteUri, roleScope.ToString(), _name, new RoleAssignmentCreateParameters(properties), cancellationToken);
@@ -271,12 +271,12 @@ public virtual Response<KeyVaultRoleAssignment> CreateRoleAssignment(KeyVaultRol
271271
/// <param name="roleScope">The scope of the role assignment to create.</param>
272272
/// <param name="roleDefinitionId">The role definition ID used in the role assignment.</param>
273273
/// <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>
274-
/// <param name="name">Optional name used to create the role assignment. A new <see cref="Guid"/> will be generated if not specified.</param>
274+
/// <param name="roleAssignmentName">Optional name used to create the role assignment. A new <see cref="Guid"/> will be generated if not specified.</param>
275275
/// <param name="cancellationToken"> The cancellation token to use. </param>
276276
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
277277
/// <exception cref="ArgumentNullException"><paramref name="roleDefinitionId"/> or <paramref name="principalId"/> is null.</exception>
278278
/// <exception cref="ArgumentException"><paramref name="roleDefinitionId"/> or <paramref name="principalId"/> is empty.</exception>
279-
public virtual async Task<Response<KeyVaultRoleAssignment>> CreateRoleAssignmentAsync(KeyVaultRoleScope roleScope, string roleDefinitionId, string principalId, Guid? name = default, CancellationToken cancellationToken = default)
279+
public virtual async Task<Response<KeyVaultRoleAssignment>> CreateRoleAssignmentAsync(KeyVaultRoleScope roleScope, string roleDefinitionId, string principalId, Guid? roleAssignmentName = default, CancellationToken cancellationToken = default)
280280
{
281281
Argument.AssertNotNullOrEmpty(roleDefinitionId, nameof(roleDefinitionId));
282282
Argument.AssertNotNullOrEmpty(principalId, nameof(principalId));
@@ -285,7 +285,7 @@ public virtual async Task<Response<KeyVaultRoleAssignment>> CreateRoleAssignment
285285
scope.Start();
286286
try
287287
{
288-
var _name = (name ?? Guid.NewGuid()).ToString();
288+
var _name = (roleAssignmentName ?? Guid.NewGuid()).ToString();
289289
var properties = new KeyVaultRoleAssignmentProperties(roleDefinitionId, principalId);
290290

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

0 commit comments

Comments
 (0)