mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2026-06-19 07:36:59 +00:00
feat(cert): skip non-success status in auto-renew worker
This commit is contained in:
@@ -42,6 +42,11 @@ func autoCert(certModel *model.Cert) {
|
||||
targetName := getAutoRenewTargetName(certModel)
|
||||
now := time.Now()
|
||||
|
||||
if shouldSkipAutoCertByStatus(certModel) {
|
||||
logger.Infof("Skip auto cert for %s due to status %s", targetName, certModel.Status)
|
||||
return
|
||||
}
|
||||
|
||||
if shouldSkipAutoRenew(certModel, now) {
|
||||
logger.Infof("Skip auto renew for %s until %s after previous failure", targetName,
|
||||
certModel.LastAutoRenewAt.Add(autoRenewFailureRetryCooldown).Format(time.DateTime))
|
||||
@@ -145,6 +150,17 @@ func shouldSkipAutoRenew(certModel *model.Cert, now time.Time) bool {
|
||||
return now.Before(certModel.LastAutoRenewAt.Add(autoRenewFailureRetryCooldown))
|
||||
}
|
||||
|
||||
// shouldSkipAutoCertByStatus returns true when the cert's most recent
|
||||
// issuance attempt has not succeeded. Pending and failed certs must
|
||||
// be retried by the user explicitly; auto-renew should not touch them.
|
||||
func shouldSkipAutoCertByStatus(certModel *model.Cert) bool {
|
||||
if certModel == nil {
|
||||
return false
|
||||
}
|
||||
return certModel.Status == model.CertStatusPending ||
|
||||
certModel.Status == model.CertStatusFailure
|
||||
}
|
||||
|
||||
func handleAutoRenewFailure(certModel *model.Cert, log *Logger, name string, err error) {
|
||||
log.Error(err)
|
||||
updateAutoRenewStatus(certModel, time.Now(), err.Error())
|
||||
|
||||
@@ -98,3 +98,24 @@ func TestGetAutoRenewNotificationResponseFallsBackToPlainText(t *testing.T) {
|
||||
t.Fatalf("unexpected fallback response: %s", text)
|
||||
}
|
||||
}
|
||||
|
||||
func TestShouldSkipAutoCertForNonSuccessStatus(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
status string
|
||||
expected bool
|
||||
}{
|
||||
{"pending is skipped", model.CertStatusPending, true},
|
||||
{"failure is skipped", model.CertStatusFailure, true},
|
||||
{"success is renewed", model.CertStatusSuccess, false},
|
||||
{"empty (legacy) is renewed", "", false},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
cert := &model.Cert{Status: tc.status}
|
||||
if got := shouldSkipAutoCertByStatus(cert); got != tc.expected {
|
||||
t.Fatalf("shouldSkipAutoCertByStatus(%q) = %v, want %v", tc.status, got, tc.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user