This repository has been archived by the owner on Jul 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
SampleConstants.cs
68 lines (60 loc) · 3.32 KB
/
SampleConstants.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System.Collections.Generic;
using System.Net;
namespace AzureKeyVaultRecoverySamples
{
public static class SampleConstants
{
/// <summary>
/// Constants representing the configuration setting keys.
/// </summary>
public static class ConfigKeys
{
public static readonly string TenantId = "TenantId";
public static readonly string VaultName = "VaultName";
public static readonly string VaultLocation = "VaultLocation";
public static readonly string ResourceGroupName = "ResourceGroupName";
public static readonly string SubscriptionId = "SubscriptionId";
public static readonly string SPObjectId = "SPObjectId";
public static readonly string SPSecret = "SPSecret";
public static readonly string ApplicationId = "ApplicationId";
}
/// <summary>
/// Predetermined policies for retrying KeyVault-bound requests.
/// </summary>
public static class RetryPolicies
{
/// <summary>
/// status codes for retriable operations.
/// </summary>
public static HashSet<HttpStatusCode> SuccessStatusCodes
= new HashSet<HttpStatusCode>(new List<HttpStatusCode> { HttpStatusCode.OK, HttpStatusCode.Accepted, HttpStatusCode.NoContent });
public static HashSet<HttpStatusCode> SoftDeleteRetriableStatusCodes
= new HashSet<HttpStatusCode>(new List<HttpStatusCode> { HttpStatusCode.Conflict, HttpStatusCode.NotFound });
public static HashSet<HttpStatusCode> AbortStatusCodes
= new HashSet<HttpStatusCode>(new List<HttpStatusCode> { HttpStatusCode.BadRequest, HttpStatusCode.InternalServerError, HttpStatusCode.Forbidden });
/// <summary>
/// Number of seconds to wait after a first, failed attempt to execute a soft-delete-related operation (such as delete, recover, purge).
/// </summary>
private static int SoftDeleteInitialBackoff = 15;
private static int SoftDeleteMaxAttempts = 3;
/// <summary>
/// Standard retry policy for soft-delete-related operations which attempt to modify transitioning entities.
/// </summary>
public static RetryPolicy DefaultSoftDeleteRetryPolicy = new RetryPolicy(
SoftDeleteInitialBackoff,
SoftDeleteMaxAttempts,
continueOn: SuccessStatusCodes,
retryOn: SoftDeleteRetriableStatusCodes,
abortOn: AbortStatusCodes);
/// <summary>
/// Standard retry policy for soft-delete-related operations which attempt to consume the outcome of an async operation.
/// </summary>
public static RetryPolicy WaitForAsyncDeletionRetryPolicy = new RetryPolicy(
SoftDeleteInitialBackoff,
SoftDeleteMaxAttempts,
continueOn: new HashSet<HttpStatusCode> { HttpStatusCode.NotFound }, // keep spinning until entity is marked as deleted
retryOn: new HashSet<HttpStatusCode> { HttpStatusCode.OK, HttpStatusCode.Accepted, HttpStatusCode.Conflict }, // retry on success and conflicts
abortOn: AbortStatusCodes);
}
}
}