pub struct Context {
    pub protocol: Option<String>,
    pub host: Option<String>,
    pub path: Option<BString>,
    pub username: Option<String>,
    pub password: Option<String>,
    pub url: Option<BString>,
    pub quit: Option<bool>,
}
Expand description

Additional context to be passed to the credentials helper.

Fields§

§protocol: Option<String>

The protocol over which the credential will be used (e.g., https).

§host: Option<String>

The remote hostname for a network credential. This includes the port number if one was specified (e.g., “example.com:8088”).

§path: Option<BString>

The path with which the credential will be used. E.g., for accessing a remote https repository, this will be the repository’s path on the server. It can also be a path on the file system.

§username: Option<String>

The credential’s username, if we already have one (e.g., from a URL, the configuration, the user, or from a previously run helper).

§password: Option<String>

The credential’s password, if we are asking it to be stored.

§url: Option<BString>

When this special attribute is read by git credential, the value is parsed as a URL and treated as if its constituent parts were read (e.g., url=https://example.com would behave as if protocol=https and host=example.com had been provided). This can help callers avoid parsing URLs themselves.

§quit: Option<bool>

If true, the caller should stop asking for credentials immediately without calling more credential helpers in the chain.

Implementations§

Convert all relevant fields into a URL for consumption.

Compute a prompt to obtain the given value.

In-place mutation

Destructure the url at our url field into parts like protocol, host, username and path and store them in our respective fields. If use_http_path is set, http paths are significant even though normally this isn’t the case.

Write ourselves to out such that from_bytes() can decode it losslessly.

Examples found in repository?
examples/invoke-git-credential.rs (line 12)
4
5
6
7
8
9
10
11
12
13
14
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
    let out = git_credentials::builtin(git_credentials::helper::Action::get_for_url(
        std::env::args()
            .nth(1)
            .ok_or("First argument must be the URL to obtain credentials for")?,
    ))?
    .ok_or("Did not obtain credentials")?;
    let ctx: git_credentials::protocol::Context = (&out.next).try_into()?;
    ctx.write_to(std::io::stdout())?;
    Ok(())
}

Like write_to(), but writes infallibly into memory.

Examples found in repository?
examples/git-credential-lite.rs (line 15)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
pub fn main() -> Result<(), git_credentials::program::main::Error> {
    git_credentials::program::main(
        std::env::args_os().skip(1),
        std::io::stdin(),
        std::io::stdout(),
        |action, context| {
            use git_credentials::program::main::Action::*;
            git_credentials::helper::Cascade::default()
                .invoke(
                    match action {
                        Get => git_credentials::helper::Action::Get(context),
                        Erase => git_credentials::helper::Action::Erase(context.to_bstring()),
                        Store => git_credentials::helper::Action::Store(context.to_bstring()),
                    },
                    git_prompt::Options::default().apply_environment(true, true, true),
                )
                .map(|outcome| outcome.and_then(|outcome| (&outcome.next).try_into().ok()))
        },
    )
}

Decode ourselves from input which is the format written by write_to().

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Converts to this type from the input type.
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
The type returned in the event of a conversion error.
Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.