From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 221661FF164 for ; Fri, 22 Nov 2024 11:08:23 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 6029BF473; Fri, 22 Nov 2024 11:08:25 +0100 (CET) From: Lukas Wagner To: pve-devel@lists.proxmox.com Date: Fri, 22 Nov 2024 11:08:15 +0100 Message-Id: <20241122100815.67255-2-l.wagner@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241122100815.67255-1-l.wagner@proxmox.com> References: <20241122100815.67255-1-l.wagner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.007 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH proxmox 2/2] notify: webhook: gotify: set HTTP request timeout X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" By default, the sync client from proxmox-http (powered by ureq) does not have any request timeout. To avoid blocking the current thread for a prolonged period of time, we now make use of the previously added `Client::new_with_timeout` function to create a new HTTP client with a default timout of 5 seconds. Signed-off-by: Lukas Wagner --- proxmox-notify/src/endpoints/gotify.rs | 5 ++++- proxmox-notify/src/endpoints/webhook.rs | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/proxmox-notify/src/endpoints/gotify.rs b/proxmox-notify/src/endpoints/gotify.rs index fae036cd..ea13d5d0 100644 --- a/proxmox-notify/src/endpoints/gotify.rs +++ b/proxmox-notify/src/endpoints/gotify.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use std::time::Duration; use serde::{Deserialize, Serialize}; use serde_json::json; @@ -13,6 +14,8 @@ use crate::renderer::TemplateType; use crate::schema::ENTITY_NAME_SCHEMA; use crate::{renderer, Content, Endpoint, Error, Notification, Origin, Severity}; +const HTTP_TIMEOUT: Duration = Duration::from_secs(5); + fn severity_to_priority(level: Severity) -> u32 { match level { Severity::Info => 1, @@ -146,7 +149,7 @@ impl Endpoint for GotifyEndpoint { ..Default::default() }; - let client = Client::new(options); + let client = Client::new_with_timeout(options, HTTP_TIMEOUT); let uri = format!("{}/message", self.config.server); client diff --git a/proxmox-notify/src/endpoints/webhook.rs b/proxmox-notify/src/endpoints/webhook.rs index 4ad9cb2f..efb70637 100644 --- a/proxmox-notify/src/endpoints/webhook.rs +++ b/proxmox-notify/src/endpoints/webhook.rs @@ -7,6 +7,8 @@ //! Secrets are kept in a private configuration file, accessible only by root, and are not retrievable via the API. //! Within templates, secrets can be referenced using `{{ secrets. }}`. //! Additionally, we take measures to prevent secrets from appearing in logs or error messages. +use std::time::Duration; + use handlebars::{ Context as HandlebarsContext, Handlebars, Helper, HelperResult, Output, RenderContext, RenderError as HandlebarsRenderError, @@ -30,6 +32,8 @@ use crate::{renderer, Content, Endpoint, Error, Notification, Origin}; /// This will be used as a section type in the public/private configuration file. pub(crate) const WEBHOOK_TYPENAME: &str = "webhook"; +const HTTP_TIMEOUT: Duration = Duration::from_secs(5); + #[api] #[derive(Serialize, Deserialize, Clone, Copy, Default)] #[serde(rename_all = "kebab-case")] @@ -270,7 +274,7 @@ impl WebhookEndpoint { ..Default::default() }; - Ok(Client::new(options)) + Ok(Client::new_with_timeout(options, HTTP_TIMEOUT)) } fn build_request(&self, notification: &Notification) -> Result, Error> { -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel