]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Adding configuration for get-forge-modules
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 23 Aug 2018 10:31:08 +0000 (12:31 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 23 Aug 2018 10:31:08 +0000 (12:31 +0200)
get-forge-modules.yaml [new file with mode: 0644]
hooks.yaml
lib/webhooks/get_forge_modules.py

diff --git a/get-forge-modules.yaml b/get-forge-modules.yaml
new file mode 100644 (file)
index 0000000..f6cf1ba
--- /dev/null
@@ -0,0 +1,6 @@
+---
+
+puppet_env_dir: '/etc/puppetlabs/code/environments'
+forge_uri: 'https://forgeapi.puppet.com/v3/modules'
+http_timeout: 20
+
index 4ca24c019d56cbe7639523842563a8a005359f28..784790265bf6a7a780c2e1034e38c45d5f2f00de 100644 (file)
@@ -8,3 +8,4 @@ smtp_server: 'localhost'
 smtp_port: 25
 mail_cc_addresses: []
 sender_address: 'Puppetmaster <puppetmaster@pixelpark.com>'
+data_dir: '/var/lib/webhooks'
index 328911c1e8ddd006304c220475eccdf5a18c2c79..e52a58ba5283ba86b2e8d28e0aa467bceb4938e4 100644 (file)
@@ -48,6 +48,7 @@ class GetForgeModulesApp(BaseHookApp):
     default_forge_uri = 'https://forgeapi.puppet.com/v3/modules'
     default_puppet_root_env_dir = os.sep + os.path.join('etc', 'puppetlabs', 'code', 'environments')
     default_http_timeout = 30
+    max_http_timeout = 600
 
     open_args = {}
     if six.PY3:
@@ -63,6 +64,8 @@ class GetForgeModulesApp(BaseHookApp):
         self.cache_file  = None
         self.environments = []
         self.puppet_root_env_dir = self.default_puppet_root_env_dir
+        self.forge_uri = self.default_forge_uri
+        self.http_timeout = self.default_http_timeout
 
         self.description = textwrap.dedent('''\
             Collects information about all used Puppet Modules from {url}
@@ -95,6 +98,7 @@ class GetForgeModulesApp(BaseHookApp):
 
         res['default_forge_uri'] = self.default_forge_uri
         res['default_http_timeout'] = self.default_http_timeout
+        res['max_http_timeout'] = self.max_http_timeout
         res['default_puppet_root_env_dir'] = self.default_puppet_root_env_dir
         res['open_args'] = self.open_args
 
@@ -108,7 +112,7 @@ class GetForgeModulesApp(BaseHookApp):
         if 'puppet_env_dir' in config and config['puppet_env_dir']:
             path = config['puppet_env_dir']
             if os.path.isabs(path):
-                self.puppet_root_env_dir = os.path.normapath(path)
+                self.puppet_root_env_dir = os.path.normpath(path)
             else:
                 msg = (
                     "Path for the Puppet environments {p!r} must be "
@@ -116,6 +120,21 @@ class GetForgeModulesApp(BaseHookApp):
                     p=path, f=yaml_file)
                 self.error_data.append(msg)
 
+        if 'forge_uri' in config and config['forge_uri'] and str(config['forge_uri']).strip():
+            self.forge_uri = str(config['forge_uri']).strip()
+
+        if 'http_timeout' in config and config['http_timeout']:
+            msg = "Invalid HTTP timeout {t!r} in {f!r} found.".format(
+                t=config['http_timeout'], f=yaml_file)
+            try:
+                http_timeout = int(config['http_timeout'])
+                if http_timeout > 0 and http_timeout < self.max_http_timeout:
+                    self.http_timeout = http_timeout
+                else:
+                    self.error_data.append(msg)
+            except ValueError:
+                self.error_data.append(msg)
+
     # -------------------------------------------------------------------------
     def run(self):
         """Main routine."""