diff options
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | README.md | 47 | ||||
| -rw-r--r-- | code/api/src/Models/Static/AppEnvironmentVariables.cs | 47 | ||||
| -rw-r--r-- | code/api/src/Services/VaultService.cs | 22 |
4 files changed, 68 insertions, 51 deletions
@@ -479,4 +479,5 @@ obj AppData secrets .fleet -.vscode
\ No newline at end of file +.vscode +flightmode.json
\ No newline at end of file @@ -1,6 +1,7 @@ # Greatoffice -> This codebase and all of its source code is licensed under the GNU General Public License v3.0, see [COPYING](COPYING). +> This codebase and all of its source code is licensed under the GNU General Public License v3.0, +> see [COPYING](COPYING). This repository contains all the code for greatoffice, a business management system. @@ -13,7 +14,8 @@ The platform aims to equip it's users with tools to do * ticketing * task management -Everything is WIP, but the platform is regularly updated at [https://stage.greatoffice.app](https://stage.greatoffice.app) +Everything is WIP, but the platform is regularly updated +at [https://stage.greatoffice.app](https://stage.greatoffice.app) ## code/api @@ -25,24 +27,32 @@ To run it you need .NET 7 and a PostgreSQL instance. ### Database schemas -The application schema is managed and described using entity framework core, to apply the latest migration use `dotnet ef database update` +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`. +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. -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 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. +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. -The configuration is described by [`code/api/src/Models/Misc/AppConfiguration.cs`](./code/api/src/Models/Misc/AppConfiguration.cs). +The configuration is described +by [`code/api/src/Models/Misc/AppConfiguration.cs`](./code/api/src/Models/Misc/AppConfiguration.cs). -I recommend using [user-secrets](https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets) to set environment variables when developing. +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/Models/Static/AppEnvironmentVariables.cs`](./code/api/src/Models/Static/AppEnvironmentVariables.cs). +All environment variables the api needs to function properly is specified +in [`code/api/src/Models/Static/AppEnvironmentVariables.cs`](./code/api/src/Models/Static/AppEnvironmentVariables.cs). #### Minimum required configuration @@ -53,11 +63,16 @@ The following configuration keys need valid values in order to start the api (re * Starting with QUARTZ_DB_ * Equal to APP_CERT -> See [`code/api/src/Models/Misc/AppConfiguration.cs`](./code/api/src/Models/Misc/AppConfiguration.cs) for expected values. +> See [`code/api/src/Models/Misc/AppConfiguration.cs`](./code/api/src/Models/Misc/AppConfiguration.cs) for expected +> values. #### Flight mode -If you need to skip the setup of vault or is unable to reach your vault instance, set FLIGHT_MODE to a positive value. +When debugging the application you sometimes don't want to, or are not able to reach the vault for configuration values. +In this case you can set the environment variable `FLIGHT_MODE` to something positive. + +This will configure the api to read configuration from a json file specified at `FLIGHT_MODE_JSON`, defaults +to `flightmode.json`. ### Building and Developing @@ -67,7 +82,7 @@ To build the server locally use `dotnet build` or `dotnet build -c Release` for 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 +* Optionally commiting, tagging 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 @@ -80,8 +95,12 @@ Noteworthy information: * The ui consists largely of components from or inspired by tailwind ui. * When you run the frontend in dev mode, most of the available components is showcased standalone at `/book`. -* The app uses [temporal-polyfill](https://github.com/fullcalendar/temporal) to do date and time operations, docs is [here](https://tc39.es/proposal-temporal/docs/#api-documentation) (excited to see this api implemented natively soon). -* Svelte headless ui is used for some of the components, while the library is great it unfortunately seems to be unmaintained and therefore i forked it into `@developermuch/dev-svelte-headlessui` where i publish additions from upstream. This package can hopefully be deprecated in the future. +* The app uses [temporal-polyfill](https://github.com/fullcalendar/temporal) to do date and time operations, docs + is [here](https://tc39.es/proposal-temporal/docs/#api-documentation) (excited to see this api implemented natively + soon). +* Svelte headless ui is used for some of the components, while the library is great it unfortunately seems to be + unmaintained and therefore i forked it into `@developermuch/dev-svelte-headlessui` where i publish additions from + upstream. This package can hopefully be deprecated in the future. ### Environment diff --git a/code/api/src/Models/Static/AppEnvironmentVariables.cs b/code/api/src/Models/Static/AppEnvironmentVariables.cs index c3f821d..0c1938d 100644 --- a/code/api/src/Models/Static/AppEnvironmentVariables.cs +++ b/code/api/src/Models/Static/AppEnvironmentVariables.cs @@ -2,20 +2,33 @@ namespace IOL.GreatOffice.Api.Data.Static; public static class AppEnvironmentVariables { - /// <summary> - /// An access token that can be used to access the Hashicorp Vault instance that is available at VAULT_URL - /// </summary> - public const string VAULT_TOKEN = "VAULT_TOKEN"; - /// <summary> - /// An url pointing to the Hashicorp Vault instance the app should use - /// </summary> - public const string VAULT_URL = "VAULT_URL"; - /// <summary> - /// The duration of which to keep a local cached version of the configuration - /// </summary> - public const string VAULT_CACHE_TTL = "VAULT_CACHE_TTL"; - /// <summary> - /// The vault key name for the main configuration json object, described by <see cref="AppConfiguration"/> - /// </summary> - public const string MAIN_CONFIG_SHEET = "MAIN_CONFIG_SHEET"; -} + /// <summary> + /// An access token that can be used to access the Hashicorp Vault instance that is available at VAULT_URL + /// </summary> + public const string VAULT_TOKEN = "VAULT_TOKEN"; + + /// <summary> + /// A url pointing to the Hashicorp Vault instance the app should use + /// </summary> + public const string VAULT_URL = "VAULT_URL"; + + /// <summary> + /// The duration of which to keep a local cached version of the configuration + /// </summary> + public const string VAULT_CACHE_TTL = "VAULT_CACHE_TTL"; + + /// <summary> + /// The vault key name for the main configuration json object, described by <see cref="AppConfiguration"/> + /// </summary> + public const string MAIN_CONFIG_SHEET = "MAIN_CONFIG_SHEET"; + + /// <summary> + /// Tells the api to enable flight mode, only acts in DEBUG + /// </summary> + public const string FLIGHT_MODE = "FLIGHT_MODE"; + + /// <summary> + /// Tells the api where to read configuration from, defaults to flightmode.json, only acts in DEBUG + /// </summary> + public const string FLIGHT_MODE_JSON = "FLIGHT_MODE_JSON"; +}
\ No newline at end of file diff --git a/code/api/src/Services/VaultService.cs b/code/api/src/Services/VaultService.cs index cd2eecf..4243929 100644 --- a/code/api/src/Services/VaultService.cs +++ b/code/api/src/Services/VaultService.cs @@ -69,25 +69,9 @@ public class VaultService public AppConfiguration GetCurrentAppConfiguration() { #if DEBUG - var isInFlightMode = true; - if (isInFlightMode) { - return new AppConfiguration() { - EMAIL_FROM_ADDRESS = "heydev@greatoffice.life", - DB_HOST = "localhost", - DB_PORT = "5432", - DB_NAME = "greatoffice_ivar_dev", - DB_PASSWORD = "ivar123", - DB_USER = "postgres", - CANONICAL_FRONTEND_URL = "http://localhost:5173", - CANONICAL_BACKEND_URL = "http://localhost:5000", - POSTMARK_TOKEN = "b530c311-45c7-43e5-aa48-f2c992886e51", - QUARTZ_DB_HOST = "localhost", - QUARTZ_DB_PORT = "5432", - QUARTZ_DB_NAME = "greatoffice_quartz_ivar_dev", - QUARTZ_DB_PASSWORD = "ivar123", - QUARTZ_DB_USER = "postgres", - APP_CERT = "MIII2QIBAzCCCJ8GCSqGSIb3DQEHAaCCCJAEggiMMIIIiDCCAz8GCSqGSIb3DQEHBqCCAzAwggMsAgEAMIIDJQYJKoZIhvcNAQcBMBwGCiqGSIb3DQEMAQYwDgQI1JebRQOOJekCAggAgIIC+FTMxILwgOWxknEWvucjaHTtf/KUcSPwc/zWg0RoFzu03o1vZkStztz92L2J+nnNrQti7WEx0C/h5ug67qCQAdzkjNHZE9wn1pI2EqaCwKYwZnOTmyJDLV86xQlH9QYTs4/L1F2qTwpKdBoB2lN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FkHuGe7R4ZpKRIVjVy7RScelCuQ0yNMGIzx/5Dz3FQXWq1Jii669Oxs/R7iupwo+f6O9XmCJAGXIw5a11Yw9cULptVNc9rPHrauAOeNpE77aSQRKEOJZADvdLB8cXjpXFf2mvzFib69Cuks8QxktAK7Yk3fke1CJpoIb75d8iHkY21epOtqavTppezEd+0uq5RJThH+/nMyZVhRI3tSJ0kVDc1HVX2bTquWcXtniuZNOWYklLxKPfQNho8n0pHRk22UmB8DOxMjnAyt3s7xBNpujU+I7D30lK9N3PH4U+Oyc9pIWc2T7pFILvvToxoE3l2flg6eHnBd6a7ENDVbz1ELwwmt36QQAVQytEngTBYkorbJcQC6e2r/RqoqpP2N4dB7+2ZDMVw97VBraMl7ELaYdf9SOdzuis2engAojSiUUO/gdKGaJGnnldOSi5rvnxs+iMjElMCMGCSqGSIb3DQEJFTEWBBRSLC58imQohokANg6rVjq9KE/MxjAxMCEwCQYFKw4DAhoFAAQUILUGtKvqxRY/ywrrlxKrsuLiNLwECCWv9bVh/bZZAgIIAA==" - }; + if (_configuration.GetValue<bool>(AppEnvironmentVariables.FLIGHT_MODE)) { + var text = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), _configuration.GetValue(AppEnvironmentVariables.FLIGHT_MODE_JSON, "flightmode.json"))); + return JsonSerializer.Deserialize<AppConfiguration>(text); } #endif |
