From d66b2f45700af4cb9ffc1ededc9372b4cce9fd41 Mon Sep 17 00:00:00 2001 From: Louis-Marie Givel Date: Fri, 21 Oct 2022 12:46:37 +0200 Subject: [PATCH] Restore add filter_prefix option (#986) It was removed by accident in the hyper_cgi merge Change: filter_prefix --- josh-proxy/src/bin/josh-proxy.rs | 13 +++++-- tests/proxy/filter_prefix.t | 61 ++++++++++++++++++++++++++++++++ tests/proxy/shell.t | 2 ++ 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 tests/proxy/filter_prefix.t diff --git a/josh-proxy/src/bin/josh-proxy.rs b/josh-proxy/src/bin/josh-proxy.rs index 363e8f3ac..dbda999bf 100644 --- a/josh-proxy/src/bin/josh-proxy.rs +++ b/josh-proxy/src/bin/josh-proxy.rs @@ -543,12 +543,16 @@ async fn call_service( meta.config.repo = parsed_url.upstream_repo; } - let filter = josh::filter::chain( + let mut filter = josh::filter::chain( meta.config.filter, josh::filter::parse(&parsed_url.filter_spec)?, ); let remote_url = [serv.upstream_url.as_str(), meta.config.repo.as_str()].join(""); + if let Some(filter_prefix) = ARGS.get_one::("filter-prefix").map(|v| v.as_str()) { + filter = josh::filter::chain(josh::filter::parse(filter_prefix)?, filter); + } + if parsed_url.pathinfo.starts_with("/info/lfs") { return Ok(Response::builder() .status(307) @@ -977,7 +981,7 @@ fn make_app() -> clap::Command { .short('n') .help("Number of concurrent upstream git fetch/push operations"), ) - .arg(clap::Arg::new("port").long("port").num_args(1)) + .arg(clap::Arg::new("port").long("port")) .arg( clap::Arg::new("cache-duration") .long("cache-duration") @@ -989,6 +993,11 @@ fn make_app() -> clap::Command { .long("static-resource-proxy-target") .help("Proxy static resource requests to a different URL"), ) + .arg( + clap::Arg::new("filter-prefix") + .long("filter-prefix") + .help("Filter to be prefixed to all queries of this instance"), + ) } fn parse_args() -> clap::ArgMatches { diff --git a/tests/proxy/filter_prefix.t b/tests/proxy/filter_prefix.t new file mode 100644 index 000000000..bd166cea3 --- /dev/null +++ b/tests/proxy/filter_prefix.t @@ -0,0 +1,61 @@ + $ EXTRA_OPTS="--filter-prefix=:/data" . ${TESTDIR}/setup_test_env.sh + $ cd ${TESTTMP} + + $ git clone -q http://localhost:8001/real_repo.git + warning: You appear to have cloned an empty repository. + + $ cd real_repo + + $ mkdir data + $ cd data + $ mkdir sub1 + $ echo contents1 > sub1/file1 + $ git add sub1 + $ git commit -m "add file1" 1> /dev/null + + $ mkdir sub2 + $ echo contents1 > sub2/file2 + $ git add sub2 + $ git commit -m "add file2" 1> /dev/null + + $ cat > tmpl_file < param: {{ param_val }} + > EOF + + $ git add tmpl_file + $ git commit -m "add tmpl_file" 1> /dev/null + + $ git push --all + To http://localhost:8001/real_repo.git + * [new branch] master -> master + + $ echo changes_contents > sub2/on_change + $ git add sub2 + $ git commit -m "add on_change" 1> /dev/null + + $ git push origin HEAD:refs/changes/123/2 + To http://localhost:8001/real_repo.git + * [new reference] HEAD -> refs/changes/123/2 + + $ cd ${TESTTMP} + $ tree real_repo + real_repo + `-- data + |-- sub1 + | `-- file1 + |-- sub2 + | |-- file2 + | `-- on_change + `-- tmpl_file + + 3 directories, 4 files + + $ git clone http://localhost:8002/real_repo.git:/sub2.git + Cloning into 'sub2'... + $ tree sub2 + sub2 + `-- file2 + + 0 directories, 1 file + $ curl -s http://localhost:8002/real_repo.git:/sub1.git?get=file1 + contents1 diff --git a/tests/proxy/shell.t b/tests/proxy/shell.t index 98699ff88..6d99e5603 100644 --- a/tests/proxy/shell.t +++ b/tests/proxy/shell.t @@ -24,6 +24,8 @@ Duration between forced cache refresh --static-resource-proxy-target Proxy static resource requests to a different URL + --filter-prefix + Filter to be prefixed to all queries of this instance -h, --help Print help information