From 461cccc61242c65575677f54ceb784ac6ce4d026 Mon Sep 17 00:00:00 2001 From: Richard Peters Date: Thu, 19 Dec 2024 09:12:07 +0100 Subject: [PATCH] Optionally read options from environment --- Dockerfile.flex | 2 +- postmaster/flex/Main.cpp | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Dockerfile.flex b/Dockerfile.flex index 3d5f3ab..bee1710 100644 --- a/Dockerfile.flex +++ b/Dockerfile.flex @@ -10,7 +10,7 @@ COPY . /workspace RUN cmake --preset flex \ && cmake --build --preset flex -RUN apt-get update && apt-get install net-tools +RUN apt-get update && apt-get install -y --no-install-recommends net-tools FROM scratch diff --git a/postmaster/flex/Main.cpp b/postmaster/flex/Main.cpp index 368d682..4c0242e 100644 --- a/postmaster/flex/Main.cpp +++ b/postmaster/flex/Main.cpp @@ -11,6 +11,7 @@ #include "services/network_instantiations/NetworkAdapter.hpp" #include "services/tracer/GlobalTracer.hpp" #include "services/tracer/TracerOnIoOutputInfrastructure.hpp" +#include int main(int argc, const char* argv[], const char* env[]) { @@ -24,7 +25,17 @@ int main(int argc, const char* argv[], const char* env[]) try { - parser.ParseCLI(argc, argv); + std::string firmwareArg = std::getenv("POSTMASTER_FIRMWARE"); + std::string urlArg = std::getenv("POSTMASTER_IP"); + std::string passwordArg = std::getenv("POSTMASTER_PASSWORD"); + + if (firmwareArg.empty() && urlArg.empty()) + { + parser.ParseCLI(argc, argv); + firmwareArg = args::get(firmwareArgument); + urlArg = args::get(urlArgument); + passwordArg = args::get(passwordArgument); + } static hal::TimerServiceGeneric timerService; static hal::SynchronousRandomDataGeneratorGeneric randomDataGenerator; @@ -32,15 +43,15 @@ int main(int argc, const char* argv[], const char* env[]) static main_::NetworkAdapter network; static hal::FileSystemGeneric fileSystem; - static auto firmware = firmwareArgument ? fileSystem.ReadBinaryFile(args::get(firmwareArgument)) : std::vector{}; + static auto firmware = !firmwareArg.empty() ? fileSystem.ReadBinaryFile(firmwareArg) : std::vector{}; static services::HttpClientConnectorWithNameResolverImpl<> connector(network.ConnectionFactoryWithNameResolver()); - static infra::BoundedString::WithStorage<512> httpUrl{ args::get(urlArgument) }; - static infra::BoundedString::WithStorage<512> webSocketUrl{ args::get(urlArgument) }; + static infra::BoundedString::WithStorage<512> httpUrl{ urlArg }; + static infra::BoundedString::WithStorage<512> webSocketUrl{ urlArg }; static application::EchoWebSocketClientFactory webSocketFactory(webSocketUrl, 80, network.ConnectionFactory(), tracer.tracer); static services::HttpClientWebSocketInitiation webSocketInitiation(webSocketFactory, connector, webSocketFactory, randomDataGenerator, services::noAutoConnect); - static application::HttpClientAuthenticationDigest::WithMaxHeaders<10> clientAuthentication{ args::get(passwordArgument), randomDataGenerator }; + static application::HttpClientAuthenticationDigest::WithMaxHeaders<10> clientAuthentication{ passwordArg, randomDataGenerator }; static services::HttpClientAuthenticationConnector clientAuthenticationConnector{ connector, clientAuthentication }; static application::FlexHttpClient httpClient(httpUrl, 80, clientAuthenticationConnector, firmware, webSocketInitiation, tracer.tracer);