[][src]Struct git2_credentials::CredentialHandler

pub struct CredentialHandler { /* fields omitted */ }

Methods

impl CredentialHandler[src]

pub fn new(cfg: Config) -> Self[src]

pub fn new_with_ui(cfg: Config, ui: Box<dyn CredentialUI>) -> Self[src]

pub fn try_next_credential(
    &mut self,
    url: &str,
    username: Option<&str>,
    allowed: CredentialType
) -> Result<Cred, Error>
[src]

Prepare the authentication callbacks for cloning a git repository.

The main purpose of this function is to construct the "authentication callback" which is used to clone a repository. This callback will attempt to find the right authentication on the system (maybe with user input) and will guide libgit2 in doing so.

The callback is provided allowed types of credentials, and we try to do as much as possible based on that:

  • Prioritize SSH keys from the local ssh agent as they're likely the most reliable. The username here is prioritized from the credential callback, then from whatever is configured in git itself, and finally we fall back to the generic user of git. If no ssh agent try to use the default key ($HOME/.ssh/id_rsa, $HOME/.ssh/id_ed25519)

  • If a username/password is allowed, then we fallback to git2-rs's implementation of the credential helper. This is what is configured with credential.helper in git, and is the interface for the macOS keychain, for example. Else ask (on ui) the for username and password.

  • After the above two have failed, we just kinda grapple attempting to return something.

If any form of authentication fails, libgit2 will repeatedly ask us for credentials until we give it a reason to not do so. To ensure we don't just sit here looping forever we keep track of authentications we've attempted and we don't try the same ones again.

Auto Trait Implementations

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]