Skip to content

Commit

Permalink
Optionally read options from environment
Browse files Browse the repository at this point in the history
  • Loading branch information
richardapeters committed Dec 19, 2024
1 parent 71f7105 commit 461cccc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.flex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 16 additions & 5 deletions postmaster/flex/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "services/network_instantiations/NetworkAdapter.hpp"
#include "services/tracer/GlobalTracer.hpp"
#include "services/tracer/TracerOnIoOutputInfrastructure.hpp"
#include <cstdlib>

int main(int argc, const char* argv[], const char* env[])
{
Expand All @@ -24,23 +25,33 @@ 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;
static main_::TracerOnIoOutputInfrastructure tracer;
static main_::NetworkAdapter network;
static hal::FileSystemGeneric fileSystem;

static auto firmware = firmwareArgument ? fileSystem.ReadBinaryFile(args::get(firmwareArgument)) : std::vector<uint8_t>{};
static auto firmware = !firmwareArg.empty() ? fileSystem.ReadBinaryFile(firmwareArg) : std::vector<uint8_t>{};

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);

Expand Down

0 comments on commit 461cccc

Please sign in to comment.