From 6a779feeeb2050178a5f22b7b1e4322feec151e2 Mon Sep 17 00:00:00 2001 From: Daniel Zinov Date: Fri, 28 Jan 2022 21:55:57 +0000 Subject: [PATCH] support body argument and response in other formats than json --- alcli/alertlogic_cli.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/alcli/alertlogic_cli.py b/alcli/alertlogic_cli.py index 4b5bcf4..8640288 100755 --- a/alcli/alertlogic_cli.py +++ b/alcli/alertlogic_cli.py @@ -199,7 +199,9 @@ def __call__(self, args, parsed_globals): # Remove optional arguments that haven't been supplied op_args = {k:self._encode(operation, k, v) for (k,v) in kwargs.items() if v is not None} res = operation(**op_args) - if res.headers.get('content-type') == 'text/plain': + content_type = res.headers.get('content-type') + json_content_types = ['application/json', 'alertlogic/json'] + if content_type and content_type not in json_content_types: print(res.text) else: try: @@ -307,7 +309,10 @@ def _encode(self, operation, param_name, param_value): (m.groupdict()['key'], m.groupdict()['value']) for m in regex.finditer(param_value) ) - return result + if result: + return result + else: + return param_value # TODO Raise an exception if we can't build a dictionary from the provided input return param_value