From 3b4da72ea307a7626b3a28f424a0c510f2f2a681 Mon Sep 17 00:00:00 2001
From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com>
Date: Sun, 6 Nov 2022 17:51:31 +0100
Subject: [PATCH] Feature/tighten validation rule of base currency (#1428)
* Tighten validation rule of BASE_CURRENCY
* Update changelog
---
CHANGELOG.md | 6 ++++
README.md | 28 +++++++++----------
.../api/src/services/configuration.service.ts | 5 +++-
3 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cf67a1c5a..5fe8f9e28 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## Unreleased
+
+### Changed
+
+- Tightened the validation rule of the base currency environment variable (`BASE_CURRENCY`)
+
## 1.209.0 - 05.11.2022
### Added
diff --git a/README.md b/README.md
index a96db529a..9d038aa41 100644
--- a/README.md
+++ b/README.md
@@ -83,20 +83,20 @@ We provide official container images hosted on [Docker Hub](https://hub.docker.c
### Supported Environment Variables
-| Name | Default Value | Description |
-| ------------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
-| `ACCESS_TOKEN_SALT` | | A random string used as salt for access tokens |
-| `BASE_CURRENCY` | `USD` | The base currency of the Ghostfolio application. Caution: This cannot be changed later! |
-| `DATABASE_URL` | | The database connection URL, e.g. `postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:5432/${POSTGRES_DB}?sslmode=prefer` |
-| `HOST` | `0.0.0.0` | The host where the Ghostfolio application will run on |
-| `JWT_SECRET_KEY` | | A random string used for _JSON Web Tokens_ (JWT) |
-| `PORT` | `3333` | The port where the Ghostfolio application will run on |
-| `POSTGRES_DB` | | The name of the _PostgreSQL_ database |
-| `POSTGRES_PASSWORD` | | The password of the _PostgreSQL_ database |
-| `POSTGRES_USER` | | The user of the _PostgreSQL_ database |
-| `REDIS_HOST` | | The host where _Redis_ is running |
-| `REDIS_PASSWORD` | | The password of _Redis_ |
-| `REDIS_PORT` | | The port where _Redis_ is running |
+| Name | Default Value | Description |
+| ------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
+| `ACCESS_TOKEN_SALT` | | A random string used as salt for access tokens |
+| `BASE_CURRENCY` | `USD` | The base currency of the Ghostfolio application.
`AUD` \| `CAD` \| `CNY` \| `EUR` \| `GBP` \| `JPY` \| `RUB` \| `USD`
Caution: Only set if you intend to track cryptocurrencies in a non-`USD` currency. This cannot be changed later! |
+| `DATABASE_URL` | | The database connection URL, e.g. `postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:5432/${POSTGRES_DB}?sslmode=prefer` |
+| `HOST` | `0.0.0.0` | The host where the Ghostfolio application will run on |
+| `JWT_SECRET_KEY` | | A random string used for _JSON Web Tokens_ (JWT) |
+| `PORT` | `3333` | The port where the Ghostfolio application will run on |
+| `POSTGRES_DB` | | The name of the _PostgreSQL_ database |
+| `POSTGRES_PASSWORD` | | The password of the _PostgreSQL_ database |
+| `POSTGRES_USER` | | The user of the _PostgreSQL_ database |
+| `REDIS_HOST` | | The host where _Redis_ is running |
+| `REDIS_PASSWORD` | | The password of _Redis_ |
+| `REDIS_PORT` | | The port where _Redis_ is running |
### Run with Docker Compose
diff --git a/apps/api/src/services/configuration.service.ts b/apps/api/src/services/configuration.service.ts
index 9cddec1f0..30e9d7c6f 100644
--- a/apps/api/src/services/configuration.service.ts
+++ b/apps/api/src/services/configuration.service.ts
@@ -12,7 +12,10 @@ export class ConfigurationService {
this.environmentConfiguration = cleanEnv(process.env, {
ACCESS_TOKEN_SALT: str(),
ALPHA_VANTAGE_API_KEY: str({ default: '' }),
- BASE_CURRENCY: str({ default: 'USD' }),
+ BASE_CURRENCY: str({
+ choices: ['AUD', 'CAD', 'CNY', 'EUR', 'GBP', 'JPY', 'RUB', 'USD'],
+ default: 'USD'
+ }),
CACHE_TTL: num({ default: 1 }),
DATA_SOURCE_PRIMARY: str({ default: DataSource.YAHOO }),
DATA_SOURCES: json({