mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-14 00:19:51 +00:00
refactor: adjust project structure
This commit is contained in:
parent
1e3c4881d0
commit
1dee14e32d
@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
"github.com/usual2970/certimate/internal/domain"
|
"github.com/usual2970/certimate/internal/domain"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
|
uploaderAliyunCas "github.com/usual2970/certimate/internal/pkg/core/uploader/providers/aliyun-cas"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AliyunALBDeployer struct {
|
type AliyunALBDeployer struct {
|
||||||
@ -38,7 +39,7 @@ func NewAliyunALBDeployer(option *DeployerOption) (Deployer, error) {
|
|||||||
return nil, xerrors.Wrap(err, "failed to create sdk client")
|
return nil, xerrors.Wrap(err, "failed to create sdk client")
|
||||||
}
|
}
|
||||||
|
|
||||||
uploader, err := uploader.NewAliyunCASUploader(&uploader.AliyunCASUploaderConfig{
|
uploader, err := uploaderAliyunCas.New(&uploaderAliyunCas.AliyunCASUploaderConfig{
|
||||||
AccessKeyId: access.AccessKeyId,
|
AccessKeyId: access.AccessKeyId,
|
||||||
AccessKeySecret: access.AccessKeySecret,
|
AccessKeySecret: access.AccessKeySecret,
|
||||||
Region: option.DeployConfig.GetConfigAsString("region"),
|
Region: option.DeployConfig.GetConfigAsString("region"),
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
"github.com/usual2970/certimate/internal/domain"
|
"github.com/usual2970/certimate/internal/domain"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
|
uploaderAliyunSlb "github.com/usual2970/certimate/internal/pkg/core/uploader/providers/aliyun-slb"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AliyunCLBDeployer struct {
|
type AliyunCLBDeployer struct {
|
||||||
@ -38,7 +39,7 @@ func NewAliyunCLBDeployer(option *DeployerOption) (Deployer, error) {
|
|||||||
return nil, xerrors.Wrap(err, "failed to create sdk client")
|
return nil, xerrors.Wrap(err, "failed to create sdk client")
|
||||||
}
|
}
|
||||||
|
|
||||||
uploader, err := uploader.NewAliyunSLBUploader(&uploader.AliyunSLBUploaderConfig{
|
uploader, err := uploaderAliyunSlb.New(&uploaderAliyunSlb.AliyunSLBUploaderConfig{
|
||||||
AccessKeyId: access.AccessKeyId,
|
AccessKeyId: access.AccessKeyId,
|
||||||
AccessKeySecret: access.AccessKeySecret,
|
AccessKeySecret: access.AccessKeySecret,
|
||||||
Region: option.DeployConfig.GetConfigAsString("region"),
|
Region: option.DeployConfig.GetConfigAsString("region"),
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
"github.com/usual2970/certimate/internal/domain"
|
"github.com/usual2970/certimate/internal/domain"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
|
uploaderAliyunCas "github.com/usual2970/certimate/internal/pkg/core/uploader/providers/aliyun-cas"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AliyunNLBDeployer struct {
|
type AliyunNLBDeployer struct {
|
||||||
@ -38,7 +39,7 @@ func NewAliyunNLBDeployer(option *DeployerOption) (Deployer, error) {
|
|||||||
return nil, xerrors.Wrap(err, "failed to create sdk client")
|
return nil, xerrors.Wrap(err, "failed to create sdk client")
|
||||||
}
|
}
|
||||||
|
|
||||||
uploader, err := uploader.NewAliyunCASUploader(&uploader.AliyunCASUploaderConfig{
|
uploader, err := uploaderAliyunCas.New(&uploaderAliyunCas.AliyunCASUploaderConfig{
|
||||||
AccessKeyId: access.AccessKeyId,
|
AccessKeyId: access.AccessKeyId,
|
||||||
AccessKeySecret: access.AccessKeySecret,
|
AccessKeySecret: access.AccessKeySecret,
|
||||||
Region: option.DeployConfig.GetConfigAsString("region"),
|
Region: option.DeployConfig.GetConfigAsString("region"),
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
"github.com/usual2970/certimate/internal/domain"
|
"github.com/usual2970/certimate/internal/domain"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
|
uploaderHcScm "github.com/usual2970/certimate/internal/pkg/core/uploader/providers/huaweicloud-scm"
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/cast"
|
"github.com/usual2970/certimate/internal/pkg/utils/cast"
|
||||||
hcCdnEx "github.com/usual2970/certimate/internal/pkg/vendors/huaweicloud-cdn-sdk"
|
hcCdnEx "github.com/usual2970/certimate/internal/pkg/vendors/huaweicloud-cdn-sdk"
|
||||||
)
|
)
|
||||||
@ -40,7 +41,7 @@ func NewHuaweiCloudCDNDeployer(option *DeployerOption) (Deployer, error) {
|
|||||||
return nil, xerrors.Wrap(err, "failed to create sdk client")
|
return nil, xerrors.Wrap(err, "failed to create sdk client")
|
||||||
}
|
}
|
||||||
|
|
||||||
uploader, err := uploader.NewHuaweiCloudSCMUploader(&uploader.HuaweiCloudSCMUploaderConfig{
|
uploader, err := uploaderHcScm.New(&uploaderHcScm.HuaweiCloudSCMUploaderConfig{
|
||||||
AccessKeyId: access.AccessKeyId,
|
AccessKeyId: access.AccessKeyId,
|
||||||
SecretAccessKey: access.SecretAccessKey,
|
SecretAccessKey: access.SecretAccessKey,
|
||||||
Region: "",
|
Region: "",
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/usual2970/certimate/internal/domain"
|
"github.com/usual2970/certimate/internal/domain"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
|
uploaderHcElb "github.com/usual2970/certimate/internal/pkg/core/uploader/providers/huaweicloud-elb"
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/cast"
|
"github.com/usual2970/certimate/internal/pkg/utils/cast"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ func NewHuaweiCloudELBDeployer(option *DeployerOption) (Deployer, error) {
|
|||||||
return nil, xerrors.Wrap(err, "failed to create sdk client")
|
return nil, xerrors.Wrap(err, "failed to create sdk client")
|
||||||
}
|
}
|
||||||
|
|
||||||
uploader, err := uploader.NewHuaweiCloudELBUploader(&uploader.HuaweiCloudELBUploaderConfig{
|
uploader, err := uploaderHcElb.New(&uploaderHcElb.HuaweiCloudELBUploaderConfig{
|
||||||
AccessKeyId: access.AccessKeyId,
|
AccessKeyId: access.AccessKeyId,
|
||||||
SecretAccessKey: access.SecretAccessKey,
|
SecretAccessKey: access.SecretAccessKey,
|
||||||
Region: option.DeployConfig.GetConfigAsString("region"),
|
Region: option.DeployConfig.GetConfigAsString("region"),
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/usual2970/certimate/internal/domain"
|
"github.com/usual2970/certimate/internal/domain"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
|
uploaderQiniu "github.com/usual2970/certimate/internal/pkg/core/uploader/providers/qiniu-sslcert"
|
||||||
qiniuEx "github.com/usual2970/certimate/internal/pkg/vendors/qiniu-sdk"
|
qiniuEx "github.com/usual2970/certimate/internal/pkg/vendors/qiniu-sdk"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ func NewQiniuCDNDeployer(option *DeployerOption) (Deployer, error) {
|
|||||||
return nil, xerrors.Wrap(err, "failed to create sdk client")
|
return nil, xerrors.Wrap(err, "failed to create sdk client")
|
||||||
}
|
}
|
||||||
|
|
||||||
uploader, err := uploader.NewQiniuSSLCertUploader(&uploader.QiniuSSLCertUploaderConfig{
|
uploader, err := uploaderQiniu.New(&uploaderQiniu.QiniuSSLCertUploaderConfig{
|
||||||
AccessKey: access.AccessKey,
|
AccessKey: access.AccessKey,
|
||||||
SecretKey: access.SecretKey,
|
SecretKey: access.SecretKey,
|
||||||
})
|
})
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
|
|
||||||
"github.com/usual2970/certimate/internal/domain"
|
"github.com/usual2970/certimate/internal/domain"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
|
uploaderTcSsl "github.com/usual2970/certimate/internal/pkg/core/uploader/providers/tencentcloud-ssl"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TencentCDNDeployer struct {
|
type TencentCDNDeployer struct {
|
||||||
@ -44,7 +45,7 @@ func NewTencentCDNDeployer(option *DeployerOption) (Deployer, error) {
|
|||||||
return nil, xerrors.Wrap(err, "failed to create sdk clients")
|
return nil, xerrors.Wrap(err, "failed to create sdk clients")
|
||||||
}
|
}
|
||||||
|
|
||||||
uploader, err := uploader.NewTencentCloudSSLUploader(&uploader.TencentCloudSSLUploaderConfig{
|
uploader, err := uploaderTcSsl.New(&uploaderTcSsl.TencentCloudSSLUploaderConfig{
|
||||||
SecretId: access.SecretId,
|
SecretId: access.SecretId,
|
||||||
SecretKey: access.SecretKey,
|
SecretKey: access.SecretKey,
|
||||||
})
|
})
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
|
|
||||||
"github.com/usual2970/certimate/internal/domain"
|
"github.com/usual2970/certimate/internal/domain"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
|
uploaderTcSsl "github.com/usual2970/certimate/internal/pkg/core/uploader/providers/tencentcloud-ssl"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TencentCLBDeployer struct {
|
type TencentCLBDeployer struct {
|
||||||
@ -44,7 +45,7 @@ func NewTencentCLBDeployer(option *DeployerOption) (Deployer, error) {
|
|||||||
return nil, xerrors.Wrap(err, "failed to create sdk clients")
|
return nil, xerrors.Wrap(err, "failed to create sdk clients")
|
||||||
}
|
}
|
||||||
|
|
||||||
uploader, err := uploader.NewTencentCloudSSLUploader(&uploader.TencentCloudSSLUploaderConfig{
|
uploader, err := uploaderTcSsl.New(&uploaderTcSsl.TencentCloudSSLUploaderConfig{
|
||||||
SecretId: access.SecretId,
|
SecretId: access.SecretId,
|
||||||
SecretKey: access.SecretKey,
|
SecretKey: access.SecretKey,
|
||||||
})
|
})
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
"github.com/usual2970/certimate/internal/domain"
|
"github.com/usual2970/certimate/internal/domain"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
|
uploaderTcSsl "github.com/usual2970/certimate/internal/pkg/core/uploader/providers/tencentcloud-ssl"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TencentCOSDeployer struct {
|
type TencentCOSDeployer struct {
|
||||||
@ -37,7 +38,7 @@ func NewTencentCOSDeployer(option *DeployerOption) (Deployer, error) {
|
|||||||
return nil, xerrors.Wrap(err, "failed to create sdk clients")
|
return nil, xerrors.Wrap(err, "failed to create sdk clients")
|
||||||
}
|
}
|
||||||
|
|
||||||
uploader, err := uploader.NewTencentCloudSSLUploader(&uploader.TencentCloudSSLUploaderConfig{
|
uploader, err := uploaderTcSsl.New(&uploaderTcSsl.TencentCloudSSLUploaderConfig{
|
||||||
SecretId: access.SecretId,
|
SecretId: access.SecretId,
|
||||||
SecretKey: access.SecretKey,
|
SecretKey: access.SecretKey,
|
||||||
})
|
})
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
|
|
||||||
"github.com/usual2970/certimate/internal/domain"
|
"github.com/usual2970/certimate/internal/domain"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
|
uploaderTcSsl "github.com/usual2970/certimate/internal/pkg/core/uploader/providers/tencentcloud-ssl"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TencentECDNDeployer struct {
|
type TencentECDNDeployer struct {
|
||||||
@ -43,7 +44,7 @@ func NewTencentECDNDeployer(option *DeployerOption) (Deployer, error) {
|
|||||||
return nil, xerrors.Wrap(err, "failed to create sdk clients")
|
return nil, xerrors.Wrap(err, "failed to create sdk clients")
|
||||||
}
|
}
|
||||||
|
|
||||||
uploader, err := uploader.NewTencentCloudSSLUploader(&uploader.TencentCloudSSLUploaderConfig{
|
uploader, err := uploaderTcSsl.New(&uploaderTcSsl.TencentCloudSSLUploaderConfig{
|
||||||
SecretId: access.SecretId,
|
SecretId: access.SecretId,
|
||||||
SecretKey: access.SecretKey,
|
SecretKey: access.SecretKey,
|
||||||
})
|
})
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
|
|
||||||
"github.com/usual2970/certimate/internal/domain"
|
"github.com/usual2970/certimate/internal/domain"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
|
uploaderTcSsl "github.com/usual2970/certimate/internal/pkg/core/uploader/providers/tencentcloud-ssl"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TencentTEODeployer struct {
|
type TencentTEODeployer struct {
|
||||||
@ -43,7 +44,7 @@ func NewTencentTEODeployer(option *DeployerOption) (Deployer, error) {
|
|||||||
return nil, xerrors.Wrap(err, "failed to create sdk clients")
|
return nil, xerrors.Wrap(err, "failed to create sdk clients")
|
||||||
}
|
}
|
||||||
|
|
||||||
uploader, err := uploader.NewTencentCloudSSLUploader(&uploader.TencentCloudSSLUploaderConfig{
|
uploader, err := uploaderTcSsl.New(&uploaderTcSsl.TencentCloudSSLUploaderConfig{
|
||||||
SecretId: access.SecretId,
|
SecretId: access.SecretId,
|
||||||
SecretKey: access.SecretKey,
|
SecretKey: access.SecretKey,
|
||||||
})
|
})
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package uploader
|
package aliyuncas
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/alibabacloud-go/tea/tea"
|
"github.com/alibabacloud-go/tea/tea"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/x509"
|
"github.com/usual2970/certimate/internal/pkg/utils/x509"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -25,7 +26,7 @@ type AliyunCASUploader struct {
|
|||||||
sdkClient *aliyunCas.Client
|
sdkClient *aliyunCas.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAliyunCASUploader(config *AliyunCASUploaderConfig) (Uploader, error) {
|
func New(config *AliyunCASUploaderConfig) (*AliyunCASUploader, error) {
|
||||||
client, err := (&AliyunCASUploader{}).createSdkClient(
|
client, err := (&AliyunCASUploader{}).createSdkClient(
|
||||||
config.AccessKeyId,
|
config.AccessKeyId,
|
||||||
config.AccessKeySecret,
|
config.AccessKeySecret,
|
||||||
@ -41,7 +42,7 @@ func NewAliyunCASUploader(config *AliyunCASUploaderConfig) (Uploader, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *AliyunCASUploader) Upload(ctx context.Context, certPem string, privkeyPem string) (res *UploadResult, err error) {
|
func (u *AliyunCASUploader) Upload(ctx context.Context, certPem string, privkeyPem string) (res *uploader.UploadResult, err error) {
|
||||||
// 解析证书内容
|
// 解析证书内容
|
||||||
certX509, err := x509.ParseCertificateFromPEM(certPem)
|
certX509, err := x509.ParseCertificateFromPEM(certPem)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -89,7 +90,7 @@ func (u *AliyunCASUploader) Upload(ctx context.Context, certPem string, privkeyP
|
|||||||
|
|
||||||
// 如果已存在相同证书,直接返回已有的证书信息
|
// 如果已存在相同证书,直接返回已有的证书信息
|
||||||
if isSameCert {
|
if isSameCert {
|
||||||
return &UploadResult{
|
return &uploader.UploadResult{
|
||||||
CertId: fmt.Sprintf("%d", tea.Int64Value(certDetail.CertificateId)),
|
CertId: fmt.Sprintf("%d", tea.Int64Value(certDetail.CertificateId)),
|
||||||
CertName: *certDetail.Name,
|
CertName: *certDetail.Name,
|
||||||
}, nil
|
}, nil
|
||||||
@ -125,7 +126,7 @@ func (u *AliyunCASUploader) Upload(ctx context.Context, certPem string, privkeyP
|
|||||||
}
|
}
|
||||||
|
|
||||||
certId = fmt.Sprintf("%d", tea.Int64Value(uploadUserCertificateResp.Body.CertId))
|
certId = fmt.Sprintf("%d", tea.Int64Value(uploadUserCertificateResp.Body.CertId))
|
||||||
return &UploadResult{
|
return &uploader.UploadResult{
|
||||||
CertId: certId,
|
CertId: certId,
|
||||||
CertName: certName,
|
CertName: certName,
|
||||||
}, nil
|
}, nil
|
@ -1,4 +1,4 @@
|
|||||||
package uploader
|
package aliyunslb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/alibabacloud-go/tea/tea"
|
"github.com/alibabacloud-go/tea/tea"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/x509"
|
"github.com/usual2970/certimate/internal/pkg/utils/x509"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -27,7 +28,7 @@ type AliyunSLBUploader struct {
|
|||||||
sdkClient *aliyunSlb.Client
|
sdkClient *aliyunSlb.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAliyunSLBUploader(config *AliyunSLBUploaderConfig) (Uploader, error) {
|
func New(config *AliyunSLBUploaderConfig) (*AliyunSLBUploader, error) {
|
||||||
client, err := (&AliyunSLBUploader{}).createSdkClient(
|
client, err := (&AliyunSLBUploader{}).createSdkClient(
|
||||||
config.AccessKeyId,
|
config.AccessKeyId,
|
||||||
config.AccessKeySecret,
|
config.AccessKeySecret,
|
||||||
@ -43,7 +44,7 @@ func NewAliyunSLBUploader(config *AliyunSLBUploaderConfig) (Uploader, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *AliyunSLBUploader) Upload(ctx context.Context, certPem string, privkeyPem string) (res *UploadResult, err error) {
|
func (u *AliyunSLBUploader) Upload(ctx context.Context, certPem string, privkeyPem string) (res *uploader.UploadResult, err error) {
|
||||||
// 解析证书内容
|
// 解析证书内容
|
||||||
certX509, err := x509.ParseCertificateFromPEM(certPem)
|
certX509, err := x509.ParseCertificateFromPEM(certPem)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -69,7 +70,7 @@ func (u *AliyunSLBUploader) Upload(ctx context.Context, certPem string, privkeyP
|
|||||||
strings.EqualFold(certX509.Subject.CommonName, *certDetail.CommonName)
|
strings.EqualFold(certX509.Subject.CommonName, *certDetail.CommonName)
|
||||||
// 如果已存在相同证书,直接返回已有的证书信息
|
// 如果已存在相同证书,直接返回已有的证书信息
|
||||||
if isSameCert {
|
if isSameCert {
|
||||||
return &UploadResult{
|
return &uploader.UploadResult{
|
||||||
CertId: *certDetail.ServerCertificateId,
|
CertId: *certDetail.ServerCertificateId,
|
||||||
CertName: *certDetail.ServerCertificateName,
|
CertName: *certDetail.ServerCertificateName,
|
||||||
}, nil
|
}, nil
|
||||||
@ -95,7 +96,7 @@ func (u *AliyunSLBUploader) Upload(ctx context.Context, certPem string, privkeyP
|
|||||||
}
|
}
|
||||||
|
|
||||||
certId = *uploadServerCertificateResp.Body.ServerCertificateId
|
certId = *uploadServerCertificateResp.Body.ServerCertificateId
|
||||||
return &UploadResult{
|
return &uploader.UploadResult{
|
||||||
CertId: certId,
|
CertId: certId,
|
||||||
CertName: certName,
|
CertName: certName,
|
||||||
}, nil
|
}, nil
|
@ -1,4 +1,4 @@
|
|||||||
package uploader
|
package huaweicloudelb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -16,6 +16,7 @@ import (
|
|||||||
hcIamRegion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iam/v3/region"
|
hcIamRegion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iam/v3/region"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/cast"
|
"github.com/usual2970/certimate/internal/pkg/utils/cast"
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/x509"
|
"github.com/usual2970/certimate/internal/pkg/utils/x509"
|
||||||
)
|
)
|
||||||
@ -31,7 +32,7 @@ type HuaweiCloudELBUploader struct {
|
|||||||
sdkClient *hcElb.ElbClient
|
sdkClient *hcElb.ElbClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHuaweiCloudELBUploader(config *HuaweiCloudELBUploaderConfig) (Uploader, error) {
|
func New(config *HuaweiCloudELBUploaderConfig) (*HuaweiCloudELBUploader, error) {
|
||||||
client, err := (&HuaweiCloudELBUploader{}).createSdkClient(
|
client, err := (&HuaweiCloudELBUploader{}).createSdkClient(
|
||||||
config.AccessKeyId,
|
config.AccessKeyId,
|
||||||
config.SecretAccessKey,
|
config.SecretAccessKey,
|
||||||
@ -47,7 +48,7 @@ func NewHuaweiCloudELBUploader(config *HuaweiCloudELBUploaderConfig) (Uploader,
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *HuaweiCloudELBUploader) Upload(ctx context.Context, certPem string, privkeyPem string) (res *UploadResult, err error) {
|
func (u *HuaweiCloudELBUploader) Upload(ctx context.Context, certPem string, privkeyPem string) (res *uploader.UploadResult, err error) {
|
||||||
// 解析证书内容
|
// 解析证书内容
|
||||||
newCert, err := x509.ParseCertificateFromPEM(certPem)
|
newCert, err := x509.ParseCertificateFromPEM(certPem)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -86,7 +87,7 @@ func (u *HuaweiCloudELBUploader) Upload(ctx context.Context, certPem string, pri
|
|||||||
|
|
||||||
// 如果已存在相同证书,直接返回已有的证书信息
|
// 如果已存在相同证书,直接返回已有的证书信息
|
||||||
if isSameCert {
|
if isSameCert {
|
||||||
return &UploadResult{
|
return &uploader.UploadResult{
|
||||||
CertId: certDetail.Id,
|
CertId: certDetail.Id,
|
||||||
CertName: certDetail.Name,
|
CertName: certDetail.Name,
|
||||||
}, nil
|
}, nil
|
||||||
@ -135,7 +136,7 @@ func (u *HuaweiCloudELBUploader) Upload(ctx context.Context, certPem string, pri
|
|||||||
|
|
||||||
certId = createCertificateResp.Certificate.Id
|
certId = createCertificateResp.Certificate.Id
|
||||||
certName = createCertificateResp.Certificate.Name
|
certName = createCertificateResp.Certificate.Name
|
||||||
return &UploadResult{
|
return &uploader.UploadResult{
|
||||||
CertId: certId,
|
CertId: certId,
|
||||||
CertName: certName,
|
CertName: certName,
|
||||||
}, nil
|
}, nil
|
@ -1,4 +1,4 @@
|
|||||||
package uploader
|
package huaweicloudscm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -11,6 +11,7 @@ import (
|
|||||||
hcScmRegion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/scm/v3/region"
|
hcScmRegion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/scm/v3/region"
|
||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/cast"
|
"github.com/usual2970/certimate/internal/pkg/utils/cast"
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/x509"
|
"github.com/usual2970/certimate/internal/pkg/utils/x509"
|
||||||
)
|
)
|
||||||
@ -26,7 +27,7 @@ type HuaweiCloudSCMUploader struct {
|
|||||||
sdkClient *hcScm.ScmClient
|
sdkClient *hcScm.ScmClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHuaweiCloudSCMUploader(config *HuaweiCloudSCMUploaderConfig) (Uploader, error) {
|
func New(config *HuaweiCloudSCMUploaderConfig) (*HuaweiCloudSCMUploader, error) {
|
||||||
client, err := (&HuaweiCloudSCMUploader{}).createSdkClient(
|
client, err := (&HuaweiCloudSCMUploader{}).createSdkClient(
|
||||||
config.AccessKeyId,
|
config.AccessKeyId,
|
||||||
config.SecretAccessKey,
|
config.SecretAccessKey,
|
||||||
@ -42,7 +43,7 @@ func NewHuaweiCloudSCMUploader(config *HuaweiCloudSCMUploaderConfig) (Uploader,
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *HuaweiCloudSCMUploader) Upload(ctx context.Context, certPem string, privkeyPem string) (res *UploadResult, err error) {
|
func (u *HuaweiCloudSCMUploader) Upload(ctx context.Context, certPem string, privkeyPem string) (res *uploader.UploadResult, err error) {
|
||||||
// 解析证书内容
|
// 解析证书内容
|
||||||
certX509, err := x509.ParseCertificateFromPEM(certPem)
|
certX509, err := x509.ParseCertificateFromPEM(certPem)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -94,7 +95,7 @@ func (u *HuaweiCloudSCMUploader) Upload(ctx context.Context, certPem string, pri
|
|||||||
|
|
||||||
// 如果已存在相同证书,直接返回已有的证书信息
|
// 如果已存在相同证书,直接返回已有的证书信息
|
||||||
if isSameCert {
|
if isSameCert {
|
||||||
return &UploadResult{
|
return &uploader.UploadResult{
|
||||||
CertId: certDetail.Id,
|
CertId: certDetail.Id,
|
||||||
CertName: certDetail.Name,
|
CertName: certDetail.Name,
|
||||||
}, nil
|
}, nil
|
||||||
@ -132,7 +133,7 @@ func (u *HuaweiCloudSCMUploader) Upload(ctx context.Context, certPem string, pri
|
|||||||
}
|
}
|
||||||
|
|
||||||
certId = *importCertificateResp.CertificateId
|
certId = *importCertificateResp.CertificateId
|
||||||
return &UploadResult{
|
return &uploader.UploadResult{
|
||||||
CertId: certId,
|
CertId: certId,
|
||||||
CertName: certName,
|
CertName: certName,
|
||||||
}, nil
|
}, nil
|
@ -1,4 +1,4 @@
|
|||||||
package uploader
|
package qiniusslcert
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -8,6 +8,7 @@ import (
|
|||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
"github.com/qiniu/go-sdk/v7/auth"
|
"github.com/qiniu/go-sdk/v7/auth"
|
||||||
|
|
||||||
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/x509"
|
"github.com/usual2970/certimate/internal/pkg/utils/x509"
|
||||||
qiniuEx "github.com/usual2970/certimate/internal/pkg/vendors/qiniu-sdk"
|
qiniuEx "github.com/usual2970/certimate/internal/pkg/vendors/qiniu-sdk"
|
||||||
)
|
)
|
||||||
@ -22,7 +23,7 @@ type QiniuSSLCertUploader struct {
|
|||||||
sdkClient *qiniuEx.Client
|
sdkClient *qiniuEx.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewQiniuSSLCertUploader(config *QiniuSSLCertUploaderConfig) (Uploader, error) {
|
func New(config *QiniuSSLCertUploaderConfig) (*QiniuSSLCertUploader, error) {
|
||||||
client, err := (&QiniuSSLCertUploader{}).createSdkClient(
|
client, err := (&QiniuSSLCertUploader{}).createSdkClient(
|
||||||
config.AccessKey,
|
config.AccessKey,
|
||||||
config.SecretKey,
|
config.SecretKey,
|
||||||
@ -37,7 +38,7 @@ func NewQiniuSSLCertUploader(config *QiniuSSLCertUploaderConfig) (Uploader, erro
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *QiniuSSLCertUploader) Upload(ctx context.Context, certPem string, privkeyPem string) (res *UploadResult, err error) {
|
func (u *QiniuSSLCertUploader) Upload(ctx context.Context, certPem string, privkeyPem string) (res *uploader.UploadResult, err error) {
|
||||||
// 解析证书内容
|
// 解析证书内容
|
||||||
certX509, err := x509.ParseCertificateFromPEM(certPem)
|
certX509, err := x509.ParseCertificateFromPEM(certPem)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -56,7 +57,7 @@ func (u *QiniuSSLCertUploader) Upload(ctx context.Context, certPem string, privk
|
|||||||
}
|
}
|
||||||
|
|
||||||
certId = uploadSslCertResp.CertID
|
certId = uploadSslCertResp.CertID
|
||||||
return &UploadResult{
|
return &uploader.UploadResult{
|
||||||
CertId: certId,
|
CertId: certId,
|
||||||
CertName: certName,
|
CertName: certName,
|
||||||
}, nil
|
}, nil
|
@ -1,4 +1,4 @@
|
|||||||
package uploader
|
package tencentcloudssl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -7,6 +7,8 @@ import (
|
|||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||||
tcSsl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl/v20191205"
|
tcSsl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl/v20191205"
|
||||||
|
|
||||||
|
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TencentCloudSSLUploaderConfig struct {
|
type TencentCloudSSLUploaderConfig struct {
|
||||||
@ -19,7 +21,7 @@ type TencentCloudSSLUploader struct {
|
|||||||
sdkClient *tcSsl.Client
|
sdkClient *tcSsl.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTencentCloudSSLUploader(config *TencentCloudSSLUploaderConfig) (Uploader, error) {
|
func New(config *TencentCloudSSLUploaderConfig) (*TencentCloudSSLUploader, error) {
|
||||||
client, err := (&TencentCloudSSLUploader{}).createSdkClient(
|
client, err := (&TencentCloudSSLUploader{}).createSdkClient(
|
||||||
config.SecretId,
|
config.SecretId,
|
||||||
config.SecretKey,
|
config.SecretKey,
|
||||||
@ -34,7 +36,7 @@ func NewTencentCloudSSLUploader(config *TencentCloudSSLUploaderConfig) (Uploader
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *TencentCloudSSLUploader) Upload(ctx context.Context, certPem string, privkeyPem string) (res *UploadResult, err error) {
|
func (u *TencentCloudSSLUploader) Upload(ctx context.Context, certPem string, privkeyPem string) (res *uploader.UploadResult, err error) {
|
||||||
// 上传新证书
|
// 上传新证书
|
||||||
// REF: https://cloud.tencent.com/document/product/400/41665
|
// REF: https://cloud.tencent.com/document/product/400/41665
|
||||||
uploadCertificateReq := tcSsl.NewUploadCertificateRequest()
|
uploadCertificateReq := tcSsl.NewUploadCertificateRequest()
|
||||||
@ -46,8 +48,8 @@ func (u *TencentCloudSSLUploader) Upload(ctx context.Context, certPem string, pr
|
|||||||
return nil, xerrors.Wrap(err, "failed to execute sdk request 'ssl.UploadCertificate'")
|
return nil, xerrors.Wrap(err, "failed to execute sdk request 'ssl.UploadCertificate'")
|
||||||
}
|
}
|
||||||
|
|
||||||
certId := *describeCertificateDetailResp.Response.CertificateId
|
certId := *uploadCertificateResp.Response.CertificateId
|
||||||
return &UploadResult{
|
return &uploader.UploadResult{
|
||||||
CertId: certId,
|
CertId: certId,
|
||||||
CertName: "",
|
CertName: "",
|
||||||
}, nil
|
}, nil
|
Loading…
x
Reference in New Issue
Block a user