From be1754ea6cc3e51e55f57e60968344c0216ae29b Mon Sep 17 00:00:00 2001
From: Lubomir Bucek <lubomir.bucek@eox.at>
Date: Mon, 28 Sep 2020 14:27:57 +0200
Subject: [PATCH] disable preprocessor debug by default, make it configurable

---
 preprocessor/Dockerfile          |  9 ++++++---
 preprocessor/preprocessor/cli.py | 11 +++++++----
 preprocessor/run-preprocessor.sh |  7 ++++++-
 3 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/preprocessor/Dockerfile b/preprocessor/Dockerfile
index a081f9a9..1d3cb90f 100644
--- a/preprocessor/Dockerfile
+++ b/preprocessor/Dockerfile
@@ -25,7 +25,6 @@
 # IN THE SOFTWARE.
 #-----------------------------------------------------------------------------
 
-# FROM osgeo/gdal:ubuntu-full-latest
 FROM osgeo/gdal:ubuntu-full-3.1.2
 
 MAINTAINER EOX
@@ -51,22 +50,26 @@ ENV INSTANCE_ID="prism-data-access-server_preprocessor" \
     COLLECTION= \
     UPLOAD_CONTAINER= \
     ST_AUTH_VERSION=3 \
-    OS_AUTH_URL="https://auth.cloud.ovh.net/v3/" \
+    OS_AUTH_URL= \
     OS_USERNAME= \
     OS_PASSWORD= \
     OS_TENANT_NAME= \
     OS_TENANT_ID= \
     OS_REGION_NAME= \
+    OS_USER_DOMAIN_NAME= \
     OS_AUTH_URL_DOWNLOAD= \
     ST_AUTH_VERSION_DOWNLOAD= \
     OS_USERNAME_DOWNLOAD= \
     OS_PASSWORD_DOWNLOAD= \
     OS_TENANT_NAME_DOWNLOAD= \
     OS_REGION_NAME_DOWNLOAD= \
+    OS_USER_DOMAIN_NAME_DOWNLOAD= \
     REDIS_HOST= \
     REDIS_PORT= \
     REDIS_PREPROCESS_QUEUE_KEY= \
-    REDIS_REGISTER_QUEUE_KEY=
+    REDIS_PREPROCESS_MD_QUEUE_KEY= \
+    REDIS_REGISTER_QUEUE_KEY= \
+    PREPROCESSOR_DEBUG= 
 
 ADD run-preprocessor.sh \
     entrypoint.sh \
diff --git a/preprocessor/preprocessor/cli.py b/preprocessor/preprocessor/cli.py
index fdd51ff1..9836ffdc 100644
--- a/preprocessor/preprocessor/cli.py
+++ b/preprocessor/preprocessor/cli.py
@@ -43,7 +43,7 @@ def validate_config(config):
 
 @click.group()
 def cli():
-    setup_logging(True)
+    pass
 
 
 @cli.command(help='Run the preprocess daemon, attaching to a Redis queue')
@@ -55,7 +55,9 @@ def cli():
 @click.option('--listen-queue', type=str)
 @click.option('--listen-md-queue', type=str)
 @click.option('--write-queue', type=str)
-def daemon(config_file=None, use_dir=None, validate=False, host=None, port=None, listen_queue=None, listen_md_queue=None, write_queue=None):
+@click.option('--debug/--no-debug', default=False)
+def daemon(config_file=None, use_dir=None, validate=False, host=None, port=None, listen_queue=None, listen_md_queue=None, write_queue=None, debug=False):
+    setup_logging(debug)
     config = load_config(config_file)
     if validate:
         validate_config(config)
@@ -68,7 +70,9 @@ def daemon(config_file=None, use_dir=None, validate=False, host=None, port=None,
 @click.option('--use-dir', type=str) # TODO: check dir
 @click.option('--validate/--no-validate', default=False)
 @click.option('--browse-report/--no-browse-report', default=False)
-def preprocess(file_path, config_file=None, use_dir=None, validate=False, browse_report=False):
+@click.option('--debug/--no-debug', default=False)
+def preprocess(file_path, config_file=None, use_dir=None, validate=False, browse_report=False, debug=False):
+    setup_logging(debug)
     config = load_config(config_file)
     if validate:
         validate_config(config)
@@ -83,6 +87,5 @@ def preprocess(file_path, config_file=None, use_dir=None, validate=False, browse
     else:
         preprocess_file(config, file_path, use_dir)
 
-
 if __name__ == '__main__':
     cli()
diff --git a/preprocessor/run-preprocessor.sh b/preprocessor/run-preprocessor.sh
index 674cad02..70a8aee6 100644
--- a/preprocessor/run-preprocessor.sh
+++ b/preprocessor/run-preprocessor.sh
@@ -1,6 +1,10 @@
 #!/bin/sh
 
 echo "Running preprocessor"
+debug="--no-debug"
+if test "$PREPROCESSOR_DEBUG" = true; then
+    debug="--debug"
+fi
 
 preprocessor daemon \
     --config-file /config.yaml \
@@ -8,4 +12,5 @@ preprocessor daemon \
     --port ${REDIS_PORT} \
     --listen-queue ${REDIS_PREPROCESS_QUEUE_KEY} \
     --listen-md-queue ${REDIS_PREPROCESS_MD_QUEUE_KEY} \
-    --write-queue ${REDIS_REGISTER_QUEUE_KEY}
+    --write-queue ${REDIS_REGISTER_QUEUE_KEY} \
+    ${debug}
\ No newline at end of file
-- 
GitLab