feat(server): add repository prefix path configuration and service struct
- Add REPO_PREFIX_PATH environment variable support in Dockerfile and main.rs - Introduce GitksService struct with repo_prefix field to manage repository paths - Implement resolve and resolve_for_init methods for repository path handling - Add path traversal protection and validation for repository operations - Update all service implementations to use self.resolve instead of global resolve - Modify serve function to accept repo_prefix parameter and pass to GitksService - Remove global resolve functions and integrate them into GitksService struct - Add proper initialization of repo directory from environment variable
This commit is contained in:
+8
-8
@@ -3,7 +3,7 @@ use tokio_stream::wrappers::ReceiverStream;
|
||||
|
||||
use crate::pb::*;
|
||||
|
||||
use super::{GitksService, into_status, resolve};
|
||||
use super::{GitksService, into_status};
|
||||
|
||||
#[tonic::async_trait]
|
||||
impl pack_service_server::PackService for GitksService {
|
||||
@@ -16,7 +16,7 @@ impl pack_service_server::PackService for GitksService {
|
||||
request: tonic::Request<AdvertiseRefsRequest>,
|
||||
) -> Result<tonic::Response<AdvertiseRefsResponse>, tonic::Status> {
|
||||
let inner = request.into_inner();
|
||||
let gb = resolve(inner.repository.as_ref())?;
|
||||
let gb = self.resolve(inner.repository.as_ref())?;
|
||||
let resp = gb.advertise_refs(inner).map_err(into_status)?;
|
||||
Ok(tonic::Response::new(resp))
|
||||
}
|
||||
@@ -30,7 +30,7 @@ impl pack_service_server::PackService for GitksService {
|
||||
.next()
|
||||
.await
|
||||
.ok_or_else(|| tonic::Status::invalid_argument("empty upload-pack stream"))??;
|
||||
let gb = resolve(first.repository.as_ref())?;
|
||||
let gb = self.resolve(first.repository.as_ref())?;
|
||||
|
||||
let (tx, rx) = tokio::sync::mpsc::channel(16);
|
||||
tx.send(Ok(first))
|
||||
@@ -57,7 +57,7 @@ impl pack_service_server::PackService for GitksService {
|
||||
.next()
|
||||
.await
|
||||
.ok_or_else(|| tonic::Status::invalid_argument("empty receive-pack stream"))??;
|
||||
let gb = resolve(first.repository.as_ref())?;
|
||||
let gb = self.resolve(first.repository.as_ref())?;
|
||||
|
||||
let (tx, rx) = tokio::sync::mpsc::channel(16);
|
||||
tx.send(Ok(first))
|
||||
@@ -80,7 +80,7 @@ impl pack_service_server::PackService for GitksService {
|
||||
request: tonic::Request<PackObjectsRequest>,
|
||||
) -> Result<tonic::Response<Self::PackObjectsStream>, tonic::Status> {
|
||||
let inner = request.into_inner();
|
||||
let gb = resolve(inner.repository.as_ref())?;
|
||||
let gb = self.resolve(inner.repository.as_ref())?;
|
||||
let stream = gb.pack_objects(inner).await?;
|
||||
Ok(tonic::Response::new(stream))
|
||||
}
|
||||
@@ -94,7 +94,7 @@ impl pack_service_server::PackService for GitksService {
|
||||
while let Some(msg) = stream.next().await {
|
||||
inputs.push(msg?);
|
||||
}
|
||||
let gb = resolve(inputs.first().and_then(|r| r.repository.as_ref()))?;
|
||||
let gb = self.resolve(inputs.first().and_then(|r| r.repository.as_ref()))?;
|
||||
let resp = gb.index_pack(inputs).map_err(into_status)?;
|
||||
Ok(tonic::Response::new(resp))
|
||||
}
|
||||
@@ -104,7 +104,7 @@ impl pack_service_server::PackService for GitksService {
|
||||
request: tonic::Request<ListPackfilesRequest>,
|
||||
) -> Result<tonic::Response<ListPackfilesResponse>, tonic::Status> {
|
||||
let inner = request.into_inner();
|
||||
let gb = resolve(inner.repository.as_ref())?;
|
||||
let gb = self.resolve(inner.repository.as_ref())?;
|
||||
let resp = gb.list_packfiles(inner).map_err(into_status)?;
|
||||
Ok(tonic::Response::new(resp))
|
||||
}
|
||||
@@ -114,7 +114,7 @@ impl pack_service_server::PackService for GitksService {
|
||||
request: tonic::Request<FsckRequest>,
|
||||
) -> Result<tonic::Response<FsckResponse>, tonic::Status> {
|
||||
let inner = request.into_inner();
|
||||
let gb = resolve(inner.repository.as_ref())?;
|
||||
let gb = self.resolve(inner.repository.as_ref())?;
|
||||
let resp = gb.fsck(inner).map_err(into_status)?;
|
||||
Ok(tonic::Response::new(resp))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user