From 73567d3230e5f9203a44e367d90ec7b99a938ff3 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Wed, 27 Sep 2023 11:36:54 +0200 Subject: [PATCH] change database configuration to env vars --- Dockerfile | 6 ++++++ sink/sink20169.c | 10 +--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7bc7803..ebf1b49 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,12 @@ FROM alpine:3.18.3 AS builder ARG VERSION="dockerized" +ENV PGHOST "" +ENV PGDATABASE "mainscnt" +ENV PGUSER "sink" +ENV PGPASSWORD "" +ENV PGSSLMODE "require" + COPY sink/ /tmp/sink RUN \ diff --git a/sink/sink20169.c b/sink/sink20169.c index 8855709..dac89b0 100644 --- a/sink/sink20169.c +++ b/sink/sink20169.c @@ -47,7 +47,6 @@ typedef struct { int receiveSockFd; int32_t lowerBound; int32_t upperBound; - const char *postgresqlConnInfo; PGconn *conn; t_device foundDevice; } t_commonHandle; @@ -61,7 +60,7 @@ int openDatabaseConnection(t_commonHandle *handle) { if (! handle->conn) { logmsg(LOG_DEBUG, "Opening connection to database"); - handle->conn = PQconnectdb(handle->postgresqlConnInfo); + handle->conn = PQconnectdb(); } else if (PQstatus(handle->conn) != CONNECTION_OK) { logmsg(LOG_DEBUG, "Resetting connection to database"); PQreset(handle->conn); @@ -234,13 +233,6 @@ int receiveAndVerifyMinuteBuffer(t_commonHandle *handle, t_minuteBuffer *buf) { int initForwarder(t_configHandle *configHandle, t_commonHandle *handle) { handle->configHandle = configHandle; - handle->postgresqlConnInfo = NULL; - config_lookup_string(&(configHandle->cfg), "postgresqlConnInfo", &(handle->postgresqlConnInfo)); - if (! handle->postgresqlConnInfo) { - logmsg(LOG_ERR, "no postgresql connInfo configured"); - return -1; - } - handle->conn = NULL; handle->lowerBound = 45000;