]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Reading in data from STDIN
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 25 Jan 2017 10:03:11 +0000 (11:03 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 25 Jan 2017 10:03:11 +0000 (11:03 +0100)
lib/webhooks/deploy.py

index 641d5ed2a7944b7aff7726fdf376f039297fd618..2f147f16a8643d0727d5ed26b973eea89df76ded 100644 (file)
@@ -14,10 +14,12 @@ import logging
 import re
 import textwrap
 import datetime
+import json
 
 # Own modules
 import webhooks
 
+from webhooks.common import pp
 
 __version__ = webhooks.__version__
 log = logging.getLogger(__name__)
@@ -59,6 +61,9 @@ class WebhookDeployApp(object):
         @type: int
         """
 
+        self.data = None
+        self.json_data = None
+
         self._log_directory = os.sep + os.path.join('var', 'log', 'webhooks')
 
         self.init_logging()
@@ -138,7 +143,7 @@ class WebhookDeployApp(object):
 
         if 'REQUEST_METHOD' in os.environ:
 
-            sys.stderr.write("Trying to open logfile {!r} ...\n".format(self.logfile))
+            #sys.stderr.write("Trying to open logfile {!r} ...\n".format(self.logfile))
             # we are in a CGI environment
             if os.path.isdir(self.log_directory) and os.access(self.log_directory, os.W_OK):
                 lh_file = logging.FileHandler(
@@ -174,7 +179,16 @@ class WebhookDeployApp(object):
         log.info("Starting ...")
         log.debug("Base directory: {!r}".format(self.base_dir))
 
+        self.data = sys.stdin.read()
+        try:
+            self.json_data = json.loads(self.data)
+        except Exception as e:
+            LOG.error("Got a {n} reading input data: {e}".format(n=e.__class__.__name__, e))
+            LOG.error("Input data:\n{}".format(self.data)
+            sys.exit(0)
 
+        LOG.debug("Got data:\n{}".format(pp(self.json_data)))
+        sys.exit(0)
 
 # =============================================================================