upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-07-26 13:38:48 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2024-07-26 13:38:48 +0100
commitf609ed6e45bb870c2b855ff6e0d4b4d7f36e7bd0 (patch)
treebb81c4b0d3dcb3afaacffee543462b67df68d5ff
parent0134ab8eb413b8b81ec8e179897ddb8ea63e134e (diff)
fix(remote): authenticate pushes
in the future we could implement our own credentials callback function to remove the dependancy
-rw-r--r--Cargo.lock31
-rw-r--r--Cargo.toml1
-rw-r--r--src/git_remote_helper.rs5
3 files changed, 35 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock
index d014782..7622dd0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -373,6 +373,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
373checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" 373checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
374 374
375[[package]] 375[[package]]
376name = "auth-git2"
377version = "0.5.4"
378source = "registry+https://github.com/rust-lang/crates.io-index"
379checksum = "e51bd0e4592409df8631ca807716dc1e5caafae5d01ce0157c966c71c7e49c3c"
380dependencies = [
381 "dirs",
382 "git2",
383 "terminal-prompt",
384]
385
386[[package]]
376name = "autocfg" 387name = "autocfg"
377version = "1.2.0" 388version = "1.2.0"
378source = "registry+https://github.com/rust-lang/crates.io-index" 389source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -814,6 +825,15 @@ dependencies = [
814] 825]
815 826
816[[package]] 827[[package]]
828name = "dirs"
829version = "5.0.1"
830source = "registry+https://github.com/rust-lang/crates.io-index"
831checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225"
832dependencies = [
833 "dirs-sys",
834]
835
836[[package]]
817name = "dirs-sys" 837name = "dirs-sys"
818version = "0.4.1" 838version = "0.4.1"
819source = "registry+https://github.com/rust-lang/crates.io-index" 839source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1747,6 +1767,7 @@ dependencies = [
1747 "anyhow", 1767 "anyhow",
1748 "assert_cmd", 1768 "assert_cmd",
1749 "async-trait", 1769 "async-trait",
1770 "auth-git2",
1750 "chacha20poly1305", 1771 "chacha20poly1305",
1751 "clap", 1772 "clap",
1752 "console", 1773 "console",
@@ -3041,6 +3062,16 @@ dependencies = [
3041] 3062]
3042 3063
3043[[package]] 3064[[package]]
3065name = "terminal-prompt"
3066version = "0.2.3"
3067source = "registry+https://github.com/rust-lang/crates.io-index"
3068checksum = "572818b3472910acbd5dff46a3413715c18e934b071ab2ba464a7b2c2af16376"
3069dependencies = [
3070 "libc",
3071 "winapi",
3072]
3073
3074[[package]]
3044name = "termtree" 3075name = "termtree"
3045version = "0.4.1" 3076version = "0.4.1"
3046source = "registry+https://github.com/rust-lang/crates.io-index" 3077source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 2ece265..fe0d74a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -14,6 +14,7 @@ categories = ["command-line-utilities","git"]
14[dependencies] 14[dependencies]
15anyhow = "1.0.75" 15anyhow = "1.0.75"
16async-trait = "0.1.73" 16async-trait = "0.1.73"
17auth-git2 = "0.5.4"
17chacha20poly1305 = "0.10.1" 18chacha20poly1305 = "0.10.1"
18clap = { version = "4.3.19", features = ["derive"] } 19clap = { version = "4.3.19", features = ["derive"] }
19console = "0.15.7" 20console = "0.15.7"
diff --git a/src/git_remote_helper.rs b/src/git_remote_helper.rs
index 6050d1a..2899fec 100644
--- a/src/git_remote_helper.rs
+++ b/src/git_remote_helper.rs
@@ -13,6 +13,7 @@ use std::{
13}; 13};
14 14
15use anyhow::{bail, Context, Result}; 15use anyhow::{bail, Context, Result};
16use auth_git2::GitAuthenticator;
16#[cfg(not(test))] 17#[cfg(not(test))]
17use client::Connect; 18use client::Connect;
18use client::{fetching_with_report, get_repo_ref_from_cache}; 19use client::{fetching_with_report, get_repo_ref_from_cache};
@@ -97,8 +98,8 @@ async fn main() -> Result<()> {
97 println!(); 98 println!();
98 } 99 }
99 ["push", refspec] => { 100 ["push", refspec] => {
100 temp_remote.connect(git2::Direction::Push)?; 101 let auth = GitAuthenticator::default();
101 temp_remote.push(&[refspec], None)?; 102 auth.push(&git_repo.git_repo, &mut temp_remote, &[refspec])?;
102 temp_remote.disconnect()?; 103 temp_remote.disconnect()?;
103 println!(); 104 println!();
104 } 105 }