Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: jans-cli-tui working branch 4 #3504

Merged
merged 36 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
90b6e5c
fix:jans-cli-tui change user password (ref: #3360)
AbdelwahabAdam Jan 3, 2023
f85ccc5
fix:jans-cli-tui show kid for each key (ref: #3405)
AbdelwahabAdam Jan 3, 2023
ce1b121
fix:jans-cli-tui improve Scope Management for OpenID Client (ref: #3460)
AbdelwahabAdam Jan 3, 2023
a8e144e
fix:jans-cli-tui remove repeated import
AbdelwahabAdam Jan 3, 2023
5f90c29
fix:jans-cli-tui change the Quit key to (ref: #3502)
AbdelwahabAdam Jan 3, 2023
254159c
fix: jans-cli-tui ctrl+c and ctrl+q to exit
devrimyatar Jan 3, 2023
71fef62
feat: jans-cli-tui status bar message for listbox
devrimyatar Jan 3, 2023
3266ad2
fix: jans-cli-tui code smells
devrimyatar Jan 3, 2023
8dcecce
fix: jans-cli-tui sort properties for ease of navigation
devrimyatar Jan 4, 2023
3bb54d1
fix: enabled components are checked for porperties (ref: #3438)
devrimyatar Jan 4, 2023
f9ac825
feat: jans-cli-tui add missing property
devrimyatar Jan 4, 2023
edc8efa
fix:jans-cli-tui make list for scopes -baseDn and displayName- (ref: …
AbdelwahabAdam Jan 4, 2023
499092b
fix: jans-cli-tui Improve Scope Management for OpenID Client (ref: #3…
AbdelwahabAdam Jan 7, 2023
7b6ba92
fix: jans-tui-client rewrite properties
devrimyatar Jan 9, 2023
8e0ccf9
fix: jans-cli-tui remove debug line
devrimyatar Jan 9, 2023
f85630c
fix: jans-cli-tui code smells
devrimyatar Jan 9, 2023
b1d3baa
fix: jans-cli-tui typo
devrimyatar Jan 9, 2023
6ad9056
fix: jans-cli-tui code smells
devrimyatar Jan 9, 2023
45c04f9
fix: jans-cli-tui widget style for checkbox
devrimyatar Jan 9, 2023
2c6dcd9
fix: jans-cli-tui remove unused imports
devrimyatar Jan 9, 2023
25e0b7a
fix: jans-cli-tui close dialog after updating client (ref: #3510)
devrimyatar Jan 9, 2023
5e7f54b
fix:jans-cli-tui add Scopes label and reverse Scopes columns
AbdelwahabAdam Jan 9, 2023
8cb7485
fix: jans-cli-tui uppercase cli
devrimyatar Jan 10, 2023
329b67b
fix:jans-cli-tui Fixing Client dialog title
AbdelwahabAdam Jan 10, 2023
8190362
fix:jans-cli-tui re-implementing Scopes
AbdelwahabAdam Jan 10, 2023
4b37b3f
fix:jans-cli-tui change background color and styling (ref: #3408)
AbdelwahabAdam Jan 10, 2023
c45ce10
feat: jans-cli-tui label container widget (ref: #3631)
devrimyatar Jan 16, 2023
0b3ed50
fix: jans-cli-tui rewrite client scopes with lable container
devrimyatar Jan 17, 2023
1612157
fix: jans-cli-tui save client scopes
devrimyatar Jan 18, 2023
3e4173d
fix: jans-cli-tui only save client scopes no patch
devrimyatar Jan 18, 2023
776f01c
fix: jans-cli-tui client edit after save
devrimyatar Jan 18, 2023
9f5fd2e
feat: jans-cli-tui check available plugins from config-api (ref: #3616)
devrimyatar Jan 18, 2023
a17f52f
fix: jans-cli-tui code smells
devrimyatar Jan 18, 2023
21a51fb
fix: jans-cli-tui on_display for label container
devrimyatar Jan 18, 2023
19ebc93
fix: jans-cli-tui code smells
devrimyatar Jan 18, 2023
bf33fe7
fix: jans-cli-tui code smells
devrimyatar Jan 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions jans-cli-tui/cli_tui/cli_style.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from prompt_toolkit.styles import Style
from types import SimpleNamespace

style = Style.from_dict(
{
Expand Down Expand Up @@ -76,6 +77,7 @@
"plugin-widget":"green",
"plugin-container":"",
"plugin-container.text":"green",
"plugin-black-bg": "bg: black",

## edit_client_dialog
"outh-client-navbar":"#2600ff",
Expand Down Expand Up @@ -130,9 +132,32 @@
"date-picker-time":"bg:#bab1b1",
"dialog-titled-widget":"bg:#ffffff fg:green",

####tab
"tab-nav-background": "fg:#b0e0e6 bg:#a9a9a9",
"tab-unselected": "fg:#b0e0e6 bg:#a9a9a9 underline",
"tab-selected": "fg:#000080 bg:#d3d3d3",

##scim
"scim-widget": "bg:black fg:white",

}
)


def get_color_for_style(style_name:str)->SimpleNamespace:
ret_val = SimpleNamespace()
ret_val.fg = '#000000'
ret_val.bg = '#ffffff'

for pstyle in style.class_names_and_attrs:
if pstyle[0].__contains__(style_name):
if pstyle[1].color:
ret_val.fg = '#'+pstyle[1].color
if pstyle[1].bgcolor:
ret_val.bg = '#'+pstyle[1].bgcolor

return ret_val

## jans nav bar
main_navbar_bgcolor = "DimGray"
outh_navbar_bgcolor = "#ADD8E6"
Expand Down
71 changes: 42 additions & 29 deletions jans-cli-tui/cli_tui/jans_cli_tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def __init__(self):
self.styles = dict(style.style_rules)
self._plugins = []
self._load_plugins()
self.available_plugins = []
self.cli_object_ok = False
self.pbar_text = ""
self.progressing_text = ""
Expand Down Expand Up @@ -217,9 +218,15 @@ def _load_plugins(self) -> None:
self._plugins.append(plugin_object)

def init_plugins(self) -> None:
"""Initilizse plugins
"""
for plugin in self._plugins:
if hasattr(plugin, 'init_plugin'):
if getattr(plugin, 'server_side_plugin', False) and plugin.pid not in self.available_plugins:
continue
self.logger.debug('Initializing plugin {}'.format(plugin.pid))
plugin.init_plugin()

self.plugins_initialised = True

def plugin_enabled(self, pid: str) -> bool:
Expand Down Expand Up @@ -317,27 +324,31 @@ async def coroutine():
self.stop_progressing()

self.cli_object_ok = True
if not self.plugins_initialised:
self.init_plugins()
self.runtime_plugins()
self.check_available_plugins()

asyncio.ensure_future(coroutine())

else:
self.cli_object_ok = True
if not self.plugins_initialised:
self.init_plugins()

self.runtime_plugins()
self.check_available_plugins()


def runtime_plugins(self) -> None:
def check_available_plugins(self) -> None:
"""Disables plugins when cli object is ready"""

if self.cli_object_ok:
response = self.cli_requests({'operation_id': 'is-license-active'})
if response.status_code == 404:
self.disable_plugin('config_api')
response = self.cli_requests({'operation_id': 'get-plugins'})
if response.ok:
plugins = response.json()
for plugin in plugins:
self.available_plugins.append(plugin['name'])

for pp in self._plugins:
if getattr(pp, 'server_side_plugin', False) and pp.pid not in self.available_plugins:
self.disable_plugin(pp.pid)

self.init_plugins()

def disable_plugin(self, pid) -> None:

Expand All @@ -355,9 +366,6 @@ async def check_jans_cli_ini(self) -> None:
else :
self.create_cli()

if self.cli_object_ok and not self.plugins_initialised:
self.init_plugins()


def jans_creds_dialog(self, *params: Any) -> None:
body=HSplit([
Expand Down Expand Up @@ -387,6 +395,7 @@ def set_keybindings(self) -> None:
self.bindings.add('tab')(self.focus_next)
self.bindings.add('s-tab')(self.focus_previous)
self.bindings.add('c-c')(do_exit)
self.bindings.add('c-q')(do_exit)
self.bindings.add('f1')(self.help)
self.bindings.add('escape')(self.escape)
self.bindings.add('s-up')(self.up)
Expand Down Expand Up @@ -569,6 +578,7 @@ def getTitledText(
focusable: Optional[bool] = None,
width: AnyDimension = None,
style: AnyFormattedText = '',
widget_style: AnyFormattedText = '',
scrollbar: Optional[bool] = False,
line_numbers: Optional[bool] = False,
lexer: PygmentsLexer = None,
Expand All @@ -583,7 +593,7 @@ def getTitledText(
height=height,
width=width,
read_only=read_only,
style=self.styles['textarea-readonly'] if read_only else self.styles['textarea'],
style=widget_style or (self.styles['textarea-readonly'] if read_only else self.styles['textarea']),
accept_handler=accept_handler,
focusable=not read_only if focusable is None else focusable,
scrollbar=scrollbar,
Expand All @@ -598,7 +608,7 @@ def getTitledText(
ta.window.jans_name = name
ta.window.jans_help = jans_help

v = VSplit([Window(FormattedTextControl(title), width=len(title)+1, style=style, height=height), ta], padding=1)
v = VSplit([Window(FormattedTextControl(title), width=len(title)+1, style=style, height=height), ta])
v.me = ta

return v
Expand All @@ -611,6 +621,7 @@ def getTitledCheckBoxList(
current_values: Optional[list] = [],
jans_help: AnyFormattedText= "",
style: AnyFormattedText= "",
widget_style: AnyFormattedText = '',
) -> AnyContainer:

title += ': '
Expand All @@ -620,9 +631,8 @@ def getTitledCheckBoxList(
cbl.current_values = current_values
cbl.window.jans_name = name
cbl.window.jans_help = jans_help
#li, cd, width = self.handle_long_string(title, values, cbl)

v = VSplit([Window(FormattedTextControl(title), width=len(title)+1, style=style,), cbl], padding=1)
v = VSplit([Window(FormattedTextControl(title), width=len(title)+1, style=style,), cbl], style=widget_style)
v.me = cbl

return v
Expand All @@ -636,10 +646,15 @@ def getTitledCheckBox(
on_selection_changed: Callable= None,
jans_help: AnyFormattedText= "",
style: AnyFormattedText= "",
widget_style: AnyFormattedText = '',
) -> AnyContainer:

title += ': '
cb = Checkbox(text)
if widget_style:
cb.default_style = widget_style
cb.checked_style = widget_style
cb.selected_style = widget_style
cb.checked = checked
cb.window.jans_name = name
cb.window.jans_help = jans_help
Expand All @@ -652,9 +667,7 @@ def custom_handler():
if on_selection_changed:
cb._handle_enter = custom_handler

#li, cd, width = self.handle_long_string(title, text, cb)

v = VSplit([Window(FormattedTextControl(title), width=len(title)+1, style=style,), cb], padding=1)
v = VSplit([Window(FormattedTextControl(title), width=len(title)+1, style=style,), cb], style=widget_style)

v.me = cb

Expand All @@ -669,6 +682,7 @@ def getTitledRadioButton(
on_selection_changed: Callable= None,
jans_help: AnyFormattedText= "",
style: AnyFormattedText= "",
widget_style: AnyFormattedText = '',
) -> AnyContainer:

title += ': '
Expand All @@ -689,7 +703,7 @@ def custom_handler():
if on_selection_changed:
rl._handle_enter = custom_handler

v = VSplit([Window(FormattedTextControl(title), width=len(title)+1, style=style,), rl], padding=1)
v = VSplit([Window(FormattedTextControl(title), width=len(title)+1, style=style,), rl])

v.me = rl

Expand All @@ -715,9 +729,9 @@ def getTitledWidget(

def getButton(
self,
text: AnyFormattedText,
name: AnyFormattedText,
jans_help: AnyFormattedText,
text: AnyFormattedText,
name: AnyFormattedText,
jans_help: AnyFormattedText,
handler: Callable= None,
) -> Button:

Expand Down Expand Up @@ -845,15 +859,14 @@ def show_message(
self.layout.focus(dialog)
self.invalidate()

def show_again(self) -> None:
self.show_message(_("Again"), _("Nasted Dialogs"),)

def get_confirm_dialog(
self,
message: AnyFormattedText
self,
message: AnyFormattedText,
confirm_handler: Optional[Callable]=None
) -> Dialog:
body = VSplit([Label(message)], align=HorizontalAlign.CENTER)
buttons = [Button(_("No")), Button(_("Yes"))]
buttons = [Button(_("No")), Button(_("Yes"), handler=confirm_handler)]
dialog = JansGDialog(self, title=_("Confirmation"), body=body, buttons=buttons)
return dialog

Expand Down
Loading