Skip to main content

GitwaySession

Struct GitwaySession 

Source
pub struct GitwaySession { /* private fields */ }
Expand description

An active SSH session connected to a GitHub (or GHE) host.

§Typical Usage

use gitway_lib::{GitwayConfig, GitwaySession};

let config = GitwayConfig::github();
let mut session = GitwaySession::connect(&config).await?;
// authenticate, exec, close…

Implementations§

Source§

impl GitwaySession

Source

pub async fn connect(config: &GitwayConfig) -> Result<Self, GitwayError>

Establishes a TCP connection to the host in config and completes the SSH handshake (including host-key verification).

Does not authenticate; call authenticate or authenticate_best after this.

§Errors

Returns an error on network failure or if the server’s host key does not match any pinned fingerprint.

Source

pub async fn authenticate( &mut self, username: &str, key: PrivateKeyWithHashAlg, ) -> Result<(), GitwayError>

Authenticates with an explicit key.

Use [authenticate_best] to let the library discover the key automatically.

§Errors

Returns an error on SSH protocol failures. Returns GitwayError::is_authentication_failed when the server accepts the exchange but rejects the key.

Source

pub async fn authenticate_with_cert( &mut self, username: &str, key: PrivateKey, cert: Certificate, ) -> Result<(), GitwayError>

Authenticates with a private key and an accompanying OpenSSH certificate (FR-12).

The certificate is presented to the server in place of the raw public key. This is typically used with organisation-issued certificates that grant access without requiring the public key to be listed in authorized_keys.

§Errors

Returns an error on SSH protocol failures or if the server rejects the certificate.

Source

pub async fn authenticate_best( &mut self, config: &GitwayConfig, ) -> Result<(), GitwayError>

Discovers the best available key and authenticates using it.

Priority order (FR-9):

  1. Explicit --identity path from config.
  2. Default .ssh paths (id_ed25519id_ecdsaid_rsa).
  3. SSH agent via $SSH_AUTH_SOCK (Unix only).

If a certificate path is configured in config.cert_file, certificate authentication (FR-12) is used instead of raw public-key authentication for file-based keys.

When the chosen key requires a passphrase this method returns an error whose is_key_encrypted predicate is true; the caller (CLI layer) should then prompt and call authenticate_with_passphrase.

§Errors

Returns GitwayError::is_no_key_found when no key is available via any discovery method.

Source

pub async fn authenticate_with_passphrase( &mut self, config: &GitwayConfig, path: &Path, passphrase: &str, ) -> Result<(), GitwayError>

Loads an encrypted key with passphrase and authenticates.

Call this after [authenticate_best] returns an encrypted-key error and the CLI has collected the passphrase from the terminal.

If config.cert_file is set, certificate authentication is used (FR-12).

§Errors

Returns an error if the passphrase is wrong or authentication fails.

Source

pub async fn authenticate_with_agent( &mut self, username: &str, conn: AgentConnection, ) -> Result<(), GitwayError>

Tries each identity held in conn until one succeeds or all are exhausted.

On Unix this is called automatically by [authenticate_best] when no file-based key is found. For plain public-key identities the signing challenge is forwarded to the agent; for certificate identities the full certificate is presented alongside the agent-signed challenge.

§Errors

Returns GitwayError::is_authentication_failed if all identities are rejected, or GitwayError::is_no_key_found if the agent was empty.

Source

pub async fn exec(&mut self, command: &str) -> Result<u32, GitwayError>

Opens a session channel, executes command, and relays stdio bidirectionally until the remote process exits.

Returns the remote exit code (FR-16). Exit-via-signal returns 128 + signal_number (FR-17).

§Errors

Returns an error on channel open failure or SSH protocol errors.

Source

pub async fn close(self) -> Result<(), GitwayError>

Sends a graceful SSH_MSG_DISCONNECT and closes the connection.

§Errors

Returns an error if the disconnect message cannot be sent.

Source

pub fn auth_banner(&self) -> Option<String>

Returns the authentication banner last received from the server (if any).

For GitHub.com this contains the “Hi !” welcome message.

§Panics

Panics if the internal mutex is poisoned, which can only occur if another thread panicked while holding the lock — a programming error.

Source

pub fn verified_fingerprint(&self) -> Option<String>

Returns the SHA-256 fingerprint of the server key that was verified.

Available after a successful connect. Returns None when host-key verification was skipped (--insecure-skip-host-check).

§Panics

Panics if the internal mutex is poisoned — a programming error.

Trait Implementations§

Source§

impl Debug for GitwaySession

Manual Debug impl because client::Handle<H> does not implement Debug.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V