| | | 1 | | using Elsa.Common.Entities; |
| | | 2 | | |
| | | 3 | | namespace Elsa.Secrets.Models; |
| | | 4 | | |
| | | 5 | | public class Secret : Entity |
| | | 6 | | { |
| | | 7 | | /// <summary> |
| | | 8 | | /// Assigns the identifier the property initializer used to provide. |
| | | 9 | | /// </summary> |
| | | 10 | | /// <remarks> |
| | | 11 | | /// <see cref="Entity.Id"/> is declared <c>null!</c>, and nothing in this module assigns a secret's id -- |
| | | 12 | | /// there is no identity generator on the create path, so the initializer this replaces was load-bearing. |
| | | 13 | | /// Dropping it while deriving would have produced a null id on every insert, which unit tests that build |
| | | 14 | | /// a Secret by hand would not have noticed. |
| | | 15 | | /// </remarks> |
| | 160 | 16 | | public Secret() |
| | | 17 | | { |
| | 160 | 18 | | Id = Guid.NewGuid().ToString("N"); |
| | 160 | 19 | | } |
| | | 20 | | |
| | 385 | 21 | | public string Name { get; set; } = default!; |
| | 265 | 22 | | public string DisplayName { get; set; } = default!; |
| | 236 | 23 | | public string? Description { get; set; } |
| | 402 | 24 | | public string TypeName { get; set; } = SecretTypeNames.Text; |
| | 414 | 25 | | public string StoreName { get; set; } = SecretStoreNames.Encrypted; |
| | 236 | 26 | | public string? Scope { get; set; } |
| | | 27 | | [System.Text.Json.Serialization.JsonConverter(typeof(CaseInsensitiveHashSetConverter))] |
| | 404 | 28 | | public HashSet<string> Tags { get; set; } = new(StringComparer.OrdinalIgnoreCase); |
| | 289 | 29 | | public SecretStatus Status { get; set; } = SecretStatus.Active; |
| | 353 | 30 | | public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow; |
| | 205 | 31 | | public DateTimeOffset? UpdatedAt { get; set; } |
| | 459 | 32 | | public IList<SecretVersion> Versions { get; set; } = []; |
| | | 33 | | |
| | 20 | 34 | | public SecretVersion? LatestActiveVersion => Versions |
| | 16 | 35 | | .Where(x => x.Status == SecretStatus.Active && !x.IsExpired()) |
| | 12 | 36 | | .OrderByDescending(x => x.Version) |
| | 20 | 37 | | .FirstOrDefault(); |
| | | 38 | | } |