index : sparkle-git.git

ascending towards madness

author holly sparkles <sparkles@holly.sh> 2023-12-09 10:54:02.0 +00:00:00
committer holly sparkles <sparkles@holly.sh> 2024-05-14 6:40:47.0 +00:00:00
commit
b0cf401350321d5ecd000392ba923112656d30d1 [patch]
tree
02be8fd8b561d3175ab9ffb60c35fc978c900d1c
parent
3f19c49c63ed70bd50001f07c180d1b4595737dc
download
b0cf401350321d5ecd000392ba923112656d30d1.tar.gz

feat: add rejecting git connection if `enable_http_clone` is `false`



Diff

 src/methods/repo/smart_git.rs | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/methods/repo/smart_git.rs b/src/methods/repo/smart_git.rs
index 5e04345..001527d 100644
--- a/src/methods/repo/smart_git.rs
+++ b/src/methods/repo/smart_git.rs
@@ -23,6 +23,7 @@ use tokio_util::io::StreamReader;
use tracing::{debug, error, info_span, warn, Instrument};

use crate::{
    configuration::AppConfig,
    methods::repo::{Repository, RepositoryPath, Result},
    StatusCode,
};
@@ -31,11 +32,22 @@ use crate::{
pub async fn handle(
    Extension(RepositoryPath(repository_path)): Extension<RepositoryPath>,
    Extension(Repository(repository)): Extension<Repository>,
    Extension(config): Extension<AppConfig>,
    method: Method,
    uri: Uri,
    headers: HeaderMap,
    body: Body,
) -> Result<impl IntoResponse> {
    if !config.http_clone_enabled() {
        let headers = Response::builder()
            .status(StatusCode::SERVICE_UNAVAILABLE)
            .body(())
            .context("error forming response when `enable_http_clone` is `false`")?;
        let body = Body::from("HTTP(s) clone is not enabled on this server.");

        return Ok((headers, body));
    }

    let path = extract_path(&uri, &repository)?;

    let mut command = Command::new("git");