| | 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.Secrets |
| | 8 | | { |
| | 9 | | internal struct SecretAttributes |
| | 10 | | { |
| | 11 | | private const string EnabledPropertyName = "enabled"; |
| | 12 | | private const string NotBeforePropertyName = "nbf"; |
| | 13 | | private const string ExpiresPropertyName = "exp"; |
| | 14 | | private const string CreatedPropertyName = "created"; |
| | 15 | | private const string UpdatedPropertyName = "updated"; |
| | 16 | | private const string RecoverableDaysPropertyName = "recoverableDays"; |
| | 17 | | private const string RecoveryLevelPropertyName = "recoveryLevel"; |
| | 18 | |
|
| 2 | 19 | | private static readonly JsonEncodedText s_enabledPropertyNameBytes = JsonEncodedText.Encode(EnabledPropertyName) |
| 2 | 20 | | private static readonly JsonEncodedText s_notBeforePropertyNameBytes = JsonEncodedText.Encode(NotBeforePropertyN |
| 2 | 21 | | private static readonly JsonEncodedText s_expiresPropertyNameBytes = JsonEncodedText.Encode(ExpiresPropertyName) |
| | 22 | |
|
| 3632 | 23 | | public bool? Enabled { get; set; } |
| | 24 | |
|
| 2060 | 25 | | public DateTimeOffset? NotBefore { get; set; } |
| | 26 | |
|
| 2076 | 27 | | public DateTimeOffset? ExpiresOn { get; set; } |
| | 28 | |
|
| 1548 | 29 | | public DateTimeOffset? CreatedOn { get; internal set; } |
| | 30 | |
|
| 1544 | 31 | | public DateTimeOffset? UpdatedOn { get; internal set; } |
| | 32 | |
|
| 10 | 33 | | public int? RecoverableDays { get; internal set; } |
| | 34 | |
|
| 1544 | 35 | | public string RecoveryLevel { get; internal set; } |
| | 36 | |
|
| | 37 | | internal void ReadProperties(JsonElement json) |
| | 38 | | { |
| 15528 | 39 | | foreach (JsonProperty prop in json.EnumerateObject()) |
| | 40 | | { |
| 6216 | 41 | | switch (prop.Name) |
| | 42 | | { |
| | 43 | | case EnabledPropertyName: |
| 1544 | 44 | | Enabled = prop.Value.GetBoolean(); |
| 1544 | 45 | | break; |
| | 46 | |
|
| | 47 | | case NotBeforePropertyName: |
| 12 | 48 | | NotBefore = DateTimeOffset.FromUnixTimeSeconds(prop.Value.GetInt64()); |
| 12 | 49 | | break; |
| | 50 | |
|
| | 51 | | case ExpiresPropertyName: |
| 24 | 52 | | ExpiresOn = DateTimeOffset.FromUnixTimeSeconds(prop.Value.GetInt64()); |
| 24 | 53 | | break; |
| | 54 | |
|
| | 55 | | case CreatedPropertyName: |
| 1544 | 56 | | CreatedOn = DateTimeOffset.FromUnixTimeSeconds(prop.Value.GetInt64()); |
| 1544 | 57 | | break; |
| | 58 | |
|
| | 59 | | case UpdatedPropertyName: |
| 1544 | 60 | | UpdatedOn = DateTimeOffset.FromUnixTimeSeconds(prop.Value.GetInt64()); |
| 1544 | 61 | | break; |
| | 62 | |
|
| | 63 | | case RecoverableDaysPropertyName: |
| 4 | 64 | | RecoverableDays = prop.Value.GetInt32(); |
| 4 | 65 | | break; |
| | 66 | |
|
| | 67 | | case RecoveryLevelPropertyName: |
| 1544 | 68 | | RecoveryLevel = prop.Value.GetString(); |
| | 69 | | break; |
| | 70 | | } |
| | 71 | | } |
| 1548 | 72 | | } |
| | 73 | |
|
| | 74 | | internal void WriteProperties(Utf8JsonWriter json) |
| | 75 | | { |
| 24 | 76 | | if (Enabled.HasValue) |
| | 77 | | { |
| 20 | 78 | | json.WriteBoolean(s_enabledPropertyNameBytes, Enabled.Value); |
| | 79 | | } |
| | 80 | |
|
| 24 | 81 | | if (NotBefore.HasValue) |
| | 82 | | { |
| 4 | 83 | | json.WriteNumber(s_notBeforePropertyNameBytes, NotBefore.Value.ToUnixTimeSeconds()); |
| | 84 | | } |
| | 85 | |
|
| 24 | 86 | | if (ExpiresOn.HasValue) |
| | 87 | | { |
| 8 | 88 | | json.WriteNumber(s_expiresPropertyNameBytes, ExpiresOn.Value.ToUnixTimeSeconds()); |
| | 89 | | } |
| | 90 | |
|
| | 91 | | // Created is read-only don't serialize |
| | 92 | | // Updated is read-only don't serialize |
| | 93 | | // RecoverableDays is read-only don't serialize |
| | 94 | | // RecoveryLevel is read-only don't serialize |
| 24 | 95 | | } |
| | 96 | | } |
| | 97 | |
|
| | 98 | | } |