From a44cddea83ccd7462bfe57d9e9e2bbd84f83cc72 Mon Sep 17 00:00:00 2001 From: Daniel Chaffelson Date: Thu, 7 Oct 2021 22:19:04 +0100 Subject: [PATCH 1/2] Add configurable user agent for CDPCLI interface Add property client_name to cdpy instantiation for configurable user-agent prefix for various downstream clients, with default of CDPY Add CDPY and version to the user agent for convenient identification Set cloudera.cloud to client_name of 'ClouderaFoundry' Signed-off-by: Daniel Chaffelson --- plugins/module_utils/cdp_common.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/module_utils/cdp_common.py b/plugins/module_utils/cdp_common.py index b1d43a2a..6092f407 100644 --- a/plugins/module_utils/cdp_common.py +++ b/plugins/module_utils/cdp_common.py @@ -60,8 +60,14 @@ def __init__(self, module): self.changed = False # Client Wrapper - self.cdpy = Cdpy(debug=self.debug, tls_verify=self.tls, strict_errors=self.strict, - error_handler=self._cdp_module_throw_error, warning_handler=self._cdp_module_throw_warning) + self.cdpy = Cdpy( + debug=self.debug, + tls_verify=self.tls, + strict_errors=self.strict, + error_handler=self._cdp_module_throw_error, + warning_handler=self._cdp_module_throw_warning, + client_name='ClouderaFoundry' + ) # Private functions From 08397636e38d0df9bdf09a621900ba244cae9628 Mon Sep 17 00:00:00 2001 From: Daniel Chaffelson Date: Fri, 8 Oct 2021 09:44:41 +0100 Subject: [PATCH 2/2] Use 'agent_header' instead of 'client_name' for user agent to be more specific Add as configurable default property in Ansible module for testing purposes Signed-off-by: Daniel Chaffelson --- plugins/module_utils/cdp_common.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/module_utils/cdp_common.py b/plugins/module_utils/cdp_common.py index 6092f407..c61e8724 100644 --- a/plugins/module_utils/cdp_common.py +++ b/plugins/module_utils/cdp_common.py @@ -53,6 +53,7 @@ def __init__(self, module): self.tls = self._get_param('verify_tls', False) self.debug = self._get_param('debug', False) self.strict = self._get_param('strict', False) + self.agent_header = self._get_param('agent_header', 'ClouderaFoundry') # Initialize common return values self.log_out = None @@ -66,7 +67,7 @@ def __init__(self, module): strict_errors=self.strict, error_handler=self._cdp_module_throw_error, warning_handler=self._cdp_module_throw_warning, - client_name='ClouderaFoundry' + client_name=self.agent_header ) # Private functions @@ -94,4 +95,5 @@ def argument_spec(**spec): verify_tls=dict(required=False, type='bool', default=True, aliases=['tls']), debug=dict(required=False, type='bool', default=False, aliases=['debug_endpoints']), strict=dict(required=False, type='bool', default=False, aliases=['strict_errors']), + agent_header=dict(required=False, type='str', default='ClouderaFoundry') )