feat: with auth sock

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2023-11-27 22:08:38 +01:00
parent a210e7beff
commit 91c73c7a4e
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912

View File

@ -41,6 +41,9 @@ async fn main() -> eyre::Result<()> {
let mut cb = RemoteCallbacks::new(); let mut cb = RemoteCallbacks::new();
cb.credentials(|_, _, _| { cb.credentials(|_, _, _| {
if let Some(sock) = std::env::var("SSH_AUTH_SOCK").ok() {
return Cred::ssh_key_from_agent("git");
}
let username = std::env::var("GIT_USERNAME").expect("GIT_USERNAME to be set"); let username = std::env::var("GIT_USERNAME").expect("GIT_USERNAME to be set");
let password = std::env::var("GIT_PASSWORD").expect("GIT_PASSWORD to be set"); let password = std::env::var("GIT_PASSWORD").expect("GIT_PASSWORD to be set");
Cred::userpass_plaintext(&username, &password) Cred::userpass_plaintext(&username, &password)
@ -116,6 +119,9 @@ async fn main() -> eyre::Result<()> {
let mut remote = repo.find_remote("origin")?; let mut remote = repo.find_remote("origin")?;
let mut cb = RemoteCallbacks::new(); let mut cb = RemoteCallbacks::new();
cb.credentials(|_, _, _| { cb.credentials(|_, _, _| {
if let Some(sock) = std::env::var("SSH_AUTH_SOCK").ok() {
return Cred::ssh_key_from_agent("git");
}
let username = std::env::var("GIT_USERNAME").expect("GIT_USERNAME to be set"); let username = std::env::var("GIT_USERNAME").expect("GIT_USERNAME to be set");
let password = std::env::var("GIT_PASSWORD").expect("GIT_PASSWORD to be set"); let password = std::env::var("GIT_PASSWORD").expect("GIT_PASSWORD to be set");
Cred::userpass_plaintext(&username, &password) Cred::userpass_plaintext(&username, &password)