feat(provider): add ProjectName support for byteplus services

This commit is contained in:
Fu Diwei
2026-06-04 01:14:21 +08:00
committed by RHQYZ
parent ee30f63717
commit a7ab5db2aa
11 changed files with 41 additions and 15 deletions
@@ -19,6 +19,7 @@ func init() {
provider, err := bytepluscdn.NewDeployer(&bytepluscdn.DeployerConfig{
AccessKey: credentials.AccessKey,
SecretKey: credentials.SecretKey,
ProjectName: credentials.ProjectName,
DomainMatchPattern: xmaps.GetString(options.ProviderExtendedConfig, "domainMatchPattern"),
Domain: xmaps.GetString(options.ProviderExtendedConfig, "domain"),
})
+3 -2
View File
@@ -135,8 +135,9 @@ type AccessConfigForBunny struct {
}
type AccessConfigForBytePlus struct {
AccessKey string `json:"accessKey"`
SecretKey string `json:"secretKey"`
AccessKey string `json:"accessKey"`
SecretKey string `json:"secretKey"`
ProjectName string `json:"projectName,omitempty"`
}
type AccessConfigForCacheFly struct {
@@ -74,7 +74,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
client, err := dynv6sdk.NewClient(config.HTTPToken)
if err != nil {
return nil, fmt.Errorf("dnsexit: %w", err)
return nil, fmt.Errorf("dynv6: %w", err)
} else {
client.SetTimeout(config.HTTPTimeout)
}
@@ -8,7 +8,7 @@ import (
"strings"
bpcdn "github.com/byteplus-sdk/byteplus-sdk-golang/service/cdn"
bp "github.com/volcengine/volcengine-go-sdk/volcengine"
"github.com/samber/lo"
"github.com/certimate-go/certimate/pkg/core/certmgr"
certmgrimpl "github.com/certimate-go/certimate/pkg/core/certmgr/providers/byteplus-cdn"
@@ -21,6 +21,8 @@ type DeployerConfig struct {
AccessKey string `json:"accessKey"`
// BytePlus SecretKey。
SecretKey string `json:"secretKey"`
// BytePlus 项目名称。
ProjectName string `json:"projectName,omitempty"`
// 域名匹配模式。
// 零值时默认值 [DOMAIN_MATCH_PATTERN_EXACT]。
DomainMatchPattern string `json:"domainMatchPattern,omitempty"`
@@ -166,10 +168,11 @@ func (d *Deployer) getMatchedDomainsByWildcard(ctx context.Context, wildcardDoma
}
listCdnDomainsReq := &bpcdn.ListCdnDomainsRequest{
Domain: bp.String(strings.TrimPrefix(wildcardDomain, "*.")),
Status: bp.String("online"),
PageNum: bp.Int64(int64(listCdnDomainsPageNum)),
PageSize: bp.Int64(int64(listCdnDomainsPageSize)),
Project: lo.EmptyableToPtr(d.config.ProjectName),
Domain: bpcdn.GetStrPtr(strings.TrimPrefix(wildcardDomain, "*.")),
Status: bpcdn.GetStrPtr("online"),
PageNum: bpcdn.GetInt64Ptr(int64(listCdnDomainsPageNum)),
PageSize: bpcdn.GetInt64Ptr(int64(listCdnDomainsPageSize)),
}
listCdnDomainsResp, err := d.sdkClient.ListCdnDomains(listCdnDomainsReq)
d.logger.Debug("sdk request 'cdn.ListCdnDomains'", slog.Any("request", listCdnDomainsReq), slog.Any("response", listCdnDomainsResp))
@@ -174,7 +174,7 @@ func (d *Deployer) deployToCertificate(ctx context.Context, certPEM, privkeyPEM
}
// 更新证书
// https://docs.ksyun.com/documents/259
// REF: https://docs.ksyun.com/documents/259
setCertificateInput := map[string]any{
"CertificateId": d.config.CertificateId,
"CertificateName": fmt.Sprintf("certimate_%d", time.Now().UnixMilli()),
@@ -194,7 +194,7 @@ func (d *Deployer) getAllDomains(ctx context.Context) ([]string, error) {
domains := make([]string, 0)
// 查询域名列表
// https://docs.ksyun.com/documents/198
// REF: https://docs.ksyun.com/documents/198
getCdnDomainsPageNumber := 1
getCdnDomainsPageSize := 100
for {
@@ -250,7 +250,7 @@ func (d *Deployer) getAllDomains(ctx context.Context) ([]string, error) {
func (d *Deployer) findDomainIdByDomain(ctx context.Context, domain string) (string, error) {
// 查询域名列表
// https://docs.ksyun.com/documents/198
// REF: https://docs.ksyun.com/documents/198
getCdnDomainsPageNumber := 1
getCdnDomainsPageSize := 100
for {
@@ -316,7 +316,7 @@ func (d *Deployer) updateDomainCertificate(ctx context.Context, domain string, c
}
// 为加速域名配置证书接口
// https://docs.ksyun.com/documents/261
// REF: https://docs.ksyun.com/documents/261
configCertificateInput := map[string]any{
"Enable": "on",
"DomainIds": domainId,
@@ -78,7 +78,7 @@ func (d *Deployer) deployToCertificate(ctx context.Context, certPEM, privkeyPEM
}
// 更新证书信息
// https://docs.ksyun.com/documents/2121
// REF: https://docs.ksyun.com/documents/2121
modifyCertificateInput := map[string]any{
"CertificateId": d.config.CertificateId,
"CertificateName": fmt.Sprintf("certimate_%d", time.Now().UnixMilli()),
@@ -190,7 +190,7 @@ func (d *Deployer) getAllDomains(ctx context.Context) ([]*veapig.ItemForListCust
domains := make([]*veapig.ItemForListCustomDomainsOutput, 0)
// 查询自定义域名列表
// https://api.volcengine.com/api-explorer?action=ListCustomDomains&serviceCode=apig&version=2021-03-03
// REF: https://api.volcengine.com/api-explorer?action=ListCustomDomains&serviceCode=apig&version=2021-03-03
listCustomDomainsPageNumber := 1
listCustomDomainsPageSize := 100
for {
@@ -236,7 +236,7 @@ func (d *Deployer) getAllDomains(ctx context.Context) ([]*zcdnsdk.DomainInfo, er
domains := make([]*zcdnsdk.DomainInfo, 0)
// 查询加速域名列表
// https://docs.console.zenlayer.com/api-reference/cn/networking/cdn/domain/describedomains
// REF: https://docs.console.zenlayer.com/api-reference/cn/networking/cdn/domain/describedomains
describeDomainsPageNum := 1
describeDomainsPageSize := 100
for {
@@ -36,6 +36,16 @@ const AccessConfigFormFieldsProviderBytePlus = () => {
>
<Input.Password autoComplete="new-password" placeholder={t("access.form.byteplus_secret_key.placeholder")} />
</Form.Item>
<Form.Item
name={[parentNamePath, "projectName"]}
initialValue={initialValues.projectName}
label={t("access.form.byteplus_project_name.label")}
rules={[formRule]}
tooltip={<span dangerouslySetInnerHTML={{ __html: t("access.form.byteplus_project_name.tooltip") }}></span>}
>
<Input allowClear placeholder={t("access.form.byteplus_project_name.placeholder")} />
</Form.Item>
</>
);
};
@@ -53,6 +63,7 @@ const getSchema = ({ i18n = getI18n() }: { i18n: ReturnType<typeof getI18n> }) =
return z.object({
accessKey: z.string().nonempty(),
secretKey: z.string().nonempty(),
projectName: z.string().nullish(),
});
};
+5
View File
@@ -336,6 +336,11 @@
"placeholder": "Please enter BytePlus SecretKey",
"tooltip": "For more information, see <a href=\"https://docs.byteplus.com/en/docs/byteplus-platform/docs-managing-keys\" target=\"_blank\">https://docs.byteplus.com/en/docs/byteplus-platform/docs-managing-keys</a>"
},
"byteplus_project_name": {
"label": "BytePlus project ID",
"placeholder": "Please enter BytePlus project ID",
"tooltip": "For more information, see <a href=\"https://docs.byteplus.com/en/docs/resourcemanagement/Project_Management\" target=\"_blank\">https://docs.byteplus.com/en/docs/resourcemanagement/Project_Management</a>"
},
"cachefly_api_token": {
"label": "CacheFly API token",
"placeholder": "Please enter CacheFly API token",
+5
View File
@@ -334,6 +334,11 @@
"placeholder": "请输入 BytePlus SecretKey",
"tooltip": "这是什么?请参阅 <a href=\"https://docs.byteplus.com/zh-CN/docs/byteplus-platform/docs-managing-keys\" target=\"_blank\">https://docs.byteplus.com/zh-CN/docs/byteplus-platform/docs-managing-keys</a>"
},
"byteplus_project_name": {
"label": "BytePlus 项目名称(可选)",
"placeholder": "请输入 BytePlus 项目名称",
"tooltip": "这是什么?请参阅 <a href=\"https://docs.byteplus.com/zh-CN/docs/resourcemanagement/Project_Management\" target=\"_blank\">https://docs.byteplus.com/zh-CN/docs/resourcemanagement/Project_Management</a>"
},
"cachefly_api_token": {
"label": "CacheFly API Token",
"placeholder": "请输入 CacheFly API Token",