From 525eb21649d18eeaa4a3dbcfa4ab2d450a356c2b Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Thu, 28 Mar 2024 03:19:15 +0100 Subject: [PATCH] Improve config (json) file creation --- .env | 1 - .gitignore | 19 ++---- Makefile | 19 +++++- config/emgauwa-controller.pkl | 112 +++++++++++++++++----------------- config/emgauwa-core.pkl | 12 ++-- config/lib/common.pkl | 12 ++-- 6 files changed, 91 insertions(+), 84 deletions(-) delete mode 100644 .env diff --git a/.env b/.env deleted file mode 100644 index 2f5ee4c..0000000 --- a/.env +++ /dev/null @@ -1 +0,0 @@ -DATABASE_URL="sqlite://emgauwa-dev.sqlite" diff --git a/.gitignore b/.gitignore index dd13990..8d95db4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,8 @@ -/target/ - -/tests/testing/ -/tests/testing_bak/ -/tests/testing_latest/ - -emgauwa-*.sqlite -emgauwa-*.sqlite-* -emgauwa-*.json - - -# Added by cargo - /target + +/.env /api.http + +/emgauwa-*.sqlite +/emgauwa-*.sqlite-* +/emgauwa-*.json \ No newline at end of file diff --git a/Makefile b/Makefile index 5284844..db699c4 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,13 @@ +ifneq (,$(wildcard ./.env)) + include .env + export +endif + +DATABASE_URL ?= sqlite://emgauwa-dev.sqlite +export DATABASE_URL + sqlx: - cargo sqlx database drop + cargo sqlx database drop -y cargo sqlx database create cargo sqlx migrate run cargo sqlx prepare --workspace @@ -7,9 +15,16 @@ sqlx: build-rpi: cross build --target arm-unknown-linux-gnueabihf -emgauwa-%.json: config/emgauwa-%.pkl config/lib/%.pkl config/lib/common.pkl +emgauwa-%.json: config/emgauwa-%.pkl config/lib/%.pkl config/lib/common.pkl $(wildcard .env) pkl eval -f json -o $@ $< configs: $(MAKE) emgauwa-core.json $(MAKE) emgauwa-controller.json + +clean: + rm -f emgauwa-controller.json + rm -f emgauwa-controller.sqlite + rm -f emgauwa-core.json + rm -f emgauwa-core.sqlite + rm -f emgauwa-dev.sqlite \ No newline at end of file diff --git a/config/emgauwa-controller.pkl b/config/emgauwa-controller.pkl index 70b60cd..04d46bb 100644 --- a/config/emgauwa-controller.pkl +++ b/config/emgauwa-controller.pkl @@ -1,71 +1,71 @@ amends "./lib/controller.pkl" server { - host = "127.0.0.1" - port = 4419 + host = "127.0.0.1" + port = 4419 } database = "sqlite://emgauwa-controller.sqlite" permissions { - user = read("env:USER") - group = read("env:USER") + user = read("env:USER") + group = read("env:USER") } logging { - level = "DEBUG" - file = "stdout" + level = read?("env:LOGGING_LEVEL") ?? "DEBUG" + file = "stdout" } relays { - new { - driver = "gpio" - pin = 5 - inverted = true - } - new { - driver = "gpio" - pin = 4 - inverted = true - } - new { - driver = "gpio" - pin = 3 - inverted = true - } - new { - driver = "gpio" - pin = 2 - inverted = true - } - new { - driver = "gpio" - pin = 1 - inverted = true - } - new { - driver = "gpio" - pin = 0 - inverted = true - } - new { - driver = "gpio" - pin = 16 - inverted = true - } - new { - driver = "gpio" - pin = 15 - inverted = true - } - new { - driver = "piface" - pin = 1 - inverted = false - } - new { - driver = "piface" - pin = 0 - inverted = false - } + new { + driver = "gpio" + pin = 5 + inverted = true + } + new { + driver = "gpio" + pin = 4 + inverted = true + } + new { + driver = "gpio" + pin = 3 + inverted = true + } + new { + driver = "gpio" + pin = 2 + inverted = true + } + new { + driver = "gpio" + pin = 1 + inverted = true + } + new { + driver = "gpio" + pin = 0 + inverted = true + } + new { + driver = "gpio" + pin = 16 + inverted = true + } + new { + driver = "gpio" + pin = 15 + inverted = true + } + new { + driver = "piface" + pin = 1 + inverted = false + } + new { + driver = "piface" + pin = 0 + inverted = false + } } diff --git a/config/emgauwa-core.pkl b/config/emgauwa-core.pkl index b43b11e..188f01c 100644 --- a/config/emgauwa-core.pkl +++ b/config/emgauwa-core.pkl @@ -1,18 +1,18 @@ amends "./lib/core.pkl" server { - host = "127.0.0.1" - port = 4419 + host = "127.0.0.1" + port = 4419 } database = "sqlite://emgauwa-core.sqlite" permissions { - user = read("env:USER") - group = read("env:USER") + user = read("env:USER") + group = read("env:USER") } logging { - level = "DEBUG" - file = "stdout" + level = read?("env:LOGGING_LEVEL") ?? "DEBUG" + file = "stdout" } diff --git a/config/lib/common.pkl b/config/lib/common.pkl index e5bb22e..5d223d0 100644 --- a/config/lib/common.pkl +++ b/config/lib/common.pkl @@ -1,15 +1,15 @@ class ServerConfig { - host: String - port: UInt16 + host: String + port: UInt16 } /// Set to a user and a group to drop privileges to after binding to the port class PermissionsConfig { - user: String - group: String + user: String + group: String } class LoggingConfig { - level: String - file: String + level: "TRACE"|"DEBUG"|"INFO"|"WARN"|"ERROR"|"FATAL" + file: String }