Files
EdgeAdmin/internal/web/actions/default/servers/certs/downloadCert.go

41 lines
1.0 KiB
Go
Raw Normal View History

2020-11-24 17:36:42 +08:00
package certs
2020-09-30 17:46:38 +08:00
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
2023-06-30 18:08:30 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
2020-09-30 17:46:38 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/sslconfigs"
"strconv"
)
type DownloadCertAction struct {
actionutils.ParentAction
}
func (this *DownloadCertAction) Init() {
this.Nav("", "", "")
}
func (this *DownloadCertAction) RunGet(params struct {
CertId int64
}) {
2023-06-30 18:08:30 +08:00
defer this.CreateLogInfo(codes.SSLCert_LogDownloadSSLCert, params.CertId)
2020-11-20 15:32:42 +08:00
certResp, err := this.RPC().SSLCertRPC().FindEnabledSSLCertConfig(this.AdminContext(), &pb.FindEnabledSSLCertConfigRequest{SslCertId: params.CertId})
2020-09-30 17:46:38 +08:00
if err != nil {
this.ErrorPage(err)
return
}
certConfig := &sslconfigs.SSLCertConfig{}
err = json.Unmarshal(certResp.SslCertJSON, certConfig)
2020-09-30 17:46:38 +08:00
if err != nil {
this.ErrorPage(err)
return
}
this.AddHeader("Content-Disposition", "attachment; filename=\"cert-"+strconv.FormatInt(params.CertId, 10)+".pem\";")
2023-08-08 14:17:16 +08:00
_, _ = this.Write(certConfig.CertData)
2020-09-30 17:46:38 +08:00
}