From 900bb5e845c3ad44defbd427cae3d44a4a43321f Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Sat, 25 Feb 2023 13:15:44 +0100 Subject: feat: Initial commit --- code/api/src/Models/Misc/ApiSpecDocument.cs | 9 ++ code/api/src/Models/Misc/AppConfiguration.cs | 118 ++++++++++++++++++++++++ code/api/src/Models/Misc/AppPath.cs | 23 +++++ code/api/src/Models/Misc/KnownProblemModel.cs | 26 ++++++ code/api/src/Models/Misc/LoggedInUserModel.cs | 8 ++ code/api/src/Models/Misc/RequestTimeZoneInfo.cs | 8 ++ 6 files changed, 192 insertions(+) create mode 100644 code/api/src/Models/Misc/ApiSpecDocument.cs create mode 100644 code/api/src/Models/Misc/AppConfiguration.cs create mode 100644 code/api/src/Models/Misc/AppPath.cs create mode 100644 code/api/src/Models/Misc/KnownProblemModel.cs create mode 100644 code/api/src/Models/Misc/LoggedInUserModel.cs create mode 100644 code/api/src/Models/Misc/RequestTimeZoneInfo.cs (limited to 'code/api/src/Models/Misc') diff --git a/code/api/src/Models/Misc/ApiSpecDocument.cs b/code/api/src/Models/Misc/ApiSpecDocument.cs new file mode 100644 index 0000000..1c7d936 --- /dev/null +++ b/code/api/src/Models/Misc/ApiSpecDocument.cs @@ -0,0 +1,9 @@ +namespace IOL.GreatOffice.Api.Data.Models; + +public class ApiSpecDocument +{ + public string VersionName { get; set; } + public string SwaggerPath { get; set; } + public ApiVersion Version { get; set; } + public OpenApiInfo OpenApiInfo { get; set; } +} diff --git a/code/api/src/Models/Misc/AppConfiguration.cs b/code/api/src/Models/Misc/AppConfiguration.cs new file mode 100644 index 0000000..31e5726 --- /dev/null +++ b/code/api/src/Models/Misc/AppConfiguration.cs @@ -0,0 +1,118 @@ +using System.Security.Cryptography.X509Certificates; + +namespace IOL.GreatOffice.Api.Data.Models; + +public class AppConfiguration +{ + /// + /// An reachable ip address or url that points to a postgres database. + /// + public string DB_HOST { get; set; } + + /// + /// The port number to use with DB_HOST to point to the postgres database. + /// + public string DB_PORT { get; set; } + + /// + /// The database user to authenticate against postgres with. + /// + public string DB_USER { get; set; } + + /// + /// The password for the database user to authenticate against postgres with. + /// + public string DB_PASSWORD { get; set; } + + /// + /// The name of the main app database. + /// + public string DB_NAME { get; set; } + + /// + /// An reachable ip address or url that points to a postgres(quartz) database. + /// + public string QUARTZ_DB_HOST { get; set; } + + /// + /// The port number to use with QUARTZ_DB_HOST to point to the postgres(quartz) database. + /// + public string QUARTZ_DB_PORT { get; set; } + + /// + /// The database user to authenticate against postgres(quartz) with. + /// + public string QUARTZ_DB_USER { get; set; } + + /// + /// The password for the database user to authenticate against postgres(quartz) with. + /// + public string QUARTZ_DB_PASSWORD { get; set; } + + /// + /// The name of the quartz database. + /// + public string QUARTZ_DB_NAME { get; set; } + + /// + /// API key to use when pushing logs to SEQ + /// + public string SEQ_API_KEY { get; set; } + + /// + /// Url pointing to the seq instance that processes server logs + /// + public string SEQ_API_URL { get; set; } + + /// + /// A token used when sending email via Postmakr + /// + public string POSTMARK_TOKEN { get; set; } + + /// + /// The address to send emails from, needs to be setup as a sender in postmark + /// + public string EMAIL_FROM_ADDRESS { get; set; } + + /// + /// The absolute url to the frontend app + /// + public string CANONICAL_FRONTEND_URL { get; set; } + + /// + /// The absolute url to the backend api + /// + public string CANONICAL_BACKEND_URL { get; set; } + + /// + /// A random string used to encrypt/decrypt for general purposes + /// + public string APP_AES_KEY { get; set; } + + /// + /// A base64 string containing a passwordless pfx cert + /// + public string APP_CERT { get; set; } + + public X509Certificate2 CERT1() => new(Convert.FromBase64String(APP_CERT)); + + public object GetPublicVersion() { + return new { + DB_HOST, + DB_PORT, + DB_USER, + DB_PASSWORD = DB_PASSWORD.Obfuscate() ?? "", + QUARTZ_DB_HOST, + QUARTZ_DB_PORT, + QUARTZ_DB_USER, + QUARTZ_DB_PASSWORD = QUARTZ_DB_PASSWORD.Obfuscate() ?? "", + SEQ_API_KEY = SEQ_API_KEY.Obfuscate() ?? "", + SEQ_API_URL, + POSTMARK_TOKEN = POSTMARK_TOKEN.Obfuscate() ?? "", + EMAIL_FROM_ADDRESS, + APP_AES_KEY = APP_AES_KEY.Obfuscate() ?? "", + CERT1 = CERT1().PublicKey.Oid.FriendlyName, + CANONICAL_FRONTEND_URL + }; + } +} \ No newline at end of file diff --git a/code/api/src/Models/Misc/AppPath.cs b/code/api/src/Models/Misc/AppPath.cs new file mode 100644 index 0000000..e47e48c --- /dev/null +++ b/code/api/src/Models/Misc/AppPath.cs @@ -0,0 +1,23 @@ +namespace IOL.GreatOffice.Api.Data.Models; + +public sealed record AppPath +{ + public string HostPath { get; init; } + public string WebPath { get; init; } + + public string GetHostPathForFilename(string filename, string fallback = "") { + if (filename.IsNullOrWhiteSpace()) { + return fallback; + } + + return Path.Combine(HostPath, filename); + } + + public string GetWebPathForFilename(string filename, string fallback = "") { + if (filename.IsNullOrWhiteSpace()) { + return fallback; + } + + return Path.Combine(WebPath, filename); + } +} diff --git a/code/api/src/Models/Misc/KnownProblemModel.cs b/code/api/src/Models/Misc/KnownProblemModel.cs new file mode 100644 index 0000000..9acc85c --- /dev/null +++ b/code/api/src/Models/Misc/KnownProblemModel.cs @@ -0,0 +1,26 @@ +namespace IOL.GreatOffice.Api.Data.Models; + +public class KnownProblemModel +{ + public KnownProblemModel(string title = default, string subtitle = default, Dictionary errors = default) { + Title = title; + Subtitle = subtitle; + Errors = errors ?? new(); + } + + public string Title { get; set; } + public string Subtitle { get; set; } + public Dictionary Errors { get; set; } + public string TraceId { get; set; } + + public void AddError(string field, string errorText) { + if (!Errors.ContainsKey(field)) { + Errors.Add(field, new[] {errorText}); + } else { + var currentErrors = Errors[field]; + var newErrors = currentErrors.Concat(new[] {errorText}); + Errors.Remove(field); + Errors.Add(field, newErrors.ToArray()); + } + } +} \ No newline at end of file diff --git a/code/api/src/Models/Misc/LoggedInUserModel.cs b/code/api/src/Models/Misc/LoggedInUserModel.cs new file mode 100644 index 0000000..541d4a5 --- /dev/null +++ b/code/api/src/Models/Misc/LoggedInUserModel.cs @@ -0,0 +1,8 @@ +namespace IOL.GreatOffice.Api.Data.Models; + +public class LoggedInUserModel +{ + public Guid Id { get; set; } + public string Username { get; set; } + public Guid TenantId { get; set; } +} \ No newline at end of file diff --git a/code/api/src/Models/Misc/RequestTimeZoneInfo.cs b/code/api/src/Models/Misc/RequestTimeZoneInfo.cs new file mode 100644 index 0000000..4c5aa13 --- /dev/null +++ b/code/api/src/Models/Misc/RequestTimeZoneInfo.cs @@ -0,0 +1,8 @@ +namespace IOL.GreatOffice.Api.Data.Models; + +public class RequestTimeZoneInfo +{ + public TimeZoneInfo TimeZoneInfo { get; set; } + public int Offset { get; set; } + public DateTime LocalDateTime { get; set; } +} \ No newline at end of file -- cgit v1.3