Skip to content

Commit

Permalink
jans-cli-tui: retreive all scopes and clean up (ref: #4034) (ref: #4267)
Browse files Browse the repository at this point in the history
* jans-cli-tui retreive all scopes rather than setting limit for clients scope list (ref: #4034)

* jans-cli-tui remove Get (ref: #4267)
  • Loading branch information
AbdelwahabAdam authored Apr 7, 2023
1 parent e0c7714 commit 5c0b586
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 48 deletions.
1 change: 0 additions & 1 deletion jans-cli-tui/cli_tui/plugins/010_auth_server/agama.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def __init__(

self.main_container = HSplit([
VSplit([
self.app.getButton(text=_("Get Projects"), name='oauth:agama:get', jans_help=_("Retreive all Agama Projects"), handler=self.get_agama_projects),
self.app.getTitledText(_("Search"), name='oauth:agama:search', jans_help=_(common_strings.enter_to_search), accept_handler=self.search_agama_project, style=cli_style.edit_text),
self.app.getButton(text=_("Upload Project"), name='oauth:agama:add', jans_help=_("To add a new Agama project press this button"), handler=self.upload_project),
],
Expand Down
1 change: 0 additions & 1 deletion jans-cli-tui/cli_tui/plugins/010_auth_server/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def __init__(

self.main_container = HSplit([
VSplit([
self.app.getButton(text=_("Get Attributes"), name='oauth:attributes:get', jans_help=_("Retreive first {} Attributes").format(self.app.entries_per_page), handler=self.get_attributes),
self.app.getTitledText(_("Search"), name='oauth:attributes:search', jans_help=_(common_strings.enter_to_search), accept_handler=self.search_attributes, style=cli_style.edit_text),
self.app.getButton(text=_("Add Attribute"), name='oauth:attributes:add', jans_help=_("To add a new Agama project press this button"), handler=self.add_attributes),
],
Expand Down
22 changes: 18 additions & 4 deletions jans-cli-tui/cli_tui/plugins/010_auth_server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,31 @@ async def get_appconfiguration(self) -> None:
self.oauth_logging()



async def retrieve_sopes(self) -> None:
"""asyncio corotune for retreiving scopes
"""
limit =60
start_index = 0

self.app.logger.debug("retreiving scopes")
cli_args = {'operation_id': 'get-oauth-scopes', 'endpoint_args': 'limit:200,startIndex:0'}
cli_args = {'operation_id': 'get-oauth-scopes', 'endpoint_args': f'limit:{limit},startIndex:{start_index}'}
response = await self.app.loop.run_in_executor(self.app.executor, self.app.cli_requests, cli_args)
common_data.scopes = response.json()['entries']
result = response.json()
max_limit = result['totalEntriesCount']

while(start_index < max_limit) :
if start_index < max_limit:
start_index +=limit
cli_args = {'operation_id': 'get-oauth-scopes', 'endpoint_args': f'limit:{limit},startIndex:{start_index}'}
response_new = await self.app.loop.run_in_executor(self.app.executor, self.app.cli_requests, cli_args)
result_new = response_new.json()
result['entries'].append(result_new.get('entries',[]))

common_data.scopes = result['entries']
self.app.logger.debug("scopes retreived")


def on_cli_object_ready(self):
self.authn.on_cli_object_ready()

Expand Down Expand Up @@ -137,7 +153,6 @@ def oauth_prepare_containers(self) -> None:

self.oauth_containers['scopes'] = HSplit([
VSplit([
self.app.getButton(text=_("Get Scopes"), name='oauth:scopes:get', jans_help=_("Retreive first {} Scopes").format(self.app.entries_per_page), handler=self.oauth_get_scopes),
self.app.getTitledText(_("Search"), name='oauth:scopes:search', jans_help=_(common_strings.enter_to_search), accept_handler=self.search_scope,style='class:outh_containers_scopes.text'),
self.app.getButton(text=_("Add Scope"), name='oauth:scopes:add', jans_help=_("To add a new scope press this button"), handler=self.add_scope),
],
Expand All @@ -149,7 +164,6 @@ def oauth_prepare_containers(self) -> None:

self.oauth_containers['clients'] = HSplit([
VSplit([
self.app.getButton(text=_("Get Clients"), name='oauth:clients:get', jans_help=_("Retreive first {} OpenID Connect clients").format(self.app.entries_per_page), handler=self.oauth_update_clients),
self.app.getTitledText(_("Search"), name='oauth:clients:search', jans_help=_(common_strings.enter_to_search), accept_handler=self.search_clients,style='class:outh_containers_clients.text'),
self.app.getButton(text=_("Add Client"), name='oauth:clients:add', jans_help=_("To add a new client press this button"), handler=self.add_client),

Expand Down
1 change: 0 additions & 1 deletion jans-cli-tui/cli_tui/plugins/010_auth_server/ssa.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def __init__(

self.main_container = HSplit([
VSplit([
self.app.getButton(text=_("Get SSA"), name='oauth:ssa:get', jans_help=_("Retreive all SSA"), handler=self.get_ssa),
self.app.getTitledText(_("Search"), name='oauth:ssa:search', jans_help=_(common_strings.enter_to_search), accept_handler=self.search_ssa, style=cli_style.edit_text),
self.app.getButton(text=_("Add SSA"), name='oauth:ssa:add', jans_help=_("To add a new SSA press this button"), handler=self.add_ssa),
],
Expand Down
22 changes: 9 additions & 13 deletions jans-cli-tui/cli_tui/plugins/060_scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,15 @@ def scripts_prepare_containers(self) -> None:
self.scripts_list_container = HSplit([], width=D(), height=D())

self.scripts_main_area = HSplit([
VSplit([
self.app.getButton(text=_("Get Scripts"), name='scripts:get', jans_help=_(
"Retreive first %d Scripts") % (20), handler=self.get_scripts),
self.app.getTitledText(_("Search"), name='scripts:search', jans_help=_(
"Press enter to perform search"), accept_handler=self.search_scripts, style='class:outh_containers_scopes.text'),
self.app.getButton(text=_("Add Script"), name='scripts:add', jans_help=_(
"To add a new scope press this button"), handler=self.add_script_dialog),
],
padding=3,
width=D(),
),
DynamicContainer(lambda: self.scripts_list_container)
], style='class:outh_containers_scopes')
VSplit([
self.app.getTitledText(_("Search"), name='scripts:search', jans_help=_("Press enter to perform search"), accept_handler=self.search_scripts, style='class:outh_containers_scopes.text'),
self.app.getButton(text=_("Add Script"), name='scripts:add', jans_help=_("To add a new scope press this button"), handler=self.add_script_dialog),
],
padding=3,
width=D(),
),
DynamicContainer(lambda: self.scripts_list_container)
],style='class:outh_containers_scopes')

def get_scripts(
self,
Expand Down
1 change: 0 additions & 1 deletion jans-cli-tui/cli_tui/plugins/070_users/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def set_center_frame(self) -> None:
self.nav_buttons = VSplit([],width=D())
self.app.center_container = HSplit([
VSplit([
self.app.getButton(text=_("Get Users"), name='oauth:scopes:get', jans_help=_("Retreive first {} users").format(self.app.entries_per_page), handler=self.get_users),
self.app.getTitledText(_("Search"), name='oauth:scopes:search', jans_help=_("Press enter to perform search"), accept_handler=self.search_user, style='class:outh_containers_scopes.text'),
self.app.getButton(text=_("Add Users"), name='oauth:scopes:add', jans_help=_("To add a new user press this button"), handler=self.edit_user_dialog),
],
Expand Down
45 changes: 18 additions & 27 deletions jans-cli-tui/wrapper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
test_client = config_cli.client_id if config_cli.test_client else None
config_cli.debug = True
cli_object = config_cli.JCA_CLI(
host=config_cli.host,
client_id=config_cli.client_id,
client_secret=config_cli.client_secret,
access_token=config_cli.access_token,
test_client=test_client
)

#print(config_cli.host, config_cli.client_id, config_cli.client_secret, config_cli.access_token, cli_object.use_test_client)
host=config_cli.host,
client_id=config_cli.client_id,
client_secret=config_cli.client_secret,
access_token=config_cli.access_token,
test_client=test_client
)

# print(config_cli.host, config_cli.client_id, config_cli.client_secret, config_cli.access_token, cli_object.use_test_client)
status = cli_object.check_connection()

print(status)
Expand Down Expand Up @@ -66,25 +66,24 @@

# endpoint_args ='pattern:2B29' ### limit the responce and wrong pattern
data = {}
inum = '40a48740-4892-4fce-b30f-81c5c45670f4' ## this user has 3 UMA
inum = '40a48740-4892-4fce-b30f-81c5c45670f4' # this user has 3 UMA
result = cli_object.process_command_by_id(
operation_id='get-all-attribute',
url_suffix='',
endpoint_args="pattern:3B47\,3692\,E7BC\,11AA",
data_fn=None,
data={}
)

x = result.json()
print(x)
operation_id='get-oauth-scopes',
url_suffix='',
endpoint_args="limit:200,startIndex:0",
data_fn=None,
data={}
)

x = result.json()
print(x['totalEntriesCount'])
# print(len(x["entries"]))
# print(x["entries"])
# for i in x["entries"]:
# if i['inum'] == '08E2':
# print(i['claimName'])



# endpoint_args ='limit:1,pattern:hasdaeat'
# endpoint_args ='limit:5,startIndex:0,pattern:sagasg'

Expand All @@ -98,13 +97,6 @@
# print(result.text)









'''
[
{"dn":"jansId=5635e18b-67b9-4997-a786-a6b2cdb84355,ou=resources,ou=uma,o=jans",
Expand Down Expand Up @@ -182,4 +174,3 @@
{"dn":"inum=C4F6,ou=scopes,o=jans","inum":"C4F6","displayName":"refresh_token","id":"offline_access","description":"This scope value requests that an OAuth 2.0 Refresh Token be issued.","scopeType":"openid","defaultScope":true,"attributes":{"showInConfigurationEndpoint":true},"creationDate":"2022-09-24T07:07:19","umaType":false,"baseDn":"inum=C4F6,ou=scopes,o=jans"}]
'''

0 comments on commit 5c0b586

Please sign in to comment.