补齐证书自动续期和手动部署任务审计记录
This commit is contained in:
1 parent
17188dad33
commit
431fd043c2
10 files changed
+502
-3
No files matched your search
@@ -237,6 +237,9 @@ func (s *RenewalScheduler) Stop() {
|
||||
}
|
||||
|
||||
func (s *RenewalScheduler) issueWithRetry(ctx context.Context, domainID string, urgent bool, policy RenewalPolicy) error {
|
||||
if executor, ok := s.issuer.(RenewalExecutor); ok {
|
||||
return executor.Renew(ctx, domainID, urgent, policy)
|
||||
}
|
||||
attempts := 1
|
||||
if urgent {
|
||||
attempts = policy.MaxRetries
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package certificate
|
||||
|
||||
import "context"
|
||||
|
||||
type RenewalExecutor interface {
|
||||
Renew(context.Context, string, bool, RenewalPolicy) error
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package certificate
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.pcux.cn/xuans/Scert/backend/internal/domain"
|
||||
)
|
||||
|
||||
type recordedRenewalExecutor struct {
|
||||
calls int
|
||||
urgent bool
|
||||
policy RenewalPolicy
|
||||
}
|
||||
|
||||
func (r *recordedRenewalExecutor) Issue(context.Context, string) (IssueResult, error) {
|
||||
panic("unexpected fallback")
|
||||
}
|
||||
|
||||
func (r *recordedRenewalExecutor) Renew(_ context.Context, _ string, urgent bool, policy RenewalPolicy) error {
|
||||
r.calls++
|
||||
r.urgent, r.policy = urgent, policy
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestRenewalSchedulerUsesRecordedExecutor(t *testing.T) {
|
||||
expires := time.Now().Add(time.Hour)
|
||||
executor := &recordedRenewalExecutor{}
|
||||
scheduler := NewRenewalScheduler(renewalLister{items: []domain.Domain{{ID: "domain", AutoRenew: true, ExpiresAt: &expires}}}, executor, 6)
|
||||
report, err := scheduler.RunOnce(t.Context())
|
||||
if err != nil || report.Succeeded != 1 || executor.calls != 1 || !executor.urgent || executor.policy.MaxRetries != 3 {
|
||||
t.Fatalf("调度器未使用带记录的续期入口:%+v %+v %v", report, executor, err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user