2 Commits

Author SHA1 Message Date
Tom Alexander
753ad6dd05 Handle errors in push events.
Some checks failed
semver Build semver has succeeded
format Build format has succeeded
rust-test Build rust-test has failed
clippy Build clippy has failed
build Build build has succeeded
2024-09-29 18:24:50 -04:00
Tom Alexander
dd4c20f0a7 Remove log of secret.
All checks were successful
semver Build semver has succeeded
format Build format has succeeded
build Build build has succeeded
clippy Build clippy has succeeded
rust-test Build rust-test has succeeded
2024-09-29 18:14:36 -04:00

View File

@@ -42,21 +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) => {
handle_push( let push_result = handle_push(
state.gitea, state.gitea,
state.kubernetes_client, state.kubernetes_client,
state.allowed_repos.borrow(), state.allowed_repos.borrow(),
webhook_payload, webhook_payload,
) )
.await .await;
.expect("Failed to handle push event."); match push_result {
( Ok(_) => (
StatusCode::OK, StatusCode::OK,
Json(HookResponse { Json(HookResponse {
ok: true, ok: true,
message: None, message: None,
}), }),
) ),
Err(_) => (
StatusCode::INTERNAL_SERVER_ERROR,
Json(HookResponse {
ok: false,
message: Some(format!("Failed to handle push event.")),
}),
),
}
} }
HookRequest::Unrecognized(payload) => ( HookRequest::Unrecognized(payload) => (
StatusCode::BAD_REQUEST, StatusCode::BAD_REQUEST,
@@ -146,9 +154,9 @@ where
} }
async fn check_hash(body: Bytes, secret: String, signature: Vec<u8>) -> Result<Bytes, Response> { async fn check_hash(body: Bytes, secret: String, signature: Vec<u8>) -> Result<Bytes, Response> {
tracing::info!("Checking signature {:02x?}", signature.as_slice()); tracing::debug!("Checking signature {:02x?}", signature.as_slice());
tracing::info!("Using secret {:?}", secret); // tracing::info!("Using secret {:?}", secret);
tracing::info!("and body {}", general_purpose::STANDARD.encode(&body)); tracing::debug!("and body {}", general_purpose::STANDARD.encode(&body));
let mut mac = HmacSha256::new_from_slice(secret.as_bytes()) let mut mac = HmacSha256::new_from_slice(secret.as_bytes())
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()).into_response())?; .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()).into_response())?;
mac.update(&body); mac.update(&body);