mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-07 21:19:51 +00:00
feat: config goedge api user role
This commit is contained in:
parent
a3a56f3346
commit
1ee3b64a19
@ -581,6 +581,7 @@ func createDeployerProvider(options *deployerProviderOptions) (deployer.Deployer
|
||||
|
||||
deployer, err := pGoEdge.NewDeployer(&pGoEdge.DeployerConfig{
|
||||
ApiUrl: access.ApiUrl,
|
||||
ApiRole: access.ApiRole,
|
||||
AccessKeyId: access.AccessKeyId,
|
||||
AccessKey: access.AccessKey,
|
||||
AllowInsecureConnections: access.AllowInsecureConnections,
|
||||
|
@ -149,6 +149,7 @@ type AccessConfigForGoDaddy struct {
|
||||
|
||||
type AccessConfigForGoEdge struct {
|
||||
ApiUrl string `json:"apiUrl"`
|
||||
ApiRole string `json:"apiRole"`
|
||||
AccessKeyId string `json:"accessKeyId"`
|
||||
AccessKey string `json:"accessKey"`
|
||||
AllowInsecureConnections bool `json:"allowInsecureConnections,omitempty"`
|
||||
|
@ -18,9 +18,11 @@ import (
|
||||
type DeployerConfig struct {
|
||||
// GoEdge URL。
|
||||
ApiUrl string `json:"apiUrl"`
|
||||
// GoEdge 用户 AccessKeyId。
|
||||
// GoEdge 用户角色。
|
||||
ApiRole string `json:"apiRole"`
|
||||
// GoEdge AccessKeyId。
|
||||
AccessKeyId string `json:"accessKeyId"`
|
||||
// GoEdge 用户 AccessKey。
|
||||
// GoEdge AccessKey。
|
||||
AccessKey string `json:"accessKey"`
|
||||
// 是否允许不安全的连接。
|
||||
AllowInsecureConnections bool `json:"allowInsecureConnections,omitempty"`
|
||||
@ -44,7 +46,7 @@ func NewDeployer(config *DeployerConfig) (*DeployerProvider, error) {
|
||||
panic("config is nil")
|
||||
}
|
||||
|
||||
client, err := createSdkClient(config.ApiUrl, config.AccessKeyId, config.AccessKey, config.AllowInsecureConnections)
|
||||
client, err := createSdkClient(config.ApiUrl, config.ApiRole, config.AccessKeyId, config.AccessKey, config.AllowInsecureConnections)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create sdk client: %w", err)
|
||||
}
|
||||
@ -116,11 +118,15 @@ func (d *DeployerProvider) deployToCertificate(ctx context.Context, certPEM stri
|
||||
return nil
|
||||
}
|
||||
|
||||
func createSdkClient(apiUrl, accessKeyId, accessKey string, skipTlsVerify bool) (*goedgesdk.Client, error) {
|
||||
func createSdkClient(apiUrl, apiRole, accessKeyId, accessKey string, skipTlsVerify bool) (*goedgesdk.Client, error) {
|
||||
if _, err := url.Parse(apiUrl); err != nil {
|
||||
return nil, errors.New("invalid goedge api url")
|
||||
}
|
||||
|
||||
if apiRole != "user" && apiRole != "admin" {
|
||||
return nil, errors.New("invalid goedge api role")
|
||||
}
|
||||
|
||||
if accessKeyId == "" {
|
||||
return nil, errors.New("invalid goedge access key id")
|
||||
}
|
||||
@ -129,7 +135,7 @@ func createSdkClient(apiUrl, accessKeyId, accessKey string, skipTlsVerify bool)
|
||||
return nil, errors.New("invalid goedge access key")
|
||||
}
|
||||
|
||||
client := goedgesdk.NewClient(apiUrl, "user", accessKeyId, accessKey)
|
||||
client := goedgesdk.NewClient(apiUrl, apiRole, accessKeyId, accessKey)
|
||||
if skipTlsVerify {
|
||||
client.WithTLSConfig(&tls.Config{InsecureSkipVerify: true})
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
|
||||
func (c *Client) getAccessToken() error {
|
||||
req := &getAPIAccessTokenRequest{
|
||||
Type: c.apiUserType,
|
||||
Type: c.apiRole,
|
||||
AccessKeyId: c.accessKeyId,
|
||||
AccessKey: c.accessKey,
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
|
||||
type Client struct {
|
||||
apiHost string
|
||||
apiUserType string
|
||||
apiRole string
|
||||
accessKeyId string
|
||||
accessKey string
|
||||
|
||||
@ -25,12 +25,12 @@ type Client struct {
|
||||
client *resty.Client
|
||||
}
|
||||
|
||||
func NewClient(apiHost, apiUserType, accessKeyId, accessKey string) *Client {
|
||||
func NewClient(apiHost, apiRole, accessKeyId, accessKey string) *Client {
|
||||
client := resty.New()
|
||||
|
||||
return &Client{
|
||||
apiHost: strings.TrimRight(apiHost, "/"),
|
||||
apiUserType: apiUserType,
|
||||
apiRole: apiRole,
|
||||
accessKeyId: accessKeyId,
|
||||
accessKey: accessKey,
|
||||
client: client,
|
||||
|
44
migrations/1747314000_upgrade.go
Normal file
44
migrations/1747314000_upgrade.go
Normal file
@ -0,0 +1,44 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
// migrate data
|
||||
{
|
||||
accesses, err := app.FindAllRecords("access")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, access := range accesses {
|
||||
changed := false
|
||||
|
||||
if access.GetString("provider") == "goedge" {
|
||||
config := make(map[string]any)
|
||||
if err := access.UnmarshalJSONField("config", &config); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
config["apiRole"] = "user"
|
||||
access.Set("config", config)
|
||||
changed = true
|
||||
}
|
||||
|
||||
if changed {
|
||||
err = app.Save(access)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}, func(app core.App) error {
|
||||
return nil
|
||||
})
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Form, type FormInstance, Input, Switch } from "antd";
|
||||
import { Form, type FormInstance, Input, Radio, Switch } from "antd";
|
||||
import { createSchemaFieldRule } from "antd-zod";
|
||||
import { z } from "zod";
|
||||
|
||||
@ -18,6 +18,7 @@ export type AccessFormGoEdgeConfigProps = {
|
||||
const initFormModel = (): AccessFormGoEdgeConfigFieldValues => {
|
||||
return {
|
||||
apiUrl: "http://<your-host-addr>:7788/",
|
||||
apiRole: "user",
|
||||
accessKeyId: "",
|
||||
accessKey: "",
|
||||
};
|
||||
@ -28,6 +29,9 @@ const AccessFormGoEdgeConfig = ({ form: formInst, formName, disabled, initialVal
|
||||
|
||||
const formSchema = z.object({
|
||||
apiUrl: z.string().url(t("common.errmsg.url_invalid")),
|
||||
role: z.union([z.literal("user"), z.literal("admin")], {
|
||||
message: t("access.form.goedge_api_role.placeholder"),
|
||||
}),
|
||||
accessKeyId: z
|
||||
.string()
|
||||
.min(1, t("access.form.goedge_access_key_id.placeholder"))
|
||||
@ -59,6 +63,10 @@ const AccessFormGoEdgeConfig = ({ form: formInst, formName, disabled, initialVal
|
||||
<Input placeholder={t("access.form.goedge_api_url.placeholder")} />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item name="apiRole" label={t("access.form.goedge_api_role.label")} rules={[formRule]}>
|
||||
<Radio.Group options={["user", "admin"].map((s) => ({ label: t(`access.form.goedge_api_role.option.${s}.label`), value: s }))} />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="accessKeyId"
|
||||
label={t("access.form.goedge_access_key_id.label")}
|
||||
|
@ -199,6 +199,7 @@ export type AccessConfigForGoDaddy = {
|
||||
|
||||
export type AccessConfigForGoEdge = {
|
||||
apiUrl: string;
|
||||
apiRole: string;
|
||||
accessKeyId: string;
|
||||
accessKey: string;
|
||||
allowInsecureConnections?: boolean;
|
||||
|
@ -201,11 +201,15 @@
|
||||
"access.form.godaddy_api_secret.tooltip": "For more information, see <a href=\"https://developer.godaddy.com/\" target=\"_blank\">https://developer.godaddy.com/</a>",
|
||||
"access.form.goedge_api_url.label": "GoEdge API URL",
|
||||
"access.form.goedge_api_url.placeholder": "Please enter GoEdge API URL",
|
||||
"access.form.goedge_access_key_id.label": "GoEdge user AccessKeyId",
|
||||
"access.form.goedge_access_key_id.placeholder": "Please enter GoEdge user AccessKeyId",
|
||||
"access.form.goedge_api_role.label": "GoEdge user role",
|
||||
"access.form.goedge_api_role.placeholder": "Please select GoEdge user role",
|
||||
"access.form.goedge_api_role.option.user.label": "Platform user",
|
||||
"access.form.goedge_api_role.option.admin.label": "Administrator user",
|
||||
"access.form.goedge_access_key_id.label": "GoEdge AccessKeyId",
|
||||
"access.form.goedge_access_key_id.placeholder": "Please enter GoEdge AccessKeyId",
|
||||
"access.form.goedge_access_key_id.tooltip": "For more information, see <a href=\"https://goedge.cloud/docs/API/Auth.md\" target=\"_blank\">https://goedge.cloud/docs/API/Auth.md</a>",
|
||||
"access.form.goedge_access_key.label": "GoEdge user AccessKey",
|
||||
"access.form.goedge_access_key.placeholder": "Please enter GoEdge user AccessKey",
|
||||
"access.form.goedge_access_key.label": "GoEdge AccessKey",
|
||||
"access.form.goedge_access_key.placeholder": "Please enter GoEdge AccessKey",
|
||||
"access.form.goedge_access_key.tooltip": "For more information, see <a href=\"https://goedge.cloud/docs/API/Auth.md\" target=\"_blank\">https://goedge.cloud/docs/API/Auth.md</a>",
|
||||
"access.form.goedge_allow_insecure_conns.label": "Insecure SSL/TLS connections",
|
||||
"access.form.goedge_allow_insecure_conns.switch.on": "Allow",
|
||||
|
@ -195,11 +195,15 @@
|
||||
"access.form.godaddy_api_secret.tooltip": "这是什么?请参阅 <a href=\"https://developer.godaddy.com/\" target=\"_blank\">https://developer.godaddy.com/</a>",
|
||||
"access.form.goedge_api_url.label": "GoEdge API URL",
|
||||
"access.form.goedge_api_url.placeholder": "请输入 GoEdge API URL",
|
||||
"access.form.goedge_access_key_id.label": "GoEdge 用户 AccessKeyId",
|
||||
"access.form.goedge_access_key_id.placeholder": "请输入 GoEdge 用户 AccessKeyId",
|
||||
"access.form.goedge_api_role.label": "GoEdge 用户角色",
|
||||
"access.form.goedge_api_role.placeholder": "请选择 GoEdge 用户角色",
|
||||
"access.form.goedge_api_role.option.user.label": "平台用户",
|
||||
"access.form.goedge_api_role.option.admin.label": "系统管理员",
|
||||
"access.form.goedge_access_key_id.label": "GoEdge AccessKeyId",
|
||||
"access.form.goedge_access_key_id.placeholder": "请输入 GoEdge AccessKeyId",
|
||||
"access.form.goedge_access_key_id.tooltip": "这是什么?请参阅 <a href=\"https://goedge.cloud/docs/API/Auth.md\" target=\"_blank\">https://goedge.cloud/docs/API/Auth.md</a>",
|
||||
"access.form.goedge_access_key.label": "GoEdge 用户 AccessKey",
|
||||
"access.form.goedge_access_key.placeholder": "请输入 GoEdge 用户 AccessKey",
|
||||
"access.form.goedge_access_key.label": "GoEdge AccessKey",
|
||||
"access.form.goedge_access_key.placeholder": "请输入 GoEdge AccessKey",
|
||||
"access.form.goedge_access_key.tooltip": "这是什么?请参阅 <a href=\"https://goedge.cloud/docs/API/Auth.md\" target=\"_blank\">https://goedge.cloud/docs/API/Auth.md</a>",
|
||||
"access.form.goedge_allow_insecure_conns.label": "忽略 SSL/TLS 证书错误",
|
||||
"access.form.goedge_allow_insecure_conns.switch.on": "允许",
|
||||
|
Loading…
x
Reference in New Issue
Block a user