mirror of
https://github.com/certimate-go/certimate.git
synced 2026-06-04 21:02:40 +08:00
chore: 调整目录结构
This commit is contained in:
parent
27ee1d3b1e
commit
ea653f6930
@ -12,7 +12,7 @@ import (
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/certimate-go/certimate/internal/certapply"
|
||||
"github.com/certimate-go/certimate/internal/certacme"
|
||||
"github.com/certimate-go/certimate/internal/tools/mproc"
|
||||
)
|
||||
|
||||
@ -39,12 +39,12 @@ func internalCertApplyCommand(app core.App) *cobra.Command {
|
||||
SilenceUsage: true,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
type InData struct {
|
||||
Account *certapply.ACMEAccount `json:"account,omitempty"`
|
||||
Request *certapply.ObtainCertificateRequest `json:"request,omitempty"`
|
||||
Account *certacme.ACMEAccount `json:"account,omitempty"`
|
||||
Request *certacme.ObtainCertificateRequest `json:"request,omitempty"`
|
||||
}
|
||||
|
||||
type OutData struct {
|
||||
Response *certapply.ObtainCertificateResponse `json:"response"`
|
||||
Response *certacme.ObtainCertificateResponse `json:"response"`
|
||||
}
|
||||
|
||||
mreceiver := mproc.NewReceiver(func(ctx context.Context, params *InData) (*OutData, error) {
|
||||
@ -60,7 +60,7 @@ func internalCertApplyCommand(app core.App) *cobra.Command {
|
||||
// see: /internal/tools/mproc/sender.go
|
||||
legolog.Logger = log.New(os.Stdout, "", 0)
|
||||
|
||||
client, err := certapply.NewACMEClientWithAccount(params.Account, func(c *lego.Config) error {
|
||||
client, err := certacme.NewACMEClientWithAccount(params.Account, func(c *lego.Config) error {
|
||||
c.UserAgent = "certimate"
|
||||
c.Certificate.KeyType = params.Request.PrivateKeyType
|
||||
return nil
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
//go:build !windows
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package cmd
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
//go:build windows
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package cmd
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
//go:build !windows
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package cmd
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
//go:build windows
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package cmd
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package certapply
|
||||
package certacme
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -1,4 +1,4 @@
|
||||
package certifiers
|
||||
package certifiers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -1,4 +1,4 @@
|
||||
package certapply
|
||||
package certacme
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@ -1,4 +1,4 @@
|
||||
package certapply
|
||||
package certacme
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -18,7 +18,7 @@ import (
|
||||
"github.com/go-acme/lego/v4/log"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/internal/certapply/certifiers"
|
||||
"github.com/certimate-go/certimate/internal/certacme/certifiers"
|
||||
"github.com/certimate-go/certimate/internal/domain"
|
||||
)
|
||||
|
||||
@ -199,43 +199,3 @@ func (c *ACMEClient) sendObtainCertificateRequest(request *ObtainCertificateRequ
|
||||
ARIReplaced: req.ReplacesCertID != "",
|
||||
}, nil
|
||||
}
|
||||
|
||||
type RevokeCertificateRequest struct {
|
||||
Certificate string
|
||||
}
|
||||
|
||||
type RevokeCertificateResponse struct{}
|
||||
|
||||
func (c *ACMEClient) RevokeCertificate(ctx context.Context, request *RevokeCertificateRequest) (*RevokeCertificateResponse, error) {
|
||||
type result struct {
|
||||
res *RevokeCertificateResponse
|
||||
err error
|
||||
}
|
||||
|
||||
done := make(chan result, 1)
|
||||
|
||||
go func() {
|
||||
res, err := c.sendRevokeCertificateRequest(request)
|
||||
done <- result{res, err}
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
case r := <-done:
|
||||
return r.res, r.err
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ACMEClient) sendRevokeCertificateRequest(request *RevokeCertificateRequest) (*RevokeCertificateResponse, error) {
|
||||
if request == nil {
|
||||
return nil, errors.New("the request is nil")
|
||||
}
|
||||
|
||||
err := c.client.Certificate.Revoke([]byte(request.Certificate))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &RevokeCertificateResponse{}, nil
|
||||
}
|
||||
46
internal/certacme/client_revoke.go
Normal file
46
internal/certacme/client_revoke.go
Normal file
@ -0,0 +1,46 @@
|
||||
package certacme
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type RevokeCertificateRequest struct {
|
||||
Certificate string
|
||||
}
|
||||
|
||||
type RevokeCertificateResponse struct{}
|
||||
|
||||
func (c *ACMEClient) RevokeCertificate(ctx context.Context, request *RevokeCertificateRequest) (*RevokeCertificateResponse, error) {
|
||||
type result struct {
|
||||
res *RevokeCertificateResponse
|
||||
err error
|
||||
}
|
||||
|
||||
done := make(chan result, 1)
|
||||
|
||||
go func() {
|
||||
res, err := c.sendRevokeCertificateRequest(request)
|
||||
done <- result{res, err}
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
case r := <-done:
|
||||
return r.res, r.err
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ACMEClient) sendRevokeCertificateRequest(request *RevokeCertificateRequest) (*RevokeCertificateResponse, error) {
|
||||
if request == nil {
|
||||
return nil, errors.New("the request is nil")
|
||||
}
|
||||
|
||||
err := c.client.Certificate.Revoke([]byte(request.Certificate))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &RevokeCertificateResponse{}, nil
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package certapply
|
||||
package certacme
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -1,4 +1,4 @@
|
||||
package certapply
|
||||
package certacme
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -14,7 +14,7 @@ import (
|
||||
"github.com/pocketbase/dbx"
|
||||
|
||||
"github.com/certimate-go/certimate/internal/app"
|
||||
"github.com/certimate-go/certimate/internal/certapply"
|
||||
"github.com/certimate-go/certimate/internal/certacme"
|
||||
"github.com/certimate-go/certimate/internal/domain"
|
||||
"github.com/certimate-go/certimate/internal/domain/dtos"
|
||||
xcert "github.com/certimate-go/certimate/pkg/utils/cert"
|
||||
@ -196,12 +196,12 @@ func (s *CertificateService) RevokeCertificate(ctx context.Context, req *dtos.Ce
|
||||
return nil, fmt.Errorf("failed to revoke certificate: could not find acme account: %w", err)
|
||||
}
|
||||
|
||||
legoClient, err := certapply.NewACMEClientWithAccount(acmeAccount)
|
||||
legoClient, err := certacme.NewACMEClientWithAccount(acmeAccount)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to revoke certificate: could not initialize acme config: %w", err)
|
||||
}
|
||||
|
||||
revokeReq := &certapply.RevokeCertificateRequest{
|
||||
revokeReq := &certacme.RevokeCertificateRequest{
|
||||
Certificate: certificate.Certificate,
|
||||
}
|
||||
_, err = legoClient.RevokeCertificate(ctx, revokeReq)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package certdeploy
|
||||
package certmgmt
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
@ -1,11 +1,11 @@
|
||||
package certdeploy
|
||||
package certmgmt
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/certimate-go/certimate/internal/certdeploy/deployers"
|
||||
"github.com/certimate-go/certimate/internal/certmgmt/deployers"
|
||||
"github.com/certimate-go/certimate/internal/domain"
|
||||
)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package deployers
|
||||
package deployers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user