diff --git a/go.mod b/go.mod index 6cc33ec57..dc2ce92bd 100644 --- a/go.mod +++ b/go.mod @@ -64,7 +64,6 @@ require ( github.com/qiniu/go-sdk/v7 v7.26.18 github.com/samber/lo v1.53.0 github.com/spf13/cobra v1.10.2 - github.com/spf13/pflag v1.0.10 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn v1.3.116 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.3.142 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.145 @@ -259,6 +258,7 @@ require ( github.com/sony/gobreaker/v2 v2.4.0 // indirect github.com/spf13/afero v1.15.0 // indirect github.com/spf13/cast v1.10.0 // indirect + github.com/spf13/pflag v1.0.10 // indirect github.com/tinylib/msgp v1.6.4 // indirect github.com/tjfoc/gmsm v1.4.1 // indirect github.com/yandex-cloud/go-sdk/services/dns v0.0.65 // indirect diff --git a/internal/certacme/certifiers/sp_ucloud_udnr.go b/internal/certacme/certifiers/sp_ucloud_udnr.go index fa6983976..ed57fff57 100644 --- a/internal/certacme/certifiers/sp_ucloud_udnr.go +++ b/internal/certacme/certifiers/sp_ucloud_udnr.go @@ -20,6 +20,7 @@ func init() { PrivateKey: credentials.PrivateKey, PublicKey: credentials.PublicKey, ProjectId: credentials.ProjectId, + Endpoint: xmaps.GetString(options.ProviderExtendedConfig, "endpoint"), DnsPropagationTimeout: options.DnsPropagationTimeout, DnsTTL: options.DnsTTL, }) diff --git a/internal/certmgmt/deployers/sp_ucloud_ualb.go b/internal/certmgmt/deployers/sp_ucloud_ualb.go index 469e5e34f..02a74c645 100644 --- a/internal/certmgmt/deployers/sp_ucloud_ualb.go +++ b/internal/certmgmt/deployers/sp_ucloud_ualb.go @@ -20,6 +20,7 @@ func init() { PrivateKey: credentials.PrivateKey, PublicKey: credentials.PublicKey, ProjectId: credentials.ProjectId, + Endpoint: xmaps.GetString(options.ProviderExtendedConfig, "endpoint"), Region: xmaps.GetString(options.ProviderExtendedConfig, "region"), DeployTarget: xmaps.GetString(options.ProviderExtendedConfig, "deployTarget"), LoadbalancerId: xmaps.GetString(options.ProviderExtendedConfig, "loadbalancerId"), diff --git a/internal/certmgmt/deployers/sp_ucloud_ucdn.go b/internal/certmgmt/deployers/sp_ucloud_ucdn.go index 46a0f864d..e52e57c8d 100644 --- a/internal/certmgmt/deployers/sp_ucloud_ucdn.go +++ b/internal/certmgmt/deployers/sp_ucloud_ucdn.go @@ -20,6 +20,7 @@ func init() { PrivateKey: credentials.PrivateKey, PublicKey: credentials.PublicKey, ProjectId: credentials.ProjectId, + Endpoint: xmaps.GetString(options.ProviderExtendedConfig, "endpoint"), DomainId: xmaps.GetString(options.ProviderExtendedConfig, "domainId"), }) return provider, err diff --git a/internal/certmgmt/deployers/sp_ucloud_uclb.go b/internal/certmgmt/deployers/sp_ucloud_uclb.go index cbe970598..fc63ce2eb 100644 --- a/internal/certmgmt/deployers/sp_ucloud_uclb.go +++ b/internal/certmgmt/deployers/sp_ucloud_uclb.go @@ -20,6 +20,7 @@ func init() { PrivateKey: credentials.PrivateKey, PublicKey: credentials.PublicKey, ProjectId: credentials.ProjectId, + Endpoint: xmaps.GetString(options.ProviderExtendedConfig, "endpoint"), Region: xmaps.GetString(options.ProviderExtendedConfig, "region"), DeployTarget: xmaps.GetString(options.ProviderExtendedConfig, "deployTarget"), LoadbalancerId: xmaps.GetString(options.ProviderExtendedConfig, "loadbalancerId"), diff --git a/internal/certmgmt/deployers/sp_ucloud_uewaf.go b/internal/certmgmt/deployers/sp_ucloud_uewaf.go index 0d576a6a1..70d385a9a 100644 --- a/internal/certmgmt/deployers/sp_ucloud_uewaf.go +++ b/internal/certmgmt/deployers/sp_ucloud_uewaf.go @@ -20,6 +20,7 @@ func init() { PrivateKey: credentials.PrivateKey, PublicKey: credentials.PublicKey, ProjectId: credentials.ProjectId, + Endpoint: xmaps.GetString(options.ProviderExtendedConfig, "endpoint"), Domain: xmaps.GetString(options.ProviderExtendedConfig, "domain"), }) return provider, err diff --git a/internal/certmgmt/deployers/sp_ucloud_upathx.go b/internal/certmgmt/deployers/sp_ucloud_upathx.go index e0f7ac2bf..7aa407043 100644 --- a/internal/certmgmt/deployers/sp_ucloud_upathx.go +++ b/internal/certmgmt/deployers/sp_ucloud_upathx.go @@ -20,6 +20,7 @@ func init() { PrivateKey: credentials.PrivateKey, PublicKey: credentials.PublicKey, ProjectId: credentials.ProjectId, + Endpoint: xmaps.GetString(options.ProviderExtendedConfig, "endpoint"), AcceleratorId: xmaps.GetString(options.ProviderExtendedConfig, "acceleratorId"), ListenerPort: xmaps.GetInt32(options.ProviderExtendedConfig, "listenerPort"), }) diff --git a/internal/certmgmt/deployers/sp_ucloud_us3.go b/internal/certmgmt/deployers/sp_ucloud_us3.go index 439a12c05..4a16ca827 100644 --- a/internal/certmgmt/deployers/sp_ucloud_us3.go +++ b/internal/certmgmt/deployers/sp_ucloud_us3.go @@ -20,6 +20,7 @@ func init() { PrivateKey: credentials.PrivateKey, PublicKey: credentials.PublicKey, ProjectId: credentials.ProjectId, + Endpoint: xmaps.GetString(options.ProviderExtendedConfig, "endpoint"), Region: xmaps.GetString(options.ProviderExtendedConfig, "region"), Bucket: xmaps.GetString(options.ProviderExtendedConfig, "bucket"), Domain: xmaps.GetString(options.ProviderExtendedConfig, "domain"), diff --git a/pkg/core/certifier/challengers/dns01/ucloud/internal/lego.go b/pkg/core/certifier/challengers/dns01/ucloud/internal/lego.go new file mode 100644 index 000000000..572584239 --- /dev/null +++ b/pkg/core/certifier/challengers/dns01/ucloud/internal/lego.go @@ -0,0 +1,186 @@ +package internal + +import ( + "context" + "errors" + "fmt" + "strconv" + "strings" + "time" + + "github.com/go-acme/lego/v5/challenge" + "github.com/go-acme/lego/v5/challenge/dns01" + "github.com/go-acme/lego/v5/platform/env" + "github.com/ucloud/ucloud-sdk-go/ucloud" + "github.com/ucloud/ucloud-sdk-go/ucloud/auth" + + ucloudsdk "github.com/certimate-go/certimate/pkg/sdk3rd/ucloud/udnr" +) + +const ( + envNamespace = "UCLOUD_" + + EnvPublicKey = envNamespace + "PUBLIC_KEY" + EnvPrivateKey = envNamespace + "PRIVATE_KEY" + EnvProjectID = envNamespace + "PROJECT_ID" + EnvBaseURL = envNamespace + "BASE_URL" + EnvRegion = envNamespace + "REGION" + + EnvTTL = envNamespace + "TTL" + EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT" + EnvPollingInterval = envNamespace + "POLLING_INTERVAL" + EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT" +) + +var _ challenge.ProviderTimeout = (*DNSProvider)(nil) + +type Config struct { + PublicKey string + PrivateKey string + ProjectID string + BaseURL string + Region string + + TTL int + PropagationTimeout time.Duration + PollingInterval time.Duration + HTTPTimeout time.Duration +} + +func NewDefaultConfig() *Config { + return &Config{ + TTL: env.GetOrDefaultInt(EnvTTL, 600), + PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout), + PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval), + HTTPTimeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second), + } +} + +// 这里有意不使用 lego 提供的 ucloud 实现, +// 因为它无法配置客户端的访问地址。 +type DNSProvider struct { + config *Config + client *ucloudsdk.UDNRClient +} + +func NewDNSProvider() (*DNSProvider, error) { + values, err := env.Get(EnvPublicKey, EnvPrivateKey) + if err != nil { + return nil, fmt.Errorf("ucloud: %w", err) + } + + config := NewDefaultConfig() + config.PublicKey = values[EnvPublicKey] + config.PrivateKey = values[EnvPrivateKey] + config.ProjectID = env.GetOrFile(EnvProjectID) + config.BaseURL = env.GetOrFile(EnvBaseURL) + config.Region = env.GetOrFile(EnvRegion) + + return NewDNSProviderConfig(config) +} + +func NewDNSProviderConfig(config *Config) (*DNSProvider, error) { + if config == nil { + return nil, errors.New("ucloud: the configuration of the DNS provider is nil") + } + + if config.PublicKey == "" || config.PrivateKey == "" { + return nil, errors.New("ucloud: credentials missing") + } + + credential := auth.NewCredential() + credential.PublicKey = config.PublicKey + credential.PrivateKey = config.PrivateKey + + cfg := ucloud.NewConfig() + + if config.ProjectID != "" { + cfg.ProjectId = config.ProjectID + } + + if config.BaseURL != "" { + if strings.Contains(config.BaseURL, "://") { + cfg.BaseUrl = config.BaseURL + } else { + cfg.BaseUrl = "https://" + config.BaseURL + } + } + + if config.Region != "" { + cfg.Region = config.Region + } + + return &DNSProvider{ + config: config, + client: ucloudsdk.NewClient(&cfg, &credential), + }, nil +} + +func (d *DNSProvider) Present(ctx context.Context, domain, token, keyAuth string) error { + info := dns01.GetChallengeInfo(ctx, domain, keyAuth) + + authZone, err := dns01.DefaultClient().FindZoneByFqdn(ctx, info.EffectiveFQDN) + if err != nil { + return fmt.Errorf("ucloud: could not find zone for domain %q: %w", domain, err) + } + + // REF: https://docs.ucloud.cn/api/udnr-api/udnr_domain_dns_add + addRequest := d.client.NewDomainDNSAddRequest() + addRequest.Dn = ucloud.String(dns01.UnFqdn(authZone)) + addRequest.RecordName = ucloud.String(dns01.UnFqdn(info.EffectiveFQDN)) + addRequest.DnsType = ucloud.String("TXT") + addRequest.Content = ucloud.String(info.Value) + addRequest.TTL = ucloud.String(strconv.Itoa(d.config.TTL)) + addRequest.WithTimeout(d.config.HTTPTimeout) + + _, err = d.client.DomainDNSAdd(addRequest) + if err != nil { + return fmt.Errorf("ucloud: domain DNS add: %w", err) + } + + return nil +} + +func (d *DNSProvider) CleanUp(ctx context.Context, domain, token, keyAuth string) error { + info := dns01.GetChallengeInfo(ctx, domain, keyAuth) + + authZone, err := dns01.DefaultClient().FindZoneByFqdn(ctx, info.EffectiveFQDN) + if err != nil { + return fmt.Errorf("ucloud: could not find zone for domain %q: %w", domain, err) + } + + // REF: https://docs.ucloud.cn/api/udnr-api/udnr_domain_dns_query + queryRequest := d.client.NewDomainDNSQueryRequest() + queryRequest.Dn = ucloud.String(dns01.UnFqdn(authZone)) + queryRequest.WithTimeout(d.config.HTTPTimeout) + + dom, err := d.client.DomainDNSQuery(queryRequest) + if err != nil { + return fmt.Errorf("ucloud: domain DNS query: %w", err) + } + + for _, record := range dom.Data { + if record.Type != "TXT" || record.Name != dns01.UnFqdn(info.EffectiveFQDN) || record.Content != info.Value { + continue + } + + // REF: https://docs.ucloud.cn/api/udnr-api/udnr_delete_dns_record + deleteRequest := d.client.NewDNSRecordDeleteRequest() + deleteRequest.Dn = ucloud.String(dns01.UnFqdn(authZone)) + deleteRequest.RecordName = ucloud.String(dns01.UnFqdn(info.EffectiveFQDN)) + deleteRequest.DnsType = ucloud.String(record.Type) + deleteRequest.Content = ucloud.String(record.Content) + deleteRequest.WithTimeout(d.config.HTTPTimeout) + + _, err = d.client.DNSRecordDelete(deleteRequest) + if err != nil { + return fmt.Errorf("ucloud: delete DNS record: %w", err) + } + } + + return nil +} + +func (d *DNSProvider) Timeout() (timeout, interval time.Duration) { + return d.config.PropagationTimeout, d.config.PollingInterval +} diff --git a/pkg/core/certifier/challengers/dns01/ucloud/ucloud.go b/pkg/core/certifier/challengers/dns01/ucloud/ucloud.go index a7a794b83..65f8c09c1 100644 --- a/pkg/core/certifier/challengers/dns01/ucloud/ucloud.go +++ b/pkg/core/certifier/challengers/dns01/ucloud/ucloud.go @@ -4,15 +4,15 @@ import ( "fmt" "time" - "github.com/go-acme/lego/v5/providers/dns/ucloud" - "github.com/certimate-go/certimate/pkg/core" + "github.com/certimate-go/certimate/pkg/core/certifier/challengers/dns01/ucloud/internal" ) type ChallengerConfig struct { PrivateKey string `json:"privateKey"` PublicKey string `json:"publicKey"` ProjectId string `json:"projectId,omitempty"` + Endpoint string `json:"endpoint,omitempty"` DnsPropagationTimeout int `json:"dnsPropagationTimeout,omitempty"` DnsTTL int `json:"dnsTTL,omitempty"` } @@ -22,10 +22,11 @@ func NewChallenger(config *ChallengerConfig) (core.ACMEChallenger, error) { return nil, fmt.Errorf("config is nil") } - providerConfig := ucloud.NewDefaultConfig() + providerConfig := internal.NewDefaultConfig() providerConfig.PrivateKey = config.PrivateKey providerConfig.PublicKey = config.PublicKey providerConfig.ProjectID = config.ProjectId + providerConfig.BaseURL = config.Endpoint if config.DnsTTL != 0 { providerConfig.TTL = config.DnsTTL } @@ -33,7 +34,7 @@ func NewChallenger(config *ChallengerConfig) (core.ACMEChallenger, error) { providerConfig.PropagationTimeout = time.Duration(config.DnsPropagationTimeout) * time.Second } - provider, err := ucloud.NewDNSProviderConfig(providerConfig) + provider, err := internal.NewDNSProviderConfig(providerConfig) if err != nil { return nil, err } diff --git a/pkg/core/certmgr/providers/ucloud-ulb/ucloud_ulb.go b/pkg/core/certmgr/providers/ucloud-ulb/ucloud_ulb.go index 374591792..1561d85f8 100644 --- a/pkg/core/certmgr/providers/ucloud-ulb/ucloud_ulb.go +++ b/pkg/core/certmgr/providers/ucloud-ulb/ucloud_ulb.go @@ -28,6 +28,8 @@ type CertmgrConfig struct { PublicKey string `json:"publicKey"` // 优刻得项目 ID。 ProjectId string `json:"projectId,omitempty"` + // 优刻得接口端点。 + Endpoint string `json:"endpoint,omitempty"` // 优刻得地域。 Region string `json:"region"` } @@ -45,7 +47,7 @@ func NewCertmgr(config *CertmgrConfig) (*Certmgr, error) { return nil, fmt.Errorf("the configuration of the certmgr provider is nil") } - client, err := createSDKClient(config.PrivateKey, config.PublicKey, config.ProjectId, config.Region) + client, err := createSDKClient(config.PrivateKey, config.PublicKey, config.ProjectId, config.Endpoint, config.Region) if err != nil { return nil, fmt.Errorf("could not create client: %w", err) } @@ -179,7 +181,7 @@ func (c *Certmgr) tryGetResultIfCertExists(ctx context.Context, certPEM, privkey return nil, false, nil } -func createSDKClient(privateKey, publicKey, projectId, region string) (*ucloudsdk.ULBClient, error) { +func createSDKClient(privateKey, publicKey, projectId, endpoint, region string) (*ucloudsdk.ULBClient, error) { if privateKey == "" { return nil, fmt.Errorf("ucloud: invalid private key") } @@ -190,6 +192,13 @@ func createSDKClient(privateKey, publicKey, projectId, region string) (*ucloudsd cfg := ucloud.NewConfig() cfg.ProjectId = projectId cfg.Region = region + if endpoint != "" { + if strings.Contains(endpoint, "://") { + cfg.BaseUrl = endpoint + } else { + cfg.BaseUrl = "https://" + endpoint + } + } credential := auth.NewCredential() credential.PrivateKey = privateKey diff --git a/pkg/core/certmgr/providers/ucloud-upathx/ucloud_upathx.go b/pkg/core/certmgr/providers/ucloud-upathx/ucloud_upathx.go index 9eb366de3..d9d18ebad 100644 --- a/pkg/core/certmgr/providers/ucloud-upathx/ucloud_upathx.go +++ b/pkg/core/certmgr/providers/ucloud-upathx/ucloud_upathx.go @@ -29,6 +29,8 @@ type CertmgrConfig struct { PublicKey string `json:"publicKey"` // 优刻得项目 ID。 ProjectId string `json:"projectId,omitempty"` + // 优刻得接口端点。 + Endpoint string `json:"endpoint,omitempty"` } type Certmgr struct { @@ -44,7 +46,7 @@ func NewCertmgr(config *CertmgrConfig) (*Certmgr, error) { return nil, fmt.Errorf("the configuration of the certmgr provider is nil") } - client, err := createSDKClient(config.PrivateKey, config.PublicKey, config.ProjectId) + client, err := createSDKClient(config.PrivateKey, config.PublicKey, config.ProjectId, config.Endpoint) if err != nil { return nil, fmt.Errorf("could not create client: %w", err) } @@ -176,7 +178,7 @@ func (c *Certmgr) tryGetResultIfCertExists(ctx context.Context, certPEM, privkey return nil, false, nil } -func createSDKClient(privateKey, publicKey, projectId string) (*ucloudsdk.UPathXClient, error) { +func createSDKClient(privateKey, publicKey, projectId, endpoint string) (*ucloudsdk.UPathXClient, error) { if privateKey == "" { return nil, fmt.Errorf("ucloud: invalid private key") } @@ -186,10 +188,17 @@ func createSDKClient(privateKey, publicKey, projectId string) (*ucloudsdk.UPathX cfg := ucloud.NewConfig() cfg.ProjectId = projectId + if endpoint != "" { + if strings.Contains(endpoint, "://") { + cfg.BaseUrl = endpoint + } else { + cfg.BaseUrl = "https://" + endpoint + } + } // PathX 相关接口要求必传 ProjectId 参数 if cfg.ProjectId == "" { - defaultProjectId, err := getSDKDefaultProjectId(privateKey, publicKey) + defaultProjectId, err := getSDKDefaultProjectId(privateKey, publicKey, endpoint) if err != nil { return nil, err } @@ -205,8 +214,15 @@ func createSDKClient(privateKey, publicKey, projectId string) (*ucloudsdk.UPathX return client, nil } -func getSDKDefaultProjectId(privateKey, publicKey string) (string, error) { +func getSDKDefaultProjectId(privateKey, publicKey, endpoint string) (string, error) { cfg := ucloud.NewConfig() + if endpoint != "" { + if strings.Contains(endpoint, "://") { + cfg.BaseUrl = endpoint + } else { + cfg.BaseUrl = "https://" + endpoint + } + } credential := auth.NewCredential() credential.PrivateKey = privateKey diff --git a/pkg/core/certmgr/providers/ucloud-ussl/ucloud_ussl.go b/pkg/core/certmgr/providers/ucloud-ussl/ucloud_ussl.go index f8f4f63d0..d2eb3af6d 100644 --- a/pkg/core/certmgr/providers/ucloud-ussl/ucloud_ussl.go +++ b/pkg/core/certmgr/providers/ucloud-ussl/ucloud_ussl.go @@ -32,6 +32,8 @@ type CertmgrConfig struct { PublicKey string `json:"publicKey"` // 优刻得项目 ID。 ProjectId string `json:"projectId,omitempty"` + // 优刻得接口端点。 + Endpoint string `json:"endpoint,omitempty"` } type Certmgr struct { @@ -47,7 +49,7 @@ func NewCertmgr(config *CertmgrConfig) (*Certmgr, error) { return nil, fmt.Errorf("the configuration of the certmgr provider is nil") } - client, err := createSDKClient(config.PrivateKey, config.PublicKey, config.ProjectId) + client, err := createSDKClient(config.PrivateKey, config.PublicKey, config.ProjectId, config.Endpoint) if err != nil { return nil, fmt.Errorf("could not create client: %w", err) } @@ -230,7 +232,7 @@ func (c *Certmgr) tryGetResultIfCertExists(ctx context.Context, certPEM string) return nil, false, nil } -func createSDKClient(privateKey, publicKey, projectId string) (*ucloudsdk.USSLClient, error) { +func createSDKClient(privateKey, publicKey, projectId, endpoint string) (*ucloudsdk.USSLClient, error) { if privateKey == "" { return nil, fmt.Errorf("ucloud: invalid private key") } @@ -240,6 +242,13 @@ func createSDKClient(privateKey, publicKey, projectId string) (*ucloudsdk.USSLCl cfg := ucloud.NewConfig() cfg.ProjectId = projectId + if endpoint != "" { + if strings.Contains(endpoint, "://") { + cfg.BaseUrl = endpoint + } else { + cfg.BaseUrl = "https://" + endpoint + } + } credential := auth.NewCredential() credential.PrivateKey = privateKey diff --git a/pkg/core/deployer/providers/ucloud-ualb/ucloud_ualb.go b/pkg/core/deployer/providers/ucloud-ualb/ucloud_ualb.go index d208de3a4..8ac241cd5 100644 --- a/pkg/core/deployer/providers/ucloud-ualb/ucloud_ualb.go +++ b/pkg/core/deployer/providers/ucloud-ualb/ucloud_ualb.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log/slog" + "strings" "time" "github.com/samber/lo" @@ -29,6 +30,8 @@ type DeployerConfig struct { PublicKey string `json:"publicKey"` // 优刻得项目 ID。 ProjectId string `json:"projectId,omitempty"` + // 优刻得接口端点。 + Endpoint string `json:"endpoint,omitempty"` // 优刻得地域。 Region string `json:"region"` // 部署目标。 @@ -58,7 +61,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) { return nil, fmt.Errorf("the configuration of the deployer provider is nil") } - client, err := createSDKClient(config.PrivateKey, config.PublicKey, config.ProjectId, config.Region) + client, err := createSDKClient(config.PrivateKey, config.PublicKey, config.ProjectId, config.Endpoint, config.Region) if err != nil { return nil, fmt.Errorf("could not create client: %w", err) } @@ -67,6 +70,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) { PrivateKey: config.PrivateKey, PublicKey: config.PublicKey, ProjectId: config.ProjectId, + Endpoint: config.Endpoint, Region: config.Region, }) if err != nil { @@ -304,7 +308,7 @@ func (d *Deployer) updateListenerSniCertificate(ctx context.Context, cloudLoadba return nil } -func createSDKClient(privateKey, publicKey, projectId, region string) (*ucloudsdk.ULBClient, error) { +func createSDKClient(privateKey, publicKey, projectId, endpoint, region string) (*ucloudsdk.ULBClient, error) { if privateKey == "" { return nil, fmt.Errorf("ucloud: invalid private key") } @@ -315,6 +319,13 @@ func createSDKClient(privateKey, publicKey, projectId, region string) (*ucloudsd cfg := ucloud.NewConfig() cfg.ProjectId = projectId cfg.Region = region + if endpoint != "" { + if strings.Contains(endpoint, "://") { + cfg.BaseUrl = endpoint + } else { + cfg.BaseUrl = "https://" + endpoint + } + } credential := auth.NewCredential() credential.PrivateKey = privateKey diff --git a/pkg/core/deployer/providers/ucloud-ucdn/ucloud_ucdn.go b/pkg/core/deployer/providers/ucloud-ucdn/ucloud_ucdn.go index 1d7b86b9e..f02bbd341 100644 --- a/pkg/core/deployer/providers/ucloud-ucdn/ucloud_ucdn.go +++ b/pkg/core/deployer/providers/ucloud-ucdn/ucloud_ucdn.go @@ -5,6 +5,7 @@ import ( "fmt" "log/slog" "strconv" + "strings" "github.com/ucloud/ucloud-sdk-go/ucloud" "github.com/ucloud/ucloud-sdk-go/ucloud/auth" @@ -26,6 +27,8 @@ type DeployerConfig struct { PublicKey string `json:"publicKey"` // 优刻得项目 ID。 ProjectId string `json:"projectId,omitempty"` + // 优刻得接口端点。 + Endpoint string `json:"endpoint,omitempty"` // 加速域名 ID。 DomainId string `json:"domainId"` } @@ -44,7 +47,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) { return nil, fmt.Errorf("the configuration of the deployer provider is nil") } - client, err := createSDKClient(config.PrivateKey, config.PublicKey, config.ProjectId) + client, err := createSDKClient(config.PrivateKey, config.PublicKey, config.ProjectId, config.Endpoint) if err != nil { return nil, fmt.Errorf("could not create client: %w", err) } @@ -53,6 +56,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) { PrivateKey: config.PrivateKey, PublicKey: config.PublicKey, ProjectId: config.ProjectId, + Endpoint: config.Endpoint, }) if err != nil { return nil, fmt.Errorf("could not create certmgr: %w", err) @@ -121,7 +125,7 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep return &DeployResult{}, nil } -func createSDKClient(privateKey, publicKey, projectId string) (*ucloudsdk.UCDNClient, error) { +func createSDKClient(privateKey, publicKey, projectId, endpoint string) (*ucloudsdk.UCDNClient, error) { if privateKey == "" { return nil, fmt.Errorf("ucloud: invalid private key") } @@ -131,6 +135,13 @@ func createSDKClient(privateKey, publicKey, projectId string) (*ucloudsdk.UCDNCl cfg := ucloud.NewConfig() cfg.ProjectId = projectId + if endpoint != "" { + if strings.Contains(endpoint, "://") { + cfg.BaseUrl = endpoint + } else { + cfg.BaseUrl = "https://" + endpoint + } + } credential := auth.NewCredential() credential.PrivateKey = privateKey diff --git a/pkg/core/deployer/providers/ucloud-uclb/ucloud_uclb.go b/pkg/core/deployer/providers/ucloud-uclb/ucloud_uclb.go index 74e3e339c..f95fa97af 100644 --- a/pkg/core/deployer/providers/ucloud-uclb/ucloud_uclb.go +++ b/pkg/core/deployer/providers/ucloud-uclb/ucloud_uclb.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log/slog" + "strings" "sync" "github.com/samber/lo" @@ -29,6 +30,8 @@ type DeployerConfig struct { PublicKey string `json:"publicKey"` // 优刻得项目 ID。 ProjectId string `json:"projectId,omitempty"` + // 优刻得接口端点。 + Endpoint string `json:"endpoint,omitempty"` // 优刻得地域。 Region string `json:"region"` // 部署目标。 @@ -58,7 +61,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) { return nil, fmt.Errorf("the configuration of the deployer provider is nil") } - client, err := createSDKClient(config.PrivateKey, config.PublicKey, config.ProjectId, config.Region) + client, err := createSDKClient(config.PrivateKey, config.PublicKey, config.ProjectId, config.Endpoint, config.Region) if err != nil { return nil, fmt.Errorf("could not create client: %w", err) } @@ -67,6 +70,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) { PrivateKey: config.PrivateKey, PublicKey: config.PublicKey, ProjectId: config.ProjectId, + Endpoint: config.Endpoint, Region: config.Region, }) if err != nil { @@ -250,7 +254,7 @@ func (d *Deployer) updateVServerCertificate(ctx context.Context, cloudLoadbalanc return nil } -func createSDKClient(privateKey, publicKey, projectId, region string) (*ucloudsdk.ULBClient, error) { +func createSDKClient(privateKey, publicKey, projectId, endpoint, region string) (*ucloudsdk.ULBClient, error) { if privateKey == "" { return nil, fmt.Errorf("ucloud: invalid private key") } @@ -261,6 +265,13 @@ func createSDKClient(privateKey, publicKey, projectId, region string) (*ucloudsd cfg := ucloud.NewConfig() cfg.ProjectId = projectId cfg.Region = region + if endpoint != "" { + if strings.Contains(endpoint, "://") { + cfg.BaseUrl = endpoint + } else { + cfg.BaseUrl = "https://" + endpoint + } + } credential := auth.NewCredential() credential.PrivateKey = privateKey diff --git a/pkg/core/deployer/providers/ucloud-uewaf/ucloud_uewaf.go b/pkg/core/deployer/providers/ucloud-uewaf/ucloud_uewaf.go index 3abfaa808..6659d7b18 100644 --- a/pkg/core/deployer/providers/ucloud-uewaf/ucloud_uewaf.go +++ b/pkg/core/deployer/providers/ucloud-uewaf/ucloud_uewaf.go @@ -7,6 +7,7 @@ import ( "encoding/hex" "fmt" "log/slog" + "strings" "time" "github.com/ucloud/ucloud-sdk-go/ucloud" @@ -28,6 +29,8 @@ type DeployerConfig struct { PublicKey string `json:"publicKey"` // 优刻得项目 ID。 ProjectId string `json:"projectId,omitempty"` + // 优刻得接口端点。 + Endpoint string `json:"endpoint,omitempty"` // 自定义域名(不支持泛域名)。 Domain string `json:"domain"` } @@ -45,7 +48,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) { return nil, fmt.Errorf("the configuration of the deployer provider is nil") } - client, err := createSDKClient(config.PrivateKey, config.PublicKey, config.ProjectId) + client, err := createSDKClient(config.PrivateKey, config.PublicKey, config.ProjectId, config.Endpoint) if err != nil { return nil, fmt.Errorf("could not create client: %w", err) } @@ -95,7 +98,7 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep return &DeployResult{}, nil } -func createSDKClient(privateKey, publicKey, projectId string) (*ucloudsdk.UEWAFClient, error) { +func createSDKClient(privateKey, publicKey, projectId, endpoint string) (*ucloudsdk.UEWAFClient, error) { if privateKey == "" { return nil, fmt.Errorf("ucloud: invalid private key") } @@ -105,6 +108,13 @@ func createSDKClient(privateKey, publicKey, projectId string) (*ucloudsdk.UEWAFC cfg := ucloud.NewConfig() cfg.ProjectId = projectId + if endpoint != "" { + if strings.Contains(endpoint, "://") { + cfg.BaseUrl = endpoint + } else { + cfg.BaseUrl = "https://" + endpoint + } + } credential := auth.NewCredential() credential.PrivateKey = privateKey diff --git a/pkg/core/deployer/providers/ucloud-upathx/ucloud_upathx.go b/pkg/core/deployer/providers/ucloud-upathx/ucloud_upathx.go index 920d6938b..adca97c0d 100644 --- a/pkg/core/deployer/providers/ucloud-upathx/ucloud_upathx.go +++ b/pkg/core/deployer/providers/ucloud-upathx/ucloud_upathx.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log/slog" + "strings" "github.com/ucloud/ucloud-sdk-go/services/uaccount" "github.com/ucloud/ucloud-sdk-go/ucloud" @@ -26,6 +27,8 @@ type DeployerConfig struct { PublicKey string `json:"publicKey"` // 优刻得项目 ID。 ProjectId string `json:"projectId,omitempty"` + // 优刻得接口端点。 + Endpoint string `json:"endpoint,omitempty"` // 加速器实例 ID。 AcceleratorId string `json:"acceleratorId"` // 加速器监听端口。 @@ -46,7 +49,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) { return nil, fmt.Errorf("the configuration of the deployer provider is nil") } - client, err := createSDKClient(config.PrivateKey, config.PublicKey, config.ProjectId) + client, err := createSDKClient(config.PrivateKey, config.PublicKey, config.ProjectId, config.Endpoint) if err != nil { return nil, fmt.Errorf("could not create client: %w", err) } @@ -55,6 +58,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) { PrivateKey: config.PrivateKey, PublicKey: config.PublicKey, ProjectId: config.ProjectId, + Endpoint: config.Endpoint, }) if err != nil { return nil, fmt.Errorf("could not create certmgr: %w", err) @@ -109,7 +113,7 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep return &DeployResult{}, nil } -func createSDKClient(privateKey, publicKey, projectId string) (*ucloudsdk.UPathXClient, error) { +func createSDKClient(privateKey, publicKey, projectId, endpoint string) (*ucloudsdk.UPathXClient, error) { if privateKey == "" { return nil, fmt.Errorf("ucloud: invalid private key") } @@ -119,10 +123,17 @@ func createSDKClient(privateKey, publicKey, projectId string) (*ucloudsdk.UPathX cfg := ucloud.NewConfig() cfg.ProjectId = projectId + if endpoint != "" { + if strings.Contains(endpoint, "://") { + cfg.BaseUrl = endpoint + } else { + cfg.BaseUrl = "https://" + endpoint + } + } // PathX 相关接口要求必传 ProjectId 参数 if cfg.ProjectId == "" { - defaultProjectId, err := getSDKDefaultProjectId(privateKey, publicKey) + defaultProjectId, err := getSDKDefaultProjectId(privateKey, publicKey, endpoint) if err != nil { return nil, err } @@ -138,8 +149,15 @@ func createSDKClient(privateKey, publicKey, projectId string) (*ucloudsdk.UPathX return client, nil } -func getSDKDefaultProjectId(privateKey, publicKey string) (string, error) { +func getSDKDefaultProjectId(privateKey, publicKey, endpoint string) (string, error) { cfg := ucloud.NewConfig() + if endpoint != "" { + if strings.Contains(endpoint, "://") { + cfg.BaseUrl = endpoint + } else { + cfg.BaseUrl = "https://" + endpoint + } + } credential := auth.NewCredential() credential.PrivateKey = privateKey diff --git a/pkg/core/deployer/providers/ucloud-us3/ucloud_us3.go b/pkg/core/deployer/providers/ucloud-us3/ucloud_us3.go index ac87337a8..2bcdf9ba4 100644 --- a/pkg/core/deployer/providers/ucloud-us3/ucloud_us3.go +++ b/pkg/core/deployer/providers/ucloud-us3/ucloud_us3.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log/slog" + "strings" "github.com/ucloud/ucloud-sdk-go/ucloud" "github.com/ucloud/ucloud-sdk-go/ucloud/auth" @@ -25,6 +26,8 @@ type DeployerConfig struct { PublicKey string `json:"publicKey"` // 优刻得项目 ID。 ProjectId string `json:"projectId,omitempty"` + // 优刻得接口端点。 + Endpoint string `json:"endpoint,omitempty"` // 优刻得地域。 Region string `json:"region"` // 存储桶名。 @@ -47,7 +50,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) { return nil, fmt.Errorf("the configuration of the deployer provider is nil") } - client, err := createSDKClient(config.PrivateKey, config.PublicKey, config.ProjectId, config.Region) + client, err := createSDKClient(config.PrivateKey, config.PublicKey, config.ProjectId, config.Endpoint, config.Region) if err != nil { return nil, fmt.Errorf("could not create client: %w", err) } @@ -56,6 +59,7 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) { PrivateKey: config.PrivateKey, PublicKey: config.PublicKey, ProjectId: config.ProjectId, + Endpoint: config.Endpoint, }) if err != nil { return nil, fmt.Errorf("could not create certmgr: %w", err) @@ -111,7 +115,7 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep return &DeployResult{}, nil } -func createSDKClient(privateKey, publicKey, projectId, region string) (*ucloudsdk.UFileClient, error) { +func createSDKClient(privateKey, publicKey, projectId, endpoint, region string) (*ucloudsdk.UFileClient, error) { if privateKey == "" { return nil, fmt.Errorf("ucloud: invalid private key") } @@ -122,6 +126,13 @@ func createSDKClient(privateKey, publicKey, projectId, region string) (*ucloudsd cfg := ucloud.NewConfig() cfg.ProjectId = projectId cfg.Region = region + if endpoint != "" { + if strings.Contains(endpoint, "://") { + cfg.BaseUrl = endpoint + } else { + cfg.BaseUrl = "https://" + endpoint + } + } credential := auth.NewCredential() credential.PrivateKey = privateKey diff --git a/pkg/sdk3rd/ucloud/ucdn/client.go b/pkg/sdk3rd/ucloud/ucdn/client.go index cb66be0f3..095906166 100644 --- a/pkg/sdk3rd/ucloud/ucdn/client.go +++ b/pkg/sdk3rd/ucloud/ucdn/client.go @@ -3,6 +3,8 @@ package ucdn import ( + "io" + "github.com/ucloud/ucloud-sdk-go/ucloud" "github.com/ucloud/ucloud-sdk-go/ucloud/auth" ) @@ -14,6 +16,7 @@ type UCDNClient struct { func NewClient(config *ucloud.Config, credential *auth.Credential) *UCDNClient { meta := ucloud.ClientMeta{Product: "UCDN"} client := ucloud.NewClientWithMeta(config, credential, meta) + client.GetLogger().SetOutput(io.Discard) return &UCDNClient{ client, } diff --git a/pkg/sdk3rd/ucloud/udnr/api_domain_dns_add.go b/pkg/sdk3rd/ucloud/udnr/api_domain_dns_add.go new file mode 100644 index 000000000..101661db6 --- /dev/null +++ b/pkg/sdk3rd/ucloud/udnr/api_domain_dns_add.go @@ -0,0 +1,44 @@ +package udnr + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +type DomainDNSAddRequest struct { + request.CommonBase + + Dn *string `required:"true"` + RecordName *string `required:"true"` + DnsType *string `required:"true"` + Content *string `required:"true"` + TTL *string `required:"false"` + Prio *string `required:"false"` +} + +type DomainDNSAddResponse struct { + response.CommonBase +} + +func (c *UDNRClient) NewDomainDNSAddRequest() *DomainDNSAddRequest { + req := &DomainDNSAddRequest{} + + c.Client.SetupRequest(req) + + req.SetRetryable(true) + return req +} + +func (c *UDNRClient) DomainDNSAdd(req *DomainDNSAddRequest) (*DomainDNSAddResponse, error) { + var err error + var res DomainDNSAddResponse + + reqCopier := *req + + err = c.Client.InvokeAction("UdnrDomainDNSAdd", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/pkg/sdk3rd/ucloud/udnr/api_domain_dns_delete.go b/pkg/sdk3rd/ucloud/udnr/api_domain_dns_delete.go new file mode 100644 index 000000000..6791ecfc8 --- /dev/null +++ b/pkg/sdk3rd/ucloud/udnr/api_domain_dns_delete.go @@ -0,0 +1,42 @@ +package udnr + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +type DNSRecordDeleteRequest struct { + request.CommonBase + + Dn *string `required:"true"` + RecordName *string `required:"true"` + DnsType *string `required:"true"` + Content *string `required:"true"` +} + +type DNSRecordDeleteResponse struct { + response.CommonBase +} + +func (c *UDNRClient) NewDNSRecordDeleteRequest() *DNSRecordDeleteRequest { + req := &DNSRecordDeleteRequest{} + + c.Client.SetupRequest(req) + + req.SetRetryable(true) + return req +} + +func (c *UDNRClient) DNSRecordDelete(req *DNSRecordDeleteRequest) (*DNSRecordDeleteResponse, error) { + var err error + var res DNSRecordDeleteResponse + + reqCopier := *req + + err = c.Client.InvokeAction("UdnrDeleteDnsRecord", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/pkg/sdk3rd/ucloud/udnr/api_domain_dns_query.go b/pkg/sdk3rd/ucloud/udnr/api_domain_dns_query.go new file mode 100644 index 000000000..39ab0a209 --- /dev/null +++ b/pkg/sdk3rd/ucloud/udnr/api_domain_dns_query.go @@ -0,0 +1,41 @@ +package udnr + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +type DomainDNSQueryRequest struct { + request.CommonBase + + Dn *string `required:"true"` +} + +type DomainDNSQueryResponse struct { + response.CommonBase + + Data []DomainDNSRecord +} + +func (c *UDNRClient) NewDomainDNSQueryRequest() *DomainDNSQueryRequest { + req := &DomainDNSQueryRequest{} + + c.Client.SetupRequest(req) + + req.SetRetryable(true) + return req +} + +func (c *UDNRClient) DomainDNSQuery(req *DomainDNSQueryRequest) (*DomainDNSQueryResponse, error) { + var err error + var res DomainDNSQueryResponse + + reqCopier := *req + + err = c.Client.InvokeAction("UdnrDomainDNSQuery", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/pkg/sdk3rd/ucloud/udnr/client.go b/pkg/sdk3rd/ucloud/udnr/client.go new file mode 100644 index 000000000..dcee976bc --- /dev/null +++ b/pkg/sdk3rd/ucloud/udnr/client.go @@ -0,0 +1,23 @@ +// An extension SDK client for UCloud DNR service. +// Based on github.com/ucloud/ucloud-sdk-go. +package udnr + +import ( + "io" + + "github.com/ucloud/ucloud-sdk-go/ucloud" + "github.com/ucloud/ucloud-sdk-go/ucloud/auth" +) + +type UDNRClient struct { + *ucloud.Client +} + +func NewClient(config *ucloud.Config, credential *auth.Credential) *UDNRClient { + meta := ucloud.ClientMeta{Product: "UDNR"} + client := ucloud.NewClientWithMeta(config, credential, meta) + client.GetLogger().SetOutput(io.Discard) + return &UDNRClient{ + client, + } +} diff --git a/pkg/sdk3rd/ucloud/udnr/types.go b/pkg/sdk3rd/ucloud/udnr/types.go new file mode 100644 index 000000000..3decfa259 --- /dev/null +++ b/pkg/sdk3rd/ucloud/udnr/types.go @@ -0,0 +1,9 @@ +package udnr + +type DomainDNSRecord struct { + Type string `json:"DnsType,omitempty"` + Name string `json:"RecordName,omitempty"` + Content string `json:"Content,omitempty"` + Priority string `json:"Prio,omitempty"` + TTL string `json:"TTL,omitempty"` +} diff --git a/pkg/sdk3rd/ucloud/uewaf/client.go b/pkg/sdk3rd/ucloud/uewaf/client.go index b67325e79..8ca95660e 100644 --- a/pkg/sdk3rd/ucloud/uewaf/client.go +++ b/pkg/sdk3rd/ucloud/uewaf/client.go @@ -3,6 +3,8 @@ package uewaf import ( + "io" + "github.com/ucloud/ucloud-sdk-go/ucloud" "github.com/ucloud/ucloud-sdk-go/ucloud/auth" ) @@ -14,6 +16,7 @@ type UEWAFClient struct { func NewClient(config *ucloud.Config, credential *auth.Credential) *UEWAFClient { meta := ucloud.ClientMeta{Product: "UEWAF"} client := ucloud.NewClientWithMeta(config, credential, meta) + client.GetLogger().SetOutput(io.Discard) return &UEWAFClient{ client, } diff --git a/pkg/sdk3rd/ucloud/ufile/client.go b/pkg/sdk3rd/ucloud/ufile/client.go index 1379f4120..802e171e2 100644 --- a/pkg/sdk3rd/ucloud/ufile/client.go +++ b/pkg/sdk3rd/ucloud/ufile/client.go @@ -3,6 +3,8 @@ package ufile import ( + "io" + "github.com/ucloud/ucloud-sdk-go/ucloud" "github.com/ucloud/ucloud-sdk-go/ucloud/auth" ) @@ -14,6 +16,7 @@ type UFileClient struct { func NewClient(config *ucloud.Config, credential *auth.Credential) *UFileClient { meta := ucloud.ClientMeta{Product: "UFile"} client := ucloud.NewClientWithMeta(config, credential, meta) + client.GetLogger().SetOutput(io.Discard) return &UFileClient{ client, } diff --git a/pkg/sdk3rd/ucloud/ulb/client.go b/pkg/sdk3rd/ucloud/ulb/client.go index 7a67472c3..a249a9384 100644 --- a/pkg/sdk3rd/ucloud/ulb/client.go +++ b/pkg/sdk3rd/ucloud/ulb/client.go @@ -3,6 +3,8 @@ package ulb import ( + "io" + "github.com/ucloud/ucloud-sdk-go/ucloud" "github.com/ucloud/ucloud-sdk-go/ucloud/auth" ) @@ -14,6 +16,7 @@ type ULBClient struct { func NewClient(config *ucloud.Config, credential *auth.Credential) *ULBClient { meta := ucloud.ClientMeta{Product: "ULB"} client := ucloud.NewClientWithMeta(config, credential, meta) + client.GetLogger().SetOutput(io.Discard) return &ULBClient{ client, } diff --git a/pkg/sdk3rd/ucloud/upathx/client.go b/pkg/sdk3rd/ucloud/upathx/client.go index 461219b7d..e4e802386 100644 --- a/pkg/sdk3rd/ucloud/upathx/client.go +++ b/pkg/sdk3rd/ucloud/upathx/client.go @@ -3,6 +3,8 @@ package upathx import ( + "io" + "github.com/ucloud/ucloud-sdk-go/ucloud" "github.com/ucloud/ucloud-sdk-go/ucloud/auth" ) @@ -14,6 +16,7 @@ type UPathXClient struct { func NewClient(config *ucloud.Config, credential *auth.Credential) *UPathXClient { meta := ucloud.ClientMeta{Product: "PathX"} client := ucloud.NewClientWithMeta(config, credential, meta) + client.GetLogger().SetOutput(io.Discard) return &UPathXClient{ client, } diff --git a/pkg/sdk3rd/ucloud/ussl/client.go b/pkg/sdk3rd/ucloud/ussl/client.go index 6cd277108..65183976a 100644 --- a/pkg/sdk3rd/ucloud/ussl/client.go +++ b/pkg/sdk3rd/ucloud/ussl/client.go @@ -3,6 +3,8 @@ package ussl import ( + "io" + "github.com/ucloud/ucloud-sdk-go/ucloud" "github.com/ucloud/ucloud-sdk-go/ucloud/auth" ) @@ -14,6 +16,7 @@ type USSLClient struct { func NewClient(config *ucloud.Config, credential *auth.Credential) *USSLClient { meta := ucloud.ClientMeta{Product: "USSL"} client := ucloud.NewClientWithMeta(config, credential, meta) + client.GetLogger().SetOutput(io.Discard) return &USSLClient{ client, } diff --git a/ui/src/components/workflow/designer/forms/BizApplyNodeConfigFieldsProvider.tsx b/ui/src/components/workflow/designer/forms/BizApplyNodeConfigFieldsProvider.tsx index 83636d30d..21b792cd6 100644 --- a/ui/src/components/workflow/designer/forms/BizApplyNodeConfigFieldsProvider.tsx +++ b/ui/src/components/workflow/designer/forms/BizApplyNodeConfigFieldsProvider.tsx @@ -12,6 +12,7 @@ import BizApplyNodeConfigFieldsProviderLocal from "./BizApplyNodeConfigFieldsPro import BizApplyNodeConfigFieldsProviderOracleCloudDNS from "./BizApplyNodeConfigFieldsProviderOracleCloudDNS"; import BizApplyNodeConfigFieldsProviderS3 from "./BizApplyNodeConfigFieldsProviderS3"; import BizApplyNodeConfigFieldsProviderSSH from "./BizApplyNodeConfigFieldsProviderSSH"; +import BizApplyNodeConfigFieldsProviderUCloudUDNR from "./BizApplyNodeConfigFieldsProviderUCloudUDNR"; const acmeDns01ProviderComponentMap: Partial>> = { /* @@ -28,6 +29,8 @@ const acmeDns01ProviderComponentMap: Partial>> = { diff --git a/ui/src/components/workflow/designer/forms/BizApplyNodeConfigFieldsProviderUCloudUDNR.tsx b/ui/src/components/workflow/designer/forms/BizApplyNodeConfigFieldsProviderUCloudUDNR.tsx new file mode 100644 index 000000000..71584201a --- /dev/null +++ b/ui/src/components/workflow/designer/forms/BizApplyNodeConfigFieldsProviderUCloudUDNR.tsx @@ -0,0 +1,50 @@ +import { getI18n, useTranslation } from "react-i18next"; +import { Form, Input } from "antd"; +import { createSchemaFieldRule } from "antd-zod"; +import { z } from "zod"; + +import { useFormNestedFieldsContext } from "./_context"; + +const BizApplyNodeConfigFieldsProviderUCloudUDNR = () => { + const { i18n, t } = useTranslation(); + + const { parentNamePath } = useFormNestedFieldsContext(); + const formSchema = z.object({ + [parentNamePath]: getSchema({ i18n }), + }); + const formRule = createSchemaFieldRule(formSchema); + const initialValues = getInitialValues(); + + return ( + <> + } + > + + + + ); +}; + +const getInitialValues = (): Nullish>> => { + return {}; +}; + +const getSchema = ({ i18n = getI18n() }: { i18n?: ReturnType }) => { + const { t: _ } = i18n; + + return z.object({ + endpoint: z.string().nullish(), + }); +}; + +const _default = Object.assign(BizApplyNodeConfigFieldsProviderUCloudUDNR, { + getInitialValues, + getSchema, +}); + +export default _default; diff --git a/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderTencentCloudCLB.tsx b/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderTencentCloudCLB.tsx index d5618ba06..cf5c25377 100644 --- a/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderTencentCloudCLB.tsx +++ b/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderTencentCloudCLB.tsx @@ -112,8 +112,8 @@ const getSchema = ({ i18n = getI18n() }: { i18n?: ReturnType }) return z .object({ endpoint: z.string().nullish(), - deployTarget: z.enum([DEPLOY_TARGET_LOADBALANCER, DEPLOY_TARGET_LISTENER, DEPLOY_TARGET_RULEDOMAIN]), region: z.string().nonempty(), + deployTarget: z.enum([DEPLOY_TARGET_LOADBALANCER, DEPLOY_TARGET_LISTENER, DEPLOY_TARGET_RULEDOMAIN]), loadbalancerId: z.string().nonempty(), listenerId: z.string().nullish(), domain: z.string().nullish(), diff --git a/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderUCloudUALB.tsx b/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderUCloudUALB.tsx index a8d949106..de12db760 100644 --- a/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderUCloudUALB.tsx +++ b/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderUCloudUALB.tsx @@ -26,6 +26,16 @@ const BizDeployNodeConfigFieldsProviderUCloudUALB = () => { return ( <> + } + > + + + }) return z .object({ endpoint: z.string().nullish(), - deployTarget: z.enum([DEPLOY_TARGET_LOADBALANCER, DEPLOY_TARGET_LISTENER]), region: z.string().nonempty(), + deployTarget: z.enum([DEPLOY_TARGET_LOADBALANCER, DEPLOY_TARGET_LISTENER]), loadbalancerId: z.string().nonempty(), listenerId: z.string().nullish(), domain: z diff --git a/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderUCloudUCDN.tsx b/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderUCloudUCDN.tsx index c3d89d785..19e5c2a09 100644 --- a/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderUCloudUCDN.tsx +++ b/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderUCloudUCDN.tsx @@ -17,6 +17,16 @@ const BizDeployNodeConfigFieldsProviderUCloudUCDN = () => { return ( <> + } + > + + + }) const { t: _ } = i18n; return z.object({ + endpoint: z.string().nullish(), domainId: z.string().nonempty(), }); }; diff --git a/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderUCloudUCLB.tsx b/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderUCloudUCLB.tsx index 5dc91ddc0..d05f82221 100644 --- a/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderUCloudUCLB.tsx +++ b/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderUCloudUCLB.tsx @@ -25,6 +25,16 @@ const BizDeployNodeConfigFieldsProviderUCloudUCLB = () => { return ( <> + } + > + + + }) return z .object({ endpoint: z.string().nullish(), - deployTarget: z.enum([DEPLOY_TARGET_LOADBALANCER, DEPLOY_TARGET_VSERVER]), region: z.string().nonempty(), + deployTarget: z.enum([DEPLOY_TARGET_LOADBALANCER, DEPLOY_TARGET_VSERVER]), loadbalancerId: z.string().nonempty(), vserverId: z.string().nullish(), }) diff --git a/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderUCloudUEWAF.tsx b/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderUCloudUEWAF.tsx index ec96738cd..1a652e19f 100644 --- a/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderUCloudUEWAF.tsx +++ b/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderUCloudUEWAF.tsx @@ -19,6 +19,16 @@ const BizDeployNodeConfigFieldsProviderUCloudUEWAF = () => { return ( <> + } + > + + + }) const { t } = i18n; return z.object({ + endpoint: z.string().nullish(), domain: z.string().refine((v) => isDomain(v), t("common.errmsg.domain_invalid")), }); }; diff --git a/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderUCloudUPathX.tsx b/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderUCloudUPathX.tsx index 8c954a96b..241e08cdd 100644 --- a/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderUCloudUPathX.tsx +++ b/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderUCloudUPathX.tsx @@ -19,6 +19,16 @@ const BizDeployNodeConfigFieldsProviderUCloudUPathX = () => { return ( <> + } + > + + + }) const { t } = i18n; return z.object({ + endpoint: z.string().nullish(), acceleratorId: z.string().nonempty(), listenerPort: z.coerce.number().refine((v) => isPortNumber(v), t("common.errmsg.port_invalid")), }); diff --git a/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderUCloudUS3.tsx b/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderUCloudUS3.tsx index 05cc217ed..19a31ab02 100644 --- a/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderUCloudUS3.tsx +++ b/ui/src/components/workflow/designer/forms/BizDeployNodeConfigFieldsProviderUCloudUS3.tsx @@ -19,6 +19,16 @@ const BizDeployNodeConfigFieldsProviderUCloudUS3 = () => { return ( <> + } + > + + + }) const { t } = i18n; return z.object({ + endpoint: z.string().nullish(), region: z.string().nonempty(), bucket: z.string().nonempty(), domain: z.string().refine((v) => isDomain(v), t("common.errmsg.domain_invalid")), diff --git a/ui/src/i18n/resources/en/nls.workflow.nodes.json b/ui/src/i18n/resources/en/nls.workflow.nodes.json index 192a18e05..bbd51c347 100644 --- a/ui/src/i18n/resources/en/nls.workflow.nodes.json +++ b/ui/src/i18n/resources/en/nls.workflow.nodes.json @@ -344,6 +344,11 @@ "ssh_use_scp": { "label": "Fallback to use SCP", "tooltip": "If the remote server does not support SFTP, please check this option to fallback to SCP." + }, + "ucloud_udnr_endpoint": { + "label": "UCloud API endpoint (Optional)", + "placeholder": "Please enter UCloud UDNR API endpoint (e.g. api.ucloud-global.com)", + "tooltip": "
  • api.ucloud-global.com for UCloud Global
  • api.ucloud.cn for UCloud in China
" } } }, @@ -2565,6 +2570,11 @@ "placeholder": "Please enter Tencent Cloud WAF domain ID", "tooltip": "For more information, see https://console.tencentcloud.com/waf" }, + "ucloud_ualb_endpoint": { + "label": "UCloud API endpoint (Optional)", + "placeholder": "Please enter UCloud UALB API endpoint (e.g. api.ucloud-global.com)", + "tooltip": "
  • api.ucloud-global.com for UCloud Global
  • api.ucloud.cn for UCloud in China
" + }, "ucloud_ualb_region": { "label": "UCloud region", "placeholder": "Please enter UCloud ALB region (e.g. cn-bj2)", @@ -2595,11 +2605,21 @@ "placeholder": "Please enter UCloud UALB SNI domain name", "help": "Notes: Leave it blank to set the default certificate; otherwise, to set the extension one for SNI." }, + "ucloud_ucdn_endpoint": { + "label": "UCloud API endpoint (Optional)", + "placeholder": "Please enter UCloud UCDN API endpoint (e.g. api.ucloud-global.com)", + "tooltip": "
  • api.ucloud-global.com for UCloud Global
  • api.ucloud.cn for UCloud in China
" + }, "ucloud_ucdn_domain_id": { "label": "UCloud UCDN domain ID", "placeholder": "Please enter UCloud UCDN domain ID", "tooltip": "For more information, see https://console.ucloud-global.com/ucdn" }, + "ucloud_uclb_endpoint": { + "label": "UCloud API endpoint (Optional)", + "placeholder": "Please enter UCloud UCLB API endpoint (e.g. api.ucloud-global.com)", + "tooltip": "
  • api.ucloud-global.com for UCloud Global
  • api.ucloud.cn for UCloud in China
" + }, "ucloud_uclb_region": { "label": "UCloud region", "placeholder": "Please enter UCloud UCLB region (e.g. cn-bj2)", @@ -2625,6 +2645,11 @@ "placeholder": "Please enter UCloud UCLB VServer ID", "tooltip": "For more information, see https://console.ucloud-global.com/ulb/ulb" }, + "ucloud_upathx_endpoint": { + "label": "UCloud API endpoint (Optional)", + "placeholder": "Please enter UCloud UPathX API endpoint (e.g. api.ucloud-global.com)", + "tooltip": "
  • api.ucloud-global.com for UCloud Global
  • api.ucloud.cn for UCloud in China
" + }, "ucloud_upathx_accelerator_id": { "label": "UCloud UPathX accelerator ID", "placeholder": "Please enter UCloud UPathX accelerator ID", @@ -2635,6 +2660,11 @@ "placeholder": "Please enter UCloud UPathX listener port", "tooltip": "For more information, see https://console.ucloud-global.com/upathx/accelerate" }, + "ucloud_us3_endpoint": { + "label": "UCloud API endpoint (Optional)", + "placeholder": "Please enter UCloud US3 API endpoint (e.g. api.ucloud-global.com)", + "tooltip": "
  • api.ucloud-global.com for UCloud Global
  • api.ucloud.cn for UCloud in China
" + }, "ucloud_us3_region": { "label": "UCloud region", "placeholder": "Please enter UCloud US3 region (e.g. cn-bj2)", @@ -2648,6 +2678,11 @@ "label": "UCloud US3 custom domain", "placeholder": "Please enter UCloud US3 bucket custom domain name" }, + "ucloud_uewaf_endpoint": { + "label": "UCloud API endpoint (Optional)", + "placeholder": "Please enter UCloud UEWAF API endpoint (e.g. api.ucloud-global.com)", + "tooltip": "
  • api.ucloud-global.com for UCloud Global
  • api.ucloud.cn for UCloud in China
" + }, "ucloud_uewaf_domain": { "label": "UCloud UEWAF domain", "placeholder": "Please enter UCloud UEWAF domain name" diff --git a/ui/src/i18n/resources/zh/nls.workflow.nodes.json b/ui/src/i18n/resources/zh/nls.workflow.nodes.json index d419af9cc..ca6d16c87 100644 --- a/ui/src/i18n/resources/zh/nls.workflow.nodes.json +++ b/ui/src/i18n/resources/zh/nls.workflow.nodes.json @@ -343,6 +343,11 @@ "ssh_use_scp": { "label": "回退使用 SCP", "tooltip": "如果你的远程服务器不支持 SFTP,请勾选此选项回退为 SCP。" + }, + "ucloud_udnr_endpoint": { + "label": "优刻得接口端点(可选)", + "placeholder": "请输入优刻得 UDNR 接口端点(例如:api.ucloud.cn)", + "tooltip": "这是什么?请参阅 https://docs.ucloud.cn/api/summary/gateway
国际站用户请填写 api.ucloud-global.com。" } } }, @@ -2401,12 +2406,12 @@ }, "tencentcloud_scf_region": { "label": "腾讯云服务地域", - "placeholder": "输入腾讯云 SCF 服务地域(例如:ap-guangzhou)", + "placeholder": "请输入腾讯云 SCF 服务地域(例如:ap-guangzhou)", "tooltip": "这是什么?请参阅 https://cloud.tencent.com/document/product/583/17299" }, "tencentcloud_scf_domain": { "label": "腾讯云 SCF 自定义域名", - "placeholder": "输入腾讯云 SCF 自定义域名" + "placeholder": "请输入腾讯云 SCF 自定义域名" }, "tencentcloud_ssl_endpoint": { "label": "腾讯云接口端点(可选)", @@ -2494,7 +2499,7 @@ }, "tencentcloud_tse_region": { "label": "腾讯云服务地域", - "placeholder": "输入腾讯云 TSE 服务地域(例如:ap-guangzhou)", + "placeholder": "请输入腾讯云 TSE 服务地域(例如:ap-guangzhou)", "tooltip": "这是什么?请参阅 https://cloud.tencent.com.cn/document/product/1364/54618" }, "tencentcloud_tse_service_type": { @@ -2513,7 +2518,7 @@ }, "tencentcloud_tse_domains": { "label": "腾讯云 TSE 云原生网关绑定域名", - "placeholder": "输入腾讯云 TSE 云原生网关绑定域名(多个值请用半角分号隔开)", + "placeholder": "请输入腾讯云 TSE 云原生网关绑定域名(多个值请用半角分号隔开)", "help": "提示:支持多个域名,以半角分号隔开。", "multiple_input_modal": { "title": "修改腾讯云 TSE 云原生网关绑定域名", @@ -2564,9 +2569,14 @@ "placeholder": "请输入腾讯云 WAF 域名 ID", "tooltip": "这是什么?请参阅 https://console.cloud.tencent.com/waf" }, + "ucloud_ualb_endpoint": { + "label": "优刻得接口端点(可选)", + "placeholder": "请输入优刻得 UALB 接口端点(例如:api.ucloud.cn)", + "tooltip": "这是什么?请参阅 https://docs.ucloud.cn/api/summary/gateway
国际站用户请填写 api.ucloud-global.com。" + }, "ucloud_ualb_region": { "label": "优刻得服务地域", - "placeholder": "优刻得 UALB 服务地域(例如:cn-bj2)", + "placeholder": "请输入优刻得 UALB 服务地域(例如:cn-bj2)", "tooltip": "这是什么?请参阅 https://docs.ucloud.cn/api/summary/regionlist" }, "ucloud_ualb_deploy_target": { @@ -2594,14 +2604,24 @@ "placeholder": "请输入优刻得 UALB 扩展域名", "help": "提示:不填写时,将替换监听器的默认证书;否则,将替换扩展域名证书。" }, + "ucloud_ucdn_endpoint": { + "label": "优刻得接口端点(可选)", + "placeholder": "请输入优刻得 UCDN 接口端点(例如:api.ucloud.cn)", + "tooltip": "这是什么?请参阅 https://docs.ucloud.cn/api/summary/gateway
国际站用户请填写 api.ucloud-global.com。" + }, "ucloud_ucdn_domain_id": { "label": "优刻得 UCDN 域名 ID", "placeholder": "请输入优刻得 UCDN 域名 ID", "tooltip": "这是什么?请参阅 https://console.ucloud.cn/ucdn" }, + "ucloud_uclb_endpoint": { + "label": "优刻得接口端点(可选)", + "placeholder": "请输入优刻得 UCLB 接口端点(例如:api.ucloud.cn)", + "tooltip": "这是什么?请参阅 https://docs.ucloud.cn/api/summary/gateway
国际站用户请填写 api.ucloud-global.com。" + }, "ucloud_uclb_region": { "label": "优刻得服务地域", - "placeholder": "优刻得 UCLB 服务地域(例如:cn-bj2)", + "placeholder": "请输入优刻得 UCLB 服务地域(例如:cn-bj2)", "tooltip": "这是什么?请参阅 https://docs.ucloud.cn/api/summary/regionlist" }, "ucloud_uclb_deploy_target": { @@ -2624,6 +2644,11 @@ "placeholder": "请输入优刻得 UCLB VServer ID", "tooltip": "这是什么?请参阅 https://console.ucloud.cn/ulb/ulb" }, + "ucloud_upathx_endpoint": { + "label": "优刻得接口端点(可选)", + "placeholder": "请输入优刻得 UPathX 接口端点(例如:api.ucloud.cn)", + "tooltip": "这是什么?请参阅 https://docs.ucloud.cn/api/summary/gateway
国际站用户请填写 api.ucloud-global.com。" + }, "ucloud_upathx_accelerator_id": { "label": "优刻得 UPathX 加速器实例 ID", "placeholder": "请输入优刻得 UPathX 加速器实例 ID", @@ -2634,9 +2659,14 @@ "placeholder": "请输入优刻得 UPathX 加速器监听端口", "tooltip": "这是什么?请参阅 https://console.ucloud.cn/upathx/accelerate" }, + "ucloud_us3_endpoint": { + "label": "优刻得接口端点(可选)", + "placeholder": "请输入优刻得 US3 接口端点(例如:api.ucloud.cn)", + "tooltip": "这是什么?请参阅 https://docs.ucloud.cn/api/summary/gateway
国际站用户请填写 api.ucloud-global.com。" + }, "ucloud_us3_region": { "label": "优刻得服务地域", - "placeholder": "优刻得 US3 服务地域(例如:cn-bj2)", + "placeholder": "请输入优刻得 US3 服务地域(例如:cn-bj2)", "tooltip": "这是什么?请参阅 https://docs.ucloud.cn/api/summary/regionlist" }, "ucloud_us3_bucket": { @@ -2647,6 +2677,11 @@ "label": "优刻得 US3 自定义域名", "placeholder": "请输入优刻得 US3 自定义域名" }, + "ucloud_uewaf_endpoint": { + "label": "优刻得接口端点(可选)", + "placeholder": "请输入优刻得 UEWAF 接口端点(例如:api.ucloud.cn)", + "tooltip": "这是什么?请参阅 https://docs.ucloud.cn/api/summary/gateway
国际站用户请填写 api.ucloud-global.com。" + }, "ucloud_uewaf_domain": { "label": "优刻得 UEWAF 防护域名", "placeholder": "请输入优刻得 UEWAF 防护域名"