Basically, if the function parameter is None, I ignore it, else I concatenate all arguments like arg1:arg1_value AND arg2:arg2_value AND arg4:arg4_value
considering arg3==None
when the function got called.
def _get_query_string_for_get_config(self, host, app_name, instance, config_source, config_name):
query_string = ""
if host is not None:
query_string += "host:{} AND ".format(host)
if app_name is not None:
query_string += "app_name:{} AND ".format(app_name)
if instance is not None:
query_string += "instance:{} AND ".format(instance)
if config_source is not None:
query_string += "config_source:{} AND ".format(config_source)
if config_name is not None:
query_string += "config_name:{}".format(config_name)
return query_string