Skip to content
Merged
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
13 changes: 11 additions & 2 deletions josh-proxy/src/bin/josh-proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<String>("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)
Expand Down Expand Up @@ -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")
Expand All @@ -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 {
Expand Down
61 changes: 61 additions & 0 deletions tests/proxy/filter_prefix.t
Original file line number Diff line number Diff line change
@@ -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 <<EOF
> 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
2 changes: 2 additions & 0 deletions tests/proxy/shell.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
Duration between forced cache refresh
--static-resource-proxy-target <static-resource-proxy-target>
Proxy static resource requests to a different URL
--filter-prefix <filter-prefix>
Filter to be prefixed to all queries of this instance
-h, --help
Print help information

Expand Down