Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd7b22c5ce | ||
|
|
1c082a5e24 | ||
|
|
9ed8905a5c | ||
|
|
8cb28459a0 |
@@ -1,5 +1,3 @@
|
|||||||
cargo-features = ["codegen-backend"]
|
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "webhook_bridge"
|
name = "webhook_bridge"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
@@ -61,10 +59,3 @@ tracing-subscriber = { version = "0.3.18", default-features = false, features =
|
|||||||
inherits = "release"
|
inherits = "release"
|
||||||
lto = true
|
lto = true
|
||||||
strip = "symbols"
|
strip = "symbols"
|
||||||
|
|
||||||
[profile.dev]
|
|
||||||
codegen-backend = "cranelift"
|
|
||||||
|
|
||||||
[profile.dev.package."*"]
|
|
||||||
codegen-backend = "llvm"
|
|
||||||
opt-level = 3
|
|
||||||
|
|||||||
@@ -2,6 +2,5 @@ FROM rustlang/rust:nightly-alpine3.20 AS builder
|
|||||||
|
|
||||||
RUN apk add --no-cache musl-dev pkgconfig libressl3.8-libssl libressl-dev
|
RUN apk add --no-cache musl-dev pkgconfig libressl3.8-libssl libressl-dev
|
||||||
RUN cargo install --locked --no-default-features --features ci-autoclean cargo-cache
|
RUN cargo install --locked --no-default-features --features ci-autoclean cargo-cache
|
||||||
RUN rustup component add rustc-codegen-cranelift
|
|
||||||
RUN rustup component add rustfmt
|
RUN rustup component add rustfmt
|
||||||
RUN rustup component add clippy
|
RUN rustup component add clippy
|
||||||
|
|||||||
@@ -42,9 +42,29 @@ pub(crate) async fn hook(
|
|||||||
debug!("REQ: {:?}", payload);
|
debug!("REQ: {:?}", payload);
|
||||||
match payload {
|
match payload {
|
||||||
HookRequest::Push(webhook_payload) => {
|
HookRequest::Push(webhook_payload) => {
|
||||||
|
let kubernetes_client: kube::Client = kube::Client::try_default()
|
||||||
|
.await
|
||||||
|
.expect("Set KUBECONFIG to a valid kubernetes config.");
|
||||||
|
|
||||||
|
let gitea_api_root = std::env::var("WEBHOOK_BRIDGE_API_ROOT");
|
||||||
|
let gitea_api_token = std::env::var("WEBHOOK_BRIDGE_OAUTH_TOKEN");
|
||||||
|
let (gitea_api_root, gitea_api_token) = match (gitea_api_root, gitea_api_token) {
|
||||||
|
(Ok(r), Ok(t)) => (r, t),
|
||||||
|
_ => {
|
||||||
|
return (
|
||||||
|
StatusCode::OK,
|
||||||
|
Json(HookResponse {
|
||||||
|
ok: true,
|
||||||
|
message: None,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let gitea = GiteaClient::new(gitea_api_root, gitea_api_token);
|
||||||
|
|
||||||
let push_result = handle_push(
|
let push_result = handle_push(
|
||||||
state.gitea,
|
gitea,
|
||||||
state.kubernetes_client,
|
kubernetes_client,
|
||||||
state.allowed_repos.borrow(),
|
state.allowed_repos.borrow(),
|
||||||
webhook_payload,
|
webhook_payload,
|
||||||
)
|
)
|
||||||
@@ -58,16 +78,18 @@ pub(crate) async fn hook(
|
|||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
Err(_) => (
|
Err(_) => (
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
// StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
StatusCode::OK,
|
||||||
Json(HookResponse {
|
Json(HookResponse {
|
||||||
ok: false,
|
ok: false,
|
||||||
message: Some(format!("Failed to handle push event.")),
|
message: Some("Failed to handle push event.".to_string()),
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HookRequest::Unrecognized(payload) => (
|
HookRequest::Unrecognized(payload) => (
|
||||||
StatusCode::BAD_REQUEST,
|
// StatusCode::BAD_REQUEST,
|
||||||
|
StatusCode::OK,
|
||||||
Json(HookResponse {
|
Json(HookResponse {
|
||||||
ok: false,
|
ok: false,
|
||||||
message: Some(format!("unrecognized event type: {payload}")),
|
message: Some(format!("unrecognized event type: {payload}")),
|
||||||
|
|||||||
Reference in New Issue
Block a user