fix: cloudflare ssl deploy

This commit is contained in:
Yoan.Liu
2026-10-08 09:35:00 +08:00
parent 8b15111df2
commit d02040c689
5 changed files with 58 additions and 15 deletions
@@ -1,7 +1,6 @@
package cloudflaressl
import (
"cmp"
"context"
"fmt"
"log/slog"
@@ -69,6 +68,11 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep
return nil, fmt.Errorf("config `zoneId` is required")
}
deploy, err := deployRequestField(d.config.Environment)
if err != nil {
return nil, err
}
if d.config.CertificateId == "" {
// 新建自定义证书
// REF: https://developers.cf.com/api/resources/custom_certificates/methods/create
@@ -77,7 +81,7 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep
Certificate: lo.ToPtr(certPEM),
PrivateKey: lo.ToPtr(privkeyPEM),
BundleMethod: lo.ToPtr("ubiquitous"),
Deploy: lo.ToPtr(cmp.Or(d.config.Environment, "production")),
Deploy: deploy,
}
customCertificateCreateResp, err := d.sdkClient.CustomCertificateCreateWithContext(ctx, customCertificateCreateReq)
d.logger.Debug("sdk request 'CustomCertificates.Create'", slog.Any("request", customCertificateCreateReq), slog.Any("response", customCertificateCreateResp))
@@ -93,7 +97,7 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep
Certificate: lo.ToPtr(certPEM),
PrivateKey: lo.ToPtr(privkeyPEM),
BundleMethod: lo.ToPtr("ubiquitous"),
Deploy: lo.ToPtr(cmp.Or(d.config.Environment, "production")),
Deploy: deploy,
}
customCertificateEditResp, err := d.sdkClient.CustomCertificateEditWithContext(ctx, customCertificateEditReq)
d.logger.Debug("sdk request 'CustomCertificates.Edit'", slog.Any("request", customCertificateEditReq), slog.Any("response", customCertificateEditResp))
@@ -0,0 +1,20 @@
package cloudflaressl
import (
"fmt"
"strings"
"github.com/samber/lo"
)
func deployRequestField(environment string) (*string, error) {
env := strings.ToLower(strings.TrimSpace(environment))
switch env {
case "", "production":
return nil, nil
case "staging":
return lo.ToPtr("staging"), nil
default:
return nil, fmt.Errorf("config `environment` must be empty, \"production\", or \"staging\", got %q", environment)
}
}
@@ -1,10 +1,12 @@
import { getI18n, useTranslation } from "react-i18next";
import { AutoComplete, Form, Input } from "antd";
import { Form, Input, Select } from "antd";
import { createSchemaFieldRule } from "antd-zod";
import { z } from "zod";
import { useFormNestedFieldsContext } from "./_context";
const CLOUDFLARE_SSL_ENVIRONMENT_STAGING = "staging";
const BizDeployNodeConfigFieldsProviderCloudflareSSL = () => {
const { i18n, t } = useTranslation();
@@ -21,12 +23,19 @@ const BizDeployNodeConfigFieldsProviderCloudflareSSL = () => {
name={[parentNamePath, "environment"]}
initialValue={initialValues.environment}
label={t("workflow_node.deploy.form.cloudflare_ssl_environment.label")}
extra={t("workflow_node.deploy.form.cloudflare_ssl_environment.help")}
rules={[formRule]}
tooltip={<span dangerouslySetInnerHTML={{ __html: t("workflow_node.deploy.form.cloudflare_ssl_environment.tooltip") }}></span>}
normalize={(value) => (value === "production" ? undefined : value)}
>
<AutoComplete
<Select
allowClear
options={["production", "staging"].map((s) => ({ value: s }))}
options={[
{
value: CLOUDFLARE_SSL_ENVIRONMENT_STAGING,
label: t("workflow_node.deploy.form.cloudflare_ssl_environment.option_staging"),
},
]}
placeholder={t("workflow_node.deploy.form.cloudflare_ssl_environment.placeholder")}
/>
</Form.Item>
@@ -57,16 +66,20 @@ const BizDeployNodeConfigFieldsProviderCloudflareSSL = () => {
const getInitialValues = (): Nullish<z.infer<ReturnType<typeof getSchema>>> => {
return {
environment: "production",
zoneId: "",
};
};
const getSchema = ({ i18n = getI18n() }: { i18n?: ReturnType<typeof getI18n> }) => {
const { t: _ } = i18n;
const { t } = i18n;
return z.object({
environment: z.string().nullish(),
environment: z
.string()
.nullish()
.refine((value) => !value || value === CLOUDFLARE_SSL_ENVIRONMENT_STAGING || value === "production", {
message: t("workflow_node.deploy.form.cloudflare_ssl_environment.errmsg_invalid"),
}),
zoneId: z.string().nonempty(),
certificateId: z.string().nullish(),
});
@@ -1432,9 +1432,12 @@
"tooltip": "You can find it on Cdnfly dashboard."
},
"cloudflare_ssl_environment": {
"label": "Cloudflare environment",
"placeholder": "Please enter Cloudflare environment",
"tooltip": "For more information, see <a href=\"https://developers.cloudflare.com/ssl/edge-certificates/staging-environment/\" target=\"_blank\">https://developers.cloudflare.com/ssl/edge-certificates/staging-environment/</a>"
"label": "Staging deploy (optional)",
"placeholder": "Leave empty for production (recommended)",
"help": "Leave empty for normal custom certificate upload to the production edge. Choose staging only if your Enterprise account uses the Staging Certificates beta.",
"option_staging": "staging (Enterprise Staging test)",
"errmsg_invalid": "Only empty or staging is allowed",
"tooltip": "Cloudflare API <code>deploy</code> field: when empty, production deployment is used and the field is omitted from the request. Staging is Enterprise-only. See <a href=\"https://developers.cloudflare.com/ssl/edge-certificates/staging-environment/\" target=\"_blank\">Staging environment</a> and <a href=\"https://developers.cloudflare.com/api/resources/custom_certificates/methods/create/\" target=\"_blank\">Create custom certificate</a>."
},
"cloudflare_ssl_zone_id": {
"label": "Cloudflare DNS zone ID",
@@ -1431,9 +1431,12 @@
"tooltip": "请登录 Cdnfly 控制台查看"
},
"cloudflare_ssl_environment": {
"label": "Cloudflare 环境",
"placeholder": "请输入 Cloudflare 环境",
"tooltip": "这是什么?请参阅 <a href=\"https://developers.cloudflare.com/ssl/edge-certificates/staging-environment/\" target=\"_blank\">https://developers.cloudflare.com/ssl/edge-certificates/staging-environment/</a>"
"label": "Staging 部署(可选)",
"placeholder": "留空即生产部署(推荐)",
"help": "常规上传自定义证书到生产边缘时无需填写。仅 Enterprise 账户在 Staging 环境测试证书时选择 staging。",
"option_staging": "staging(Enterprise Staging 测试)",
"errmsg_invalid": "仅支持留空或 staging",
"tooltip": "Cloudflare API 的 <code>deploy</code> 参数:留空时默认生产部署且不会显式传递该字段。Staging 仅面向 Enterprise 开放,请参阅 <a href=\"https://developers.cloudflare.com/ssl/edge-certificates/staging-environment/\" target=\"_blank\">Staging 环境</a> 与 <a href=\"https://developers.cloudflare.com/api/resources/custom_certificates/methods/create/\" target=\"_blank\">Create custom certificate</a>。"
},
"cloudflare_ssl_zone_id": {
"label": "Cloudflare DNS 区域 ID",