Skip to content

Commit

Permalink
feat: jans-cli display users in tabular form (#1296)
Browse files Browse the repository at this point in the history
  • Loading branch information
devrimyatar authored May 6, 2022
1 parent 76ffef3 commit 7f75d39
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions jans-cli/cli/config_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

tabulate_endpoints = {
'jca.get-config-scripts': ['scriptType', 'name', 'enabled', 'inum'],
'jca.get-user': ['inum', 'userId', 'mail','sn', 'givenName', 'jansStatus'],
}

my_op_mode = 'scim' if 'scim' in os.path.basename(sys.argv[0]) else 'jca'
Expand Down Expand Up @@ -1017,7 +1018,7 @@ def tabular_data(self, data, ome):
for i, entry in enumerate(data):
row_ = [i + 1]
for header in headers:
row_.append(entry[header])
row_.append(entry.get(header, ''))
tab_data.append(row_)

print(tabulate(tab_data, headers, tablefmt="grid"))
Expand Down Expand Up @@ -1087,9 +1088,18 @@ 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:
self.tabular_data(api_response_unmapped, op_mode_endpoint)
api_response_unmapped_ext = copy.deepcopy(api_response_unmapped)
if endpoint.info['operationId'] == 'get-user':
for entry in api_response_unmapped_ext:
for attrib in entry['customAttributes']:
if attrib['name'] == 'mail':
entry['mail'] = ', '.join(attrib['values'])
elif attrib['name'] in tabulate_endpoints[op_mode_endpoint]:
entry[attrib['name']] = attrib['values'][0]

self.tabular_data(api_response_unmapped_ext, op_mode_endpoint)
item_counters = [str(i + 1) for i in range(len(api_response_unmapped))]
tabulated = True
else:
Expand Down

0 comments on commit 7f75d39

Please sign in to comment.