diff --git a/.github/workflows/push_image.yml b/.github/workflows/push_image.yml index e0c063d98..c50378a37 100644 --- a/.github/workflows/push_image.yml +++ b/.github/workflows/push_image.yml @@ -30,7 +30,6 @@ jobs: - name: Build UI run: | - echo "VITE_APP_VERSION=${GITHUB_REF#refs/tags/}" > ./ui/.env npm --prefix=./ui ci npm --prefix=./ui run build @@ -85,10 +84,6 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - # - name: Inject tag version of UI - # run: | - # echo "VITE_APP_VERSION=${GITHUB_REF#refs/tags/}" > ./ui/.env - - name: Download UI build artifacts uses: actions/download-artifact@v6 with: diff --git a/.github/workflows/push_image_next.yml b/.github/workflows/push_image_next.yml index 617f52731..14f0d587e 100644 --- a/.github/workflows/push_image_next.yml +++ b/.github/workflows/push_image_next.yml @@ -29,7 +29,6 @@ jobs: - name: Build UI run: | - echo "VITE_APP_VERSION=${GITHUB_REF#refs/tags/}" > ./ui/.env npm --prefix=./ui ci npm --prefix=./ui run build @@ -84,10 +83,6 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - # - name: Inject tag version of UI - # run: | - # echo "VITE_APP_VERSION=${GITHUB_REF#refs/tags/}" > ./ui/.env - - name: Download UI build artifacts uses: actions/download-artifact@v6 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a02c985c2..251ac8e17 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,7 +21,6 @@ jobs: - name: Build UI run: | - echo "VITE_APP_VERSION=${GITHUB_REF#refs/tags/}" > ./ui/.env npm --prefix=./ui ci npm --prefix=./ui run build diff --git a/cmd/intercmd.go b/cmd/intercmd.go index 8ee28b7a6..7ed406783 100644 --- a/cmd/intercmd.go +++ b/cmd/intercmd.go @@ -12,6 +12,7 @@ import ( "github.com/pocketbase/pocketbase/core" "github.com/spf13/cobra" + "github.com/certimate-go/certimate/internal/app" "github.com/certimate-go/certimate/internal/certacme" "github.com/certimate-go/certimate/internal/tools/mproc" ) @@ -27,7 +28,7 @@ func NewInternalCommand(app core.App) *cobra.Command { return command } -func internalCertApplyCommand(app core.App) *cobra.Command { +func internalCertApplyCommand(_ core.App) *cobra.Command { var flagInput string var flagOutput string var flagError string @@ -61,7 +62,7 @@ func internalCertApplyCommand(app core.App) *cobra.Command { legolog.Logger = log.New(os.Stdout, "", 0) client, err := certacme.NewACMEClientWithAccount(params.Account, func(c *lego.Config) error { - c.UserAgent = "certimate" + c.UserAgent = app.AppUserAgent c.Certificate.KeyType = params.Request.PrivateKeyType c.Certificate.DisableCommonName = params.Request.NoCommonName return nil diff --git a/cmd/winsc_windows.go b/cmd/winsc_windows.go index 0463c68dd..4b790d3f6 100644 --- a/cmd/winsc_windows.go +++ b/cmd/winsc_windows.go @@ -14,6 +14,8 @@ import ( "golang.org/x/sys/windows/svc" "golang.org/x/sys/windows/svc/eventlog" "golang.org/x/sys/windows/svc/mgr" + + "github.com/certimate-go/certimate/internal/app" ) const winscName = "certimate" @@ -32,7 +34,7 @@ func NewWinscCommand(app core.App) *cobra.Command { return command } -func winscInstallCommand(app core.App) *cobra.Command { +func winscInstallCommand(_ core.App) *cobra.Command { command := &cobra.Command{ Use: "install [args...]", Example: "winsc install", @@ -53,7 +55,7 @@ func winscInstallCommand(app core.App) *cobra.Command { defer manager.Disconnect() config := mgr.Config{ - DisplayName: "Certimate", + DisplayName: app.AppName, Description: "https://github.com/certimate-go/certimate", StartType: mgr.StartAutomatic, } @@ -79,7 +81,7 @@ func winscInstallCommand(app core.App) *cobra.Command { return command } -func winscUninstallCommand(app core.App) *cobra.Command { +func winscUninstallCommand(_ core.App) *cobra.Command { command := &cobra.Command{ Use: "uninstall", Example: "winsc uninstall", @@ -122,7 +124,7 @@ func winscUninstallCommand(app core.App) *cobra.Command { return command } -func winscStartCommand(app core.App) *cobra.Command { +func winscStartCommand(_ core.App) *cobra.Command { command := &cobra.Command{ Use: "start", Example: "winsc start", diff --git a/internal/app/app.go b/internal/app/app.go index b1b44cf70..555a3f487 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -1,57 +1,7 @@ -package app +package app -import ( - "log/slog" - "sync" - - "github.com/pocketbase/dbx" - "github.com/pocketbase/pocketbase" - "github.com/pocketbase/pocketbase/core" +const ( + AppName = "Certimate" + AppVersion = "0.4.13-dev" + AppUserAgent = AppName + "/" + AppVersion ) - -var ( - instance core.App - intanceOnce sync.Once -) - -func GetApp() core.App { - intanceOnce.Do(func() { - pb := pocketbase.NewWithConfig(pocketbase.Config{ - HideStartBanner: true, - }) - - pb.RootCmd.Flags().MarkHidden("encryptionEnv") - pb.RootCmd.Flags().MarkHidden("queryTimeout") - - pb.OnBootstrap().BindFunc(func(e *core.BootstrapEvent) error { - err := e.Next() - if err != nil { - return err - } - - settings := pb.Settings() - if !settings.Batch.Enabled { - settings.Batch.Enabled = true - settings.Batch.MaxRequests = 1000 - settings.Batch.Timeout = 30 - if err := pb.Save(settings); err != nil { - return err - } - } - - return nil - }) - - instance = pb - }) - - return instance -} - -func GetDB() dbx.Builder { - return GetApp().DB() -} - -func GetLogger() *slog.Logger { - return GetApp().Logger() -} diff --git a/internal/app/singleton.go b/internal/app/singleton.go new file mode 100644 index 000000000..b1b44cf70 --- /dev/null +++ b/internal/app/singleton.go @@ -0,0 +1,57 @@ +package app + +import ( + "log/slog" + "sync" + + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase" + "github.com/pocketbase/pocketbase/core" +) + +var ( + instance core.App + intanceOnce sync.Once +) + +func GetApp() core.App { + intanceOnce.Do(func() { + pb := pocketbase.NewWithConfig(pocketbase.Config{ + HideStartBanner: true, + }) + + pb.RootCmd.Flags().MarkHidden("encryptionEnv") + pb.RootCmd.Flags().MarkHidden("queryTimeout") + + pb.OnBootstrap().BindFunc(func(e *core.BootstrapEvent) error { + err := e.Next() + if err != nil { + return err + } + + settings := pb.Settings() + if !settings.Batch.Enabled { + settings.Batch.Enabled = true + settings.Batch.MaxRequests = 1000 + settings.Batch.Timeout = 30 + if err := pb.Save(settings); err != nil { + return err + } + } + + return nil + }) + + instance = pb + }) + + return instance +} + +func GetDB() dbx.Builder { + return GetApp().DB() +} + +func GetLogger() *slog.Logger { + return GetApp().Logger() +} diff --git a/internal/workflow/engine/executor_bizapply.go b/internal/workflow/engine/executor_bizapply.go index 9c2c61d33..993db9f6d 100644 --- a/internal/workflow/engine/executor_bizapply.go +++ b/internal/workflow/engine/executor_bizapply.go @@ -412,7 +412,7 @@ func (ne *bizApplyNodeExecutor) executeObtain(execCtx *NodeExecutionContext, nod // 初始化 ACME 客户端 legolog.Logger = certacme.NewLegoLogger(app.GetLogger()) legoClient, err := certacme.NewACMEClientWithAccount(legoUser, func(c *lego.Config) error { - c.UserAgent = "certimate" + c.UserAgent = app.AppUserAgent c.Certificate.KeyType = legoKeyType c.Certificate.DisableCommonName = obtainReq.NoCommonName return nil diff --git a/internal/workflow/engine/executor_bizmonitor.go b/internal/workflow/engine/executor_bizmonitor.go index a03b2da43..e0eb67e95 100644 --- a/internal/workflow/engine/executor_bizmonitor.go +++ b/internal/workflow/engine/executor_bizmonitor.go @@ -11,6 +11,7 @@ import ( "strings" "time" + "github.com/certimate-go/certimate/internal/app" "github.com/certimate-go/certimate/internal/repository" xcertx509 "github.com/certimate-go/certimate/pkg/utils/cert/x509" xhttp "github.com/certimate-go/certimate/pkg/utils/http" @@ -139,7 +140,7 @@ func (ne *bizMonitorNodeExecutor) tryRetrievePeerCertificates(execCtx *NodeExecu } req.Header.Set("Host", domain) - req.Header.Set("User-Agent", "certimate") + req.Header.Set("User-Agent", app.AppUserAgent) resp, err := client.Do(req) if err != nil { err = fmt.Errorf("failed to send http request: %w", err) diff --git a/pkg/core/notifier/providers/dingtalkbot/dingtalkbot.go b/pkg/core/notifier/providers/dingtalkbot/dingtalkbot.go index e13fe5138..8571dc98e 100644 --- a/pkg/core/notifier/providers/dingtalkbot/dingtalkbot.go +++ b/pkg/core/notifier/providers/dingtalkbot/dingtalkbot.go @@ -15,6 +15,7 @@ import ( "github.com/go-resty/resty/v2" + "github.com/certimate-go/certimate/internal/app" "github.com/certimate-go/certimate/pkg/core/notifier" ) @@ -40,7 +41,7 @@ func NewNotifier(config *NotifierConfig) (*Notifier, error) { client := resty.New(). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetPreRequestHook(func(c *resty.Client, req *http.Request) error { if config.Secret != "" { timestamp := fmt.Sprintf("%d", time.Now().UnixMilli()) diff --git a/pkg/core/notifier/providers/discordbot/discordbot.go b/pkg/core/notifier/providers/discordbot/discordbot.go index 185d62c7f..bc8481e66 100644 --- a/pkg/core/notifier/providers/discordbot/discordbot.go +++ b/pkg/core/notifier/providers/discordbot/discordbot.go @@ -8,6 +8,7 @@ import ( "github.com/go-resty/resty/v2" + "github.com/certimate-go/certimate/internal/app" "github.com/certimate-go/certimate/pkg/core/notifier" ) @@ -34,7 +35,7 @@ func NewNotifier(config *NotifierConfig) (*Notifier, error) { client := resty.New(). SetHeader("Authorization", fmt.Sprintf("Bot %s", config.BotToken)). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate") + SetHeader("User-Agent", app.AppUserAgent) return &Notifier{ config: config, diff --git a/pkg/core/notifier/providers/larkbot/larkbot.go b/pkg/core/notifier/providers/larkbot/larkbot.go index 746fd2926..3f874c8dd 100644 --- a/pkg/core/notifier/providers/larkbot/larkbot.go +++ b/pkg/core/notifier/providers/larkbot/larkbot.go @@ -14,6 +14,7 @@ import ( "github.com/go-resty/resty/v2" + "github.com/certimate-go/certimate/internal/app" "github.com/certimate-go/certimate/pkg/core/notifier" ) @@ -39,7 +40,7 @@ func NewNotifier(config *NotifierConfig) (*Notifier, error) { client := resty.New(). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate") + SetHeader("User-Agent", app.AppUserAgent) return &Notifier{ config: config, diff --git a/pkg/core/notifier/providers/mattermost/mattermost.go b/pkg/core/notifier/providers/mattermost/mattermost.go index be0b19a8f..491c653d7 100644 --- a/pkg/core/notifier/providers/mattermost/mattermost.go +++ b/pkg/core/notifier/providers/mattermost/mattermost.go @@ -9,6 +9,7 @@ import ( "github.com/go-resty/resty/v2" + "github.com/certimate-go/certimate/internal/app" "github.com/certimate-go/certimate/pkg/core/notifier" ) @@ -38,7 +39,7 @@ func NewNotifier(config *NotifierConfig) (*Notifier, error) { client := resty.New(). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate") + SetHeader("User-Agent", app.AppUserAgent) return &Notifier{ config: config, diff --git a/pkg/core/notifier/providers/slackbot/slackbot.go b/pkg/core/notifier/providers/slackbot/slackbot.go index 622c4587e..c5cc3b063 100644 --- a/pkg/core/notifier/providers/slackbot/slackbot.go +++ b/pkg/core/notifier/providers/slackbot/slackbot.go @@ -8,6 +8,7 @@ import ( "github.com/go-resty/resty/v2" + "github.com/certimate-go/certimate/internal/app" "github.com/certimate-go/certimate/pkg/core/notifier" ) @@ -34,7 +35,7 @@ func NewNotifier(config *NotifierConfig) (*Notifier, error) { client := resty.New(). SetHeader("Authorization", fmt.Sprintf("Bearer %s", config.BotToken)). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate") + SetHeader("User-Agent", app.AppUserAgent) return &Notifier{ config: config, diff --git a/pkg/core/notifier/providers/telegrambot/telegrambot.go b/pkg/core/notifier/providers/telegrambot/telegrambot.go index b514278fd..154cec4a9 100644 --- a/pkg/core/notifier/providers/telegrambot/telegrambot.go +++ b/pkg/core/notifier/providers/telegrambot/telegrambot.go @@ -8,6 +8,7 @@ import ( "github.com/go-resty/resty/v2" + "github.com/certimate-go/certimate/internal/app" "github.com/certimate-go/certimate/pkg/core/notifier" ) @@ -33,7 +34,7 @@ func NewNotifier(config *NotifierConfig) (*Notifier, error) { client := resty.New(). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate") + SetHeader("User-Agent", app.AppUserAgent) return &Notifier{ config: config, diff --git a/pkg/core/notifier/providers/wecombot/wecombot.go b/pkg/core/notifier/providers/wecombot/wecombot.go index 985dac026..612b1e943 100644 --- a/pkg/core/notifier/providers/wecombot/wecombot.go +++ b/pkg/core/notifier/providers/wecombot/wecombot.go @@ -10,6 +10,7 @@ import ( "github.com/go-resty/resty/v2" + "github.com/certimate-go/certimate/internal/app" "github.com/certimate-go/certimate/pkg/core/notifier" ) @@ -33,7 +34,7 @@ func NewNotifier(config *NotifierConfig) (*Notifier, error) { client := resty.New(). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate") + SetHeader("User-Agent", app.AppUserAgent) return &Notifier{ config: config, diff --git a/pkg/sdk3rd/1panel/client.go b/pkg/sdk3rd/1panel/client.go index 2e222a28d..932a1475e 100644 --- a/pkg/sdk3rd/1panel/client.go +++ b/pkg/sdk3rd/1panel/client.go @@ -12,6 +12,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -33,7 +35,7 @@ func NewClient(serverUrl, apiKey string) (*Client, error) { SetBaseURL(strings.TrimRight(serverUrl, "/")+"/api/v1"). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetPreRequestHook(func(c *resty.Client, req *http.Request) error { timestamp := fmt.Sprintf("%d", time.Now().Unix()) tokenMd5 := md5.Sum([]byte("1panel" + apiKey + timestamp)) diff --git a/pkg/sdk3rd/1panel/v2/client.go b/pkg/sdk3rd/1panel/v2/client.go index 85a8d3c85..37f314e73 100644 --- a/pkg/sdk3rd/1panel/v2/client.go +++ b/pkg/sdk3rd/1panel/v2/client.go @@ -12,6 +12,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -33,7 +35,7 @@ func NewClient(serverUrl, apiKey string) (*Client, error) { SetBaseURL(strings.TrimRight(serverUrl, "/")+"/api/v2"). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetPreRequestHook(func(c *resty.Client, req *http.Request) error { timestamp := fmt.Sprintf("%d", time.Now().Unix()) tokenMd5 := md5.Sum([]byte("1panel" + apiKey + timestamp)) diff --git a/pkg/sdk3rd/51dnscom/client.go b/pkg/sdk3rd/51dnscom/client.go index da88d1f9e..6609af4fb 100644 --- a/pkg/sdk3rd/51dnscom/client.go +++ b/pkg/sdk3rd/51dnscom/client.go @@ -9,6 +9,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -30,7 +32,7 @@ func NewClient(apiKey, apiSecret string) (*Client, error) { SetBaseURL("https://www.51dns.com/api"). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate") + SetHeader("User-Agent", app.AppUserAgent) return &Client{ apiKey: apiKey, diff --git a/pkg/sdk3rd/baishan/client.go b/pkg/sdk3rd/baishan/client.go index 485e0b1f0..93c4a3e7e 100644 --- a/pkg/sdk3rd/baishan/client.go +++ b/pkg/sdk3rd/baishan/client.go @@ -6,6 +6,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -21,7 +23,7 @@ func NewClient(apiToken string) (*Client, error) { SetBaseURL("https://cdn.api.baishan.com"). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetQueryParam("token", apiToken) return &Client{client}, nil diff --git a/pkg/sdk3rd/btpanel/client.go b/pkg/sdk3rd/btpanel/client.go index 5ff349fbe..335a313c0 100644 --- a/pkg/sdk3rd/btpanel/client.go +++ b/pkg/sdk3rd/btpanel/client.go @@ -12,6 +12,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -35,7 +37,7 @@ func NewClient(serverUrl, apiKey string) (*Client, error) { SetBaseURL(strings.TrimRight(serverUrl, "/")). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/x-www-form-urlencoded"). - SetHeader("User-Agent", "certimate") + SetHeader("User-Agent", app.AppUserAgent) return &Client{ apiKey: apiKey, diff --git a/pkg/sdk3rd/btpanelgo/client.go b/pkg/sdk3rd/btpanelgo/client.go index 9df6c5aba..e300f384f 100644 --- a/pkg/sdk3rd/btpanelgo/client.go +++ b/pkg/sdk3rd/btpanelgo/client.go @@ -13,6 +13,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -36,7 +38,7 @@ func NewClient(serverUrl, apiKey string) (*Client, error) { SetBaseURL(strings.TrimRight(serverUrl, "/")). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/x-www-form-urlencoded"). - SetHeader("User-Agent", "certimate") + SetHeader("User-Agent", app.AppUserAgent) return &Client{ apiKey: apiKey, diff --git a/pkg/sdk3rd/btwaf/client.go b/pkg/sdk3rd/btwaf/client.go index a7840b176..958e4dde5 100644 --- a/pkg/sdk3rd/btwaf/client.go +++ b/pkg/sdk3rd/btwaf/client.go @@ -12,6 +12,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -33,7 +35,7 @@ func NewClient(serverUrl, apiKey string) (*Client, error) { SetBaseURL(strings.TrimRight(serverUrl, "/")+"/api"). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetPreRequestHook(func(c *resty.Client, req *http.Request) error { timestamp := fmt.Sprintf("%d", time.Now().Unix()) keyMd5 := md5.Sum([]byte(apiKey)) diff --git a/pkg/sdk3rd/bunny/client.go b/pkg/sdk3rd/bunny/client.go index 1e39e5afd..7bb95e81a 100644 --- a/pkg/sdk3rd/bunny/client.go +++ b/pkg/sdk3rd/bunny/client.go @@ -5,6 +5,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -20,7 +22,7 @@ func NewClient(apiToken string) (*Client, error) { SetBaseURL("https://api.bunny.net"). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetHeader("AccessKey", apiToken) return &Client{client}, nil diff --git a/pkg/sdk3rd/cachefly/client.go b/pkg/sdk3rd/cachefly/client.go index d535ecfd5..8aa0cc61b 100644 --- a/pkg/sdk3rd/cachefly/client.go +++ b/pkg/sdk3rd/cachefly/client.go @@ -6,6 +6,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -21,7 +23,7 @@ func NewClient(apiToken string) (*Client, error) { SetBaseURL("https://api.cachefly.com/api/2.5"). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetHeader("X-CF-Authorization", "Bearer "+apiToken) return &Client{client}, nil diff --git a/pkg/sdk3rd/cdnfly/client.go b/pkg/sdk3rd/cdnfly/client.go index f111c5208..5a16a3475 100644 --- a/pkg/sdk3rd/cdnfly/client.go +++ b/pkg/sdk3rd/cdnfly/client.go @@ -9,6 +9,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -33,7 +35,7 @@ func NewClient(serverUrl, apiKey, apiSecret string) (*Client, error) { SetBaseURL(strings.TrimRight(serverUrl, "/")+"/v1"). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetHeader("API-Key", apiKey). SetHeader("API-Secret", apiSecret) diff --git a/pkg/sdk3rd/cpanel/client.go b/pkg/sdk3rd/cpanel/client.go index b6bf34bdc..3212d3bd9 100644 --- a/pkg/sdk3rd/cpanel/client.go +++ b/pkg/sdk3rd/cpanel/client.go @@ -9,6 +9,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -33,7 +35,7 @@ func NewClient(serverUrl string, username, apiToken string) (*Client, error) { SetBaseURL(strings.TrimRight(serverUrl, "/")+"/execute"). SetHeader("Accept", "application/json"). SetHeader("Authorization", fmt.Sprintf("cpanel %s:%s", username, apiToken)). - SetHeader("User-Agent", "certimate") + SetHeader("User-Agent", app.AppUserAgent) return &Client{client}, nil } diff --git a/pkg/sdk3rd/ctyun/openapi/client.go b/pkg/sdk3rd/ctyun/openapi/client.go index edc3f5330..11ff7f583 100644 --- a/pkg/sdk3rd/ctyun/openapi/client.go +++ b/pkg/sdk3rd/ctyun/openapi/client.go @@ -14,6 +14,8 @@ import ( "github.com/go-resty/resty/v2" "github.com/pocketbase/pocketbase/tools/security" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -38,7 +40,7 @@ func NewClient(endpoint, accessKeyId, secretAccessKey string) (*Client, error) { SetBaseURL(endpoint). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetPreRequestHook(func(c *resty.Client, req *http.Request) error { // 生成时间戳及流水号 now := time.Now() diff --git a/pkg/sdk3rd/dcloud/unicloud/client.go b/pkg/sdk3rd/dcloud/unicloud/client.go index fb0a7512d..c6cd97e48 100644 --- a/pkg/sdk3rd/dcloud/unicloud/client.go +++ b/pkg/sdk3rd/dcloud/unicloud/client.go @@ -15,6 +15,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -59,12 +61,12 @@ func NewClient(username, password string) (*Client, error) { client.serverlessClient = resty.New(). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate") + SetHeader("User-Agent", app.AppUserAgent) client.apiClient = resty.New(). SetBaseURL("https://unicloud-api.dcloud.net.cn/unicloud/api"). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetPreRequestHook(func(c *resty.Client, req *http.Request) error { if client.apiUserToken != "" { req.Header.Set("Token", client.apiUserToken) @@ -86,12 +88,12 @@ func (c *Client) buildServerlessClientInfo(appId string) (_clientInfo map[string "PLATFORM": "web", "OS": strings.ToUpper(runtime.GOOS), "APPID": appId, - "DEVICEID": "certimate", + "DEVICEID": app.AppName, "LOCALE": "zh-Hans", "osName": runtime.GOOS, "appId": appId, "appName": "uniCloud", - "deviceId": "certimate", + "deviceId": app.AppName, "deviceType": "pc", "uniPlatform": "web", "uniCompilerVersion": "4.45", diff --git a/pkg/sdk3rd/dnsexit/client.go b/pkg/sdk3rd/dnsexit/client.go index 9b1a62103..e44e56707 100644 --- a/pkg/sdk3rd/dnsexit/client.go +++ b/pkg/sdk3rd/dnsexit/client.go @@ -7,6 +7,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -22,7 +24,7 @@ func NewClient(apiKey string) (*Client, error) { SetBaseURL("https://api.dnsexit.com"). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetPreRequestHook(func(c *resty.Client, req *http.Request) error { req.Header.Set("apikey", apiKey) diff --git a/pkg/sdk3rd/dnsla/client.go b/pkg/sdk3rd/dnsla/client.go index 40fcc9054..f7420461f 100644 --- a/pkg/sdk3rd/dnsla/client.go +++ b/pkg/sdk3rd/dnsla/client.go @@ -6,6 +6,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -25,7 +27,7 @@ func NewClient(apiId, apiSecret string) (*Client, error) { SetBasicAuth(apiId, apiSecret). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate") + SetHeader("User-Agent", app.AppUserAgent) return &Client{client}, nil } diff --git a/pkg/sdk3rd/dogecloud/client.go b/pkg/sdk3rd/dogecloud/client.go index 6fb1cf103..cd55db831 100644 --- a/pkg/sdk3rd/dogecloud/client.go +++ b/pkg/sdk3rd/dogecloud/client.go @@ -11,6 +11,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -29,7 +31,7 @@ func NewClient(accessKey, secretKey string) (*Client, error) { SetBaseURL("https://api.dogecloud.com"). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetPreRequestHook(func(ctx *resty.Client, req *http.Request) error { requestUrl := req.URL.Path requestQuery := req.URL.Query().Encode() diff --git a/pkg/sdk3rd/dokploy/client.go b/pkg/sdk3rd/dokploy/client.go index 13b632853..b71c37fbf 100644 --- a/pkg/sdk3rd/dokploy/client.go +++ b/pkg/sdk3rd/dokploy/client.go @@ -9,6 +9,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -30,7 +32,7 @@ func NewClient(serverUrl string, apiKey string) (*Client, error) { SetBaseURL(strings.TrimRight(serverUrl, "/")+"/api"). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetHeader("X-Api-Key", apiKey) return &Client{client}, nil diff --git a/pkg/sdk3rd/flexcdn/client.go b/pkg/sdk3rd/flexcdn/client.go index 3ffd871df..eab8e93bd 100644 --- a/pkg/sdk3rd/flexcdn/client.go +++ b/pkg/sdk3rd/flexcdn/client.go @@ -11,6 +11,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -54,7 +56,7 @@ func NewClient(serverUrl, apiRole, accessKeyId, accessKey string) (*Client, erro SetBaseURL(strings.TrimRight(serverUrl, "/")). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetPreRequestHook(func(c *resty.Client, req *http.Request) error { if client.accessToken != "" { req.Header.Set("X-Cloud-Access-Token", client.accessToken) diff --git a/pkg/sdk3rd/gname/client.go b/pkg/sdk3rd/gname/client.go index bd118916e..4d906fb5e 100644 --- a/pkg/sdk3rd/gname/client.go +++ b/pkg/sdk3rd/gname/client.go @@ -10,6 +10,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -31,7 +33,7 @@ func NewClient(appId, appKey string) (*Client, error) { SetBaseURL("https://api.gname.com"). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/x-www-form-urlencoded"). - SetHeader("User-Agent", "certimate") + SetHeader("User-Agent", app.AppUserAgent) return &Client{ appId: appId, diff --git a/pkg/sdk3rd/goedge/client.go b/pkg/sdk3rd/goedge/client.go index 5e2bebdae..a9830c817 100644 --- a/pkg/sdk3rd/goedge/client.go +++ b/pkg/sdk3rd/goedge/client.go @@ -11,6 +11,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -54,7 +56,7 @@ func NewClient(serverUrl, apiRole, accessKeyId, accessKey string) (*Client, erro SetBaseURL(strings.TrimRight(serverUrl, "/")). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetPreRequestHook(func(c *resty.Client, req *http.Request) error { if client.accessToken != "" { req.Header.Set("X-Edge-Access-Token", client.accessToken) diff --git a/pkg/sdk3rd/lecdn/v3/client/client.go b/pkg/sdk3rd/lecdn/v3/client/client.go index 3a13f1f48..f7463264e 100644 --- a/pkg/sdk3rd/lecdn/v3/client/client.go +++ b/pkg/sdk3rd/lecdn/v3/client/client.go @@ -11,6 +11,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -43,7 +45,7 @@ func NewClient(serverUrl, username, password string) (*Client, error) { } client.client = resty.New(). SetBaseURL(strings.TrimRight(serverUrl, "/")+"/prod-api"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetPreRequestHook(func(c *resty.Client, req *http.Request) error { if client.accessToken != "" { req.Header.Set("Authorization", "Bearer "+client.accessToken) diff --git a/pkg/sdk3rd/lecdn/v3/master/client.go b/pkg/sdk3rd/lecdn/v3/master/client.go index b818de9a1..a26fd7c64 100644 --- a/pkg/sdk3rd/lecdn/v3/master/client.go +++ b/pkg/sdk3rd/lecdn/v3/master/client.go @@ -11,6 +11,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -45,7 +47,7 @@ func NewClient(serverUrl, username, password string) (*Client, error) { SetBaseURL(strings.TrimRight(serverUrl, "/")+"/prod-api"). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetPreRequestHook(func(c *resty.Client, req *http.Request) error { if client.accessToken != "" { req.Header.Set("Authorization", "Bearer "+client.accessToken) diff --git a/pkg/sdk3rd/netlify/client.go b/pkg/sdk3rd/netlify/client.go index 7bbe6a107..25ca5b014 100644 --- a/pkg/sdk3rd/netlify/client.go +++ b/pkg/sdk3rd/netlify/client.go @@ -6,6 +6,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -22,7 +24,7 @@ func NewClient(apiToken string) (*Client, error) { SetHeader("Accept", "application/json"). SetHeader("Authorization", "Bearer "+apiToken). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate") + SetHeader("User-Agent", app.AppUserAgent) return &Client{client}, nil } diff --git a/pkg/sdk3rd/nginxproxymanager/client.go b/pkg/sdk3rd/nginxproxymanager/client.go index 2726310ea..222dd39b0 100644 --- a/pkg/sdk3rd/nginxproxymanager/client.go +++ b/pkg/sdk3rd/nginxproxymanager/client.go @@ -11,6 +11,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -45,7 +47,7 @@ func NewClient(serverUrl, identity, secret string) (*Client, error) { SetBaseURL(strings.TrimRight(serverUrl, "/")+"/api"). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetPreRequestHook(func(c *resty.Client, req *http.Request) error { if client.jwtToken != "" { req.Header.Set("Authorization", "Bearer "+client.jwtToken) @@ -75,7 +77,7 @@ func NewClientWithJwtToken(serverUrl, jwtToken string) (*Client, error) { SetBaseURL(strings.TrimRight(serverUrl, "/")+"/api"). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetPreRequestHook(func(c *resty.Client, req *http.Request) error { if client.jwtToken != "" { req.Header.Set("Authorization", "Bearer "+client.jwtToken) diff --git a/pkg/sdk3rd/qingcloud/dns/client.go b/pkg/sdk3rd/qingcloud/dns/client.go index 204324aa7..f56155705 100644 --- a/pkg/sdk3rd/qingcloud/dns/client.go +++ b/pkg/sdk3rd/qingcloud/dns/client.go @@ -11,6 +11,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -30,7 +32,7 @@ func NewClient(accessKeyId, secretAccessKey string) (*Client, error) { SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). SetHeader("Host", "api.routewize.com"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetPreRequestHook(func(c *resty.Client, req *http.Request) error { // 生成时间 date := time.Now().UTC().Format(time.RFC1123) diff --git a/pkg/sdk3rd/rainyun/client.go b/pkg/sdk3rd/rainyun/client.go index 845618133..61a085905 100644 --- a/pkg/sdk3rd/rainyun/client.go +++ b/pkg/sdk3rd/rainyun/client.go @@ -6,6 +6,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -21,7 +23,7 @@ func NewClient(apiKey string) (*Client, error) { SetBaseURL("https://api.v2.rainyun.com"). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetHeader("X-API-Key", apiKey) return &Client{client}, nil diff --git a/pkg/sdk3rd/ratpanel/client.go b/pkg/sdk3rd/ratpanel/client.go index b45a0f325..32cc34789 100644 --- a/pkg/sdk3rd/ratpanel/client.go +++ b/pkg/sdk3rd/ratpanel/client.go @@ -15,6 +15,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -39,7 +41,7 @@ func NewClient(serverUrl string, accessTokenId int64, accessToken string) (*Clie SetBaseURL(strings.TrimRight(serverUrl, "/")+"/api"). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetPreRequestHook(func(c *resty.Client, req *http.Request) error { var body []byte var err error diff --git a/pkg/sdk3rd/safeline/client.go b/pkg/sdk3rd/safeline/client.go index fc0dfd369..3e9958a22 100644 --- a/pkg/sdk3rd/safeline/client.go +++ b/pkg/sdk3rd/safeline/client.go @@ -9,6 +9,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -30,7 +32,7 @@ func NewClient(serverUrl, apiToken string) (*Client, error) { SetBaseURL(strings.TrimRight(serverUrl, "/")). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetHeader("X-SLCE-API-TOKEN", apiToken) return &Client{client}, nil diff --git a/pkg/sdk3rd/upyun/console/client.go b/pkg/sdk3rd/upyun/console/client.go index b86ce7348..0c7baad62 100644 --- a/pkg/sdk3rd/upyun/console/client.go +++ b/pkg/sdk3rd/upyun/console/client.go @@ -9,6 +9,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -37,7 +39,7 @@ func NewClient(username, password string) (*Client, error) { SetBaseURL("https://console.upyun.com"). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetPreRequestHook(func(c *resty.Client, req *http.Request) error { if client.loginCookie != "" { req.Header.Set("Cookie", client.loginCookie) diff --git a/pkg/sdk3rd/wangsu/openapi/client.go b/pkg/sdk3rd/wangsu/openapi/client.go index 941b415a1..183536106 100644 --- a/pkg/sdk3rd/wangsu/openapi/client.go +++ b/pkg/sdk3rd/wangsu/openapi/client.go @@ -14,6 +14,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -36,7 +38,7 @@ func NewClient(accessKey, secretKey string) (*Client, error) { SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). SetHeader("Host", "open.chinanetcenter.com"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetPreRequestHook(func(c *resty.Client, req *http.Request) error { // Step 1: Get request method method := req.Method diff --git a/pkg/sdk3rd/xinnet/client.go b/pkg/sdk3rd/xinnet/client.go index 6a3f82823..d5e87a0d3 100644 --- a/pkg/sdk3rd/xinnet/client.go +++ b/pkg/sdk3rd/xinnet/client.go @@ -12,6 +12,8 @@ import ( "time" "github.com/go-resty/resty/v2" + + "github.com/certimate-go/certimate/internal/app" ) type Client struct { @@ -30,7 +32,7 @@ func NewClient(agentId, appSecret string) (*Client, error) { SetBaseURL("https://apiv2.xinnet.com/api"). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("User-Agent", "certimate"). + SetHeader("User-Agent", app.AppUserAgent). SetPreRequestHook(func(c *resty.Client, req *http.Request) error { // 生成时间戳 timestamp := time.Now().UTC().Format("20060102T150405Z") diff --git a/ui/src/components/access/forms/AccessConfigFieldsProviderWebhook.tsx b/ui/src/components/access/forms/AccessConfigFieldsProviderWebhook.tsx index 639facbf8..04eb68a9c 100644 --- a/ui/src/components/access/forms/AccessConfigFieldsProviderWebhook.tsx +++ b/ui/src/components/access/forms/AccessConfigFieldsProviderWebhook.tsx @@ -232,7 +232,7 @@ const AccessConfigFormFieldsProviderWebhook = ({ usage = "none" }: AccessConfigF menu={{ items: [ { - key: "certimate", + key: "common", label: t("access.form.webhook_preset_data.common"), onClick: handlePresetDataForDeploymentClick, }, diff --git a/ui/src/domain/app.ts b/ui/src/domain/app.ts index 11bcc27fc..cff56a24f 100644 --- a/ui/src/domain/app.ts +++ b/ui/src/domain/app.ts @@ -1,7 +1,7 @@ import i18next from "i18next"; // fallback policy: .env > git tag > "v0.0.0-dev" -export const APP_VERSION: string = import.meta.env.VITE_APP_VERSION || __APP_VERSION__ || "v0.0.0-dev"; +export const APP_VERSION: string = "v" + (__APP_VERSION__ || "0.0.0-dev").replace(/^v/, ""); export const APP_REPO_URL = "https://github.com/certimate-go/certimate"; export const APP_DOWNLOAD_URL = APP_REPO_URL + "/releases"; diff --git a/ui/vite.config.ts b/ui/vite.config.ts index b9181dfd8..824ac9836 100644 --- a/ui/vite.config.ts +++ b/ui/vite.config.ts @@ -1,11 +1,10 @@ -import { type SpawnSyncReturns, execFileSync } from "node:child_process"; import path from "node:path"; import tailwindcssPlugin from "@tailwindcss/vite"; import legacyPlugin from "@vitejs/plugin-legacy"; import reactPlugin from "@vitejs/plugin-react"; import fs from "fs-extra"; -import { type Plugin, defineConfig, loadEnv } from "vite"; +import { type Plugin, defineConfig } from "vite"; const preserveFilesPlugin = (filesToPreserve: string[]): Plugin => { return { @@ -34,18 +33,19 @@ const preserveFilesPlugin = (filesToPreserve: string[]): Plugin => { }; }; -export default defineConfig(({ mode }) => { - const envs = loadEnv(mode, process.cwd()); +export default defineConfig(() => { let appVersion = undefined; - if (!envs?.VITE_APP_VERSION) { - try { - appVersion = execFileSync("git", ["describe", "--match", "v[0-9]*", "--tags", "--abbrev=8"], { - stdio: [], - })?.toString(); - } catch (error) { - const err = error as SpawnSyncReturns; - console.warn("failed to get version number through git", err?.stderr?.toString()); + try { + const content = fs.readFileSync(path.resolve(__dirname, "../internal/app/app.go"), "utf-8"); + const matches = content.match(/AppVersion\s+=\s+"(.+?)"/); + if (matches) { + appVersion = matches[1]; + console.info("[certimate] AppVersion is " + appVersion); + } else { + throw new Error("AppVersion not found in '/internal/app/app.go'"); } + } catch (err) { + throw new Error("Could not read app version: " + (err as Error).message); } return {