Make the foreman callback more defensive (#36527)

* Foreman: Make the foreman callback more defensive

This ensures the ssl_verify attribute is always set. It also handles
None in _disable_plugin.

* Foreman: Handle ints in verify_certs

The default value for verify_certs is 1 which is an int. That has no
lower() function. By casting it to a str we can handle it later in
_ssl_verify().

* Foreman: Clean up coding style

* Foreman: Use get_option in favor of _plugin_options
This commit is contained in:
Ewoud Kohl van Wijngaarden 2018-04-12 15:58:57 +02:00 committed by Brian Coca
parent db80504839
commit d303c0706c

View file

@ -94,15 +94,15 @@ class CallbackModule(CallbackBase):
super(CallbackModule, self).set_options(task_keys=task_keys, var_options=var_options, direct=direct)
self.FOREMAN_URL = self._plugin_options['url']
self.FOREMAN_SSL_CERT = (self._plugin_options['ssl_cert'], self._plugin_options['ssl_key'])
self.FOREMAN_SSL_VERIFY = self._plugin_options['verify_certs']
self.FOREMAN_URL = self.get_option('url')
self.FOREMAN_SSL_CERT = (self.get_option['ssl_cert'], self.get_option['ssl_key'])
self.FOREMAN_SSL_VERIFY = str(self.get_option['verify_certs'])
self.ssl_verify = self._ssl_verify()
if HAS_REQUESTS:
requests_major = int(requests.__version__.split('.')[0])
if requests_major >= 2:
self.ssl_verify = self._ssl_verify()
else:
if requests_major < 2:
self._disable_plugin('The `requests` python module is too old.')
else:
self._disable_plugin('The `requests` python module is not installed.')
@ -116,7 +116,10 @@ class CallbackModule(CallbackBase):
def _disable_plugin(self, msg):
self.disabled = True
self._display.warning(msg + ' Disabling the Foreman callback plugin.')
if msg:
self._display.warning(msg + ' Disabling the Foreman callback plugin.')
else:
self._display.warning('Disabling the Foreman callback plugin.')
def _ssl_verify(self):
if self.FOREMAN_SSL_VERIFY.lower() in ["1", "true", "on"]:
@ -157,8 +160,10 @@ class CallbackModule(CallbackBase):
source, msg = entry
if 'failed' in msg:
level = 'err'
elif 'changed' in msg and msg['changed']:
level = 'notice'
else:
level = 'notice' if 'changed' in msg and msg['changed'] else 'info'
level = 'info'
logs.append({
"log": {
'sources': {