Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

git-server: Add /info path #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions git-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ tracing = "0.1"
tracing-subscriber = "0.2"
warp = { version = "0.3.1", features = ["tls"] }
radicle-source = { version = "0.2.0" }
serde_json = { version = "1", features = ["preserve_order"] }

# hooks feature enabled dependencies
envconfig = { version = "0.10.0", optional = true }
Expand Down
42 changes: 40 additions & 2 deletions git-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use librad::identities::SomeIdentity;
use librad::paths::Paths;
use librad::profile::Profile;
use librad::PeerId;
use serde_json::json;
use tokio::sync::RwLock;
use warp::hyper::StatusCode;
use warp::reply;
Expand Down Expand Up @@ -295,7 +296,15 @@ pub async fn run(options: Options) -> anyhow::Result<()> {
.map(Some)
.or_else(|_| async { Ok::<(Option<PeerId>,), Infallible>((None,)) });

let server = warp::filters::any::any()
let _ctx = ctx.clone();
let info = warp::path("info").and(
warp::get()
.map(move || _ctx.clone())
.and(path::end())
.and_then(info_handler),
);

let git = warp::filters::any::any()
.map(move || ctx.clone())
.and(warp::method())
.and(warp::filters::header::headers_cloned())
Expand All @@ -312,7 +321,9 @@ pub async fn run(options: Options) -> anyhow::Result<()> {
.and_then(git_handler)
.recover(recover)
.with(warp::log("radicle_git_server"));
let server = warp::serve(server);

let routes = info.or(git);
let server = warp::serve(routes);

if let (Some(cert), Some(key)) = (options.tls_cert, options.tls_key) {
server
Expand Down Expand Up @@ -384,6 +395,33 @@ async fn git_handler(
Ok(Box::new(response))
}

async fn info_handler(ctx: Context) -> Result<impl Reply, Rejection> {
let git_version = Command::new("git")
.arg("version")
.output()
.map_err(Error::from)?
.stdout;

let git_version = std::str::from_utf8(&git_version)
.map_err(Error::from)?
.trim();

let mut authorized_keys = ctx.load_authorized_keys().map_err(Error::from)?;
if authorized_keys.is_empty() && ctx.allow_unauthorized_keys {
authorized_keys.push(String::from("*"));
}

let response = json!({
"git": {
"version": git_version
},
"root": ctx.root,
"authorized-keys": authorized_keys,
});

Ok(warp::reply::json(&response))
}

async fn git(
ctx: Context,
method: Method,
Expand Down