diff options
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | README.md | 72 | ||||
| -rw-r--r-- | code/api/sql/quartz-create.sql (renamed from sql/quartz-create.sql) | 0 | ||||
| -rw-r--r-- | code/api/sql/quartz-drop.sql (renamed from sql/quartz-drop.sql) | 0 | ||||
| -rw-r--r-- | code/api/src/Data/Models/AppConfiguration.cs | 5 | ||||
| -rw-r--r-- | code/api/src/Services/VaultService.cs | 59 | ||||
| -rw-r--r-- | code/app/src/lib/models/internal/ErrorResult.ts | 4 |
7 files changed, 102 insertions, 40 deletions
@@ -478,3 +478,5 @@ bin obj AppData secrets +.fleet +.vscode
\ No newline at end of file @@ -1,8 +1,20 @@ -# Great Office +# Greatoffice -This codebase and all of its source code is licensed under the GNU General Public License v3.0, see [COPYING](COPYING) for more information. +> This codebase and all of its source code is licensed under the GNU General Public License v3.0, see [COPYING](COPYING) for more information. -## server +This repository contains all the code for greatoffice, a business management system. + +The platform aims to equip it's users with tools to do +- project management +- time tracking +- invoicing +- documenting +- ticketing +- task management + +See it live at https://dev.greatoffice.app + +## code/api Contains an ASP.NET Core Web API project using the [ApiEndpoints](https://github.com/ardalis/ApiEndpoints) paradigm. @@ -10,11 +22,36 @@ It handles all data operations (except administrative operations) for the platfo To run it you need .NET 6 and a PostgreSQL instance. -### Environment +### Database schemas + +The application schema is managed and described using entity framework core, to apply the latest migration use `dotnet ef database update` + +> This operation requires that you have the dotnet-ef tools installed, use `dotnet tool install -g dotnet-ef` to do so. +> +> In addition to that it requires you to have populated the required environment variables or enabled flight mode. + +Besides the application schema the api also needs a quartz database, sql scripts to create these in postgres is provided at `code/api/sql/quartz-*.sql`. + +I recommend using a seperate database for the quartz schema and app schema, since the app schema is managed by ef core and the quartz schema is not. +### Environment/Configuration -The server is configured through environments variables, in development [user-secret](https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets) is a nifty tool. +The api uses Hashicorp's vault to manage it's configuration, environment variables is used to point the api in the direction of the vault json object that contains the configuration. -All environment variables the server needs to function properly is specified in [src/server/Data/Static/AppEnvironmentVariables.cs](./server/src/Data/Static/AppEnvironmentVariables.cs). +The configuration is described by [code/api/src/Data/Models/AppConfiguration.cs](./code/api/src/Data/Models/AppConfiguration.cs). + +I recommend using [user-secrets](https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets) to set environment variables when developing. + +All environment variables the api needs to function properly is specified in [code/api/src/Data/Static/AppEnvironmentVariables.cs](./code/api/src/Data/Static/AppEnvironmentVariables.cs). + +#### Minimum required configuration + +The following configuration keys need valid values in order to start the api (regardless of environment): +- Starting with DB_ +- Starting with QUARTZ_DB_ +- Equal to APP_CERT + +#### Flight mode +If you need to skip the setup of vault or is unable to reach your vault instance, set isInFlightMode to true in [code/api/src/Services/VaultService.cs](./code/api/src/Services/VaultService.cs). ### Building and Developing @@ -22,21 +59,24 @@ To run the server in development mode use `dotnet run` (`dotnet watch` for hot-r To build the server locally use `dotnet build` or `dotnet build -c Release` for production builds. -## tests +A helper script is available at [`code/api/build_and_push.sh`](code/api/build_and_push.sh) that handles, +- Optionally commiting, taging and pushing latest changes to remote git source +- Building a docker image +- Pushing the docker image to the default registry at dr.ivar.systems +- Bumping version number -Contains integration tests for the web-app, written in .NET and xunit with Playwright for browser mocking. +## code/app -It automatically starts the server and expects the server to host the web-app at /index.html. +Contains an svelte kit application that acts as the frontend for greatoffice -Use `dotnet run` to run the tests. +### Environment -## apps/projects +The app reads environment variables from [`code/app/.env`](code/app/.env), keys need to start with `VITE_`. -The projects app is a svelte pwa that handles +### Building and Developing -- project management -- time tracking +To run the app in development mode use `pnpm run dev`. -## apps/web-shared +To build a production build use `pnpm run build`, the production build is placed in the `build` folder. -A source lib containing models, shared styles and shared components for all of great office's js clients/apps. +> Use `node build/index.js` (minimum v16) to run the app
\ No newline at end of file diff --git a/sql/quartz-create.sql b/code/api/sql/quartz-create.sql index d0dc298..d0dc298 100644 --- a/sql/quartz-create.sql +++ b/code/api/sql/quartz-create.sql diff --git a/sql/quartz-drop.sql b/code/api/sql/quartz-drop.sql index 87b0797..87b0797 100644 --- a/sql/quartz-drop.sql +++ b/code/api/sql/quartz-drop.sql diff --git a/code/api/src/Data/Models/AppConfiguration.cs b/code/api/src/Data/Models/AppConfiguration.cs index f4346bb..6bd93d0 100644 --- a/code/api/src/Data/Models/AppConfiguration.cs +++ b/code/api/src/Data/Models/AppConfiguration.cs @@ -26,10 +26,13 @@ public class AppConfiguration public string GITHUB_CLIENT_ID { get; set; } public string GITHUB_CLIENT_SECRET { get; set; } public string APP_AES_KEY { get; set; } + /// <summary> + /// A base64 string containing a passwordless pfx cert + /// </summary> public string APP_CERT { get; set; } public X509Certificate2 CERT1() => new (Convert.FromBase64String(APP_CERT)); - + public object GetPublicVersion() { return new { DB_HOST, diff --git a/code/api/src/Services/VaultService.cs b/code/api/src/Services/VaultService.cs index 3d58608..b64e6a2 100644 --- a/code/api/src/Services/VaultService.cs +++ b/code/api/src/Services/VaultService.cs @@ -10,7 +10,8 @@ public class VaultService private readonly ILogger<VaultService> _logger; private int CACHE_TTL { get; set; } - public VaultService(HttpClient client, IConfiguration configuration, IMemoryCache cache, ILogger<VaultService> logger) { + public VaultService(HttpClient client, IConfiguration configuration, IMemoryCache cache, ILogger<VaultService> logger) + { var token = configuration.GetValue<string>(AppEnvironmentVariables.VAULT_TOKEN); var vaultUrl = configuration.GetValue<string>(AppEnvironmentVariables.VAULT_URL); CACHE_TTL = configuration.GetValue(AppEnvironmentVariables.VAULT_CACHE_TTL, 60 * 60 * 12); @@ -24,16 +25,20 @@ public class VaultService _logger = logger; } - public T Get<T>(string path) { + public T Get<T>(string path) + { var result = _cache.GetOrCreate(AppConstants.VAULT_CACHE_KEY, - cacheEntry => { + cacheEntry => + { cacheEntry.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(CACHE_TTL); var getSecretResponse = _client.GetFromJsonAsync<GetSecretResponse<T>>("/v1/kv/data/" + path).Result; - if (getSecretResponse == null) { + if (getSecretResponse == null) + { return default; } - Log.Debug("Setting new vault cache, " + new { + Log.Debug("Setting new vault cache, " + new + { PATH = path, CACHE_TTL, Data = JsonSerializer.Serialize(getSecretResponse.Data.Data) @@ -43,28 +48,36 @@ public class VaultService return result; } - public T Refresh<T>(string path) { + public T Refresh<T>(string path) + { _cache.Remove(AppConstants.VAULT_CACHE_KEY); CACHE_TTL = _configuration.GetValue(AppEnvironmentVariables.VAULT_CACHE_TTL, 60 * 60 * 12); return Get<T>(path); } - public async Task<RenewTokenResponse> RenewTokenAsync<T>(string token) { + public async Task<RenewTokenResponse> RenewTokenAsync<T>(string token) + { var response = await _client.PostAsJsonAsync("v1/auth/token/renew", - new { + new + { Token = token }); - if (response.IsSuccessStatusCode) { + if (response.IsSuccessStatusCode) + { return await response.Content.ReadFromJsonAsync<RenewTokenResponse>(); } return default; } - public AppConfiguration GetCurrentAppConfiguration() { + public AppConfiguration GetCurrentAppConfiguration() + { +#if DEBUG var isInFlightMode = true; - if (isInFlightMode) { - return new AppConfiguration() { + if (isInFlightMode) + { + return new AppConfiguration() + { DB_HOST = "localhost", DB_PORT = "5432", DB_NAME = "greatoffice_ivar_dev", @@ -78,10 +91,12 @@ public class VaultService APP_CERT = "MIII2QIBAzCCCJ8GCSqGSIb3DQEHAaCCCJAEggiMMIIIiDCCAz8GCSqGSIb3DQEHBqCCAzAwggMsAgEAMIIDJQYJKoZIhvcNAQcBMBwGCiqGSIb3DQEMAQYwDgQI1JebRQOOJekCAggAgIIC+FTMxILwgOWxknEWvucjaHTtf/KUcSPwc/zWg0RoFzu03o1vZkStztz92L2J+nnNrQti7WEx0C/h5ug67qCQAdzkjNHZE9wn1pI2EqaCwKYwZnOTmyJDLV86xQlH9QYTs4/L1F2qTwpKdBoB2lNyTswYgZ8WNYY65fbFKUUVIaHkReGnma/ERm8F38Ymp7cudqQ4G6sh6E+JFSo2IfcTFb260fWO/iMDU3GryNsaUl4amT4aQfsSrNtf6ODy8Ivh7tJeLbR6bqzMtsKPzavT5ZbA6AP2GYAQSVejNP79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7Yk3fke1CJpoIb75d8iHkY21epOtqavTppezEd+0uq5RJThH+/nMyZVhRI3tSJ0kVDc1HVX2bTquWcXtniuZNOWYklLxKPfQNho8n0pHRk22UmB8DOxMjnAyt3s7xBNpujU+I7D30lK9N3PH4U+Oyc9pIWc2T7pFILvvToxoE3l2flg6eHnBd6a7ENDVbz1ELwwmt36QQAVQytEngTBYkorbJcQC6e2r/RqoqpP2N4dB7+2ZDMVw97VBraMl7ELaYdf9SOdzuis2engAojSiUUO/gdKGaJGnnldOSi5rvnxs+iMjElMCMGCSqGSIb3DQEJFTEWBBRSLC58imQohokANg6rVjq9KE/MxjAxMCEwCQYFKw4DAhoFAAQUILUGtKvqxRY/ywrrlxKrsuLiNLwECCWv9bVh/bZZAgIIAA==" }; } +#endif var path = _configuration.GetValue<string>(AppEnvironmentVariables.MAIN_CONFIG_SHEET); var result = Get<AppConfiguration>(path); - var overwrites = new { + var overwrites = new + { DB_HOST = _configuration.GetValue("OVERWRITE_DB_HOST", string.Empty), DB_PORT = _configuration.GetValue("OVERWRITE_DB_PORT", string.Empty), DB_USER = _configuration.GetValue("OVERWRITE_DB_USER", string.Empty), @@ -89,27 +104,32 @@ public class VaultService DB_NAME = _configuration.GetValue("OVERWRITE_DB_NAME", string.Empty), }; - if (overwrites.DB_HOST.HasValue()) { + if (overwrites.DB_HOST.HasValue()) + { _logger.LogInformation("OVERWRITE_DB_HOST is specified, using it's value: {DB_HOST}", overwrites.DB_HOST); result.DB_HOST = overwrites.DB_HOST; } - if (overwrites.DB_PORT.HasValue()) { + if (overwrites.DB_PORT.HasValue()) + { _logger.LogInformation("OVERWRITE_DB_PORT is specified, using it's value: {DB_PORT}", overwrites.DB_PORT); result.DB_PORT = overwrites.DB_PORT; } - if (overwrites.DB_USER.HasValue()) { + if (overwrites.DB_USER.HasValue()) + { _logger.LogInformation("OVERWRITE_DB_USER is specified, using it's value: {DB_USER}", overwrites.DB_USER); result.DB_USER = overwrites.DB_USER; } - if (overwrites.DB_PASSWORD.HasValue()) { + if (overwrites.DB_PASSWORD.HasValue()) + { _logger.LogInformation("OVERWRITE_DB_PASSWORD is specified, using it's value: (redacted)"); result.DB_PASSWORD = overwrites.DB_PASSWORD; } - if (overwrites.DB_NAME.HasValue()) { + if (overwrites.DB_NAME.HasValue()) + { _logger.LogInformation("OVERWRITE_DB_NAME is specified, using it's value: {DB_NAME}", overwrites.DB_NAME); result.DB_NAME = overwrites.DB_NAME; } @@ -117,7 +137,8 @@ public class VaultService return result; } - public AppConfiguration RefreshCurrentAppConfiguration() { + public AppConfiguration RefreshCurrentAppConfiguration() + { var path = _configuration.GetValue<string>(AppEnvironmentVariables.MAIN_CONFIG_SHEET); return Refresh<AppConfiguration>(path); } diff --git a/code/app/src/lib/models/internal/ErrorResult.ts b/code/app/src/lib/models/internal/ErrorResult.ts deleted file mode 100644 index 930b9f3..0000000 --- a/code/app/src/lib/models/internal/ErrorResult.ts +++ /dev/null @@ -1,4 +0,0 @@ -export type ErrorResult = { - title: string, - text: string -} |
