From 91ba58c4c87fc0a472a6372b889ef7337e516cc6 Mon Sep 17 00:00:00 2001 From: Ignasi Barrera Date: Fri, 9 Feb 2024 18:16:22 +0100 Subject: [PATCH] Properly validate configuration --- Makefile | 2 +- internal/config.go | 9 ++++++++- internal/testdata/mock.json | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 16dcc0f..e7f202f 100644 --- a/Makefile +++ b/Makefile @@ -102,7 +102,7 @@ config/lint: ## Lint the Config Proto generated code test: ## Run all the tests @go test $(TEST_OPTS) $(TEST_PKGS) -COVERAGE_OPTS ?= +COVERAGE_OPTS ?= .PHONY: coverage coverage: ## Creates coverage report for all projects @echo "Running test coverage" diff --git a/internal/config.go b/internal/config.go index 2219d70..0a3440f 100644 --- a/internal/config.go +++ b/internal/config.go @@ -57,5 +57,12 @@ func (l *LocalConfigFile) Validate() error { return err } - return protojson.Unmarshal(content, &l.Config) + if err = protojson.Unmarshal(content, &l.Config); err != nil { + return err + } + + // Set reasonable defaults for non-supported values + l.Config.Threads = 1 + + return l.Config.Validate() } diff --git a/internal/testdata/mock.json b/internal/testdata/mock.json index eee0934..45f6b2e 100644 --- a/internal/testdata/mock.json +++ b/internal/testdata/mock.json @@ -1,4 +1,6 @@ { + "listen_address": "0.0.0.0", + "listen_port": 8080, "log_level": "debug", "chains": [ {