Skip to content

Commit

Permalink
fix: jans-cli only users have admin role can use TUI (ref: #2129)
Browse files Browse the repository at this point in the history
  • Loading branch information
devrimyatar committed Oct 25, 2022
1 parent 43be9ba commit 1177165
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
27 changes: 19 additions & 8 deletions jans-cli-tui/cli/config_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,9 @@ def get_device_verification_code(self):
def raise_error(self, msg):
if not self.wrapped:
msg = self.colored_text(msg, error_color)
print(msg)
sys.exit()

raise ValueError(msg)


Expand Down Expand Up @@ -578,11 +581,19 @@ def get_jwt_access_token(self, device_verified=None):
)
self.log_response(response)
if response.status_code != 200:
self.raise_error("Unable to get access token")
self.raise_error("Unable to get user info")


result = response.text
config['DEFAULT']['user_data'] = result


user_info = self.get_user_info()

if 'api-admin' not in user_info.get('jansAdminUIRole', []):
config['DEFAULT']['user_data'] = ''
self.raise_error("The logged user do not have valid role.")

"""
STEP 4: Get access token for config-api endpoints
Use client creditentials to retreive access token for client endpoints.
Expand Down Expand Up @@ -1439,13 +1450,13 @@ def main():
#try:
if not access_token:
cli_object.check_connection()
else:
if args.info:
cli_object.help_for(args.info)
elif args.schema:
cli_object.get_sample_schema(args.schema)
elif args.operation_id:
cli_object.process_command_by_id(args.operation_id, args.url_suffix, args.endpoint_args, args.data)

if args.info:
cli_object.help_for(args.info)
elif args.schema:
cli_object.get_sample_schema(args.schema)
elif args.operation_id:
cli_object.process_command_by_id(args.operation_id, args.url_suffix, args.endpoint_args, args.data)

#except Exception as e:
# print(u"\u001b[38;5;{}mAn Unhandled error raised: {}\u001b[0m".format(error_color, e))
Expand Down
2 changes: 2 additions & 0 deletions jans-cli-tui/jans-cli-tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ async def coroutine():
except Exception as e:
err_dialog = JansGDialog(self, title=_("Error!"), body=HSplit([Label(str(e))]))
await self.show_dialog_as_float(err_dialog)
self.cli_object_ok = False
self.create_cli()
return
self.cli_object_ok = True
if not self.plugins_initialised:
self.init_plugins()
Expand Down

0 comments on commit 1177165

Please sign in to comment.