From: Frank Brehm Date: Thu, 23 Aug 2018 10:31:08 +0000 (+0200) Subject: Adding configuration for get-forge-modules X-Git-Tag: 0.9.8^2~13 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=19abc34c6d4157145d540e69613efe1ed14fc353;p=pixelpark%2Fpuppetmaster-webhooks.git Adding configuration for get-forge-modules --- diff --git a/get-forge-modules.yaml b/get-forge-modules.yaml new file mode 100644 index 0000000..f6cf1ba --- /dev/null +++ b/get-forge-modules.yaml @@ -0,0 +1,6 @@ +--- + +puppet_env_dir: '/etc/puppetlabs/code/environments' +forge_uri: 'https://forgeapi.puppet.com/v3/modules' +http_timeout: 20 + diff --git a/hooks.yaml b/hooks.yaml index 4ca24c0..7847902 100644 --- a/hooks.yaml +++ b/hooks.yaml @@ -8,3 +8,4 @@ smtp_server: 'localhost' smtp_port: 25 mail_cc_addresses: [] sender_address: 'Puppetmaster ' +data_dir: '/var/lib/webhooks' diff --git a/lib/webhooks/get_forge_modules.py b/lib/webhooks/get_forge_modules.py index 328911c..e52a58b 100644 --- a/lib/webhooks/get_forge_modules.py +++ b/lib/webhooks/get_forge_modules.py @@ -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."""