feat: update access fields to AccessKeyId and SecretAccessKey for byteplus services

This commit is contained in:
Fu Diwei
2026-06-04 01:14:21 +08:00
committed by RHQYZ
parent bc7aa5d157
commit 141cb538dc
16 changed files with 171 additions and 105 deletions
@@ -17,8 +17,8 @@ func init() {
}
provider, err := byteplus.NewChallenger(&byteplus.ChallengerConfig{
AccessKey: credentials.AccessKey,
SecretKey: credentials.SecretKey,
AccessKeyId: credentials.AccessKeyId,
SecretAccessKey: credentials.SecretAccessKey,
DnsPropagationTimeout: options.DnsPropagationTimeout,
DnsTTL: options.DnsTTL,
})
@@ -17,8 +17,8 @@ func init() {
}
provider, err := bytepluscdn.NewDeployer(&bytepluscdn.DeployerConfig{
AccessKey: credentials.AccessKey,
SecretKey: credentials.SecretKey,
AccessKeyId: credentials.AccessKeyId,
SecretAccessKey: credentials.SecretAccessKey,
ProjectName: credentials.ProjectName,
DomainMatchPattern: xmaps.GetString(options.ProviderExtendedConfig, "domainMatchPattern"),
Domain: xmaps.GetString(options.ProviderExtendedConfig, "domain"),
@@ -17,10 +17,10 @@ func init() {
}
provider, err := bytepluscertcenter.NewDeployer(&bytepluscertcenter.DeployerConfig{
AccessKey: credentials.AccessKey,
SecretKey: credentials.SecretKey,
ProjectName: credentials.ProjectName,
Region: xmaps.GetString(options.ProviderExtendedConfig, "region"),
AccessKeyId: credentials.AccessKeyId,
SecretAccessKey: credentials.SecretAccessKey,
ProjectName: credentials.ProjectName,
Region: xmaps.GetString(options.ProviderExtendedConfig, "region"),
})
return provider, err
})
+3 -3
View File
@@ -135,9 +135,9 @@ type AccessConfigForBunny struct {
}
type AccessConfigForBytePlus struct {
AccessKey string `json:"accessKey"`
SecretKey string `json:"secretKey"`
ProjectName string `json:"projectName,omitempty"`
AccessKeyId string `json:"accessKeyId"`
SecretAccessKey string `json:"secretAccessKey"`
ProjectName string `json:"projectName,omitempty"`
}
type AccessConfigForCacheFly struct {
+66
View File
@@ -0,0 +1,66 @@
package migrations
import (
"github.com/pocketbase/pocketbase/core"
m "github.com/pocketbase/pocketbase/migrations"
)
func init() {
m.Register(func(app core.App) error {
tracer := NewTracer("v0.4.25")
tracer.Printf("go ...")
// update collection `access`
// - modify field `config` schema
{
collection, err := app.FindCollectionByNameOrId("4yzbv8urny5ja1e")
if err != nil {
return err
}
records, err := app.FindAllRecords(collection)
if err != nil {
return err
}
for _, record := range records {
changed := false
provider := record.GetString("provider")
config := make(map[string]any)
if err := record.UnmarshalJSONField("config", &config); err != nil {
return err
}
switch provider {
case "byteplus":
if _, ok := config["accessKey"]; ok {
config["accessKeyId"] = config["accessKey"]
delete(config, "accessKey")
record.Set("config", config)
changed = true
}
if _, ok := config["secretKey"]; ok {
config["secretAccessKey"] = config["secretKey"]
delete(config, "secretKey")
record.Set("config", config)
changed = true
}
}
if changed {
if err := app.Save(record); err != nil {
return err
}
tracer.Printf("record #%s in collection '%s' updated", record.Id, collection.Name)
}
}
}
tracer.Printf("done")
return nil
}, func(app core.App) error {
return nil
})
}
@@ -10,8 +10,8 @@ import (
)
type ChallengerConfig struct {
AccessKey string `json:"accessKey"`
SecretKey string `json:"secretKey"`
AccessKeyId string `json:"accessKeyId"`
SecretAccessKey string `json:"secretAccessKey"`
DnsPropagationTimeout int `json:"dnsPropagationTimeout,omitempty"`
DnsTTL int `json:"dnsTTL,omitempty"`
}
@@ -22,8 +22,8 @@ func NewChallenger(config *ChallengerConfig) (certifier.ACMEChallenger, error) {
}
providerConfig := internal.NewDefaultConfig()
providerConfig.AccessKey = config.AccessKey
providerConfig.SecretKey = config.SecretKey
providerConfig.AccessKey = config.AccessKeyId
providerConfig.SecretKey = config.SecretAccessKey
if config.DnsPropagationTimeout != 0 {
providerConfig.PropagationTimeout = time.Duration(config.DnsPropagationTimeout) * time.Second
}
@@ -17,10 +17,10 @@ import (
)
type CertmgrConfig struct {
// BytePlus AccessKey。
AccessKey string `json:"accessKey"`
// BytePlus SecretKey。
SecretKey string `json:"secretKey"`
// BytePlus AccessKeyId。
AccessKeyId string `json:"accessKeyId"`
// BytePlus SecretAccessKey。
SecretAccessKey string `json:"secretAccessKey"`
}
type Certmgr struct {
@@ -37,8 +37,8 @@ func NewCertmgr(config *CertmgrConfig) (*Certmgr, error) {
}
client := bpcdn.NewInstance()
client.Client.SetAccessKey(config.AccessKey)
client.Client.SetSecretKey(config.SecretKey)
client.Client.SetAccessKey(config.AccessKeyId)
client.Client.SetSecretKey(config.SecretAccessKey)
return &Certmgr{
config: config,
@@ -8,18 +8,18 @@ import (
)
var (
fp = tester.Args("BYTEPLUSCDN_")
fTestCertPath string
fTestKeyPath string
fAccessKey string
fSecretKey string
fp = tester.Args("BYTEPLUSCDN_")
fTestCertPath string
fTestKeyPath string
fAccessKeyId string
fSecretAccessKey string
)
func init() {
fp.DefineString(&fTestCertPath, "TESTCERTPATH")
fp.DefineString(&fTestKeyPath, "TESTKEYPATH")
fp.DefineString(&fAccessKey, "ACCESSKEY")
fp.DefineString(&fSecretKey, "SECRETKEY")
fp.DefineString(&fAccessKeyId, "ACCESSKEYID")
fp.DefineString(&fSecretAccessKey, "SECRETACCESSKEY")
}
/*
@@ -28,16 +28,16 @@ Shell command to run this test:
go test -v ./byteplus_cdn_test.go -args \
--BYTEPLUSCDN_TESTCERTPATH="/path/to/your-test-cert.pem" \
--BYTEPLUSCDN_TESTKEYPATH="/path/to/your-test-key.pem" \
--BYTEPLUSCDN_ACCESSKEY="your-access-key" \
--BYTEPLUSCDN_SECRETKEY="your-secret-key"
--BYTEPLUSCDN_ACCESSKEYID="your-access-key-id" \
--BYTEPLUSCDN_SECRETACCESSKEY="your-secret-access-key"
*/
func TestProvider(t *testing.T) {
fp.Parse()
t.Run("Upload", func(t *testing.T) {
provider, err := impl.NewCertmgr(&impl.CertmgrConfig{
AccessKey: fAccessKey,
SecretKey: fSecretKey,
AccessKeyId: fAccessKeyId,
SecretAccessKey: fSecretAccessKey,
})
if err != nil {
t.Errorf("err: %+v", err)
@@ -14,10 +14,10 @@ import (
)
type CertmgrConfig struct {
// BytePlus AccessKey。
AccessKey string `json:"accessKey"`
// BytePlus SecretKey。
SecretKey string `json:"secretKey"`
// BytePlus AccessKeyId。
AccessKeyId string `json:"accessKeyId"`
// BytePlus SecretAccessKey。
SecretAccessKey string `json:"secretAccessKey"`
// BytePlus 项目名称。
ProjectName string `json:"projectName,omitempty"`
// BytePlus 地域。
@@ -37,7 +37,7 @@ func NewCertmgr(config *CertmgrConfig) (*Certmgr, error) {
return nil, fmt.Errorf("the configuration of the certmgr provider is nil")
}
client, err := createSDKClient(config.AccessKey, config.SecretKey, config.Region)
client, err := createSDKClient(config.AccessKeyId, config.SecretAccessKey, config.Region)
if err != nil {
return nil, fmt.Errorf("could not create client: %w", err)
}
@@ -95,13 +95,13 @@ func (c *Certmgr) Replace(ctx context.Context, certIdOrName string, certPEM, pri
return nil, certmgr.ErrUnsupported
}
func createSDKClient(accessKey, secretKey, region string) (*bpcertificateservice.CERTIFICATESERVICE, error) {
func createSDKClient(accessKeyId, secretAccessKey, region string) (*bpcertificateservice.CERTIFICATESERVICE, error) {
if region == "" {
region = "ap-singapore-1" // 证书中心默认区域:新加坡
}
config := bp.NewConfig().
WithAkSk(accessKey, secretKey).
WithAkSk(accessKeyId, secretAccessKey).
WithRegion(region)
session, err := bpsesion.NewSession(config)
@@ -8,18 +8,18 @@ import (
)
var (
fp = tester.Args("BYTEPLUSCERTCENTER_")
fTestCertPath string
fTestKeyPath string
fAccessKey string
fSecretKey string
fp = tester.Args("BYTEPLUSCERTCENTER_")
fTestCertPath string
fTestKeyPath string
fAccessKeyId string
fSecretAccessKey string
)
func init() {
fp.DefineString(&fTestCertPath, "TESTCERTPATH")
fp.DefineString(&fTestKeyPath, "TESTKEYPATH")
fp.DefineString(&fAccessKey, "ACCESSKEY")
fp.DefineString(&fSecretKey, "SECRETKEY")
fp.DefineString(&fAccessKeyId, "ACCESSKEYID")
fp.DefineString(&fSecretAccessKey, "SECRETACCESSKEY")
}
/*
@@ -28,16 +28,16 @@ Shell command to run this test:
go test -v ./byteplus_certcenter_test.go -args \
--BYTEPLUSCERTCENTER_TESTCERTPATH="/path/to/your-test-cert.pem" \
--BYTEPLUSCERTCENTER_TESTKEYPATH="/path/to/your-test-key.pem" \
--BYTEPLUSCERTCENTER_ACCESSKEY="your-access-key" \
--BYTEPLUSCERTCENTER_SECRETKEY="your-secret-key"
--BYTEPLUSCERTCENTER_ACCESSKEYID="your-access-key-id" \
--BYTEPLUSCERTCENTER_SECRETACCESSKEY="your-secret-access-key"
*/
func TestProvider(t *testing.T) {
fp.Parse()
t.Run("Upload", func(t *testing.T) {
provider, err := impl.NewCertmgr(&impl.CertmgrConfig{
AccessKey: fAccessKey,
SecretKey: fSecretKey,
AccessKeyId: fAccessKeyId,
SecretAccessKey: fSecretAccessKey,
})
if err != nil {
t.Errorf("err: %+v", err)
@@ -17,10 +17,10 @@ import (
)
type DeployerConfig struct {
// BytePlus AccessKey。
AccessKey string `json:"accessKey"`
// BytePlus SecretKey。
SecretKey string `json:"secretKey"`
// BytePlus AccessKeyId。
AccessKeyId string `json:"accessKeyId"`
// BytePlus SecretAccessKey。
SecretAccessKey string `json:"secretAccessKey"`
// BytePlus 项目名称。
ProjectName string `json:"projectName,omitempty"`
// 域名匹配模式。
@@ -45,12 +45,12 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) {
}
client := bpcdn.NewInstance()
client.Client.SetAccessKey(config.AccessKey)
client.Client.SetSecretKey(config.SecretKey)
client.Client.SetAccessKey(config.AccessKeyId)
client.Client.SetSecretKey(config.SecretAccessKey)
pcertmgr, err := certmgrimpl.NewCertmgr(&certmgrimpl.CertmgrConfig{
AccessKey: config.AccessKey,
SecretKey: config.SecretKey,
AccessKeyId: config.AccessKeyId,
SecretAccessKey: config.SecretAccessKey,
})
if err != nil {
return nil, fmt.Errorf("could not create certmgr: %w", err)
@@ -8,19 +8,19 @@ import (
)
var (
fp = tester.Args("BYTEPLUSCDN_")
fTestCertPath string
fTestKeyPath string
fAccessKey string
fSecretKey string
fDomain string
fp = tester.Args("BYTEPLUSCDN_")
fTestCertPath string
fTestKeyPath string
fAccessKeyId string
fSecretAccessKey string
fDomain string
)
func init() {
fp.DefineString(&fTestCertPath, "TESTCERTPATH")
fp.DefineString(&fTestKeyPath, "TESTKEYPATH")
fp.DefineString(&fAccessKey, "ACCESSKEY")
fp.DefineString(&fSecretKey, "SECRETKEY")
fp.DefineString(&fAccessKeyId, "ACCESSKEYID")
fp.DefineString(&fSecretAccessKey, "SECRETACCESSKEY")
fp.DefineString(&fDomain, "DOMAIN")
}
@@ -30,8 +30,8 @@ Shell command to run this test:
go test -v ./byteplus_cdn_test.go -args \
--BYTEPLUSCDN_TESTCERTPATH="/path/to/your-test-cert.pem" \
--BYTEPLUSCDN_TESTKEYPATH="/path/to/your-test-key.pem" \
--BYTEPLUSCDN_ACCESSKEY="your-access-key" \
--BYTEPLUSCDN_SECRETKEY="your-secret-key" \
--BYTEPLUSCDN_ACCESSKEYID="your-access-key-id" \
--BYTEPLUSCDN_SECRETACCESSKEY="your-secret-access-key" \
--BYTEPLUSCDN_DOMAIN="example.com"
*/
func TestProvider(t *testing.T) {
@@ -39,9 +39,9 @@ func TestProvider(t *testing.T) {
t.Run("Deploy", func(t *testing.T) {
provider, err := impl.NewDeployer(&impl.DeployerConfig{
AccessKey: fAccessKey,
SecretKey: fSecretKey,
Domain: fDomain,
AccessKeyId: fAccessKeyId,
SecretAccessKey: fSecretAccessKey,
Domain: fDomain,
})
if err != nil {
t.Errorf("err: %+v", err)
@@ -11,10 +11,10 @@ import (
)
type DeployerConfig struct {
// BytePlus AccessKey。
AccessKey string `json:"accessKey"`
// BytePlus SecretKey。
SecretKey string `json:"secretKey"`
// BytePlus AccessKeyId。
AccessKeyId string `json:"accessKeyId"`
// BytePlus SecretAccessKey。
SecretAccessKey string `json:"secretAccessKey"`
// BytePlus 项目名称。
ProjectName string `json:"projectName,omitempty"`
// BytePlus 地域。
@@ -35,10 +35,10 @@ func NewDeployer(config *DeployerConfig) (*Deployer, error) {
}
pcertmgr, err := certmgrimpl.NewCertmgr(&certmgrimpl.CertmgrConfig{
AccessKey: config.AccessKey,
SecretKey: config.SecretKey,
ProjectName: config.ProjectName,
Region: config.Region,
AccessKeyId: config.AccessKeyId,
SecretAccessKey: config.SecretAccessKey,
ProjectName: config.ProjectName,
Region: config.Region,
})
if err != nil {
return nil, fmt.Errorf("could not create certmgr: %w", err)
@@ -18,23 +18,23 @@ const AccessConfigFormFieldsProviderBytePlus = () => {
return (
<>
<Form.Item
name={[parentNamePath, "accessKey"]}
initialValue={initialValues.accessKey}
label={t("access.form.byteplus_access_key.label")}
name={[parentNamePath, "accessKeyId"]}
initialValue={initialValues.accessKeyId}
label={t("access.form.byteplus_access_key_id.label")}
rules={[formRule]}
tooltip={<span dangerouslySetInnerHTML={{ __html: t("access.form.byteplus_access_key.tooltip") }}></span>}
tooltip={<span dangerouslySetInnerHTML={{ __html: t("access.form.byteplus_access_key_id.tooltip") }}></span>}
>
<Input autoComplete="new-password" placeholder={t("access.form.byteplus_access_key.placeholder")} />
<Input autoComplete="new-password" placeholder={t("access.form.byteplus_access_key_id.placeholder")} />
</Form.Item>
<Form.Item
name={[parentNamePath, "secretKey"]}
initialValue={initialValues.secretKey}
label={t("access.form.byteplus_secret_key.label")}
name={[parentNamePath, "secretAccessKey"]}
initialValue={initialValues.secretAccessKey}
label={t("access.form.byteplus_secret_access_key.label")}
rules={[formRule]}
tooltip={<span dangerouslySetInnerHTML={{ __html: t("access.form.byteplus_secret_key.tooltip") }}></span>}
tooltip={<span dangerouslySetInnerHTML={{ __html: t("access.form.byteplus_secret_access_key.tooltip") }}></span>}
>
<Input.Password autoComplete="new-password" placeholder={t("access.form.byteplus_secret_key.placeholder")} />
<Input.Password autoComplete="new-password" placeholder={t("access.form.byteplus_secret_access_key.placeholder")} />
</Form.Item>
<Form.Item
@@ -52,8 +52,8 @@ const AccessConfigFormFieldsProviderBytePlus = () => {
const getInitialValues = (): Nullish<z.infer<ReturnType<typeof getSchema>>> => {
return {
accessKey: "",
secretKey: "",
accessKeyId: "",
secretAccessKey: "",
};
};
@@ -61,8 +61,8 @@ const getSchema = ({ i18n = getI18n() }: { i18n: ReturnType<typeof getI18n> }) =
const { t: _ } = i18n;
return z.object({
accessKey: z.string().nonempty(),
secretKey: z.string().nonempty(),
accessKeyId: z.string().nonempty(),
secretAccessKey: z.string().nonempty(),
projectName: z.string().nullish(),
});
};
+6 -6
View File
@@ -326,14 +326,14 @@
"placeholder": "Please enter Bunny API key",
"tooltip": "For more information, see <a href=\"https://docs.bunny.net/reference/bunnynet-api-overview\" target=\"_blank\">https://docs.bunny.net/reference/bunnynet-api-overview</a>"
},
"byteplus_access_key": {
"label": "BytePlus AccessKey",
"placeholder": "Please enter BytePlus AccessKey",
"byteplus_access_key_id": {
"label": "BytePlus AccessKeyID",
"placeholder": "Please enter BytePlus AccessKeyID",
"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_secret_key": {
"label": "BytePlus SecretKey",
"placeholder": "Please enter BytePlus SecretKey",
"byteplus_secret_access_key": {
"label": "BytePlus SecretAccessKey",
"placeholder": "Please enter BytePlus SecretAccessKey",
"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": {
+6 -6
View File
@@ -324,14 +324,14 @@
"placeholder": "请输入 Bunny API Key",
"tooltip": "这是什么?请参阅 <a href=\"https://docs.bunny.net/reference/bunnynet-api-overview\" target=\"_blank\">https://docs.bunny.net/reference/bunnynet-api-overview</a>"
},
"byteplus_access_key": {
"label": "BytePlus AccessKey",
"placeholder": "请输入 BytePlus AccessKey",
"byteplus_access_key_id": {
"label": "BytePlus AccessKeyID",
"placeholder": "请输入 BytePlus AccessKeyID",
"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_secret_key": {
"label": "BytePlus SecretKey",
"placeholder": "请输入 BytePlus SecretKey",
"byteplus_secret_access_key": {
"label": "BytePlus SecretAccessKey",
"placeholder": "请输入 BytePlus SecretAccessKey",
"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": {