| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Text.Json; |
| | 6 | |
|
| | 7 | | namespace Azure.Security.KeyVault.Keys |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// Represents a Key Vault key that has been deleted, allowing it to be recovered, if needed. |
| | 11 | | /// </summary> |
| | 12 | | public class DeletedKey : KeyVaultKey |
| | 13 | | { |
| | 14 | | private const string RecoveryIdPropertyName = "recoveryId"; |
| | 15 | | private const string DeletedOnPropertyName = "deletedDate"; |
| | 16 | | private const string ScheduledPurgeDatePropertyName = "scheduledPurgeDate"; |
| | 17 | |
|
| | 18 | | private string _recoveryId; |
| | 19 | |
|
| 16 | 20 | | internal DeletedKey(KeyProperties properties = null) : base(properties) |
| | 21 | | { |
| 16 | 22 | | } |
| | 23 | |
|
| 56 | 24 | | internal DeletedKey(string name) : base(name) |
| | 25 | | { |
| 56 | 26 | | } |
| | 27 | |
|
| | 28 | | /// <summary> |
| | 29 | | /// Gets a <see cref="Uri"/> of the deleted key that can be used to recover it. |
| | 30 | | /// </summary> |
| | 31 | | public Uri RecoveryId |
| | 32 | | { |
| 68 | 33 | | get => _recoveryId is null ? null : new Uri(_recoveryId); |
| 0 | 34 | | internal set => _recoveryId = value?.ToString(); |
| | 35 | | } |
| | 36 | |
|
| | 37 | | /// <summary> |
| | 38 | | /// Gets a <see cref="DateTimeOffset"/> indicating when the key was deleted. |
| | 39 | | /// </summary> |
| 96 | 40 | | public DateTimeOffset? DeletedOn { get; internal set; } |
| | 41 | |
|
| | 42 | | /// <summary> |
| | 43 | | /// Gets a <see cref="DateTimeOffset"/> for when the deleted key will be purged. |
| | 44 | | /// </summary> |
| 96 | 45 | | public DateTimeOffset? ScheduledPurgeDate { get; internal set; } |
| | 46 | |
|
| | 47 | | internal override void ReadProperty(JsonProperty prop) |
| | 48 | | { |
| 360 | 49 | | switch (prop.Name) |
| | 50 | | { |
| | 51 | | case RecoveryIdPropertyName: |
| 72 | 52 | | _recoveryId = prop.Value.GetString(); |
| 72 | 53 | | break; |
| | 54 | |
|
| | 55 | | case DeletedOnPropertyName: |
| 72 | 56 | | DeletedOn = DateTimeOffset.FromUnixTimeSeconds(prop.Value.GetInt64()); |
| 72 | 57 | | break; |
| | 58 | |
|
| | 59 | | case ScheduledPurgeDatePropertyName: |
| 72 | 60 | | ScheduledPurgeDate = DateTimeOffset.FromUnixTimeSeconds(prop.Value.GetInt64()); |
| 72 | 61 | | break; |
| | 62 | |
|
| | 63 | | default: |
| 144 | 64 | | base.ReadProperty(prop); |
| | 65 | | break; |
| | 66 | | } |
| 144 | 67 | | } |
| | 68 | | } |
| | 69 | | } |