Support optional URL prefix for hook URL
This commit is contained in:
parent
3a2da3fba8
commit
bddff51ab3
@ -16,6 +16,7 @@ pub struct RepoConfig {
|
|||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub bind_address: Option<String>,
|
pub bind_address: Option<String>,
|
||||||
pub bind_port: Option<u16>,
|
pub bind_port: Option<u16>,
|
||||||
|
pub url_prefix: Option<String>,
|
||||||
#[serde(deserialize_with = "deser_user_id")]
|
#[serde(deserialize_with = "deser_user_id")]
|
||||||
pub user_id: OwnedUserId,
|
pub user_id: OwnedUserId,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
|
16
src/main.rs
16
src/main.rs
@ -161,8 +161,20 @@ async fn run() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
let matrix_client = matrix_connect(&config).await.context("Failed to connect to Matrix")?;
|
let matrix_client = matrix_connect(&config).await.context("Failed to connect to Matrix")?;
|
||||||
|
|
||||||
let gitlab = warp::path!("hooks" / "gitlab")
|
let gitlab_root_path = if let Some(url_prefix) = config.url_prefix.as_ref() {
|
||||||
.and(warp::path::end())
|
url_prefix.split('/').fold(warp::any().boxed(), |last, segment| {
|
||||||
|
if segment.is_empty() {
|
||||||
|
last
|
||||||
|
} else {
|
||||||
|
last.and(warp::path(segment.to_string())).boxed()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
warp::any().boxed()
|
||||||
|
};
|
||||||
|
|
||||||
|
let gitlab = gitlab_root_path
|
||||||
|
.and(warp::path!("hooks" / "gitlab"))
|
||||||
.and(warp::post())
|
.and(warp::post())
|
||||||
.and(warp::header::<String>("x-gitlab-token"))
|
.and(warp::header::<String>("x-gitlab-token"))
|
||||||
.and(warp::body::json())
|
.and(warp::body::json())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user