Skip to content

Commit 8711de1

Browse files
committed
add multiline pretty_repr for ssh config
useful for debugging connections
1 parent 2964b58 commit 8711de1

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

exec_helpers/_ssh_helpers.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
# External Dependencies
99
import paramiko # type: ignore
1010

11+
if typing.TYPE_CHECKING:
12+
# noinspection PyPackageRequirements
13+
import logwrap
14+
1115

1216
# Parse default SSHConfig if available
1317
SSH_CONFIG_FILE_SYSTEM = pathlib.Path("/etc/ssh/ssh_config")
@@ -132,6 +136,34 @@ def __repr__(self) -> str:
132136
f")"
133137
)
134138

139+
def __pretty_repr__(self, log_wrap: "logwrap.PrettyRepr", indent: int = 0, no_indent_start: bool = False) -> str:
140+
"""Make human readable representation of object.
141+
142+
:param log_wrap: logwrap instance
143+
:type log_wrap: logwrap.PrettyRepr
144+
:param indent: start indentation
145+
:type indent: int
146+
:param no_indent_start: do not indent open bracket and simple parameters
147+
:type no_indent_start: bool
148+
:return: formatted string
149+
:rtype: str
150+
"""
151+
next_indent = log_wrap.next_indent(indent)
152+
msg = (
153+
f"{'':<{0 if no_indent_start else indent}}{self.__class__.__name__}(\n"
154+
f"{'':<{next_indent}}hostname={self.hostname!r},\n"
155+
f"{'':<{next_indent}}port={self.port!r},\n"
156+
f"{'':<{next_indent}}user={self.user!r},\n"
157+
f"{'':<{next_indent}}identityfile={self.identityfile!r},\n"
158+
f"{'':<{next_indent}}proxycommand={self.proxycommand!r},\n"
159+
f"{'':<{next_indent}}proxyjump={self.proxyjump!r},\n"
160+
f"{'':<{next_indent}}controlpath={self.controlpath!r},\n"
161+
f"{'':<{next_indent}}controlmaster={self.controlmaster!r},\n"
162+
f"{'':<{next_indent}}compression={self.compression!r},\n"
163+
f"{'':<{0 if no_indent_start else indent}})"
164+
)
165+
return msg
166+
135167
@staticmethod
136168
def _parse_optional_int(value: typing.Optional[typing.Union[str, int]]) -> typing.Optional[int]:
137169
if value is None or isinstance(value, int):

0 commit comments

Comments
 (0)