Skip to content

Commit

Permalink
fix: Jans cli SCIM fixes (#2394)
Browse files Browse the repository at this point in the history
* fix: jans-cli print tabulated data

* fix: jans-cli remove duplicated option in scim-user (ref: #2382)

* fix: jans-cli update fido2 (ref: #2374)

* fix: jans-cli remove unused line

* fix: jans-cli do not ask non-required fields
  • Loading branch information
devrimyatar authored Sep 16, 2022
1 parent d893e13 commit a009943
Showing 1 changed file with 40 additions and 27 deletions.
67 changes: 40 additions & 27 deletions jans-cli/cli/config_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
}

tabular_dataset = {'scim.get-users': 'Resources'}
excluded_operations = {'scim': ['search-user'], 'jca':[]}

my_op_mode = 'scim' if 'scim' in os.path.basename(sys.argv[0]) else 'jca'
sys.path.append(os.path.join(cur_dir, my_op_mode))
Expand All @@ -63,6 +64,7 @@
grey_color = 242

clear = lambda: os.system('clear')

urllib3.disable_warnings()
config = configparser.ConfigParser()

Expand Down Expand Up @@ -478,6 +480,8 @@ def get_methods_of_tag(tag):
path = self.cfg_yml['paths'][path_name]
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
Expand All @@ -489,7 +493,6 @@ def get_methods_of_tag(tag):

menu = Menu('Main Menu')


for grp in menu_groups:
methods = get_methods_of_tag(grp.tag)
m = Menu(name=grp.mname)
Expand Down Expand Up @@ -1022,8 +1025,7 @@ def get_path_by_id(self, operation_id):
retVal = {}
for path in self.cfg_yml['paths']:
for method in self.cfg_yml['paths'][path]:
if 'operationId' in self.cfg_yml['paths'][path][method] and self.cfg_yml['paths'][path][method][
'operationId'] == operation_id:
if 'operationId' in self.cfg_yml['paths'][path][method] and self.cfg_yml['paths'][path][method]['operationId'] == operation_id:
retVal = self.cfg_yml['paths'][path][method].copy()
retVal['__path__'] = path
retVal['__method__'] = method
Expand All @@ -1044,8 +1046,7 @@ def get_tag_from_api_name(self, api_name, qmethod=None):

for method in self.cfg_yml['paths'][path]:

if 'tags' in self.cfg_yml['paths'][path][method] and tag['name'] in self.cfg_yml['paths'][path][method][
'tags'] and 'operationId' in self.cfg_yml['paths'][path][method]:
if 'tags' in self.cfg_yml['paths'][path][method] and tag['name'] in self.cfg_yml['paths'][path][method]['tags'] and 'operationId' in self.cfg_yml['paths'][path][method]:
retVal = self.cfg_yml['paths'][path][method].copy()
retVal['__path__'] = path
retVal['__method__'] = method
Expand Down Expand Up @@ -1227,7 +1228,11 @@ def process_get(self, endpoint, return_value=False, parameters=None):
print("An error ocurred while saving data")
self.print_exception(e)
elif selection in item_counters:
self.pretty_print(api_response_unmapped[int(selection) - 1])
if my_op_mode == 'scim' and 'Resources' in api_response_unmapped:
items = api_response_unmapped['Resources']
elif my_op_mode == 'jca' and 'data' in api_response_unmapped:
items = api_response_unmapped['data']
self.pretty_print(items[int(selection) - 1])

def get_schema_from_reference(self, ref):
schema_path_list = ref.strip('/#').split('/')
Expand Down Expand Up @@ -1332,7 +1337,7 @@ def get_input_for_schema_(self, schema, model, spacing=0, initialised=False, get
if getitem and prop != getitem['__name__'] or prop in ('dn', 'inum'):
continue

if (required_only and schema.get('required')) and not prop in schema.get('required'):
if required_only and not prop in schema.get('required', []):
continue

prop_ = self.get_model_key_map(model, prop)
Expand Down Expand Up @@ -1635,7 +1640,6 @@ def process_patch(self, endpoint):
if selection == 'b':
self.display_menu(endpoint.parent)


def process_put(self, endpoint):

schema = self.get_scheme_for_endpoint(endpoint)
Expand Down Expand Up @@ -1665,29 +1669,38 @@ def process_put(self, endpoint):
break

else:
for m in endpoint.parent:
if m.method == 'get' and m.path.endswith('}'):
while True:
if endpoint.info['operationId'] == 'put-properties-fido2':
for m in endpoint.parent:
if m.method == 'get':
break
cur_model = self.process_get(m, return_value=True)
initialised = True
get_endpoint = m

else:
for m in endpoint.parent:
if m.method == 'get' and m.path.endswith('}'):
while True:
try:
key_name_desc = self.get_endpiont_url_param(m)
if key_name_desc and 'name' in key_name_desc:
key_name = key_name_desc['name']
cur_model = self.process_get(m, return_value=True)
break
except ValueError as e:
print(self.colored_text("Server returned no data", error_color))
retry = self.get_input(values=['y', 'n'], text='Retry?')
if retry == 'n':
self.display_menu(endpoint.parent)
while True:
try:
key_name_desc = self.get_endpiont_url_param(m)
if key_name_desc and 'name' in key_name_desc:
key_name = key_name_desc['name']
cur_model = self.process_get(m, return_value=True)
break
except ValueError as e:
print(self.colored_text("Server returned no data", error_color))
retry = self.get_input(values=['y', 'n'], text='Retry?')
if retry == 'n':
self.display_menu(endpoint.parent)
break

if not cur_model is False:
break
if not cur_model is False:
break

initialised = True
get_endpoint = m
break
initialised = True
get_endpoint = m
break

if not cur_model:
for m in endpoint.parent:
Expand Down

0 comments on commit a009943

Please sign in to comment.