From 5143823e43965895fdda1493feb521d0d8bdfa0c Mon Sep 17 00:00:00 2001 From: imlonghao Date: Sun, 13 Apr 2025 12:39:02 +0800 Subject: [PATCH] feat: support bunny as dns and cdn provider --- go.mod | 1 + go.sum | 4 + internal/applicant/providers.go | 16 +++ internal/deployer/providers.go | 16 +++ internal/domain/access.go | 4 + internal/domain/provider.go | 2 + .../acme-dns-01/lego-providers/bunny/bunny.go | 36 ++++++ .../deployer/providers/bunny-cdn/bunny_cdn.go | 70 ++++++++++++ .../providers/bunny-cdn/bunny_cdn_test.go | 75 ++++++++++++ internal/pkg/vendors/bunny-sdk/api.go | 11 ++ internal/pkg/vendors/bunny-sdk/client.go | 66 +++++++++++ internal/pkg/vendors/bunny-sdk/models.go | 8 ++ migrations/1744459000_upgrade.go | 98 ++++++++++++++++ ui/public/imgs/providers/bunny.svg | 108 ++++++++++++++++++ ui/src/components/access/AccessForm.tsx | 3 + .../access/AccessFormBunnyConfig.tsx | 62 ++++++++++ .../workflow/node/DeployNodeConfigForm.tsx | 3 + .../DeployNodeConfigFormBunnyCDNConfig.tsx | 76 ++++++++++++ ui/src/domain/access.ts | 5 + ui/src/domain/provider.ts | 6 + ui/src/i18n/locales/en/nls.access.json | 3 + ui/src/i18n/locales/en/nls.provider.json | 2 + .../i18n/locales/en/nls.workflow.nodes.json | 6 + ui/src/i18n/locales/zh/nls.access.json | 3 + ui/src/i18n/locales/zh/nls.provider.json | 2 + .../i18n/locales/zh/nls.workflow.nodes.json | 6 + 26 files changed, 692 insertions(+) create mode 100644 internal/pkg/core/applicant/acme-dns-01/lego-providers/bunny/bunny.go create mode 100644 internal/pkg/core/deployer/providers/bunny-cdn/bunny_cdn.go create mode 100644 internal/pkg/core/deployer/providers/bunny-cdn/bunny_cdn_test.go create mode 100644 internal/pkg/vendors/bunny-sdk/api.go create mode 100644 internal/pkg/vendors/bunny-sdk/client.go create mode 100644 internal/pkg/vendors/bunny-sdk/models.go create mode 100644 migrations/1744459000_upgrade.go create mode 100644 ui/public/imgs/providers/bunny.svg create mode 100644 ui/src/components/access/AccessFormBunnyConfig.tsx create mode 100644 ui/src/components/workflow/node/DeployNodeConfigFormBunnyCDNConfig.tsx diff --git a/go.mod b/go.mod index 7c8723af..f17c4e51 100644 --- a/go.mod +++ b/go.mod @@ -107,6 +107,7 @@ require ( github.com/mailru/easyjson v0.9.0 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04 // indirect + github.com/nrdcg/bunny-go v0.0.0-20240207213615-dde5bf4577a3 // indirect github.com/nrdcg/desec v0.10.0 // indirect github.com/nrdcg/mailinabox v0.2.0 // indirect github.com/nrdcg/porkbun v0.4.0 // indirect diff --git a/go.sum b/go.sum index 98e8211f..a5cf6ac3 100644 --- a/go.sum +++ b/go.sum @@ -498,6 +498,8 @@ github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9n github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= github.com/hashicorp/go-hclog v0.12.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= github.com/hashicorp/go-hclog v0.16.2/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= +github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k= +github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= @@ -649,6 +651,8 @@ github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJm github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nikoksr/notify v1.3.0 h1:UxzfxzAYGQD9a5JYLBTVx0lFMxeHCke3rPCkfWdPgLs= github.com/nikoksr/notify v1.3.0/go.mod h1:Xor2hMmkvrCfkCKvXGbcrESez4brac2zQjhd6U2BbeM= +github.com/nrdcg/bunny-go v0.0.0-20240207213615-dde5bf4577a3 h1:ouZ2JWDl8IW5k1qugYbmpbmW8hn85Ig6buSMBRlz3KI= +github.com/nrdcg/bunny-go v0.0.0-20240207213615-dde5bf4577a3/go.mod h1:ZwadWt7mVhMHMbAQ1w8IhDqtWO3eWqWq72W7trnaiE8= github.com/nrdcg/desec v0.10.0 h1:qrEDiqnsvNU9QE7lXIXi/tIHAfyaFXKxF2/8/52O8uM= github.com/nrdcg/desec v0.10.0/go.mod h1:5+4vyhMRTs49V9CNoODF/HwT8Mwxv9DJ6j+7NekUnBs= github.com/nrdcg/mailinabox v0.2.0 h1:IKq8mfKiVwNW2hQii/ng1dJ4yYMMv3HAP3fMFIq2CFk= diff --git a/internal/applicant/providers.go b/internal/applicant/providers.go index 74a12678..ddecad7c 100644 --- a/internal/applicant/providers.go +++ b/internal/applicant/providers.go @@ -11,6 +11,7 @@ import ( pAWSRoute53 "github.com/usual2970/certimate/internal/pkg/core/applicant/acme-dns-01/lego-providers/aws-route53" pAzureDNS "github.com/usual2970/certimate/internal/pkg/core/applicant/acme-dns-01/lego-providers/azure-dns" pBaiduCloud "github.com/usual2970/certimate/internal/pkg/core/applicant/acme-dns-01/lego-providers/baiducloud" + pBunny "github.com/usual2970/certimate/internal/pkg/core/applicant/acme-dns-01/lego-providers/bunny" pCloudflare "github.com/usual2970/certimate/internal/pkg/core/applicant/acme-dns-01/lego-providers/cloudflare" pClouDNS "github.com/usual2970/certimate/internal/pkg/core/applicant/acme-dns-01/lego-providers/cloudns" pCMCCCloud "github.com/usual2970/certimate/internal/pkg/core/applicant/acme-dns-01/lego-providers/cmcccloud" @@ -128,6 +129,21 @@ func createApplicant(options *applicantOptions) (challenge.Provider, error) { return applicant, err } + case domain.ApplyDNSProviderTypeBunny: + { + access := domain.AccessConfigForBunny{} + if err := maputil.Populate(options.ProviderAccessConfig, &access); err != nil { + return nil, fmt.Errorf("failed to populate provider access config: %w", err) + } + + applicant, err := pBunny.NewChallengeProvider(&pBunny.ChallengeProviderConfig{ + ApiKey: access.ApiKey, + DnsPropagationTimeout: options.DnsPropagationTimeout, + DnsTTL: options.DnsTTL, + }) + return applicant, err + } + case domain.ApplyDNSProviderTypeCloudflare: { access := domain.AccessConfigForCloudflare{} diff --git a/internal/deployer/providers.go b/internal/deployer/providers.go index fc3c7a37..947e60d3 100644 --- a/internal/deployer/providers.go +++ b/internal/deployer/providers.go @@ -31,6 +31,7 @@ import ( pBaishanCDN "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/baishan-cdn" pBaotaPanelConsole "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/baotapanel-console" pBaotaPanelSite "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/baotapanel-site" + pBunnyCDN "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/bunny-cdn" pBytePlusCDN "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/byteplus-cdn" pCacheFly "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/cachefly" pCdnfly "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/cdnfly" @@ -414,6 +415,21 @@ func createDeployer(options *deployerOptions) (deployer.Deployer, error) { } } + case domain.DeployProviderTypeBunnyCDN: + { + access := domain.AccessConfigForBunny{} + if err := maputil.Populate(options.ProviderAccessConfig, &access); err != nil { + return nil, fmt.Errorf("failed to populate provider access config: %w", err) + } + + deployer, err := pBunnyCDN.NewDeployer(&pBunnyCDN.DeployerConfig{ + ApiKey: access.ApiKey, + PullZoneId: maputil.GetString(options.ProviderDeployConfig, "pullZoneId"), + HostName: maputil.GetString(options.ProviderDeployConfig, "hostName"), + }) + return deployer, err + } + case domain.DeployProviderTypeBytePlusCDN: { access := domain.AccessConfigForBytePlus{} diff --git a/internal/domain/access.go b/internal/domain/access.go index 0d3528ab..0d7f1fea 100644 --- a/internal/domain/access.go +++ b/internal/domain/access.go @@ -64,6 +64,10 @@ type AccessConfigForBytePlus struct { SecretKey string `json:"secretKey"` } +type AccessConfigForBunny struct { + ApiKey string `json:"apiKey"` +} + type AccessConfigForCacheFly struct { ApiToken string `json:"apiToken"` } diff --git a/internal/domain/provider.go b/internal/domain/provider.go index d8726034..6e91eef2 100644 --- a/internal/domain/provider.go +++ b/internal/domain/provider.go @@ -103,6 +103,7 @@ const ( ApplyDNSProviderTypeAzureDNS = ApplyDNSProviderType("azure-dns") ApplyDNSProviderTypeBaiduCloud = ApplyDNSProviderType("baiducloud") // 兼容旧值,等同于 [ApplyDNSProviderTypeBaiduCloudDNS] ApplyDNSProviderTypeBaiduCloudDNS = ApplyDNSProviderType("baiducloud-dns") + ApplyDNSProviderTypeBunny = ApplyDNSProviderType("bunny") ApplyDNSProviderTypeCloudflare = ApplyDNSProviderType("cloudflare") ApplyDNSProviderTypeClouDNS = ApplyDNSProviderType("cloudns") ApplyDNSProviderTypeCMCCCloud = ApplyDNSProviderType("cmcccloud") @@ -167,6 +168,7 @@ const ( DeployProviderTypeBaishanCDN = DeployProviderType("baishan-cdn") DeployProviderTypeBaotaPanelConsole = DeployProviderType("baotapanel-console") DeployProviderTypeBaotaPanelSite = DeployProviderType("baotapanel-site") + DeployProviderTypeBunnyCDN = DeployProviderType("bunny-cdn") DeployProviderTypeBytePlusCDN = DeployProviderType("byteplus-cdn") DeployProviderTypeCacheFly = DeployProviderType("cachefly") DeployProviderTypeCdnfly = DeployProviderType("cdnfly") diff --git a/internal/pkg/core/applicant/acme-dns-01/lego-providers/bunny/bunny.go b/internal/pkg/core/applicant/acme-dns-01/lego-providers/bunny/bunny.go new file mode 100644 index 00000000..558f7773 --- /dev/null +++ b/internal/pkg/core/applicant/acme-dns-01/lego-providers/bunny/bunny.go @@ -0,0 +1,36 @@ +package bunny + +import ( + "time" + + "github.com/go-acme/lego/v4/challenge" + "github.com/go-acme/lego/v4/providers/dns/bunny" +) + +type ChallengeProviderConfig struct { + ApiKey string `json:"apiKey"` + DnsPropagationTimeout int32 `json:"dnsPropagationTimeout,omitempty"` + DnsTTL int32 `json:"dnsTTL,omitempty"` +} + +func NewChallengeProvider(config *ChallengeProviderConfig) (challenge.Provider, error) { + if config == nil { + panic("config is nil") + } + + providerConfig := bunny.NewDefaultConfig() + providerConfig.APIKey = config.ApiKey + if config.DnsPropagationTimeout != 0 { + providerConfig.PropagationTimeout = time.Duration(config.DnsPropagationTimeout) * time.Second + } + if config.DnsTTL != 0 { + providerConfig.TTL = int(config.DnsTTL) + } + + provider, err := bunny.NewDNSProviderConfig(providerConfig) + if err != nil { + return nil, err + } + + return provider, nil +} diff --git a/internal/pkg/core/deployer/providers/bunny-cdn/bunny_cdn.go b/internal/pkg/core/deployer/providers/bunny-cdn/bunny_cdn.go new file mode 100644 index 00000000..bcf22635 --- /dev/null +++ b/internal/pkg/core/deployer/providers/bunny-cdn/bunny_cdn.go @@ -0,0 +1,70 @@ +package bunnycdn + +import ( + "context" + "encoding/base64" + "log/slog" + + xerrors "github.com/pkg/errors" + + "github.com/usual2970/certimate/internal/pkg/core/deployer" + bunnysdk "github.com/usual2970/certimate/internal/pkg/vendors/bunny-sdk" +) + +type DeployerConfig struct { + // Bunny API Key + ApiKey string `json:"apiKey"` + // Bunny Pull Zone ID + PullZoneId string `json:"pullZoneId"` + // Bunny CDN Hostname(支持泛域名) + HostName string `json:"hostName"` +} + +type DeployerProvider struct { + config *DeployerConfig + logger *slog.Logger + sdkClient *bunnysdk.Client +} + +var _ deployer.Deployer = (*DeployerProvider)(nil) + +func NewDeployer(config *DeployerConfig) (*DeployerProvider, error) { + if config == nil { + panic("config is nil") + } + + return &DeployerProvider{ + config: config, + logger: slog.Default(), + sdkClient: bunnysdk.NewClient(config.ApiKey), + }, nil +} + +func (d *DeployerProvider) WithLogger(logger *slog.Logger) deployer.Deployer { + if logger == nil { + d.logger = slog.Default() + } else { + d.logger = logger + } + return d +} + +func (d *DeployerProvider) Deploy(ctx context.Context, certPem string, privkeyPem string) (*deployer.DeployResult, error) { + // Prepare + certPemBase64 := base64.StdEncoding.EncodeToString([]byte(certPem)) + privkeyPemBase64 := base64.StdEncoding.EncodeToString([]byte(privkeyPem)) + // 上传证书 + createCertificateReq := &bunnysdk.AddCustomCertificateRequest{ + Hostname: d.config.HostName, + PullZoneId: d.config.PullZoneId, + Certificate: certPemBase64, + CertificateKey: privkeyPemBase64, + } + createCertificateResp, err := d.sdkClient.AddCustomCertificate(createCertificateReq) + d.logger.Debug("sdk request 'bunny-cdn.AddCustomCertificate'", slog.Any("request", createCertificateReq), slog.Any("response", createCertificateResp)) + if err != nil { + return nil, xerrors.Wrap(err, "failed to execute sdk request 'bunny-cdn.AddCustomCertificate'") + } + + return &deployer.DeployResult{}, nil +} diff --git a/internal/pkg/core/deployer/providers/bunny-cdn/bunny_cdn_test.go b/internal/pkg/core/deployer/providers/bunny-cdn/bunny_cdn_test.go new file mode 100644 index 00000000..e4e54a20 --- /dev/null +++ b/internal/pkg/core/deployer/providers/bunny-cdn/bunny_cdn_test.go @@ -0,0 +1,75 @@ +package bunnycdn_test + +import ( + "context" + "flag" + "fmt" + "os" + "strings" + "testing" + + provider "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/bunny-cdn" +) + +var ( + fInputCertPath string + fInputKeyPath string + fApiKey string + fPullZoneId string + fHostName string +) + +func init() { + argsPrefix := "CERTIMATE_DEPLOYER_BUNNYCDN_" + + flag.StringVar(&fInputCertPath, argsPrefix+"INPUTCERTPATH", "", "") + flag.StringVar(&fInputKeyPath, argsPrefix+"INPUTKEYPATH", "", "") + flag.StringVar(&fApiKey, argsPrefix+"APIKEY", "", "") + flag.StringVar(&fPullZoneId, argsPrefix+"PULLZONEID", "", "") + flag.StringVar(&fHostName, argsPrefix+"HOSTNAME", "", "") +} + +/* +Shell command to run this test: + + go test -v ./bunny_cdn_test.go -args \ + --CERTIMATE_DEPLOYER_BUNNYCDN_INPUTCERTPATH="/path/to/your-input-cert.pem" \ + --CERTIMATE_DEPLOYER_BUNNYCDN_INPUTKEYPATH="/path/to/your-input-key.pem" \ + --CERTIMATE_DEPLOYER_BUNNYCDN_APITOKEN="your-api-token" \ + --CERTIMATE_DEPLOYER_BUNNYCDN_PULLZONEID="your-pull-zone-id" \ + --CERTIMATE_DEPLOYER_BUNNYCDN_HOSTNAME="example.com" +*/ +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("APIKEY: %v", fApiKey), + fmt.Sprintf("PULLZONEID: %v", fPullZoneId), + fmt.Sprintf("HOSTNAME: %v", fHostName), + }, "\n")) + + deployer, err := provider.NewDeployer(&provider.DeployerConfig{ + ApiKey: fApiKey, + PullZoneId: fPullZoneId, + HostName: fHostName, + }) + 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) + }) +} diff --git a/internal/pkg/vendors/bunny-sdk/api.go b/internal/pkg/vendors/bunny-sdk/api.go new file mode 100644 index 00000000..8cff90b4 --- /dev/null +++ b/internal/pkg/vendors/bunny-sdk/api.go @@ -0,0 +1,11 @@ +package bunnysdk + +import ( + "fmt" + "net/http" +) + +func (c *Client) AddCustomCertificate(req *AddCustomCertificateRequest) ([]byte, error) { + resp, err := c.sendRequest(http.MethodPost, fmt.Sprintf("/pullzone/%s/addCertificate", req.PullZoneId), req) + return resp.Body(), err +} diff --git a/internal/pkg/vendors/bunny-sdk/client.go b/internal/pkg/vendors/bunny-sdk/client.go new file mode 100644 index 00000000..398d5cb2 --- /dev/null +++ b/internal/pkg/vendors/bunny-sdk/client.go @@ -0,0 +1,66 @@ +package bunnysdk + +import ( + "encoding/json" + "fmt" + "net/http" + "strings" + "time" + + "github.com/go-resty/resty/v2" +) + +type Client struct { + apiToken string + + client *resty.Client +} + +func NewClient(apiToken string) *Client { + client := resty.New() + + return &Client{ + apiToken: apiToken, + client: client, + } +} + +func (c *Client) WithTimeout(timeout time.Duration) *Client { + c.client.SetTimeout(timeout) + return c +} + +func (c *Client) sendRequest(method string, path string, params interface{}) (*resty.Response, error) { + req := c.client.R() + req.Method = method + req.URL = "https://api.bunny.net" + path + req = req.SetHeader("AccessKey", c.apiToken) + if strings.EqualFold(method, http.MethodGet) { + qs := make(map[string]string) + if params != nil { + temp := make(map[string]any) + jsonb, _ := json.Marshal(params) + json.Unmarshal(jsonb, &temp) + for k, v := range temp { + if v != nil { + qs[k] = fmt.Sprintf("%v", v) + } + } + } + + req = req.SetQueryParams(qs) + } else { + req = req. + SetHeader("Content-Type", "application/json"). + SetBody(params) + } + + resp, err := req.Send() + if err != nil { + return resp, fmt.Errorf("bunny api error: failed to send request: %w", err) + } else if resp.IsError() { + return resp, fmt.Errorf("bunny api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body()) + } + + return resp, nil +} diff --git a/internal/pkg/vendors/bunny-sdk/models.go b/internal/pkg/vendors/bunny-sdk/models.go new file mode 100644 index 00000000..3306cf5b --- /dev/null +++ b/internal/pkg/vendors/bunny-sdk/models.go @@ -0,0 +1,8 @@ +package bunnysdk + +type AddCustomCertificateRequest struct { + Hostname string `json:"Hostname"` + PullZoneId string `json:"-"` + Certificate string `json:"Certificate"` + CertificateKey string `json:"CertificateKey"` +} diff --git a/migrations/1744459000_upgrade.go b/migrations/1744459000_upgrade.go new file mode 100644 index 00000000..d2f95004 --- /dev/null +++ b/migrations/1744459000_upgrade.go @@ -0,0 +1,98 @@ +package migrations + +import ( + "github.com/pocketbase/pocketbase/core" + m "github.com/pocketbase/pocketbase/migrations" +) + +func init() { + m.Register(func(app core.App) error { + // update collection `access` + { + collection, err := app.FindCollectionByNameOrId("4yzbv8urny5ja1e") + if err != nil { + return err + } + + // update field + if err := collection.Fields.AddMarshaledJSONAt(2, []byte(`{ + "hidden": false, + "id": "hwy7m03o", + "maxSelect": 1, + "name": "provider", + "presentable": false, + "required": false, + "system": false, + "type": "select", + "values": [ + "1panel", + "acmehttpreq", + "akamai", + "aliyun", + "aws", + "azure", + "baiducloud", + "baishan", + "baotapanel", + "bunny", + "byteplus", + "buypass", + "cachefly", + "cdnfly", + "cloudflare", + "cloudns", + "cmcccloud", + "ctcccloud", + "cucccloud", + "desec", + "dnsla", + "dogecloud", + "dynv6", + "edgio", + "fastly", + "gname", + "gcore", + "godaddy", + "goedge", + "googletrustservices", + "huaweicloud", + "jdcloud", + "k8s", + "letsencrypt", + "letsencryptstaging", + "local", + "namecheap", + "namedotcom", + "namesilo", + "ns1", + "porkbun", + "powerdns", + "qiniu", + "qingcloud", + "rainyun", + "safeline", + "ssh", + "sslcom", + "tencentcloud", + "ucloud", + "upyun", + "vercel", + "volcengine", + "webhook", + "westcn", + "zerossl" + ] + }`)); err != nil { + return err + } + + if err := app.Save(collection); err != nil { + return err + } + } + + return nil + }, func(app core.App) error { + return nil + }) +} diff --git a/ui/public/imgs/providers/bunny.svg b/ui/public/imgs/providers/bunny.svg new file mode 100644 index 00000000..edbbab32 --- /dev/null +++ b/ui/public/imgs/providers/bunny.svg @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ui/src/components/access/AccessForm.tsx b/ui/src/components/access/AccessForm.tsx index d5906434..0f28ccbe 100644 --- a/ui/src/components/access/AccessForm.tsx +++ b/ui/src/components/access/AccessForm.tsx @@ -17,6 +17,7 @@ import AccessFormAzureConfig from "./AccessFormAzureConfig"; import AccessFormBaiduCloudConfig from "./AccessFormBaiduCloudConfig"; import AccessFormBaishanConfig from "./AccessFormBaishanConfig"; import AccessFormBaotaPanelConfig from "./AccessFormBaotaPanelConfig"; +import AccessFormBunnyConfig from "./AccessFormBunnyConfig"; import AccessFormBytePlusConfig from "./AccessFormBytePlusConfig"; import AccessFormCacheFlyConfig from "./AccessFormCacheFlyConfig"; import AccessFormCdnflyConfig from "./AccessFormCdnflyConfig"; @@ -161,6 +162,8 @@ const AccessForm = forwardRef(({ className, return ; case ACCESS_PROVIDERS.BAOTAPANEL: return ; + case ACCESS_PROVIDERS.BUNNY: + return ; case ACCESS_PROVIDERS.BYTEPLUS: return ; case ACCESS_PROVIDERS.CACHEFLY: diff --git a/ui/src/components/access/AccessFormBunnyConfig.tsx b/ui/src/components/access/AccessFormBunnyConfig.tsx new file mode 100644 index 00000000..0906d3d0 --- /dev/null +++ b/ui/src/components/access/AccessFormBunnyConfig.tsx @@ -0,0 +1,62 @@ +import { useTranslation } from "react-i18next"; +import { Form, type FormInstance, Input } from "antd"; +import { createSchemaFieldRule } from "antd-zod"; +import { z } from "zod"; + +import { type AccessConfigForBunny } from "@/domain/access"; + +type AccessFormBunnyConfigFieldValues = Nullish; + +export type AccessFormBunnyConfigProps = { + form: FormInstance; + formName: string; + disabled?: boolean; + initialValues?: AccessFormBunnyConfigFieldValues; + onValuesChange?: (values: AccessFormBunnyConfigFieldValues) => void; +}; + +const initFormModel = (): AccessFormBunnyConfigFieldValues => { + return { + apiKey: "", + }; +}; + +const AccessFormBunnyConfig = ({ form: formInst, formName, disabled, initialValues, onValuesChange }: AccessFormBunnyConfigProps) => { + const { t } = useTranslation(); + + const formSchema = z.object({ + apiKey: z + .string() + .nonempty(t("access.form.bunny_api_key.placeholder")) + .trim(), + }); + const formRule = createSchemaFieldRule(formSchema); + + const handleFormChange = (_: unknown, values: z.infer) => { + onValuesChange?.(values); + }; + + return ( +
+ + } + > + + + +
+ ); +}; + +export default AccessFormBunnyConfig; diff --git a/ui/src/components/workflow/node/DeployNodeConfigForm.tsx b/ui/src/components/workflow/node/DeployNodeConfigForm.tsx index 33d1012c..c89cfa42 100644 --- a/ui/src/components/workflow/node/DeployNodeConfigForm.tsx +++ b/ui/src/components/workflow/node/DeployNodeConfigForm.tsx @@ -39,6 +39,7 @@ import DeployNodeConfigFormBaiduCloudCDNConfig from "./DeployNodeConfigFormBaidu import DeployNodeConfigFormBaishanCDNConfig from "./DeployNodeConfigFormBaishanCDNConfig"; import DeployNodeConfigFormBaotaPanelConsoleConfig from "./DeployNodeConfigFormBaotaPanelConsoleConfig"; import DeployNodeConfigFormBaotaPanelSiteConfig from "./DeployNodeConfigFormBaotaPanelSiteConfig"; +import DeployNodeConfigFormBunnyCDNConfig from "./DeployNodeConfigFormBunnyCDNConfig.tsx"; import DeployNodeConfigFormBytePlusCDNConfig from "./DeployNodeConfigFormBytePlusCDNConfig"; import DeployNodeConfigFormCdnflyConfig from "./DeployNodeConfigFormCdnflyConfig"; import DeployNodeConfigFormDogeCloudCDNConfig from "./DeployNodeConfigFormDogeCloudCDNConfig"; @@ -217,6 +218,8 @@ const DeployNodeConfigForm = forwardRef; case DEPLOY_PROVIDERS.BAOTAPANEL_SITE: return ; + case DEPLOY_PROVIDERS.BUNNY_CDN: + return ; case DEPLOY_PROVIDERS.BYTEPLUS_CDN: return ; case DEPLOY_PROVIDERS.CDNFLY: diff --git a/ui/src/components/workflow/node/DeployNodeConfigFormBunnyCDNConfig.tsx b/ui/src/components/workflow/node/DeployNodeConfigFormBunnyCDNConfig.tsx new file mode 100644 index 00000000..3b68f811 --- /dev/null +++ b/ui/src/components/workflow/node/DeployNodeConfigFormBunnyCDNConfig.tsx @@ -0,0 +1,76 @@ +import { useTranslation } from "react-i18next"; +import { Form, type FormInstance, Input } from "antd"; +import { createSchemaFieldRule } from "antd-zod"; +import { z } from "zod"; +import { validDomainName } from "@/utils/validators"; + +type DeployNodeConfigFormBunnyCDNConfigFieldValues = Nullish<{ + pullZoneId: string | number; + hostName: string; +}>; + +export type DeployNodeConfigFormBunnyCDNConfigProps = { + form: FormInstance; + formName: string; + disabled?: boolean; + initialValues?: DeployNodeConfigFormBunnyCDNConfigFieldValues; + onValuesChange?: (values: DeployNodeConfigFormBunnyCDNConfigFieldValues) => void; +}; + +const initFormModel = (): DeployNodeConfigFormBunnyCDNConfigFieldValues => { + return {}; +}; + +const DeployNodeConfigFormBunnyCDNConfig = ({ form: formInst, formName, disabled, initialValues, onValuesChange }: DeployNodeConfigFormBunnyCDNConfigProps) => { + const { t } = useTranslation(); + + const formSchema = z.object({ + pullZoneId: z + .union([z.string(), z.number().int()]) + .refine((v) => { + return /^\d+$/.test(v + "") && +v! > 0; + }, t("workflow_node.deploy.form.bunny_cdn_pull_zone_id.placeholder")), + hostName: z + .string({ message: t("workflow_node.deploy.form.bunny_cdn_host_name.placeholder") }) + .nonempty(t("workflow_node.deploy.form.bunny_cdn_host_name.placeholder")) + .refine((v) => { + return !v || validDomainName(v!, { allowWildcard: true }); + }, t("common.errmsg.domain_invalid")), + }); + const formRule = createSchemaFieldRule(formSchema); + + const handleFormChange = (_: unknown, values: z.infer) => { + onValuesChange?.(values); + }; + + return ( +
+ } + > + + + + } + > + + +
+ ); +}; + +export default DeployNodeConfigFormBunnyCDNConfig; diff --git a/ui/src/domain/access.ts b/ui/src/domain/access.ts index 86d644fa..c0ebd971 100644 --- a/ui/src/domain/access.ts +++ b/ui/src/domain/access.ts @@ -14,6 +14,7 @@ export interface AccessModel extends BaseModel { | AccessConfigForBaiduCloud | AccessConfigForBaishan | AccessConfigForBaotaPanel + | AccessConfigForBunny | AccessConfigForBytePlus | AccessConfigForCacheFly | AccessConfigForCdnfly @@ -99,6 +100,10 @@ export type AccessConfigForBaotaPanel = { allowInsecureConnections?: boolean; }; +export type AccessConfigForBunny = { + apiKey: string; +}; + export type AccessConfigForBytePlus = { accessKey: string; secretKey: string; diff --git a/ui/src/domain/provider.ts b/ui/src/domain/provider.ts index 74296917..8d5493f7 100644 --- a/ui/src/domain/provider.ts +++ b/ui/src/domain/provider.ts @@ -12,6 +12,7 @@ export const ACCESS_PROVIDERS = Object.freeze({ BAIDUCLOUD: "baiducloud", BAISHAN: "baishan", BAOTAPANEL: "baotapanel", + BUNNY: "bunny", BYTEPLUS: "byteplus", BUYPASS: "buypass", CACHEFLY: "cachefly", @@ -93,6 +94,7 @@ export const accessProvidersMap: Maphttps://intl.cloud.baidu.com/doc/Reference/s/jjwvz2e3p-en", + "access.form.bunny_api_key.label": "Bunny API Key", + "access.form.bunny_api_key.placeholder": "Please enter Bunny API key", + "access.form.bunny_api_key.tooltip": "For more information, see https://docs.bunny.net/reference/bunnynet-api-overview", "access.form.upyun_username.label": "UPYUN subaccount username", "access.form.upyun_username.placeholder": "Please enter UPYUN subaccount username", "access.form.upyun_username.tooltip": "For more information, see https://console.upyun.com/account/subaccount/", diff --git a/ui/src/i18n/locales/en/nls.provider.json b/ui/src/i18n/locales/en/nls.provider.json index a7b5c292..160284ad 100644 --- a/ui/src/i18n/locales/en/nls.provider.json +++ b/ui/src/i18n/locales/en/nls.provider.json @@ -38,6 +38,8 @@ "provider.baotapanel": "aaPanel (aka BaoTaPanel)", "provider.baotapanel.console": "aaPanel (aka BaoTaPanel) - Console", "provider.baotapanel.site": "aaPanel (aka BaoTaPanel) - Website", + "provider.bunny": "Bunny", + "provider.bunny.cdn": "Bunny - CDN (Content Delivery Network)", "provider.byteplus": "BytePlus", "provider.byteplus.cdn": "BytePlus - CDN (Content Delivery Network)", "provider.buypass": "Buypass AS", diff --git a/ui/src/i18n/locales/en/nls.workflow.nodes.json b/ui/src/i18n/locales/en/nls.workflow.nodes.json index af3a6796..17f0e442 100644 --- a/ui/src/i18n/locales/en/nls.workflow.nodes.json +++ b/ui/src/i18n/locales/en/nls.workflow.nodes.json @@ -289,6 +289,12 @@ "workflow_node.deploy.form.baotapanel_site_names.tooltip": "Usually equal to the websites domain name.", "workflow_node.deploy.form.baotapanel_site_names.multiple_input_modal.title": "Change aaPanel site names", "workflow_node.deploy.form.baotapanel_site_names.multiple_input_modal.placeholder": "Please enter aaPanel site name", + "workflow_node.deploy.form.bunny_cdn_pull_zone_id.label": "Bunny CDN pull zone ID", + "workflow_node.deploy.form.bunny_cdn_pull_zone_id.placeholder": "Please enter Bunny CDN pull zone ID", + "workflow_node.deploy.form.bunny_cdn_pull_zone_id.tooltip": "What is this? See https://dash.bunny.net/cdn", + "workflow_node.deploy.form.bunny_cdn_host_name.label": "Bunny CDN hostname", + "workflow_node.deploy.form.bunny_cdn_host_name.placeholder": "Please enter Bunny CDN hostname", + "workflow_node.deploy.form.bunny_cdn_host_name.tooltip": "What is this? See https://dash.bunny.net/cdn", "workflow_node.deploy.form.byteplus_cdn_domain.label": "BytePlus CDN domain", "workflow_node.deploy.form.byteplus_cdn_domain.placeholder": "Please enter BytePlus CDN domain name", "workflow_node.deploy.form.byteplus_cdn_domain.tooltip": "For more information, see https://console.byteplus.com/cdn", diff --git a/ui/src/i18n/locales/zh/nls.access.json b/ui/src/i18n/locales/zh/nls.access.json index 657c2d68..fb3cd479 100644 --- a/ui/src/i18n/locales/zh/nls.access.json +++ b/ui/src/i18n/locales/zh/nls.access.json @@ -96,6 +96,9 @@ "access.form.baotapanel_allow_insecure_conns.tooltip": "忽略 SSL/TLS 证书错误可能导致数据泄露或被篡改。建议仅在可信网络下启用。", "access.form.baotapanel_allow_insecure_conns.switch.on": "允许", "access.form.baotapanel_allow_insecure_conns.switch.off": "不允许", + "access.form.bunny_api_key.label": "Bunny API Key", + "access.form.bunny_api_key.placeholder": "请输入 Bunny API Key", + "access.form.bunny_api_key.tooltip": "这是什么?请参阅 https://docs.bunny.net/reference/bunnynet-api-overview", "access.form.byteplus_access_key.label": "BytePlus AccessKey", "access.form.byteplus_access_key.placeholder": "请输入 BytePlus AccessKey", "access.form.byteplus_access_key.tooltip": "这是什么?请参阅 https://docs.byteplus.com/zh-CN/docs/byteplus-platform/docs-managing-keys", diff --git a/ui/src/i18n/locales/zh/nls.provider.json b/ui/src/i18n/locales/zh/nls.provider.json index 3d7c1e58..57148fc6 100644 --- a/ui/src/i18n/locales/zh/nls.provider.json +++ b/ui/src/i18n/locales/zh/nls.provider.json @@ -38,6 +38,8 @@ "provider.baotapanel": "宝塔面板", "provider.baotapanel.console": "宝塔面板 - 面板", "provider.baotapanel.site": "宝塔面板 - 网站", + "provider.bunny": "Bunny", + "provider.bunny.cdn": "Bunny - 内容分发网络 CDN", "provider.byteplus": "BytePlus", "provider.byteplus.cdn": "BytePlus - 内容分发网络 CDN", "provider.buypass": "Buypass AS", diff --git a/ui/src/i18n/locales/zh/nls.workflow.nodes.json b/ui/src/i18n/locales/zh/nls.workflow.nodes.json index 7338912f..54986ed5 100644 --- a/ui/src/i18n/locales/zh/nls.workflow.nodes.json +++ b/ui/src/i18n/locales/zh/nls.workflow.nodes.json @@ -288,6 +288,12 @@ "workflow_node.deploy.form.baotapanel_site_names.tooltip": "通常为网站域名。", "workflow_node.deploy.form.baotapanel_site_names.multiple_input_modal.title": "修改宝塔面板网站名称", "workflow_node.deploy.form.baotapanel_site_names.multiple_input_modal.placeholder": "请输入宝塔面板网站名称", + "workflow_node.deploy.form.bunny_cdn_pull_zone_id.label": "Bunny CDN 拉取区域 ID", + "workflow_node.deploy.form.bunny_cdn_pull_zone_id.placeholder": "请输入 Bunny CDN 拉取区域 ID", + "workflow_node.deploy.form.bunny_cdn_pull_zone_id.tooltip": "这是什么?请参阅 https://dash.bunny.net/cdn", + "workflow_node.deploy.form.bunny_cdn_host_name.label": "Bunny CDN 主机名", + "workflow_node.deploy.form.bunny_cdn_host_name.placeholder": "请输入 Bunny CDN 主机名", + "workflow_node.deploy.form.bunny_cdn_host_name.tooltip": "这是什么?请参阅 https://dash.bunny.net/cdn", "workflow_node.deploy.form.byteplus_cdn_domain.label": "BytePlus CDN 域名", "workflow_node.deploy.form.byteplus_cdn_domain.placeholder": "请输入 BytePlus CDN 域名(支持泛域名)", "workflow_node.deploy.form.byteplus_cdn_domain.tooltip": "这是什么?请参阅 https://console.byteplus.com/cdn",