mirror of https://github.com/usual2970/certimate
				
				
				
			feat: add volcengine clb deployer
							parent
							
								
									a5c9ed8d17
								
							
						
					
					
						commit
						e5518b1067
					
				| 
						 | 
				
			
			@ -27,6 +27,7 @@ import (
 | 
			
		|||
	providerTencentCloudECDN "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/tencentcloud-ecdn"
 | 
			
		||||
	providerTencentCloudEO "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/tencentcloud-eo"
 | 
			
		||||
	providerVolcEngineCDN "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/volcengine-cdn"
 | 
			
		||||
	providerVolcEngineCLB "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/volcengine-clb"
 | 
			
		||||
	providerVolcEngineDCDN "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/volcengine-dcdn"
 | 
			
		||||
	providerVolcEngineLive "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/volcengine-live"
 | 
			
		||||
	providerVolcEngineTOS "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/volcengine-tos"
 | 
			
		||||
| 
						 | 
				
			
			@ -332,7 +333,7 @@ func createDeployer(options *deployerOptions) (deployer.Deployer, logger.Logger,
 | 
			
		|||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	case domain.DeployProviderTypeVolcEngineCDN, domain.DeployProviderTypeVolcEngineDCDN, domain.DeployProviderTypeVolcEngineLive, domain.DeployProviderTypeVolcEngineTOS:
 | 
			
		||||
	case domain.DeployProviderTypeVolcEngineCDN, domain.DeployProviderTypeVolcEngineCLB, domain.DeployProviderTypeVolcEngineDCDN, domain.DeployProviderTypeVolcEngineLive, domain.DeployProviderTypeVolcEngineTOS:
 | 
			
		||||
		{
 | 
			
		||||
			access := domain.AccessConfigForVolcEngine{}
 | 
			
		||||
			if err := maps.Decode(options.ProviderAccessConfig, &access); err != nil {
 | 
			
		||||
| 
						 | 
				
			
			@ -348,6 +349,16 @@ func createDeployer(options *deployerOptions) (deployer.Deployer, logger.Logger,
 | 
			
		|||
				}, logger)
 | 
			
		||||
				return deployer, logger, err
 | 
			
		||||
 | 
			
		||||
			case domain.DeployProviderTypeVolcEngineCLB:
 | 
			
		||||
				deployer, err := providerVolcEngineCLB.NewWithLogger(&providerVolcEngineCLB.VolcEngineCLBDeployerConfig{
 | 
			
		||||
					AccessKeyId:     access.AccessKeyId,
 | 
			
		||||
					AccessKeySecret: access.SecretAccessKey,
 | 
			
		||||
					Region:          maps.GetValueAsString(options.ProviderDeployConfig, "region"),
 | 
			
		||||
					ResourceType:    providerVolcEngineCLB.DeployResourceType(maps.GetValueAsString(options.ProviderDeployConfig, "resourceType")),
 | 
			
		||||
					ListenerId:      maps.GetValueAsString(options.ProviderDeployConfig, "listenerId"),
 | 
			
		||||
				}, logger)
 | 
			
		||||
				return deployer, logger, err
 | 
			
		||||
 | 
			
		||||
			case domain.DeployProviderTypeVolcEngineDCDN:
 | 
			
		||||
				deployer, err := providerVolcEngineDCDN.NewWithLogger(&providerVolcEngineDCDN.VolcEngineDCDNDeployerConfig{
 | 
			
		||||
					AccessKeyId:     access.AccessKeyId,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -89,6 +89,7 @@ const (
 | 
			
		|||
	DeployProviderTypeTencentCloudECDN = DeployProviderType("tencentcloud-ecdn")
 | 
			
		||||
	DeployProviderTypeTencentCloudEO   = DeployProviderType("tencentcloud-eo")
 | 
			
		||||
	DeployProviderTypeVolcEngineCDN    = DeployProviderType("volcengine-cdn")
 | 
			
		||||
	DeployProviderTypeVolcEngineCLB    = DeployProviderType("volcengine-clb")
 | 
			
		||||
	DeployProviderTypeVolcEngineDCDN   = DeployProviderType("volcengine-dcdn")
 | 
			
		||||
	DeployProviderTypeVolcEngineLive   = DeployProviderType("volcengine-live")
 | 
			
		||||
	DeployProviderTypeVolcEngineTOS    = DeployProviderType("volcengine-tos")
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,8 @@
 | 
			
		|||
package volcengineclb
 | 
			
		||||
 | 
			
		||||
type DeployResourceType string
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	// 资源类型:部署到指定监听器。
 | 
			
		||||
	DEPLOY_RESOURCE_LISTENER = DeployResourceType("listener")
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,132 @@
 | 
			
		|||
package volcengineclb
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"errors"
 | 
			
		||||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	xerrors "github.com/pkg/errors"
 | 
			
		||||
	veClb "github.com/volcengine/volcengine-go-sdk/service/clb"
 | 
			
		||||
	ve "github.com/volcengine/volcengine-go-sdk/volcengine"
 | 
			
		||||
	veSession "github.com/volcengine/volcengine-go-sdk/volcengine/session"
 | 
			
		||||
 | 
			
		||||
	"github.com/usual2970/certimate/internal/pkg/core/deployer"
 | 
			
		||||
	"github.com/usual2970/certimate/internal/pkg/core/logger"
 | 
			
		||||
	"github.com/usual2970/certimate/internal/pkg/core/uploader"
 | 
			
		||||
	providerCertCenter "github.com/usual2970/certimate/internal/pkg/core/uploader/providers/volcengine-certcenter"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type VolcEngineCLBDeployerConfig struct {
 | 
			
		||||
	// 火山引擎 AccessKeyId。
 | 
			
		||||
	AccessKeyId string `json:"accessKeyId"`
 | 
			
		||||
	// 火山引擎 AccessKeySecret。
 | 
			
		||||
	AccessKeySecret string `json:"accessKeySecret"`
 | 
			
		||||
	// 火山引擎地域。
 | 
			
		||||
	Region string `json:"region"`
 | 
			
		||||
	// 部署资源类型。
 | 
			
		||||
	ResourceType DeployResourceType `json:"resourceType"`
 | 
			
		||||
	// 负载均衡监听器 ID。
 | 
			
		||||
	// 部署资源类型为 [DEPLOY_RESOURCE_LISTENER] 时必填。
 | 
			
		||||
	ListenerId string `json:"listenerId,omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type VolcEngineCLBDeployer struct {
 | 
			
		||||
	config      *VolcEngineCLBDeployerConfig
 | 
			
		||||
	logger      logger.Logger
 | 
			
		||||
	sdkClient   *veClb.CLB
 | 
			
		||||
	sslUploader uploader.Uploader
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var _ deployer.Deployer = (*VolcEngineCLBDeployer)(nil)
 | 
			
		||||
 | 
			
		||||
func New(config *VolcEngineCLBDeployerConfig) (*VolcEngineCLBDeployer, error) {
 | 
			
		||||
	return NewWithLogger(config, logger.NewNilLogger())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewWithLogger(config *VolcEngineCLBDeployerConfig, logger logger.Logger) (*VolcEngineCLBDeployer, error) {
 | 
			
		||||
	if config == nil {
 | 
			
		||||
		return nil, errors.New("config is nil")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if logger == nil {
 | 
			
		||||
		return nil, errors.New("logger is nil")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	client, err := createSdkClient(config.AccessKeyId, config.AccessKeySecret, config.Region)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, xerrors.Wrap(err, "failed to create sdk client")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	uploader, err := providerCertCenter.New(&providerCertCenter.VolcEngineCertCenterUploaderConfig{
 | 
			
		||||
		AccessKeyId:     config.AccessKeyId,
 | 
			
		||||
		AccessKeySecret: config.AccessKeySecret,
 | 
			
		||||
		Region:          config.Region,
 | 
			
		||||
	})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, xerrors.Wrap(err, "failed to create ssl uploader")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &VolcEngineCLBDeployer{
 | 
			
		||||
		logger:      logger,
 | 
			
		||||
		config:      config,
 | 
			
		||||
		sdkClient:   client,
 | 
			
		||||
		sslUploader: uploader,
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *VolcEngineCLBDeployer) Deploy(ctx context.Context, certPem string, privkeyPem string) (*deployer.DeployResult, error) {
 | 
			
		||||
	// 上传证书到证书中心
 | 
			
		||||
	upres, err := d.sslUploader.Upload(ctx, certPem, privkeyPem)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, xerrors.Wrap(err, "failed to upload certificate file")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	d.logger.Logt("certificate file uploaded", upres)
 | 
			
		||||
 | 
			
		||||
	// 根据部署资源类型决定部署方式
 | 
			
		||||
	switch d.config.ResourceType {
 | 
			
		||||
	case DEPLOY_RESOURCE_LISTENER:
 | 
			
		||||
		if err := d.deployToListener(ctx, upres.CertId); err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	default:
 | 
			
		||||
		return nil, fmt.Errorf("unsupported resource type: %s", d.config.ResourceType)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &deployer.DeployResult{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *VolcEngineCLBDeployer) deployToListener(ctx context.Context, cloudCertId string) error {
 | 
			
		||||
	if d.config.ListenerId == "" {
 | 
			
		||||
		return errors.New("config `listenerId` is required")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 修改监听器
 | 
			
		||||
	// REF: https://www.volcengine.com/docs/6406/71775
 | 
			
		||||
	modifyListenerAttributesReq := &veClb.ModifyListenerAttributesInput{
 | 
			
		||||
		ListenerId:              ve.String(d.config.ListenerId),
 | 
			
		||||
		CertificateSource:       ve.String("cert_center"),
 | 
			
		||||
		CertCenterCertificateId: ve.String(cloudCertId),
 | 
			
		||||
	}
 | 
			
		||||
	modifyListenerAttributesResp, err := d.sdkClient.ModifyListenerAttributes(modifyListenerAttributesReq)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return xerrors.Wrap(err, "failed to execute sdk request 'clb.ModifyListenerAttributes'")
 | 
			
		||||
	} else {
 | 
			
		||||
		d.logger.Logt("已修改监听器", modifyListenerAttributesResp)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func createSdkClient(accessKeyId, accessKeySecret, region string) (*veClb.CLB, error) {
 | 
			
		||||
	config := ve.NewConfig().WithRegion(region).WithAkSk(accessKeyId, accessKeySecret)
 | 
			
		||||
 | 
			
		||||
	session, err := veSession.NewSession(config)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	client := veClb.New(session)
 | 
			
		||||
	return client, nil
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,81 @@
 | 
			
		|||
package volcengineclb_test
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"flag"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"os"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	provider "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/volcengine-clb"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	fInputCertPath   string
 | 
			
		||||
	fInputKeyPath    string
 | 
			
		||||
	fAccessKeyId     string
 | 
			
		||||
	fAccessKeySecret string
 | 
			
		||||
	fRegion          string
 | 
			
		||||
	fListenerId      string
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	argsPrefix := "CERTIMATE_DEPLOYER_VOLCENGINECLB_"
 | 
			
		||||
 | 
			
		||||
	flag.StringVar(&fInputCertPath, argsPrefix+"INPUTCERTPATH", "", "")
 | 
			
		||||
	flag.StringVar(&fInputKeyPath, argsPrefix+"INPUTKEYPATH", "", "")
 | 
			
		||||
	flag.StringVar(&fAccessKeyId, argsPrefix+"ACCESSKEYID", "", "")
 | 
			
		||||
	flag.StringVar(&fAccessKeySecret, argsPrefix+"ACCESSKEYSECRET", "", "")
 | 
			
		||||
	flag.StringVar(&fRegion, argsPrefix+"REGION", "", "")
 | 
			
		||||
	flag.StringVar(&fListenerId, argsPrefix+"LISTENERID", "", "")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
Shell command to run this test:
 | 
			
		||||
 | 
			
		||||
	go test -v ./volcengine_clb_test.go -args \
 | 
			
		||||
	--CERTIMATE_DEPLOYER_VOLCENGINECLB_INPUTCERTPATH="/path/to/your-input-cert.pem" \
 | 
			
		||||
	--CERTIMATE_DEPLOYER_VOLCENGINECLB_INPUTKEYPATH="/path/to/your-input-key.pem" \
 | 
			
		||||
	--CERTIMATE_DEPLOYER_VOLCENGINECLB_ACCESSKEYID="your-access-key-id" \
 | 
			
		||||
	--CERTIMATE_DEPLOYER_VOLCENGINECLB_ACCESSKEYSECRET="your-access-key-secret" \
 | 
			
		||||
	--CERTIMATE_DEPLOYER_VOLCENGINECLB_REGION="cn-beijing" \
 | 
			
		||||
	--CERTIMATE_DEPLOYER_VOLCENGINECLB_LISTENERID="cn-beijing"
 | 
			
		||||
*/
 | 
			
		||||
func TestDeploy(t *testing.T) {
 | 
			
		||||
	flag.Parse()
 | 
			
		||||
 | 
			
		||||
	t.Run("Deploy", func(t *testing.T) {
 | 
			
		||||
		t.Log(strings.Join([]string{
 | 
			
		||||
			"args:",
 | 
			
		||||
			fmt.Sprintf("INPUTCERTPATH: %v", fInputCertPath),
 | 
			
		||||
			fmt.Sprintf("INPUTKEYPATH: %v", fInputKeyPath),
 | 
			
		||||
			fmt.Sprintf("ACCESSKEYID: %v", fAccessKeyId),
 | 
			
		||||
			fmt.Sprintf("ACCESSKEYSECRET: %v", fAccessKeySecret),
 | 
			
		||||
			fmt.Sprintf("REGION: %v", fRegion),
 | 
			
		||||
			fmt.Sprintf("LISTENERID: %v", fListenerId),
 | 
			
		||||
		}, "\n"))
 | 
			
		||||
 | 
			
		||||
		deployer, err := provider.New(&provider.VolcEngineCLBDeployerConfig{
 | 
			
		||||
			AccessKeyId:     fAccessKeyId,
 | 
			
		||||
			AccessKeySecret: fAccessKeySecret,
 | 
			
		||||
			Region:          fRegion,
 | 
			
		||||
			ResourceType:    provider.DEPLOY_RESOURCE_LISTENER,
 | 
			
		||||
			ListenerId:      fListenerId,
 | 
			
		||||
		})
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			t.Errorf("err: %+v", err)
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		fInputCertData, _ := os.ReadFile(fInputCertPath)
 | 
			
		||||
		fInputKeyData, _ := os.ReadFile(fInputKeyPath)
 | 
			
		||||
		res, err := deployer.Deploy(context.Background(), string(fInputCertData), string(fInputKeyData))
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			t.Errorf("err: %+v", err)
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		t.Logf("ok: %v", res)
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -21,7 +21,7 @@ type VolcEngineDCDNDeployerConfig struct {
 | 
			
		|||
	AccessKeyId string `json:"accessKeyId"`
 | 
			
		||||
	// 火山引擎 AccessKeySecret。
 | 
			
		||||
	AccessKeySecret string `json:"accessKeySecret"`
 | 
			
		||||
	// 火山引擎区域。
 | 
			
		||||
	// 火山引擎地域。
 | 
			
		||||
	Region string `json:"region"`
 | 
			
		||||
	// 加速域名(支持泛域名)。
 | 
			
		||||
	Domain string `json:"domain"`
 | 
			
		||||
| 
						 | 
				
			
			@ -102,7 +102,7 @@ func (d *VolcEngineDCDNDeployer) Deploy(ctx context.Context, certPem string, pri
 | 
			
		|||
 | 
			
		||||
func createSdkClient(accessKeyId, accessKeySecret, region string) (*veDcdn.DCDN, error) {
 | 
			
		||||
	if region == "" {
 | 
			
		||||
		region = "cn-beijing"
 | 
			
		||||
		region = "cn-beijing" // 证书中心默认区域:北京
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	config := ve.NewConfig().WithRegion(region).WithAkSk(accessKeyId, accessKeySecret)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,7 +19,7 @@ type VolcEngineTOSDeployerConfig struct {
 | 
			
		|||
	AccessKeyId string `json:"accessKeyId"`
 | 
			
		||||
	// 火山引擎 AccessKeySecret。
 | 
			
		||||
	AccessKeySecret string `json:"accessKeySecret"`
 | 
			
		||||
	// 火山引擎区域。
 | 
			
		||||
	// 火山引擎地域。
 | 
			
		||||
	Region string `json:"region"`
 | 
			
		||||
	// 存储桶名。
 | 
			
		||||
	Bucket string `json:"bucket"`
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,7 +17,7 @@ type VolcEngineCertCenterUploaderConfig struct {
 | 
			
		|||
	AccessKeyId string `json:"accessKeyId"`
 | 
			
		||||
	// 火山引擎 AccessKeySecret。
 | 
			
		||||
	AccessKeySecret string `json:"accessKeySecret"`
 | 
			
		||||
	// 火山引擎区域。
 | 
			
		||||
	// 火山引擎地域。
 | 
			
		||||
	Region string `json:"region"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -73,7 +73,7 @@ func (u *VolcEngineCertCenterUploader) Upload(ctx context.Context, certPem strin
 | 
			
		|||
 | 
			
		||||
func createSdkClient(accessKeyId, accessKeySecret, region string) (*veCertCenter.CertCenter, error) {
 | 
			
		||||
	if region == "" {
 | 
			
		||||
		region = "cn-beijing"
 | 
			
		||||
		region = "cn-beijing" // 证书中心默认区域:北京
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	config := ve.NewConfig().WithRegion(region).WithAkSk(accessKeyId, accessKeySecret)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -36,6 +36,7 @@ import DeployNodeConfigFormTencentCloudCOSConfig from "./DeployNodeConfigFormTen
 | 
			
		|||
import DeployNodeConfigFormTencentCloudECDNConfig from "./DeployNodeConfigFormTencentCloudECDNConfig.tsx";
 | 
			
		||||
import DeployNodeConfigFormTencentCloudEOConfig from "./DeployNodeConfigFormTencentCloudEOConfig.tsx";
 | 
			
		||||
import DeployNodeConfigFormVolcEngineCDNConfig from "./DeployNodeConfigFormVolcEngineCDNConfig.tsx";
 | 
			
		||||
import DeployNodeConfigFormVolcEngineCLBConfig from "./DeployNodeConfigFormVolcEngineCLBConfig.tsx";
 | 
			
		||||
import DeployNodeConfigFormVolcEngineDCDNConfig from "./DeployNodeConfigFormVolcEngineDCDNConfig.tsx";
 | 
			
		||||
import DeployNodeConfigFormVolcEngineLiveConfig from "./DeployNodeConfigFormVolcEngineLiveConfig.tsx";
 | 
			
		||||
import DeployNodeConfigFormVolcEngineTOSConfig from "./DeployNodeConfigFormVolcEngineTOSConfig.tsx";
 | 
			
		||||
| 
						 | 
				
			
			@ -151,6 +152,8 @@ const DeployNodeConfigForm = forwardRef<DeployNodeConfigFormInstance, DeployNode
 | 
			
		|||
          return <DeployNodeConfigFormTencentCloudEOConfig {...nestedFormProps} />;
 | 
			
		||||
        case DEPLOY_PROVIDERS.VOLCENGINE_CDN:
 | 
			
		||||
          return <DeployNodeConfigFormVolcEngineCDNConfig {...nestedFormProps} />;
 | 
			
		||||
        case DEPLOY_PROVIDERS.VOLCENGINE_CLB:
 | 
			
		||||
          return <DeployNodeConfigFormVolcEngineCLBConfig {...nestedFormProps} />;
 | 
			
		||||
        case DEPLOY_PROVIDERS.VOLCENGINE_DCDN:
 | 
			
		||||
          return <DeployNodeConfigFormVolcEngineDCDNConfig {...nestedFormProps} />;
 | 
			
		||||
        case DEPLOY_PROVIDERS.VOLCENGINE_LIVE:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -28,7 +28,9 @@ const RESOURCE_TYPE_LISTENER = "listener" as const;
 | 
			
		|||
const RESOURCE_TYPE_RULEDOMAIN = "ruledomain" as const;
 | 
			
		||||
 | 
			
		||||
const initFormModel = (): DeployNodeConfigFormTencentCloudCLBConfigFieldValues => {
 | 
			
		||||
  return {};
 | 
			
		||||
  return {
 | 
			
		||||
    resourceType: RESOURCE_TYPE_SSLDEPLOY,
 | 
			
		||||
  };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const DeployNodeConfigFormTencentCloudCLBConfig = ({
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,105 @@
 | 
			
		|||
import { useTranslation } from "react-i18next";
 | 
			
		||||
import { Form, type FormInstance, Input, Select } from "antd";
 | 
			
		||||
import { createSchemaFieldRule } from "antd-zod";
 | 
			
		||||
import { z } from "zod";
 | 
			
		||||
 | 
			
		||||
import Show from "@/components/Show";
 | 
			
		||||
 | 
			
		||||
type DeployNodeConfigFormVolcEngineCLBConfigFieldValues = Nullish<{
 | 
			
		||||
  resourceType: string;
 | 
			
		||||
  region: string;
 | 
			
		||||
  loadbalancerId?: string;
 | 
			
		||||
  listenerId?: string;
 | 
			
		||||
  domain?: string;
 | 
			
		||||
}>;
 | 
			
		||||
 | 
			
		||||
export type DeployNodeConfigFormVolcEngineCLBConfigProps = {
 | 
			
		||||
  form: FormInstance;
 | 
			
		||||
  formName: string;
 | 
			
		||||
  disabled?: boolean;
 | 
			
		||||
  initialValues?: DeployNodeConfigFormVolcEngineCLBConfigFieldValues;
 | 
			
		||||
  onValuesChange?: (values: DeployNodeConfigFormVolcEngineCLBConfigFieldValues) => void;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const RESOURCE_TYPE_LISTENER = "listener" as const;
 | 
			
		||||
 | 
			
		||||
const initFormModel = (): DeployNodeConfigFormVolcEngineCLBConfigFieldValues => {
 | 
			
		||||
  return {
 | 
			
		||||
    resourceType: RESOURCE_TYPE_LISTENER,
 | 
			
		||||
  };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const DeployNodeConfigFormVolcEngineCLBConfig = ({
 | 
			
		||||
  form: formInst,
 | 
			
		||||
  formName,
 | 
			
		||||
  disabled,
 | 
			
		||||
  initialValues,
 | 
			
		||||
  onValuesChange,
 | 
			
		||||
}: DeployNodeConfigFormVolcEngineCLBConfigProps) => {
 | 
			
		||||
  const { t } = useTranslation();
 | 
			
		||||
 | 
			
		||||
  const formSchema = z.object({
 | 
			
		||||
    resourceType: z.literal(RESOURCE_TYPE_LISTENER, { message: t("workflow_node.deploy.form.volcengine_clb_resource_type.placeholder") }),
 | 
			
		||||
    region: z
 | 
			
		||||
      .string({ message: t("workflow_node.deploy.form.volcengine_clb_region.placeholder") })
 | 
			
		||||
      .nonempty(t("workflow_node.deploy.form.volcengine_clb_region.placeholder"))
 | 
			
		||||
      .trim(),
 | 
			
		||||
    listenerId: z
 | 
			
		||||
      .string()
 | 
			
		||||
      .max(64, t("common.errmsg.string_max", { max: 64 }))
 | 
			
		||||
      .trim()
 | 
			
		||||
      .nullish()
 | 
			
		||||
      .refine(
 | 
			
		||||
        (v) => ![RESOURCE_TYPE_LISTENER].includes(fieldResourceType) || !!v?.trim(),
 | 
			
		||||
        t("workflow_node.deploy.form.volcengine_clb_listener_id.placeholder")
 | 
			
		||||
      ),
 | 
			
		||||
  });
 | 
			
		||||
  const formRule = createSchemaFieldRule(formSchema);
 | 
			
		||||
 | 
			
		||||
  const fieldResourceType = Form.useWatch("resourceType", formInst);
 | 
			
		||||
 | 
			
		||||
  const handleFormChange = (_: unknown, values: z.infer<typeof formSchema>) => {
 | 
			
		||||
    onValuesChange?.(values);
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <Form
 | 
			
		||||
      form={formInst}
 | 
			
		||||
      disabled={disabled}
 | 
			
		||||
      initialValues={initialValues ?? initFormModel()}
 | 
			
		||||
      layout="vertical"
 | 
			
		||||
      name={formName}
 | 
			
		||||
      onValuesChange={handleFormChange}
 | 
			
		||||
    >
 | 
			
		||||
      <Form.Item name="resourceType" label={t("workflow_node.deploy.form.volcengine_clb_resource_type.label")} rules={[formRule]}>
 | 
			
		||||
        <Select placeholder={t("workflow_node.deploy.form.volcengine_clb_resource_type.placeholder")}>
 | 
			
		||||
          <Select.Option key={RESOURCE_TYPE_LISTENER} value={RESOURCE_TYPE_LISTENER}>
 | 
			
		||||
            {t("workflow_node.deploy.form.volcengine_clb_resource_type.option.listener.label")}
 | 
			
		||||
          </Select.Option>
 | 
			
		||||
        </Select>
 | 
			
		||||
      </Form.Item>
 | 
			
		||||
 | 
			
		||||
      <Form.Item
 | 
			
		||||
        name="region"
 | 
			
		||||
        label={t("workflow_node.deploy.form.volcengine_clb_region.label")}
 | 
			
		||||
        rules={[formRule]}
 | 
			
		||||
        tooltip={<span dangerouslySetInnerHTML={{ __html: t("workflow_node.deploy.form.volcengine_clb_region.tooltip") }}></span>}
 | 
			
		||||
      >
 | 
			
		||||
        <Input placeholder={t("workflow_node.deploy.form.volcengine_clb_region.placeholder")} />
 | 
			
		||||
      </Form.Item>
 | 
			
		||||
 | 
			
		||||
      <Show when={fieldResourceType === RESOURCE_TYPE_LISTENER}>
 | 
			
		||||
        <Form.Item
 | 
			
		||||
          name="listenerId"
 | 
			
		||||
          label={t("workflow_node.deploy.form.volcengine_clb_listener_id.label")}
 | 
			
		||||
          rules={[formRule]}
 | 
			
		||||
          tooltip={<span dangerouslySetInnerHTML={{ __html: t("workflow_node.deploy.form.volcengine_clb_listener_id.tooltip") }}></span>}
 | 
			
		||||
        >
 | 
			
		||||
          <Input placeholder={t("workflow_node.deploy.form.volcengine_clb_listener_id.placeholder")} />
 | 
			
		||||
        </Form.Item>
 | 
			
		||||
      </Show>
 | 
			
		||||
    </Form>
 | 
			
		||||
  );
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export default DeployNodeConfigFormVolcEngineCLBConfig;
 | 
			
		||||
| 
						 | 
				
			
			@ -163,6 +163,7 @@ export const DEPLOY_PROVIDERS = Object.freeze({
 | 
			
		|||
  TENCENTCLOUD_ECDN: `${ACCESS_PROVIDERS.TENCENTCLOUD}-ecdn`,
 | 
			
		||||
  TENCENTCLOUD_EO: `${ACCESS_PROVIDERS.TENCENTCLOUD}-eo`,
 | 
			
		||||
  VOLCENGINE_CDN: `${ACCESS_PROVIDERS.VOLCENGINE}-cdn`,
 | 
			
		||||
  VOLCENGINE_CLB: `${ACCESS_PROVIDERS.VOLCENGINE}-clb`,
 | 
			
		||||
  VOLCENGINE_DCDN: `${ACCESS_PROVIDERS.VOLCENGINE}-dcdn`,
 | 
			
		||||
  VOLCENGINE_LIVE: `${ACCESS_PROVIDERS.VOLCENGINE}-live`,
 | 
			
		||||
  VOLCENGINE_TOS: `${ACCESS_PROVIDERS.VOLCENGINE}-tos`,
 | 
			
		||||
| 
						 | 
				
			
			@ -206,6 +207,7 @@ export const deployProvidersMap: Map<DeployProvider["type"] | string, DeployProv
 | 
			
		|||
    [DEPLOY_PROVIDERS.VOLCENGINE_CDN, "common.provider.volcengine.cdn"],
 | 
			
		||||
    [DEPLOY_PROVIDERS.VOLCENGINE_DCDN, "common.provider.volcengine.dcdn"],
 | 
			
		||||
    [DEPLOY_PROVIDERS.VOLCENGINE_LIVE, "common.provider.volcengine.live"],
 | 
			
		||||
    [DEPLOY_PROVIDERS.VOLCENGINE_CLB, "common.provider.volcengine.clb"],
 | 
			
		||||
    [DEPLOY_PROVIDERS.QINIU_CDN, "common.provider.qiniu.cdn"],
 | 
			
		||||
    [DEPLOY_PROVIDERS.DOGECLOUD_CDN, "common.provider.dogecloud.cdn"],
 | 
			
		||||
    [DEPLOY_PROVIDERS.BYTEPLUS_CDN, "common.provider.byteplus.cdn"],
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -76,6 +76,7 @@
 | 
			
		|||
  "common.provider.tencentcloud.eo": "Tencent Cloud - EdgeOne",
 | 
			
		||||
  "common.provider.volcengine": "Volcengine",
 | 
			
		||||
  "common.provider.volcengine.cdn": "Volcengine - CDN",
 | 
			
		||||
  "common.provider.volcengine.clb": "Volcengine - CLB",
 | 
			
		||||
  "common.provider.volcengine.dcdn": "Volcengine - DCDN",
 | 
			
		||||
  "common.provider.volcengine.dns": "Volcengine - DNS",
 | 
			
		||||
  "common.provider.volcengine.live": "Volcengine - Live",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -289,6 +289,15 @@
 | 
			
		|||
  "workflow_node.deploy.form.volcengine_cdn_domain.label": "VolcEngine CDN domain",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_cdn_domain.placeholder": "Please enter VolcEngine CDN domain name",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_cdn_domain.tooltip": "For more information, see <a href=\"https://console.volcengine.com/cdn/homepage\" target=\"_blank\">https://console.volcengine.com/cdn/homepage</a>",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_clb_resource_type.label": "Resource type",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_clb_resource_type.placeholder": "Please select resource type",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_clb_resource_type.option.listener.label": "CLB listener",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_clb_region.label": "VolcEngine region",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_clb_region.placeholder": "Please enter VolcEngine region (e.g. cn-beijing)",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_clb_region.tooltip": "For more information, see <a href=\"https://www.volcengine.com/docs/6406/74892\" target=\"_blank\">https://www.volcengine.com/docs/6406/74892</a>",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_clb_listener_id.label": "VolcEngine CLB listener ID",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_clb_listener_id.placeholder": "Please enter VolcEngine CLB listener ID",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_clb_listener_id.tooltip": "For more information, see <a href=\"https://console.volcengine.com/clb/LoadBalancer\" target=\"_blank\">https://console.volcengine.com/clb/LoadBalancer</a>",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_dcdn_domain.label": "VolcEngine DCDN domain",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_dcdn_domain.placeholder": "Please enter VolcEngine DCDN domain name",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_dcdn_domain.tooltip": "For more information, see <a href=\"https://console.volcengine.com/dcdn/dashboard\" target=\"_blank\">https://console.volcengine.com/dcdn/dashboard</a>",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -76,6 +76,7 @@
 | 
			
		|||
  "common.provider.tencentcloud.eo": "腾讯云 - 边缘安全加速平台 EdgeOne",
 | 
			
		||||
  "common.provider.volcengine": "火山引擎",
 | 
			
		||||
  "common.provider.volcengine.cdn": "火山引擎 - 内容分发网络 CDN",
 | 
			
		||||
  "common.provider.volcengine.clb": "火山引擎 - 负载均衡 CLB",
 | 
			
		||||
  "common.provider.volcengine.dcdn": "火山引擎 - 全站加速 DCDN",
 | 
			
		||||
  "common.provider.volcengine.dns": "火山引擎 - 云解析 DNS",
 | 
			
		||||
  "common.provider.volcengine.live": "火山引擎 - 视频直播 Live",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -289,6 +289,15 @@
 | 
			
		|||
  "workflow_node.deploy.form.volcengine_cdn_domain.label": "火山引擎 CDN 加速域名(支持泛域名)",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_cdn_domain.placeholder": "请输入火山引擎 CDN 加速域名",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_cdn_domain.tooltip": "这是什么?请参阅 <a href=\"https://console.volcengine.com/cdn/homepage\" target=\"_blank\">https://console.volcengine.com/cdn/homepage</a><br><br>泛域名表示形式为:*.example.com",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_clb_resource_type.label": "证书替换方式",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_clb_resource_type.placeholder": "请选择证书替换方式",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_clb_resource_type.option.listener.label": "替换指定监听器的证书",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_clb_region.label": "火山引擎地域",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_clb_region.placeholder": "请输入火山引擎地域(例如:cn-beijing)",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_clb_region.tooltip": "这是什么?请参阅 <a href=\"https://www.volcengine.com/docs/6406/74892\" target=\"_blank\">https://www.volcengine.com/docs/6406/74892</a>",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_clb_listener_id.label": "火山引擎 CLB 监听器 ID",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_clb_listener_id.placeholder": "请输入火山引擎 CLB 监听器 ID",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_clb_listener_id.tooltip": "这是什么?请参阅 <a href=\"https://console.volcengine.com/clb/LoadBalancer\" target=\"_blank\">https://console.volcengine.com/clb/LoadBalancer</a>",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_dcdn_domain.label": "火山引擎 DCDN 加速域名(支持泛域名)",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_dcdn_domain.placeholder": "请输入火山引擎 DCDN 加速域名",
 | 
			
		||||
  "workflow_node.deploy.form.volcengine_dcdn_domain.tooltip": "这是什么?请参阅 <a href=\"https://console.volcengine.com/dcdn/dashboard\" target=\"_blank\">https://console.volcengine.com/dcdn/dashboard</a><br><br>泛域名表示形式为:*.example.com",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue