mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-04 05:04:22 -07:00
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:
parent
db80504839
commit
d303c0706c
1 changed files with 13 additions and 8 deletions
|
@ -94,15 +94,15 @@ class CallbackModule(CallbackBase):
|
||||||
|
|
||||||
super(CallbackModule, self).set_options(task_keys=task_keys, var_options=var_options, direct=direct)
|
super(CallbackModule, self).set_options(task_keys=task_keys, var_options=var_options, direct=direct)
|
||||||
|
|
||||||
self.FOREMAN_URL = self._plugin_options['url']
|
self.FOREMAN_URL = self.get_option('url')
|
||||||
self.FOREMAN_SSL_CERT = (self._plugin_options['ssl_cert'], self._plugin_options['ssl_key'])
|
self.FOREMAN_SSL_CERT = (self.get_option['ssl_cert'], self.get_option['ssl_key'])
|
||||||
self.FOREMAN_SSL_VERIFY = self._plugin_options['verify_certs']
|
self.FOREMAN_SSL_VERIFY = str(self.get_option['verify_certs'])
|
||||||
|
|
||||||
|
self.ssl_verify = self._ssl_verify()
|
||||||
|
|
||||||
if HAS_REQUESTS:
|
if HAS_REQUESTS:
|
||||||
requests_major = int(requests.__version__.split('.')[0])
|
requests_major = int(requests.__version__.split('.')[0])
|
||||||
if requests_major >= 2:
|
if requests_major < 2:
|
||||||
self.ssl_verify = self._ssl_verify()
|
|
||||||
else:
|
|
||||||
self._disable_plugin('The `requests` python module is too old.')
|
self._disable_plugin('The `requests` python module is too old.')
|
||||||
else:
|
else:
|
||||||
self._disable_plugin('The `requests` python module is not installed.')
|
self._disable_plugin('The `requests` python module is not installed.')
|
||||||
|
@ -116,7 +116,10 @@ class CallbackModule(CallbackBase):
|
||||||
|
|
||||||
def _disable_plugin(self, msg):
|
def _disable_plugin(self, msg):
|
||||||
self.disabled = True
|
self.disabled = True
|
||||||
|
if msg:
|
||||||
self._display.warning(msg + ' Disabling the Foreman callback plugin.')
|
self._display.warning(msg + ' Disabling the Foreman callback plugin.')
|
||||||
|
else:
|
||||||
|
self._display.warning('Disabling the Foreman callback plugin.')
|
||||||
|
|
||||||
def _ssl_verify(self):
|
def _ssl_verify(self):
|
||||||
if self.FOREMAN_SSL_VERIFY.lower() in ["1", "true", "on"]:
|
if self.FOREMAN_SSL_VERIFY.lower() in ["1", "true", "on"]:
|
||||||
|
@ -157,8 +160,10 @@ class CallbackModule(CallbackBase):
|
||||||
source, msg = entry
|
source, msg = entry
|
||||||
if 'failed' in msg:
|
if 'failed' in msg:
|
||||||
level = 'err'
|
level = 'err'
|
||||||
|
elif 'changed' in msg and msg['changed']:
|
||||||
|
level = 'notice'
|
||||||
else:
|
else:
|
||||||
level = 'notice' if 'changed' in msg and msg['changed'] else 'info'
|
level = 'info'
|
||||||
logs.append({
|
logs.append({
|
||||||
"log": {
|
"log": {
|
||||||
'sources': {
|
'sources': {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue