From f7cf2fcc200a3340fa1961abc723727b55a4d209 Mon Sep 17 00:00:00 2001 From: Tola Leng Date: Thu, 31 Jul 2025 17:28:41 +0700 Subject: [PATCH] Fix: Set SSL initialize check with the current time. Closes: #100 - When adding a new SSL certificate, initialize with the current time. This ensures that the SSL check is triggered shortly after the certificate is added to the monitoring system. --- .../services/ssl/sslCertificateOperations.ts | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/application/src/services/ssl/sslCertificateOperations.ts b/application/src/services/ssl/sslCertificateOperations.ts index d1e87a3..aa422b0 100644 --- a/application/src/services/ssl/sslCertificateOperations.ts +++ b/application/src/services/ssl/sslCertificateOperations.ts @@ -13,6 +13,8 @@ export const addSSLCertificate = async ( certificateData: AddSSLCertificateDto ): Promise => { try { + const currentTime = new Date().toISOString(); + // Prepare the data for saving to database // The Go service will handle the actual SSL checking const data = { @@ -23,14 +25,15 @@ export const addSSLCertificate = async ( cert_sans: "", cert_alg: "", serial_number: "", - valid_from: new Date().toISOString(), // Will be updated by Go service - valid_till: new Date().toISOString(), // Will be updated by Go service + valid_from: currentTime, // Will be updated by Go service + valid_till: currentTime, // Will be updated by Go service validity_days: 0, // Will be updated by Go service days_left: 0, // Will be updated by Go service warning_threshold: Number(certificateData.warning_threshold) || 30, expiry_threshold: Number(certificateData.expiry_threshold) || 7, notification_channel: certificateData.notification_channel || "", check_interval: Number(certificateData.check_interval) || 1, // New field + check_at: currentTime, // Set to current time to trigger immediate check }; // Save to database @@ -38,7 +41,7 @@ export const addSSLCertificate = async ( return record as unknown as SSLCertificate; } catch (error) { - // console.error("Error adding SSL certificate:", error); + console.error("Error adding SSL certificate:", error); throw error; } }; @@ -67,7 +70,7 @@ export const checkAndUpdateCertificate = async ( // Return the current certificate data return typedCertificate; } catch (error) { - // console.error("Error updating SSL certificate:", error); + console.error("Error updating SSL certificate:", error); throw error; } }; @@ -84,10 +87,10 @@ export const triggerImmediateCheck = async (certificateId: string): Promise => { await pb.collection("ssl_certificates").delete(id); return true; } catch (error) { - // console.error("Error deleting SSL certificate:", error); + console.error("Error deleting SSL certificate:", error); throw error; } }; @@ -112,10 +115,10 @@ export const deleteSSLCertificate = async (id: string): Promise => { */ export const refreshAllCertificates = async (): Promise<{ success: number; failed: number }> => { try { - const response = await pb.collection("ssl_certificates").getList(1, 200); + const response = await pb.collection("ssl_certificates").getList(1, 100); const certificates = response.items as unknown as SSLCertificate[]; - // console.log(`Refreshing ${certificates.length} certificates...`); + console.log(`Refreshing ${certificates.length} certificates...`); let success = 0; let failed = 0; @@ -125,14 +128,14 @@ export const refreshAllCertificates = async (): Promise<{ success: number; faile await checkCertificateAndNotify(cert); success++; } catch (error) { - // console.error(`Failed to refresh certificate ${cert.domain}:`, error); + console.error(`Failed to refresh certificate ${cert.domain}:`, error); failed++; } } return { success, failed }; } catch (error) { - // console.error("Error refreshing certificates:", error); + console.error("Error refreshing certificates:", error); throw error; } }; \ No newline at end of file