Skip to content

Commit

Permalink
Hide the ssh cridential widgets when it is 2FA
Browse files Browse the repository at this point in the history
f-m: typos
  • Loading branch information
unkcpz committed Oct 2, 2023
1 parent 13d8b7c commit e6026e4
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions aiidalab_widgets_base/computational_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1402,10 +1402,10 @@ def _templates_changed(self, _=None):
def _render(self):
"""Render the template variables widget."""
metadata = self.templates.get("metadata", {})
tooptip = metadata.get("tooltip", None)
tooltip = metadata.get("tooltip", None)

if tooptip:
self._help_text.value = f"""<div>{tooptip}</div>"""
if tooltip:
self._help_text.value = f"""<div>{tooltip}</div>"""

for line_key, line_str in self.templates.items():
env = Environment()
Expand Down Expand Up @@ -1576,6 +1576,17 @@ def __init__(self, default_calc_job_plugin=None, **kwargs):
self._on_template_variables_code_filled, names="filled_templates"
)

self.ssh_credential_help = ipw.HTML(
"""<div>SSH credential to the remote machine</div>"""
)
self.ssh_widgets = ipw.VBox(
children=[
self.ssh_credential_help,
self.ssh_computer_setup.username,
self.ssh_computer_setup.password_box,
]
)

super().__init__(
children=[
ipw.HTML(
Expand All @@ -1585,9 +1596,10 @@ def __init__(self, default_calc_job_plugin=None, **kwargs):
self.comp_resources_database,
self.template_variables_computer,
self.template_variables_code,
ipw.HTML("""<div>SSH credential to the remote machine</div>"""),
self.ssh_computer_setup.username,
self.ssh_computer_setup.password_box,
# self.ssh_credential_help,
# self.ssh_computer_setup.username,
# self.ssh_computer_setup.password_box,
self.ssh_widgets,
quick_setup_button,
],
**kwargs,
Expand Down Expand Up @@ -1631,6 +1643,14 @@ def _on_select_computer(self, change):
# ssh config need to sync hostname etc to resource database.
self.ssh_config = self.comp_resources_database.ssh_config

# decide whether to show the ssh credential config (username and password) widget.
# Since for 2FA ssh credential, the username and password are not needed but set from
# independent mechanism.
if new_setup["setup"].get("metadata", {}).get("ssh_auth", None) == "2FA":
self.ssh_widgets.layout.display = "none"
else:
self.ssh_widgets.layout.display = "block"

def _on_select_code(self, change):
"""Update the code trait"""
self.message = ""
Expand Down Expand Up @@ -1693,15 +1713,20 @@ def _on_quick_setup(self, _=None):
self.code_setup = code_setup

# Setup the computer and code.
try:
self.ssh_computer_setup.key_pair_prepare()
except ValueError as exc:
self.message = f"Invalid inputs: {exc}"

# Only copy the ssh key if the ssh connection is setable.
if self.ssh_widgets.layout.display == "block":
try:
self.ssh_computer_setup.key_pair_prepare()
except ValueError as exc:
self.message = f"Invalid inputs: {exc}"

if self.aiida_computer_setup.on_setup_computer():
self.aiida_code_setup.on_setup_code()

self.ssh_computer_setup.thread_ssh_copy_id()
# Only copy the ssh key if the ssh connection is setable.
if self.ssh_widgets.layout.display == "block":
self.ssh_computer_setup.thread_ssh_copy_id()

def _on_setup_computer_success(self):
"""Callback that is called when the computer is successfully set up."""
Expand Down

0 comments on commit e6026e4

Please sign in to comment.