优化阿里云 DNS 权限验证等待时长
This commit is contained in:
1 parent
91eaf31d15
commit
d8205ae651
20 files changed
+560
-38
No files matched your search
@@ -7,7 +7,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
@@ -76,7 +75,7 @@ func newDNSPermissionCommand(verify dnsPermissionVerifier, readOnly bool) *cobra
|
||||
return err
|
||||
}
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(cmd.Context(), 45*time.Second)
|
||||
ctx, cancel := context.WithTimeout(cmd.Context(), dnsprovider.PermissionVerificationTimeoutFor(dnsprovider.Aliyun))
|
||||
defer cancel()
|
||||
report, verifyErr := verify(ctx, requestedDomain, credentials)
|
||||
if err := printJSON(cmd, report); err != nil {
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.pcux.cn/xuans/Scert/backend/internal/config"
|
||||
"git.pcux.cn/xuans/Scert/backend/internal/dnsprovider"
|
||||
@@ -79,9 +80,14 @@ func TestDNSCheckReportsLiveResultWithoutPersistingConfiguration(t *testing.T) {
|
||||
if name != "example.com" || credentials["access_key_id"] != "test-id" {
|
||||
t.Fatal("检查目标或凭据来源不正确")
|
||||
}
|
||||
if _, ok := ctx.Deadline(); !ok {
|
||||
deadline, ok := ctx.Deadline()
|
||||
if !ok {
|
||||
t.Fatal("权限请求必须设置超时")
|
||||
}
|
||||
remaining := time.Until(deadline)
|
||||
if remaining < 14*time.Second || remaining > 16*time.Second {
|
||||
t.Fatalf("阿里云 CLI 权限验证时限错误:%s", remaining)
|
||||
}
|
||||
report := dnsprovider.AuthorizationReport{Provider: "aliyun", RequestedDomain: name, Verified: outcome == "allowed"}
|
||||
switch outcome {
|
||||
case "denied":
|
||||
|
||||
@@ -106,7 +106,7 @@ func verifyExistingDNSCredentials(ctx context.Context, cfg config.Config, input
|
||||
if err != nil {
|
||||
return func() {}, fmt.Errorf("读取已有 DNS 凭据失败:%w", err)
|
||||
}
|
||||
verifyCtx, cancel := context.WithTimeout(ctx, dnsprovider.PermissionVerificationTimeout)
|
||||
verifyCtx, cancel := context.WithTimeout(ctx, dnsprovider.PermissionVerificationTimeoutFor(input.DNSProvider))
|
||||
defer cancel()
|
||||
if err := checker.VerifyDomain(verifyCtx, input.DNSProvider, target, credentials); err != nil {
|
||||
return func() {}, fmt.Errorf("已有 DNS 凭据在线权限校验失败:%w", err)
|
||||
|
||||
@@ -479,11 +479,15 @@ func prepareDNSCredentials(ctx context.Context, cfg config.Config, input *setup.
|
||||
dnsprovider.NewTester(dnsprovider.NewLegoFactory()),
|
||||
store,
|
||||
)
|
||||
return prepareDNSCredentialsWithManagerAndTimeout(ctx, input, output, manager, store, dnsprovider.PermissionVerificationTimeout)
|
||||
return prepareDNSCredentialsWithManagerAndTimeout(ctx, input, output, manager, store, dnsprovider.PermissionVerificationTimeoutFor(input.DNSProvider))
|
||||
}
|
||||
|
||||
func prepareDNSCredentialsWithManager(ctx context.Context, input *setup.Input, output io.Writer, manager *setup.DNSVerificationManager, store *secretstore.Store) (func(), error) {
|
||||
return prepareDNSCredentialsWithManagerAndTimeout(ctx, input, output, manager, store, dnsprovider.PermissionVerificationTimeout)
|
||||
timeout := dnsprovider.PermissionVerificationTimeout
|
||||
if input != nil {
|
||||
timeout = dnsprovider.PermissionVerificationTimeoutFor(input.DNSProvider)
|
||||
}
|
||||
return prepareDNSCredentialsWithManagerAndTimeout(ctx, input, output, manager, store, timeout)
|
||||
}
|
||||
|
||||
func prepareDNSCredentialsWithManagerAndTimeout(ctx context.Context, input *setup.Input, output io.Writer, manager *setup.DNSVerificationManager, store *secretstore.Store, timeout time.Duration) (func(), error) {
|
||||
|
||||
Reference in new issue
Block a user