| | | 1 | | using System.ComponentModel.DataAnnotations.Schema; |
| | | 2 | | using System.Text.Json.Serialization; |
| | | 3 | | using Elsa.Common.Entities; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Secrets.Models; |
| | | 6 | | |
| | | 7 | | public class Secret : Entity |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Assigns the identifier the property initializer used to provide. |
| | | 11 | | /// </summary> |
| | | 12 | | /// <remarks> |
| | | 13 | | /// <see cref="Entity.Id"/> is declared <c>null!</c>, and nothing in this module assigns a secret's id -- |
| | | 14 | | /// there is no identity generator on the create path, so the initializer this replaces was load-bearing. |
| | | 15 | | /// Dropping it while deriving would have produced a null id on every insert, which unit tests that build |
| | | 16 | | /// a Secret by hand would not have noticed. |
| | | 17 | | /// </remarks> |
| | 601 | 18 | | public Secret() |
| | | 19 | | { |
| | 601 | 20 | | Id = Guid.NewGuid().ToString("N"); |
| | 601 | 21 | | } |
| | | 22 | | |
| | 1571 | 23 | | public string Name { get; set; } = default!; |
| | 917 | 24 | | public string DisplayName { get; set; } = default!; |
| | 681 | 25 | | public string? Description { get; set; } |
| | 1296 | 26 | | public string TypeName { get; set; } = SecretTypeNames.Text; |
| | 1322 | 27 | | public string StoreName { get; set; } = SecretStoreNames.Encrypted; |
| | 686 | 28 | | public string? Scope { get; set; } |
| | | 29 | | /// <summary>Stable owner identifier for a lifecycle-managed generation. Generic secret requests cannot set this mar |
| | 750 | 30 | | public string? ManagedOwnerId { get; set; } |
| | | 31 | | |
| | | 32 | | /// <summary>Generation identifier owned by <see cref="ManagedOwnerId"/>.</summary> |
| | 738 | 33 | | public string? ManagedGenerationId { get; set; } |
| | | 34 | | |
| | | 35 | | [JsonIgnore] |
| | | 36 | | [NotMapped] |
| | 123 | 37 | | public bool IsLifecycleManaged => ManagedOwnerId != null || ManagedGenerationId != null; |
| | | 38 | | |
| | | 39 | | [System.Text.Json.Serialization.JsonConverter(typeof(CaseInsensitiveHashSetConverter))] |
| | 1379 | 40 | | public HashSet<string> Tags { get; set; } = new(StringComparer.OrdinalIgnoreCase); |
| | 919 | 41 | | public SecretStatus Status { get; set; } = SecretStatus.Active; |
| | 1225 | 42 | | public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow; |
| | 650 | 43 | | public DateTimeOffset? UpdatedAt { get; set; } |
| | 1542 | 44 | | public IList<SecretVersion> Versions { get; set; } = []; |
| | | 45 | | |
| | 137 | 46 | | public SecretVersion? LatestActiveVersion => Versions |
| | 90 | 47 | | .Where(x => x.Status == SecretStatus.Active && !x.IsExpired()) |
| | 72 | 48 | | .OrderByDescending(x => x.Version) |
| | 137 | 49 | | .FirstOrDefault(); |
| | | 50 | | } |