add upload certificate node

This commit is contained in:
Yoan.liu
2025-01-21 08:02:46 +08:00
parent 6bdcfaaef0
commit 1039591677
14 changed files with 556 additions and 0 deletions

View File

@@ -12,6 +12,8 @@ import (
type certificateService interface {
ArchiveFile(ctx context.Context, req *dtos.CertificateArchiveFileReq) ([]byte, error)
ValidateCertificate(ctx context.Context, req *dtos.CertificateValidateCertificateReq) (*dtos.CertificateValidateCertificateResp, error)
ValidatePrivateKey(ctx context.Context, req *dtos.CertificateValidatePrivateKeyReq) error
}
type CertificateHandler struct {
@@ -25,6 +27,32 @@ func NewCertificateHandler(router *router.RouterGroup[*core.RequestEvent], servi
group := router.Group("/certificates")
group.POST("/{id}/archive", handler.run)
group.POST("/validate/certificate", handler.validateCertificate)
group.POST("/validate/private-key", handler.validatePrivateKey)
}
func (handler *CertificateHandler) validateCertificate(e *core.RequestEvent) error {
req := &dtos.CertificateValidateCertificateReq{}
if err := e.BindBody(req); err != nil {
return resp.Err(e, err)
}
if rs, err := handler.service.ValidateCertificate(e.Request.Context(), req); err != nil {
return resp.Err(e, err)
} else {
return resp.Ok(e, rs)
}
}
func (handler *CertificateHandler) validatePrivateKey(e *core.RequestEvent) error {
req := &dtos.CertificateValidatePrivateKeyReq{}
if err := e.BindBody(req); err != nil {
return resp.Err(e, err)
}
if err := handler.service.ValidatePrivateKey(e.Request.Context(), req); err != nil {
return resp.Err(e, err)
} else {
return resp.Ok(e, nil)
}
}
func (handler *CertificateHandler) run(e *core.RequestEvent) error {