Skip to content
This repository has been archived by the owner on Jan 5, 2025. It is now read-only.

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
rodriguestiago0 committed Jul 30, 2024
1 parent 2dbd121 commit 9d1a8b5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 21 deletions.
12 changes: 8 additions & 4 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ EDENRED_USERNAME=
EDENRED_PASSWORD=
EDENRED_TOKEN=

# Comma-separated.
# both need to have the same length
EDENRED_ACCOUNT_MAP=
ACTUAL_ACCOUNT_MAP=
EDENRED_ACCOUNT=
ACTUAL_ACCOUNT=

EDENRED_ACCOUNT_1=
ACTUAL_ACCOUNT_1=
EDENRED_ACCOUNT_2=
ACTUAL_ACCOUNT_2=
# ...

ACTUAL_SERVER_URL="server url"
ACTUAL_SERVER_PASSWORD="server password"
Expand Down
12 changes: 8 additions & 4 deletions README.Docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ services:
- EDENRED_USERNAME=
- EDENRED_PIN=
- EDENRED_VERSION= # default 4.1.0
- EDENRED_ACCOUNT_MAP=comma separated vlue (Both EDENRED_ACCOUNT_MAP and ACTUAL_ACCOUNT_MAP need to have the same size)
- ACTUAL_ACCOUNT_MAP=#comma separated vlue
- EDENRED_ACCOUNT=
- ACTUAL_ACCOUNT=
- EDENRED_ACCOUNT_1=
- ACTUAL_ACCOUNT_1=
- ACTUAL_SERVER_URL=
- ACTUAL_SERVER_PASSWORD=
- ACTUAL_SYNC_ID=
Expand All @@ -31,8 +33,10 @@ docker run -d --name myedenredactual \
- e 'EDENRED_USERNAME=' \
- e 'EDENRED_PIN=' \
- e 'EDENRED_VERSION=' \
- e 'EDENRED_ACCOUNT_MAP=' \
- e 'ACTUAL_ACCOUNT_MAP=' \
- e 'EDENRED_ACCOUNT=' \
- e 'ACTUAL_ACCOUNT=' \
- e 'EDENRED_ACCOUNT_1=' \
- e 'ACTUAL_ACCOUNT_1=' \
- e 'ACTUAL_SERVER_URL= ' \
- e 'ACTUAL_SERVER_PASSWORD=' \
- e 'ACTUAL_SYNC_ID=' \
Expand Down
33 changes: 22 additions & 11 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,45 @@ const EDENRED_VERSION = process.env.EDENRED_VERSION || "4.1.0";

const EDENRED_USERNAME = process.env.EDENRED_USERNAME || "";
const EDENRED_PIN = process.env.EDENRED_PIN || "";
const EDENRED_ACCOUNT_MAP = process.env.EDENRED_ACCOUNT_MAP || "";
const ACTUAL_ACCOUNT_MAP = process.env.ACTUAL_ACCOUNT_MAP || "";
const EDENRED_ACCOUNT = process.env.EDENRED_ACCOUNT || "";
const ACTUAL_ACCOUNT = process.env.ACTUAL_ACCOUNT || "";
const CRON_EXPRESSION = process.env.CRON_EXPRESSION || "";
const ACTUAL_SYNC_ID = process.env.ACTUAL_SYNC_ID || "";


function getAppConfigFromEnv() {
var EDENRED_ACCOUNT_MAPPING = {}
var ACTUAL_ACCOUNT_MAPPING = {}
var edenredSplit = EDENRED_ACCOUNT_MAP.split(',');
var actualSplit = ACTUAL_ACCOUNT_MAP.split(',');
if (edenredSplit.length != actualSplit.length) {
throw new Error(`Invalid accounts configs`);
if (!EDENRED_ACCOUNT){
throw new Error(`Missing environment variable: EDENRED_ACCOUNT`);
}
for (var i = 0; i < edenredSplit.length; i++) {
EDENRED_ACCOUNT_MAPPING[edenredSplit[i]] = actualSplit[i];
ACTUAL_ACCOUNT_MAPPING[actualSplit[i]] = edenredSplit[i];

if (!ACTUAL_ACCOUNT){
throw new Error(`Missing environment variable: ACTUAL_ACCOUNT`);
}

EDENRED_ACCOUNT_MAPPING[EDENRED_ACCOUNT] = ACTUAL_ACCOUNT
ACTUAL_ACCOUNT_MAPPING[ACTUAL_ACCOUNT] = EDENRED_ACCOUNT

var i = 1;
while(true){
edenred = process.env[`EDENRED_ACCOUNT_${i}`] || ""
actualSplit = process.env[`ACTUAL_ACCOUNT_${i}`] || ""
if (!edenred || !actualSplit) {
break;
}
i++;
EDENRED_ACCOUNT_MAPPING[edenred] = actualSplit;
ACTUAL_ACCOUNT_MAPPING[actualSplit] = edenred;
}
const appConfig = {
APP_PORT,
APP_URL,
EDENRED_USERNAME,
EDENRED_PIN,
EDENRED_VERSION,
EDENRED_ACCOUNT_MAP,
ACTUAL_ACCOUNT_MAPPING,
EDENRED_ACCOUNT_MAPPING,
ACTUAL_ACCOUNT_MAP,
ACTUAL_SERVER_URL,
ACTUAL_SERVER_PASSWORD,
ACTUAL_SYNC_ID,
Expand Down
6 changes: 4 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ services:
- EDENRED_USERNAME=
- EDENRED_PIN=
- EDENRED_VERSION= # default 4.1.0
- EDENRED_ACCOUNT_MAP= #comma separated vlue (Both EDENRED_ACCOUNT_MAP and ACTUAL_ACCOUNT_MAP need to have the same size)
- ACTUAL_ACCOUNT_MAP= #comma separated vlue
- EDENRED_ACCOUNT=
- ACTUAL_ACCOUNT=
- EDENRED_ACCOUNT_1=
- ACTUAL_ACCOUNT_1=
- ACTUAL_SERVER_URL=
- ACTUAL_SERVER_PASSWORD=
- ACTUAL_SYNC_ID=
Expand Down

0 comments on commit 9d1a8b5

Please sign in to comment.