This commit is contained in:
Fu Diwei
2026-05-20 17:35:15 +08:00
committed by RHQYZ
parent 2ac97335c4
commit 4a48ddcc4a
7 changed files with 73 additions and 56 deletions
+5 -5
View File
@@ -35,7 +35,7 @@ func internalCertApplyCommand(_ core.App) *cobra.Command {
command := &cobra.Command{
Use: "certapply",
Example: "internal certapply --in ./in.file --out ./out.file --enckey aeskey",
Example: "internal certapply --mprocIn ./in.file --mprocOut ./out.file --mprocSecret aeskey",
SilenceUsage: true,
Run: func(cmd *cobra.Command, args []string) {
type InData struct {
@@ -85,10 +85,10 @@ func internalCertApplyCommand(_ core.App) *cobra.Command {
},
}
command.PersistentFlags().StringVar(&flagInput, "in", "", "")
command.PersistentFlags().StringVar(&flagOutput, "out", "", "")
command.PersistentFlags().StringVar(&flagError, "err", "", "")
command.PersistentFlags().StringVar(&flagEncryptionKey, "enckey", "", "")
command.PersistentFlags().StringVar(&flagInput, "mprocIn", "", "")
command.PersistentFlags().StringVar(&flagOutput, "mprocOut", "", "")
command.PersistentFlags().StringVar(&flagError, "mprocErr", "", "")
command.PersistentFlags().StringVar(&flagEncryptionKey, "mprocSecret", "", "")
return command
}
-19
View File
@@ -23,25 +23,6 @@ func GetApp() core.App {
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
})
+1
View File
@@ -45,6 +45,7 @@ func newACMEClientWithAccount(account *ACMEAccount, configures ...func(*lego.Con
legoCfg := lego.NewConfig(account)
legoCfg.CADirURL = account.ACMEDirUrl
// TODO: fix this after migrate lego to v5
settingsRepo := repository.NewSettingsRepository()
settings, _ := settingsRepo.GetByName(context.Background(), domain.SettingsNameSSLProvider)
if settings != nil {
+1
View File
@@ -89,6 +89,7 @@ func NewACMEConfig(options *ACMEConfigOptions) (*ACMEConfig, error) {
}
case domain.CAProviderTypeSSLCom:
// TODO: fix this after migrate lego to v5
if strings.HasPrefix(string(options.CertifierKeyType), "RSA") {
ca.CADirUrl = acmeDirUrls[string(domain.CAProviderTypeSSLCom)+"RSA"]
} else if strings.HasPrefix(string(options.CertifierKeyType), "EC") {
+8 -5
View File
@@ -12,6 +12,7 @@ import (
"github.com/go-cmd/cmd"
"github.com/certimate-go/certimate/internal/app"
xcrypto "github.com/certimate-go/certimate/pkg/utils/crypto"
)
@@ -78,7 +79,7 @@ func (s *sender[TIn, TOut]) SendWithContext(ctx context.Context, params *TIn) (*
} else {
tempErr.Close()
}
defer os.Remove(tempOut.Name())
defer os.Remove(tempErr.Name())
// 初始化子进程
done := make(chan struct{})
@@ -86,10 +87,12 @@ func (s *sender[TIn, TOut]) SendWithContext(ctx context.Context, params *TIn) (*
s.getEntrypoint(),
"intercmd",
s.command,
"--in", tempIn.Name(),
"--out", tempOut.Name(),
"--err", tempErr.Name(),
"--enckey", hex.EncodeToString(aesKey),
"--dir", app.GetApp().DataDir(), // inject `--dir` of Pocketbase
"--encryptionEnv", app.GetApp().EncryptionEnv(), // inject `--encryptionEnv` of Pocketbase
"--mprocIn", tempIn.Name(),
"--mprocOut", tempOut.Name(),
"--mprocErr", tempErr.Name(),
"--mprocSecret", hex.EncodeToString(aesKey),
)
go func() {
defer close(done)
@@ -14,8 +14,8 @@ import (
type bizNotifyNodeExecutor struct {
nodeExecutor
accessRepo accessRepository
settingsRepo settingsRepository
accessRepo accessRepository
}
func (ne *bizNotifyNodeExecutor) Execute(execCtx *NodeExecutionContext) (*NodeExecutionResult, error) {
@@ -108,7 +108,7 @@ func (ne *bizNotifyNodeExecutor) checkCanSkip(execCtx *NodeExecutionContext) (_s
func newBizNotifyNodeExecutor() NodeExecutor {
return &bizNotifyNodeExecutor{
nodeExecutor: nodeExecutor{logger: slog.Default()},
accessRepo: repository.NewAccessRepository(),
settingsRepo: repository.NewSettingsRepository(),
accessRepo: repository.NewAccessRepository(),
}
}
+56 -25
View File
@@ -46,34 +46,65 @@ func main() {
pb.RootCmd.AddCommand(cmd.NewInternalCommand(pb))
pb.RootCmd.AddCommand(cmd.NewWinscCommand(pb))
pb.OnServe().BindFunc(func(e *core.ServeEvent) error {
scheduler.Setup()
workflow.Setup()
routes.BindRouter(e.Router)
return e.Next()
})
switch os.Args[1] {
case "serve":
{
pb.OnServe().BindFunc(func(e *core.ServeEvent) error {
scheduler.Setup()
workflow.Setup()
routes.BindRouter(e.Router)
return e.Next()
})
pb.OnServe().Bind(&hook.Handler[*core.ServeEvent]{
Func: func(e *core.ServeEvent) error {
e.Router.
GET("/{path...}", apis.Static(ui.DistDirFS, false)).
Bind(apis.Gzip())
return e.Next()
},
Priority: 999,
})
pb.OnServe().Bind(&hook.Handler[*core.ServeEvent]{
Func: func(e *core.ServeEvent) error {
e.Router.
GET("/{path...}", apis.Static(ui.DistDirFS, false)).
Bind(apis.Gzip())
return e.Next()
},
Priority: 999,
})
pb.OnServe().BindFunc(func(e *core.ServeEvent) error {
slog.Info("[CERTIMATE] Visit the website: http://" + flagHttp)
return e.Next()
})
pb.OnServe().BindFunc(func(e *core.ServeEvent) error {
slog.Info("[CERTIMATE] Visit the website: http://" + flagHttp)
return e.Next()
})
pb.OnTerminate().BindFunc(func(e *core.TerminateEvent) error {
workflow.Teardown()
return e.Next()
})
pb.OnBootstrap().BindFunc(func(e *core.BootstrapEvent) error {
err := e.Next()
if err != nil {
return err
}
if err := cmd.Serve(pb); err != nil {
slog.Error("[CERTIMATE] Start failed.", slog.Any("error", 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
})
pb.OnTerminate().BindFunc(func(e *core.TerminateEvent) error {
workflow.Teardown()
return e.Next()
})
if err := cmd.Serve(pb); err != nil {
slog.Error("[CERTIMATE] Serve failed.", slog.Any("error", err))
}
}
default:
{
if err := pb.Execute(); err != nil {
slog.Error("[CERTIMATE] Start failed.", slog.Any("error", err))
}
}
}
}