From ccaacc8ae564e8f2ef5fd91134bc1c6512634bd5 Mon Sep 17 00:00:00 2001 From: Devrim Date: Mon, 3 Oct 2022 13:31:00 +0300 Subject: [PATCH] fix: jans-cli fixes (#2515) * fix: jans-cli user list * fix: get endpoint params from json rather that path (ref: #2516 #2336) --- jans-cli/cli/config_cli.py | 54 +++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/jans-cli/cli/config_cli.py b/jans-cli/cli/config_cli.py index 4350c67eeab..039f79f93ee 100755 --- a/jans-cli/cli/config_cli.py +++ b/jans-cli/cli/config_cli.py @@ -18,6 +18,7 @@ import ast import base64 import pprint +import copy from pathlib import Path from types import SimpleNamespace @@ -484,13 +485,24 @@ def get_methods_of_tag(tag): if tag: for path_name in self.cfg_yml['paths']: path = self.cfg_yml['paths'][path_name] + path_parameters = [] + if 'parameters' in path: + for pparam in path['parameters']: + if pparam.get('in') == 'path': + path_parameters.append(dict(pparam)) + for method_name in path: method = path[method_name] + + + if hasattr(method, 'get') and method.get('operationId') in excluded_operations[my_op_mode]: continue if 'tags' in method and tag in method['tags'] and 'operationId' in method: if method.get('x-cli-plugin') and method['x-cli-plugin'] not in plugins: continue + if path_parameters: + method['__path_parameters__'] = path_parameters method['__method_name__'] = method_name method['__path_name__'] = path_name methods.append(method) @@ -996,9 +1008,12 @@ def obtain_parameters(self, endpoint, single=False): if 'parameters' in endpoint.info: endpoint_parameters = endpoint.info['parameters'] - end_point_param = self.get_endpiont_url_param(endpoint) - if end_point_param and not end_point_param in endpoint_parameters: - endpoint_parameters.insert(0, end_point_param) + + if '__path_parameters__' in endpoint.info: + end_point_param = endpoint.info['__path_parameters__'][0] + + if end_point_param and not end_point_param in endpoint_parameters: + endpoint_parameters.insert(0, end_point_param) n = 1 if single else len(endpoint_parameters) @@ -1193,9 +1208,12 @@ def process_get(self, endpoint, return_value=False, parameters=None): api_response_unmapped = data_dict op_mode_endpoint = my_op_mode + '.' + endpoint.info['operationId'] - import copy + if op_mode_endpoint in tabulate_endpoints: api_response_unmapped_ext = copy.deepcopy(api_response_unmapped) + if 'entries' in api_response_unmapped_ext: + api_response_unmapped_ext = api_response_unmapped_ext['entries'] + if endpoint.info['operationId'] == 'get-user': for entry in api_response_unmapped_ext: if entry.get('customAttributes'): @@ -1205,10 +1223,6 @@ def process_get(self, endpoint, return_value=False, parameters=None): elif attrib['name'] in tabulate_endpoints[op_mode_endpoint]: entry[attrib['name']] = attrib['values'][0] - - if 'entries' in api_response_unmapped_ext: - api_response_unmapped_ext = api_response_unmapped_ext['entries'] - if endpoint.info['operationId'] == 'get-oauth-openid-clients': for entry in api_response_unmapped_ext: for custom_attrib in entry.get('customAttributes', []): @@ -1526,12 +1540,34 @@ def process_post(self, endpoint): selection = 'y' model = None + + path_vals = {} + if '__path_parameters__' in endpoint.info: + for pparam in endpoint.info['__path_parameters__']: + swagger_var = self.make_swagger_var(pparam['name']) + path_vals[swagger_var] = self.get_input( + values=pparam['schema'].get('enum', []), + text=pparam['name'], + itype=pparam['schema']['type'], + help_text= pparam.get('description'), + enforce='__true__', + ) + + if selection == 'y': api_caller = self.get_api_caller(endpoint) print("Please wait while posting data ...\n") try: - api_response = api_caller(body=model) if model else api_caller() + if model: + if path_vals: + api_response = api_caller(**path_vals, body=model) + else: + api_response = api_caller(body=model) + + else: + api_response = api_caller(**path_vals) + except Exception as e: api_response = None self.print_exception(e)