From 7168ceab942157f899af86f03fd240d3d25ca000 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 15 Mar 2022 13:14:53 +0530 Subject: [PATCH] Make askpass a choice var --- kittens/ssh/options/definition.py | 6 +++--- kittens/ssh/options/parse.py | 7 ++++++- kittens/ssh/options/types.py | 6 +++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/kittens/ssh/options/definition.py b/kittens/ssh/options/definition.py index a71318711..f144c8b47 100644 --- a/kittens/ssh/options/definition.py +++ b/kittens/ssh/options/definition.py @@ -107,14 +107,14 @@ opt('login_shell', '', long_text=''' The login shell to execute on the remote host. By default, the remote user account's login shell is used.''') -opt('askpass', 'unless-set', long_text=''' +opt('askpass', 'unless-set', choices=('unless-set', 'ssh', 'native'), long_text=''' Control the program SSH uses to ask for passwords or confirmation of host keys etc. The default is to use kitty's native askpass, unless the SSH_ASKPASS environment variable is set. Set it to :code:`ssh` to not interfere with the normal ssh askpass mechanism at all, which typically means that ssh will prompt at the terminal. Set it to :code:`native` to always use kitty's native, -built-in askpass implementation. Note that not using an askpass implementation -means that SSH needs to use the terminal before the connection is established +built-in askpass implementation. Note that not using the kitty askpass implementation +means that SSH might need to use the terminal before the connection is established so the kitten cannot use the terminal to send data without an extra roundtrip, adding to initial connection latency. ''') diff --git a/kittens/ssh/options/parse.py b/kittens/ssh/options/parse.py index 855479538..11221378b 100644 --- a/kittens/ssh/options/parse.py +++ b/kittens/ssh/options/parse.py @@ -8,7 +8,12 @@ from kitty.conf.utils import merge_dicts, to_bool class Parser: def askpass(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: - ans['askpass'] = str(val) + val = val.lower() + if val not in self.choices_for_askpass: + raise ValueError(f"The value {val} is not a valid choice for askpass") + ans["askpass"] = val + + choices_for_askpass = frozenset(('unless-set', 'ssh', 'native')) def copy(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: for k, v in copy(val, ans["copy"]): diff --git a/kittens/ssh/options/types.py b/kittens/ssh/options/types.py index 7f18aa4d7..8c1a8ed92 100644 --- a/kittens/ssh/options/types.py +++ b/kittens/ssh/options/types.py @@ -3,6 +3,10 @@ import typing import kittens.ssh.copy +if typing.TYPE_CHECKING: + choices_for_askpass = typing.Literal['unless-set', 'ssh', 'native'] +else: + choices_for_askpass = str option_names = ( # {{{ 'askpass', @@ -18,7 +22,7 @@ option_names = ( # {{{ class Options: - askpass: str = 'unless-set' + askpass: choices_for_askpass = 'unless-set' cwd: str = '' hostname: str = '*' interpreter: str = 'sh'