| | | 1 | | namespace ArturRios.Heimdall.Data.Seeding; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Credentials for the master system administrator, read from the |
| | | 5 | | /// <c>HEIMDALL_MASTER_USER_*</c> environment variables. They are used only when the |
| | | 6 | | /// database holds no system administrator yet — see <c>DatabaseSeeder</c>. |
| | | 7 | | /// </summary> |
| | 927 | 8 | | public sealed record MasterUserOptions(string Name, string Email, string Password) |
| | | 9 | | { |
| | | 10 | | /// <summary>Environment variable holding the master user's display name.</summary> |
| | | 11 | | public const string NameVariable = "HEIMDALL_MASTER_USER_NAME"; |
| | | 12 | | |
| | | 13 | | /// <summary>Environment variable holding the master user's e-mail address.</summary> |
| | | 14 | | public const string EmailVariable = "HEIMDALL_MASTER_USER_EMAIL"; |
| | | 15 | | |
| | | 16 | | /// <summary>Environment variable holding the master user's plain-text password.</summary> |
| | | 17 | | public const string PasswordVariable = "HEIMDALL_MASTER_USER_PASSWORD"; |
| | | 18 | | |
| | | 19 | | /// <summary>Whether all three values are present, so a master user could be created.</summary> |
| | | 20 | | public bool IsComplete => |
| | 7 | 21 | | !string.IsNullOrWhiteSpace(Name) && |
| | 7 | 22 | | !string.IsNullOrWhiteSpace(Email) && |
| | 7 | 23 | | !string.IsNullOrWhiteSpace(Password); |
| | | 24 | | |
| | | 25 | | /// <summary>Reads the three variables from the current process environment.</summary> |
| | 901 | 26 | | public static MasterUserOptions FromEnvironment() => new( |
| | 901 | 27 | | Environment.GetEnvironmentVariable(NameVariable) ?? string.Empty, |
| | 901 | 28 | | Environment.GetEnvironmentVariable(EmailVariable) ?? string.Empty, |
| | 901 | 29 | | Environment.GetEnvironmentVariable(PasswordVariable) ?? string.Empty); |
| | | 30 | | } |