Metadata-Version: 2.4
Name: hegemony-transport-scrapli
Version: 0.59.1
Summary: Scrapli network-CLI device transport for Hegemony
License-Expression: AGPL-3.0-or-later
License-File: LICENSE-AGPL-3.0-or-later.txt
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: System Administrators
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: System :: Systems Administration
Requires-Dist: hegemony-step-sdk==1.1.1
Requires-Dist: hegemony-transport-support==0.59.1
Requires-Dist: scrapli[asyncssh]>=2024.7.30,<2026.10
Requires-Python: >=3.11
Project-URL: Homepage, https://hegemony.sh
Project-URL: Documentation, https://hegemony.sh
Project-URL: Source, https://github.com/hegemony-sh/hegemony-step-plugins
Project-URL: Issues, https://github.com/hegemony-sh/hegemony-step-plugins/issues
Project-URL: Changelog, https://github.com/hegemony-sh/hegemony-step-plugins/blob/main/CHANGELOG.md
Description-Content-Type: text/markdown

<!--
SPDX-FileCopyrightText: 2025-2026 Rexonix s.r.o.
SPDX-FileContributor: Jakub Trávník <jakub.travnik@gmail.com>

SPDX-License-Identifier: AGPL-3.0-or-later
-->

# hegemony-transport-scrapli

Scrapli network-CLI device transport for
[Hegemony](https://github.com/hegemony-sh/hegemony).

Registers the `scrapli` transport under the `hegemony.device_transports`
entry-point group — an alternative to the default netmiko transport for the
scrapli core platforms (IOS-XE, IOS-XR, NX-OS, EOS, Junos), running
`AsyncScrapli` over scrapli's asyncssh transport plugin (natively async, no
paramiko in the dependency tree). Implements the SDK `Transport` command
surface (`execute_command(s)`, `execute_command_timing`) and HTTP staging
(`http_transfer`: the device pulls a download link with `copy <url> <fs>`, as
over netmiko). SCP staging (`scp_put`) is not supported by this transport and
raises `NotImplementedError` — use the netmiko transport for it.

The transport is **not** named in handler ids: `netcli.*` and other
credentialed handlers reach it through `ctx.services.connect()`, and which
transport runs is resolved host-side from `device.access_config`
(`access_config.ssh.transport: "scrapli"`). The host resolves credentials into
a `DeviceConnectionSpec` and injects its cancellation registry, so this wheel
never imports the platform's secret pipeline or settings.

## Host keys

When the host passes a `host_key_verifier` (hosts that check SSH host keys
do; the transport advertises `supports_host_key_verifier`), each hop, the
jump host first and then the device, accepts only the keys the verifier
trusts for it. A host that presents another key fails the connection during
the key exchange, before a password or private key is sent, and the
transport reports the key it saw to the verifier. On first contact the
transport fetches the host's key without logging in, has the verifier record
it, and then logs in accepting only that key. Without a verifier the
transport refuses to connect: it never connects without checking. Checks
switched off for a host (the verifier answers None) are the only way to
connect unchecked.

## Agreed algorithms

When the host passes an `ssh_algorithm_recorder` (the transport advertises
`supports_ssh_algorithm_recorder`), each hop, the jump host first and then
the device, reports the key exchange, host key, cipher and MAC it agreed on
once it is logged in. scrapli runs over asyncssh, which keeps both sides'
KEXINIT messages, and the agreement is worked out from them. A failure to
record is logged and never fails the connection.

## SSH algorithm policy

Connections use the SDK's secure SSH policy by default. Both the device and
jump host follow that policy. The netcli steps expose an explicit
`allow_legacy_ssh` override; see the
[netcli security reference](https://github.com/hegemony-sh/hegemony-step-plugins/blob/main/plugins/steps_netcli/README.md#ssh-security)
for algorithms, key sizes, risks and library limitations.

Hosts constructing the transport directly can call
`configure_ssh_security(allow_legacy=True)` before any I/O. The setting belongs
to that transport instance and never changes library-wide defaults.

The connection spec can also allow legacy SSH for one hop:
`DeviceConnectionSpec.allow_legacy_ssh` for the device and
`JumpHostSpec.allow_legacy_ssh` for the jump host. Neither flag reaches the
other hop. Each recorded hop says whether the host key it presented is a weak
one (`SshAlgorithms.weak_host_key`).
