From 1f9b62dd133d442d66ef5d3ed6a8cd3ad6da5f7b Mon Sep 17 00:00:00 2001 From: Mustafa Baser Date: Thu, 5 May 2022 19:18:32 +0300 Subject: [PATCH] feat: jans-cli obtain list of attrbiutes from server when creating user --- jans-cli/cli/config_cli.py | 59 +++++++++++++++++++++++++++++++------- jans-cli/cli/enums.json | 7 +++++ 2 files changed, 56 insertions(+), 10 deletions(-) mode change 100644 => 100755 jans-cli/cli/config_cli.py create mode 100644 jans-cli/cli/enums.json diff --git a/jans-cli/cli/config_cli.py b/jans-cli/cli/config_cli.py old mode 100644 new mode 100755 index da9e037c5b8..a28519ad0a8 --- a/jans-cli/cli/config_cli.py +++ b/jans-cli/cli/config_cli.py @@ -300,6 +300,13 @@ def __init__(self, host, client_id, client_secret, access_token, test_client=Fal self.cfg_yml = self.get_yaml() self.make_menu() self.current_menu = self.menu + self.enums() + + def enums(self): + self.enum_dict = {} + enum_json = Path(os.path.join(cur_dir, 'enums.json')) + if enum_json.is_file(): + self.enum_dict = json.loads(enum_json.read_text()) def set_user(self): @@ -1013,21 +1020,23 @@ def tabular_data(self, data, ome): print(tabulate(tab_data, headers, tablefmt="grid")) - def process_get(self, endpoint, return_value=False): + def process_get(self, endpoint, return_value=False, parameters={}): clear() - title = endpoint.name - if endpoint.name != endpoint.info['description'].strip('.'): - title += '\n' + endpoint.info['description'] + if not return_value: + title = endpoint.name + if endpoint.name != endpoint.info['description'].strip('.'): + title += '\n' + endpoint.info['description'] - self.print_underlined(title) + self.print_underlined(title) - parameters = self.obtain_parameters(endpoint, single=return_value) + if not parameters: + parameters = self.obtain_parameters(endpoint, single=return_value) - for param in parameters.copy(): - if not parameters[param]: - del parameters[param] + for param in parameters.copy(): + if not parameters[param]: + del parameters[param] - if parameters: + if parameters and not return_value: print("Calling Api with parameters:", parameters) print("Please wait while retreiving data ...\n") @@ -1169,7 +1178,37 @@ def get_swagger_types(self, model, name): if model.swagger_types[attribute] == name: return attribute + def get_attrib_list(self): + for parent in self.menu: + for children in parent: + if children.info['operationId'] == 'get-attributes': + attributes = self.process_get(children, return_value=True, parameters={'limit': 1000} ) + attrib_names = [] + for a in attributes: + attrib_names.append(a.name) + attrib_names.sort() + return attrib_names + + def get_enum(self, schema): + if schema['__schema_name__'] in self.enum_dict: + enum_obj = schema + + for path in self.enum_dict[schema['__schema_name__']].copy(): + for p in path.split('.'): + enum_obj = enum_obj[p] + + if not 'enum' in self.enum_dict[schema['__schema_name__']][path]: + self.enum_dict[schema['__schema_name__']][path]['enum'] = getattr(self, self.enum_dict[schema['__schema_name__']][path]['f'])() + + enum_obj['enum'] = self.enum_dict[schema['__schema_name__']][path]['enum'] + + def get_input_for_schema_(self, schema, model, spacing=0, initialised=False, getitem=None, required_only=False): + #print(self.current_menu, self.current_menu.path) + #print(schema) + #input("enter: ") + self.get_enum(schema) + data = {} for prop in schema['properties']: item = schema['properties'][prop] diff --git a/jans-cli/cli/enums.json b/jans-cli/cli/enums.json new file mode 100644 index 00000000000..230f73e633e --- /dev/null +++ b/jans-cli/cli/enums.json @@ -0,0 +1,7 @@ +{ + "CustomAttribute": { + "properties.name": { + "f": "get_attrib_list" + } + } +} \ No newline at end of file