Merge pull request #414 from fudiwei/feat/new-workflow
feat: more providers
This commit is contained in:
@@ -8,7 +8,8 @@ import (
|
||||
"github.com/usual2970/certimate/internal/domain"
|
||||
providerACMEHttpReq "github.com/usual2970/certimate/internal/pkg/core/applicant/acme-dns-01/lego-providers/acmehttpreq"
|
||||
providerAliyun "github.com/usual2970/certimate/internal/pkg/core/applicant/acme-dns-01/lego-providers/aliyun"
|
||||
providerAWS "github.com/usual2970/certimate/internal/pkg/core/applicant/acme-dns-01/lego-providers/aws"
|
||||
providerAWSRoute53 "github.com/usual2970/certimate/internal/pkg/core/applicant/acme-dns-01/lego-providers/aws-route53"
|
||||
providerAzureDNS "github.com/usual2970/certimate/internal/pkg/core/applicant/acme-dns-01/lego-providers/azure-dns"
|
||||
providerCloudflare "github.com/usual2970/certimate/internal/pkg/core/applicant/acme-dns-01/lego-providers/cloudflare"
|
||||
providerGoDaddy "github.com/usual2970/certimate/internal/pkg/core/applicant/acme-dns-01/lego-providers/godaddy"
|
||||
providerHuaweiCloud "github.com/usual2970/certimate/internal/pkg/core/applicant/acme-dns-01/lego-providers/huaweicloud"
|
||||
@@ -65,7 +66,7 @@ func createApplicant(options *applicantOptions) (challenge.Provider, error) {
|
||||
return nil, fmt.Errorf("failed to decode provider access config: %w", err)
|
||||
}
|
||||
|
||||
applicant, err := providerAWS.NewChallengeProvider(&providerAWS.AWSApplicantConfig{
|
||||
applicant, err := providerAWSRoute53.NewChallengeProvider(&providerAWSRoute53.AWSRoute53ApplicantConfig{
|
||||
AccessKeyId: access.AccessKeyId,
|
||||
SecretAccessKey: access.SecretAccessKey,
|
||||
Region: maps.GetValueAsString(options.ProviderApplyConfig, "region"),
|
||||
@@ -75,6 +76,23 @@ func createApplicant(options *applicantOptions) (challenge.Provider, error) {
|
||||
return applicant, err
|
||||
}
|
||||
|
||||
case domain.ApplyDNSProviderTypeAzureDNS:
|
||||
{
|
||||
access := domain.AccessConfigForAzure{}
|
||||
if err := maps.Decode(options.ProviderAccessConfig, &access); err != nil {
|
||||
return nil, fmt.Errorf("failed to decode provider access config: %w", err)
|
||||
}
|
||||
|
||||
applicant, err := providerAzureDNS.NewChallengeProvider(&providerAzureDNS.AzureDNSApplicantConfig{
|
||||
TenantId: access.TenantId,
|
||||
ClientId: access.ClientId,
|
||||
ClientSecret: access.ClientSecret,
|
||||
CloudName: access.CloudName,
|
||||
PropagationTimeout: options.PropagationTimeout,
|
||||
})
|
||||
return applicant, err
|
||||
}
|
||||
|
||||
case domain.ApplyDNSProviderTypeCloudflare:
|
||||
{
|
||||
access := domain.AccessConfigForCloudflare{}
|
||||
|
||||
@@ -26,7 +26,10 @@ import (
|
||||
providerTencentCloudECDN "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/tencentcloud-ecdn"
|
||||
providerTencentCloudEO "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/tencentcloud-eo"
|
||||
providerVolcEngineCDN "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/volcengine-cdn"
|
||||
providerVolcEngineCLB "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/volcengine-clb"
|
||||
providerVolcEngineDCDN "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/volcengine-dcdn"
|
||||
providerVolcEngineLive "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/volcengine-live"
|
||||
providerVolcEngineTOS "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/volcengine-tos"
|
||||
providerWebhook "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/webhook"
|
||||
"github.com/usual2970/certimate/internal/pkg/core/logger"
|
||||
"github.com/usual2970/certimate/internal/pkg/utils/maps"
|
||||
@@ -329,7 +332,7 @@ func createDeployer(options *deployerOptions) (deployer.Deployer, logger.Logger,
|
||||
}
|
||||
}
|
||||
|
||||
case domain.DeployProviderTypeVolcEngineCDN, domain.DeployProviderTypeVolcEngineLive:
|
||||
case domain.DeployProviderTypeVolcEngineCDN, domain.DeployProviderTypeVolcEngineCLB, domain.DeployProviderTypeVolcEngineDCDN, domain.DeployProviderTypeVolcEngineLive, domain.DeployProviderTypeVolcEngineTOS:
|
||||
{
|
||||
access := domain.AccessConfigForVolcEngine{}
|
||||
if err := maps.Decode(options.ProviderAccessConfig, &access); err != nil {
|
||||
@@ -339,17 +342,45 @@ func createDeployer(options *deployerOptions) (deployer.Deployer, logger.Logger,
|
||||
switch options.Provider {
|
||||
case domain.DeployProviderTypeVolcEngineCDN:
|
||||
deployer, err := providerVolcEngineCDN.NewWithLogger(&providerVolcEngineCDN.VolcEngineCDNDeployerConfig{
|
||||
AccessKey: access.AccessKeyId,
|
||||
SecretKey: access.SecretAccessKey,
|
||||
Domain: maps.GetValueAsString(options.ProviderDeployConfig, "domain"),
|
||||
AccessKeyId: access.AccessKeyId,
|
||||
AccessKeySecret: access.SecretAccessKey,
|
||||
Domain: maps.GetValueAsString(options.ProviderDeployConfig, "domain"),
|
||||
}, logger)
|
||||
return deployer, logger, err
|
||||
|
||||
case domain.DeployProviderTypeVolcEngineCLB:
|
||||
deployer, err := providerVolcEngineCLB.NewWithLogger(&providerVolcEngineCLB.VolcEngineCLBDeployerConfig{
|
||||
AccessKeyId: access.AccessKeyId,
|
||||
AccessKeySecret: access.SecretAccessKey,
|
||||
Region: maps.GetValueAsString(options.ProviderDeployConfig, "region"),
|
||||
ResourceType: providerVolcEngineCLB.DeployResourceType(maps.GetValueAsString(options.ProviderDeployConfig, "resourceType")),
|
||||
ListenerId: maps.GetValueAsString(options.ProviderDeployConfig, "listenerId"),
|
||||
}, logger)
|
||||
return deployer, logger, err
|
||||
|
||||
case domain.DeployProviderTypeVolcEngineDCDN:
|
||||
deployer, err := providerVolcEngineDCDN.NewWithLogger(&providerVolcEngineDCDN.VolcEngineDCDNDeployerConfig{
|
||||
AccessKeyId: access.AccessKeyId,
|
||||
AccessKeySecret: access.SecretAccessKey,
|
||||
Domain: maps.GetValueAsString(options.ProviderDeployConfig, "domain"),
|
||||
}, logger)
|
||||
return deployer, logger, err
|
||||
|
||||
case domain.DeployProviderTypeVolcEngineLive:
|
||||
deployer, err := providerVolcEngineLive.NewWithLogger(&providerVolcEngineLive.VolcEngineLiveDeployerConfig{
|
||||
AccessKey: access.AccessKeyId,
|
||||
SecretKey: access.SecretAccessKey,
|
||||
Domain: maps.GetValueAsString(options.ProviderDeployConfig, "domain"),
|
||||
AccessKeyId: access.AccessKeyId,
|
||||
AccessKeySecret: access.SecretAccessKey,
|
||||
Domain: maps.GetValueAsString(options.ProviderDeployConfig, "domain"),
|
||||
}, logger)
|
||||
return deployer, logger, err
|
||||
|
||||
case domain.DeployProviderTypeVolcEngineTOS:
|
||||
deployer, err := providerVolcEngineTOS.NewWithLogger(&providerVolcEngineTOS.VolcEngineTOSDeployerConfig{
|
||||
AccessKeyId: access.AccessKeyId,
|
||||
AccessKeySecret: access.SecretAccessKey,
|
||||
Region: maps.GetValueAsString(options.ProviderDeployConfig, "region"),
|
||||
Bucket: maps.GetValueAsString(options.ProviderDeployConfig, "bucket"),
|
||||
Domain: maps.GetValueAsString(options.ProviderDeployConfig, "domain"),
|
||||
}, logger)
|
||||
return deployer, logger, err
|
||||
|
||||
|
||||
@@ -40,6 +40,13 @@ type AccessConfigForAWS struct {
|
||||
SecretAccessKey string `json:"secretAccessKey"`
|
||||
}
|
||||
|
||||
type AccessConfigForAzure struct {
|
||||
TenantId string `json:"tenantId"`
|
||||
ClientId string `json:"clientId"`
|
||||
ClientSecret string `json:"clientSecret"`
|
||||
CloudName string `json:"cloudName,omitempty"`
|
||||
}
|
||||
|
||||
type AccessConfigForBaiduCloud struct {
|
||||
AccessKeyId string `json:"accessKeyId"`
|
||||
SecretAccessKey string `json:"secretAccessKey"`
|
||||
|
||||
@@ -12,6 +12,7 @@ const (
|
||||
AccessProviderTypeACMEHttpReq = AccessProviderType("acmehttpreq")
|
||||
AccessProviderTypeAliyun = AccessProviderType("aliyun")
|
||||
AccessProviderTypeAWS = AccessProviderType("aws")
|
||||
AccessProviderTypeAzure = AccessProviderType("azure")
|
||||
AccessProviderTypeBaiduCloud = AccessProviderType("baiducloud")
|
||||
AccessProviderTypeBytePlus = AccessProviderType("byteplus")
|
||||
AccessProviderTypeCloudflare = AccessProviderType("cloudflare")
|
||||
@@ -45,6 +46,7 @@ const (
|
||||
ApplyDNSProviderTypeAliyunDNS = ApplyDNSProviderType("aliyun-dns")
|
||||
ApplyDNSProviderTypeAWS = ApplyDNSProviderType("aws") // 兼容旧值,等同于 [ApplyDNSProviderTypeAWSRoute53]
|
||||
ApplyDNSProviderTypeAWSRoute53 = ApplyDNSProviderType("aws-route53")
|
||||
ApplyDNSProviderTypeAzureDNS = ApplyDNSProviderType("azure-dns")
|
||||
ApplyDNSProviderTypeCloudflare = ApplyDNSProviderType("cloudflare")
|
||||
ApplyDNSProviderTypeGoDaddy = ApplyDNSProviderType("godaddy")
|
||||
ApplyDNSProviderTypeHuaweiCloud = ApplyDNSProviderType("huaweicloud") // 兼容旧值,等同于 [ApplyDNSProviderTypeHuaweiCloudDNS]
|
||||
@@ -89,6 +91,9 @@ const (
|
||||
DeployProviderTypeTencentCloudECDN = DeployProviderType("tencentcloud-ecdn")
|
||||
DeployProviderTypeTencentCloudEO = DeployProviderType("tencentcloud-eo")
|
||||
DeployProviderTypeVolcEngineCDN = DeployProviderType("volcengine-cdn")
|
||||
DeployProviderTypeVolcEngineCLB = DeployProviderType("volcengine-clb")
|
||||
DeployProviderTypeVolcEngineDCDN = DeployProviderType("volcengine-dcdn")
|
||||
DeployProviderTypeVolcEngineLive = DeployProviderType("volcengine-live")
|
||||
DeployProviderTypeVolcEngineTOS = DeployProviderType("volcengine-tos")
|
||||
DeployProviderTypeWebhook = DeployProviderType("webhook")
|
||||
)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package aws
|
||||
package awsroute53
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/go-acme/lego/v4/providers/dns/route53"
|
||||
)
|
||||
|
||||
type AWSApplicantConfig struct {
|
||||
type AWSRoute53ApplicantConfig struct {
|
||||
AccessKeyId string `json:"accessKeyId"`
|
||||
SecretAccessKey string `json:"secretAccessKey"`
|
||||
Region string `json:"region"`
|
||||
@@ -16,7 +16,7 @@ type AWSApplicantConfig struct {
|
||||
PropagationTimeout int32 `json:"propagationTimeout,omitempty"`
|
||||
}
|
||||
|
||||
func NewChallengeProvider(config *AWSApplicantConfig) (challenge.Provider, error) {
|
||||
func NewChallengeProvider(config *AWSRoute53ApplicantConfig) (challenge.Provider, error) {
|
||||
if config == nil {
|
||||
return nil, errors.New("config is nil")
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package azuredns
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
|
||||
"github.com/go-acme/lego/v4/challenge"
|
||||
"github.com/go-acme/lego/v4/providers/dns/azuredns"
|
||||
)
|
||||
|
||||
type AzureDNSApplicantConfig struct {
|
||||
TenantId string `json:"tenantId"`
|
||||
ClientId string `json:"clientId"`
|
||||
ClientSecret string `json:"clientSecret"`
|
||||
CloudName string `json:"cloudName,omitempty"`
|
||||
PropagationTimeout int32 `json:"propagationTimeout,omitempty"`
|
||||
}
|
||||
|
||||
func NewChallengeProvider(config *AzureDNSApplicantConfig) (challenge.Provider, error) {
|
||||
if config == nil {
|
||||
return nil, errors.New("config is nil")
|
||||
}
|
||||
|
||||
providerConfig := azuredns.NewDefaultConfig()
|
||||
providerConfig.TenantID = config.TenantId
|
||||
providerConfig.ClientID = config.ClientId
|
||||
providerConfig.ClientSecret = config.ClientSecret
|
||||
if config.CloudName != "" {
|
||||
switch strings.ToLower(config.CloudName) {
|
||||
case "default", "public", "cloud", "azurecloud":
|
||||
providerConfig.Environment = cloud.AzurePublic
|
||||
case "usgovernment", "azureusgovernment":
|
||||
providerConfig.Environment = cloud.AzureGovernment
|
||||
case "china", "chinacloud", "azurechina", "azurechinacloud":
|
||||
providerConfig.Environment = cloud.AzureChina
|
||||
default:
|
||||
return nil, fmt.Errorf("azuredns: unknown environment %s", config.CloudName)
|
||||
}
|
||||
}
|
||||
if config.PropagationTimeout != 0 {
|
||||
providerConfig.PropagationTimeout = time.Duration(config.PropagationTimeout) * time.Second
|
||||
}
|
||||
|
||||
provider, err := azuredns.NewDNSProviderConfig(providerConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return provider, nil
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||
providerScm "github.com/usual2970/certimate/internal/pkg/core/uploader/providers/huaweicloud-scm"
|
||||
"github.com/usual2970/certimate/internal/pkg/utils/cast"
|
||||
huaweicloudsdk "github.com/usual2970/certimate/internal/pkg/vendors/huaweicloud-cdn-sdk"
|
||||
hcCdnSdk "github.com/usual2970/certimate/internal/pkg/vendors/huaweicloud-sdk/cdn"
|
||||
)
|
||||
|
||||
type HuaweiCloudCDNDeployerConfig struct {
|
||||
@@ -32,7 +32,7 @@ type HuaweiCloudCDNDeployerConfig struct {
|
||||
type HuaweiCloudCDNDeployer struct {
|
||||
config *HuaweiCloudCDNDeployerConfig
|
||||
logger logger.Logger
|
||||
sdkClient *huaweicloudsdk.Client
|
||||
sdkClient *hcCdnSdk.Client
|
||||
sslUploader uploader.Uploader
|
||||
}
|
||||
|
||||
@@ -100,15 +100,15 @@ func (d *HuaweiCloudCDNDeployer) Deploy(ctx context.Context, certPem string, pri
|
||||
// 更新加速域名配置
|
||||
// REF: https://support.huaweicloud.com/api-cdn/UpdateDomainMultiCertificates.html
|
||||
// REF: https://support.huaweicloud.com/usermanual-cdn/cdn_01_0306.html
|
||||
updateDomainMultiCertificatesReqBodyContent := &huaweicloudsdk.UpdateDomainMultiCertificatesExRequestBodyContent{}
|
||||
updateDomainMultiCertificatesReqBodyContent := &hcCdnSdk.UpdateDomainMultiCertificatesExRequestBodyContent{}
|
||||
updateDomainMultiCertificatesReqBodyContent.DomainName = d.config.Domain
|
||||
updateDomainMultiCertificatesReqBodyContent.HttpsSwitch = 1
|
||||
updateDomainMultiCertificatesReqBodyContent.CertificateType = cast.Int32Ptr(2)
|
||||
updateDomainMultiCertificatesReqBodyContent.SCMCertificateId = cast.StringPtr(upres.CertId)
|
||||
updateDomainMultiCertificatesReqBodyContent.CertName = cast.StringPtr(upres.CertName)
|
||||
updateDomainMultiCertificatesReqBodyContent = updateDomainMultiCertificatesReqBodyContent.MergeConfig(showDomainFullConfigResp.Configs)
|
||||
updateDomainMultiCertificatesReq := &huaweicloudsdk.UpdateDomainMultiCertificatesExRequest{
|
||||
Body: &huaweicloudsdk.UpdateDomainMultiCertificatesExRequestBody{
|
||||
updateDomainMultiCertificatesReq := &hcCdnSdk.UpdateDomainMultiCertificatesExRequest{
|
||||
Body: &hcCdnSdk.UpdateDomainMultiCertificatesExRequestBody{
|
||||
Https: updateDomainMultiCertificatesReqBodyContent,
|
||||
},
|
||||
}
|
||||
@@ -122,7 +122,7 @@ func (d *HuaweiCloudCDNDeployer) Deploy(ctx context.Context, certPem string, pri
|
||||
return &deployer.DeployResult{}, nil
|
||||
}
|
||||
|
||||
func createSdkClient(accessKeyId, secretAccessKey, region string) (*huaweicloudsdk.Client, error) {
|
||||
func createSdkClient(accessKeyId, secretAccessKey, region string) (*hcCdnSdk.Client, error) {
|
||||
if region == "" {
|
||||
region = "cn-north-1" // CDN 服务默认区域:华北一北京
|
||||
}
|
||||
@@ -148,6 +148,6 @@ func createSdkClient(accessKeyId, secretAccessKey, region string) (*huaweiclouds
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := huaweicloudsdk.NewClient(hcClient)
|
||||
client := hcCdnSdk.NewClient(hcClient)
|
||||
return client, nil
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@ import (
|
||||
)
|
||||
|
||||
type VolcEngineCDNDeployerConfig struct {
|
||||
// 火山引擎 AccessKey。
|
||||
AccessKey string `json:"accessKey"`
|
||||
// 火山引擎 SecretKey。
|
||||
SecretKey string `json:"secretKey"`
|
||||
// 火山引擎 AccessKeyId。
|
||||
AccessKeyId string `json:"accessKeyId"`
|
||||
// 火山引擎 AccessKeySecret。
|
||||
AccessKeySecret string `json:"accessKeySecret"`
|
||||
// 加速域名(支持泛域名)。
|
||||
Domain string `json:"domain"`
|
||||
}
|
||||
@@ -47,12 +47,12 @@ func NewWithLogger(config *VolcEngineCDNDeployerConfig, logger logger.Logger) (*
|
||||
}
|
||||
|
||||
client := veCdn.NewInstance()
|
||||
client.Client.SetAccessKey(config.AccessKey)
|
||||
client.Client.SetSecretKey(config.SecretKey)
|
||||
client.Client.SetAccessKey(config.AccessKeyId)
|
||||
client.Client.SetSecretKey(config.AccessKeySecret)
|
||||
|
||||
uploader, err := providerCdn.New(&providerCdn.VolcEngineCDNUploaderConfig{
|
||||
AccessKeyId: config.AccessKey,
|
||||
AccessKeySecret: config.SecretKey,
|
||||
AccessKeyId: config.AccessKeyId,
|
||||
AccessKeySecret: config.AccessKeySecret,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, xerrors.Wrap(err, "failed to create ssl uploader")
|
||||
|
||||
@@ -12,11 +12,11 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
fInputCertPath string
|
||||
fInputKeyPath string
|
||||
fAccessKey string
|
||||
fSecretKey string
|
||||
fDomain string
|
||||
fInputCertPath string
|
||||
fInputKeyPath string
|
||||
fAccessKeyId string
|
||||
fAccessKeySecret string
|
||||
fDomain string
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -24,8 +24,8 @@ func init() {
|
||||
|
||||
flag.StringVar(&fInputCertPath, argsPrefix+"INPUTCERTPATH", "", "")
|
||||
flag.StringVar(&fInputKeyPath, argsPrefix+"INPUTKEYPATH", "", "")
|
||||
flag.StringVar(&fAccessKey, argsPrefix+"ACCESSKEY", "", "")
|
||||
flag.StringVar(&fSecretKey, argsPrefix+"SECRETKEY", "", "")
|
||||
flag.StringVar(&fAccessKeyId, argsPrefix+"ACCESSKEYID", "", "")
|
||||
flag.StringVar(&fAccessKeySecret, argsPrefix+"ACCESSKEYSECRET", "", "")
|
||||
flag.StringVar(&fDomain, argsPrefix+"DOMAIN", "", "")
|
||||
}
|
||||
|
||||
@@ -35,8 +35,8 @@ Shell command to run this test:
|
||||
go test -v ./volcengine_cdn_test.go -args \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINECDN_INPUTCERTPATH="/path/to/your-input-cert.pem" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINECDN_INPUTKEYPATH="/path/to/your-input-key.pem" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINECDN_ACCESSKEY="your-access-key" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINECDN_SECRETKEY="your-secret-key" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINECDN_ACCESSKEYID="your-access-key-id" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINECDN_ACCESSKEYSECRET="your-access-key-secret" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINECDN_DOMAIN="example.com"
|
||||
*/
|
||||
func TestDeploy(t *testing.T) {
|
||||
@@ -47,15 +47,15 @@ func TestDeploy(t *testing.T) {
|
||||
"args:",
|
||||
fmt.Sprintf("INPUTCERTPATH: %v", fInputCertPath),
|
||||
fmt.Sprintf("INPUTKEYPATH: %v", fInputKeyPath),
|
||||
fmt.Sprintf("ACCESSKEY: %v", fAccessKey),
|
||||
fmt.Sprintf("SECRETKEY: %v", fSecretKey),
|
||||
fmt.Sprintf("ACCESSKEYID: %v", fAccessKeyId),
|
||||
fmt.Sprintf("ACCESSKEYSECRET: %v", fAccessKeySecret),
|
||||
fmt.Sprintf("DOMAIN: %v", fDomain),
|
||||
}, "\n"))
|
||||
|
||||
deployer, err := provider.New(&provider.VolcEngineCDNDeployerConfig{
|
||||
AccessKey: fAccessKey,
|
||||
SecretKey: fSecretKey,
|
||||
Domain: fDomain,
|
||||
AccessKeyId: fAccessKeyId,
|
||||
AccessKeySecret: fAccessKeySecret,
|
||||
Domain: fDomain,
|
||||
})
|
||||
if err != nil {
|
||||
t.Errorf("err: %+v", err)
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package volcengineclb
|
||||
|
||||
type DeployResourceType string
|
||||
|
||||
const (
|
||||
// 资源类型:部署到指定监听器。
|
||||
DEPLOY_RESOURCE_LISTENER = DeployResourceType("listener")
|
||||
)
|
||||
@@ -0,0 +1,132 @@
|
||||
package volcengineclb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
xerrors "github.com/pkg/errors"
|
||||
veClb "github.com/volcengine/volcengine-go-sdk/service/clb"
|
||||
ve "github.com/volcengine/volcengine-go-sdk/volcengine"
|
||||
veSession "github.com/volcengine/volcengine-go-sdk/volcengine/session"
|
||||
|
||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||
"github.com/usual2970/certimate/internal/pkg/core/logger"
|
||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||
providerCertCenter "github.com/usual2970/certimate/internal/pkg/core/uploader/providers/volcengine-certcenter"
|
||||
)
|
||||
|
||||
type VolcEngineCLBDeployerConfig struct {
|
||||
// 火山引擎 AccessKeyId。
|
||||
AccessKeyId string `json:"accessKeyId"`
|
||||
// 火山引擎 AccessKeySecret。
|
||||
AccessKeySecret string `json:"accessKeySecret"`
|
||||
// 火山引擎地域。
|
||||
Region string `json:"region"`
|
||||
// 部署资源类型。
|
||||
ResourceType DeployResourceType `json:"resourceType"`
|
||||
// 负载均衡监听器 ID。
|
||||
// 部署资源类型为 [DEPLOY_RESOURCE_LISTENER] 时必填。
|
||||
ListenerId string `json:"listenerId,omitempty"`
|
||||
}
|
||||
|
||||
type VolcEngineCLBDeployer struct {
|
||||
config *VolcEngineCLBDeployerConfig
|
||||
logger logger.Logger
|
||||
sdkClient *veClb.CLB
|
||||
sslUploader uploader.Uploader
|
||||
}
|
||||
|
||||
var _ deployer.Deployer = (*VolcEngineCLBDeployer)(nil)
|
||||
|
||||
func New(config *VolcEngineCLBDeployerConfig) (*VolcEngineCLBDeployer, error) {
|
||||
return NewWithLogger(config, logger.NewNilLogger())
|
||||
}
|
||||
|
||||
func NewWithLogger(config *VolcEngineCLBDeployerConfig, logger logger.Logger) (*VolcEngineCLBDeployer, error) {
|
||||
if config == nil {
|
||||
return nil, errors.New("config is nil")
|
||||
}
|
||||
|
||||
if logger == nil {
|
||||
return nil, errors.New("logger is nil")
|
||||
}
|
||||
|
||||
client, err := createSdkClient(config.AccessKeyId, config.AccessKeySecret, config.Region)
|
||||
if err != nil {
|
||||
return nil, xerrors.Wrap(err, "failed to create sdk client")
|
||||
}
|
||||
|
||||
uploader, err := providerCertCenter.New(&providerCertCenter.VolcEngineCertCenterUploaderConfig{
|
||||
AccessKeyId: config.AccessKeyId,
|
||||
AccessKeySecret: config.AccessKeySecret,
|
||||
Region: config.Region,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, xerrors.Wrap(err, "failed to create ssl uploader")
|
||||
}
|
||||
|
||||
return &VolcEngineCLBDeployer{
|
||||
logger: logger,
|
||||
config: config,
|
||||
sdkClient: client,
|
||||
sslUploader: uploader,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (d *VolcEngineCLBDeployer) Deploy(ctx context.Context, certPem string, privkeyPem string) (*deployer.DeployResult, error) {
|
||||
// 上传证书到证书中心
|
||||
upres, err := d.sslUploader.Upload(ctx, certPem, privkeyPem)
|
||||
if err != nil {
|
||||
return nil, xerrors.Wrap(err, "failed to upload certificate file")
|
||||
}
|
||||
|
||||
d.logger.Logt("certificate file uploaded", upres)
|
||||
|
||||
// 根据部署资源类型决定部署方式
|
||||
switch d.config.ResourceType {
|
||||
case DEPLOY_RESOURCE_LISTENER:
|
||||
if err := d.deployToListener(ctx, upres.CertId); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported resource type: %s", d.config.ResourceType)
|
||||
}
|
||||
|
||||
return &deployer.DeployResult{}, nil
|
||||
}
|
||||
|
||||
func (d *VolcEngineCLBDeployer) deployToListener(ctx context.Context, cloudCertId string) error {
|
||||
if d.config.ListenerId == "" {
|
||||
return errors.New("config `listenerId` is required")
|
||||
}
|
||||
|
||||
// 修改监听器
|
||||
// REF: https://www.volcengine.com/docs/6406/71775
|
||||
modifyListenerAttributesReq := &veClb.ModifyListenerAttributesInput{
|
||||
ListenerId: ve.String(d.config.ListenerId),
|
||||
CertificateSource: ve.String("cert_center"),
|
||||
CertCenterCertificateId: ve.String(cloudCertId),
|
||||
}
|
||||
modifyListenerAttributesResp, err := d.sdkClient.ModifyListenerAttributes(modifyListenerAttributesReq)
|
||||
if err != nil {
|
||||
return xerrors.Wrap(err, "failed to execute sdk request 'clb.ModifyListenerAttributes'")
|
||||
} else {
|
||||
d.logger.Logt("已修改监听器", modifyListenerAttributesResp)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func createSdkClient(accessKeyId, accessKeySecret, region string) (*veClb.CLB, error) {
|
||||
config := ve.NewConfig().WithRegion(region).WithAkSk(accessKeyId, accessKeySecret)
|
||||
|
||||
session, err := veSession.NewSession(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := veClb.New(session)
|
||||
return client, nil
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package volcengineclb_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
provider "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/volcengine-clb"
|
||||
)
|
||||
|
||||
var (
|
||||
fInputCertPath string
|
||||
fInputKeyPath string
|
||||
fAccessKeyId string
|
||||
fAccessKeySecret string
|
||||
fRegion string
|
||||
fListenerId string
|
||||
)
|
||||
|
||||
func init() {
|
||||
argsPrefix := "CERTIMATE_DEPLOYER_VOLCENGINECLB_"
|
||||
|
||||
flag.StringVar(&fInputCertPath, argsPrefix+"INPUTCERTPATH", "", "")
|
||||
flag.StringVar(&fInputKeyPath, argsPrefix+"INPUTKEYPATH", "", "")
|
||||
flag.StringVar(&fAccessKeyId, argsPrefix+"ACCESSKEYID", "", "")
|
||||
flag.StringVar(&fAccessKeySecret, argsPrefix+"ACCESSKEYSECRET", "", "")
|
||||
flag.StringVar(&fRegion, argsPrefix+"REGION", "", "")
|
||||
flag.StringVar(&fListenerId, argsPrefix+"LISTENERID", "", "")
|
||||
}
|
||||
|
||||
/*
|
||||
Shell command to run this test:
|
||||
|
||||
go test -v ./volcengine_clb_test.go -args \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINECLB_INPUTCERTPATH="/path/to/your-input-cert.pem" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINECLB_INPUTKEYPATH="/path/to/your-input-key.pem" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINECLB_ACCESSKEYID="your-access-key-id" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINECLB_ACCESSKEYSECRET="your-access-key-secret" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINECLB_REGION="cn-beijing" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINECLB_LISTENERID="cn-beijing"
|
||||
*/
|
||||
func TestDeploy(t *testing.T) {
|
||||
flag.Parse()
|
||||
|
||||
t.Run("Deploy", func(t *testing.T) {
|
||||
t.Log(strings.Join([]string{
|
||||
"args:",
|
||||
fmt.Sprintf("INPUTCERTPATH: %v", fInputCertPath),
|
||||
fmt.Sprintf("INPUTKEYPATH: %v", fInputKeyPath),
|
||||
fmt.Sprintf("ACCESSKEYID: %v", fAccessKeyId),
|
||||
fmt.Sprintf("ACCESSKEYSECRET: %v", fAccessKeySecret),
|
||||
fmt.Sprintf("REGION: %v", fRegion),
|
||||
fmt.Sprintf("LISTENERID: %v", fListenerId),
|
||||
}, "\n"))
|
||||
|
||||
deployer, err := provider.New(&provider.VolcEngineCLBDeployerConfig{
|
||||
AccessKeyId: fAccessKeyId,
|
||||
AccessKeySecret: fAccessKeySecret,
|
||||
Region: fRegion,
|
||||
ResourceType: provider.DEPLOY_RESOURCE_LISTENER,
|
||||
ListenerId: fListenerId,
|
||||
})
|
||||
if err != nil {
|
||||
t.Errorf("err: %+v", err)
|
||||
return
|
||||
}
|
||||
|
||||
fInputCertData, _ := os.ReadFile(fInputCertPath)
|
||||
fInputKeyData, _ := os.ReadFile(fInputKeyPath)
|
||||
res, err := deployer.Deploy(context.Background(), string(fInputCertData), string(fInputKeyData))
|
||||
if err != nil {
|
||||
t.Errorf("err: %+v", err)
|
||||
return
|
||||
}
|
||||
|
||||
t.Logf("ok: %v", res)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package volcenginedcdn
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
xerrors "github.com/pkg/errors"
|
||||
veDcdn "github.com/volcengine/volcengine-go-sdk/service/dcdn"
|
||||
ve "github.com/volcengine/volcengine-go-sdk/volcengine"
|
||||
veSession "github.com/volcengine/volcengine-go-sdk/volcengine/session"
|
||||
|
||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||
"github.com/usual2970/certimate/internal/pkg/core/logger"
|
||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||
providerCertCenter "github.com/usual2970/certimate/internal/pkg/core/uploader/providers/volcengine-certcenter"
|
||||
)
|
||||
|
||||
type VolcEngineDCDNDeployerConfig struct {
|
||||
// 火山引擎 AccessKeyId。
|
||||
AccessKeyId string `json:"accessKeyId"`
|
||||
// 火山引擎 AccessKeySecret。
|
||||
AccessKeySecret string `json:"accessKeySecret"`
|
||||
// 火山引擎地域。
|
||||
Region string `json:"region"`
|
||||
// 加速域名(支持泛域名)。
|
||||
Domain string `json:"domain"`
|
||||
}
|
||||
|
||||
type VolcEngineDCDNDeployer struct {
|
||||
config *VolcEngineDCDNDeployerConfig
|
||||
logger logger.Logger
|
||||
sdkClient *veDcdn.DCDN
|
||||
sslUploader uploader.Uploader
|
||||
}
|
||||
|
||||
var _ deployer.Deployer = (*VolcEngineDCDNDeployer)(nil)
|
||||
|
||||
func New(config *VolcEngineDCDNDeployerConfig) (*VolcEngineDCDNDeployer, error) {
|
||||
return NewWithLogger(config, logger.NewNilLogger())
|
||||
}
|
||||
|
||||
func NewWithLogger(config *VolcEngineDCDNDeployerConfig, logger logger.Logger) (*VolcEngineDCDNDeployer, error) {
|
||||
if config == nil {
|
||||
return nil, errors.New("config is nil")
|
||||
}
|
||||
|
||||
if logger == nil {
|
||||
return nil, errors.New("logger is nil")
|
||||
}
|
||||
|
||||
client, err := createSdkClient(config.AccessKeyId, config.AccessKeySecret, config.Region)
|
||||
if err != nil {
|
||||
return nil, xerrors.Wrap(err, "failed to create sdk client")
|
||||
}
|
||||
|
||||
uploader, err := providerCertCenter.New(&providerCertCenter.VolcEngineCertCenterUploaderConfig{
|
||||
AccessKeyId: config.AccessKeyId,
|
||||
AccessKeySecret: config.AccessKeySecret,
|
||||
Region: config.Region,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, xerrors.Wrap(err, "failed to create ssl uploader")
|
||||
}
|
||||
|
||||
return &VolcEngineDCDNDeployer{
|
||||
logger: logger,
|
||||
config: config,
|
||||
sdkClient: client,
|
||||
sslUploader: uploader,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (d *VolcEngineDCDNDeployer) Deploy(ctx context.Context, certPem string, privkeyPem string) (*deployer.DeployResult, error) {
|
||||
// 上传证书到证书中心
|
||||
upres, err := d.sslUploader.Upload(ctx, certPem, privkeyPem)
|
||||
if err != nil {
|
||||
return nil, xerrors.Wrap(err, "failed to upload certificate file")
|
||||
}
|
||||
|
||||
d.logger.Logt("certificate file uploaded", upres)
|
||||
|
||||
// "*.example.com" → ".example.com",适配火山引擎 DCDN 要求的泛域名格式
|
||||
domain := strings.TrimPrefix(d.config.Domain, "*")
|
||||
|
||||
// 绑定证书
|
||||
// REF: https://www.volcengine.com/docs/6559/1250189
|
||||
createCertBindReq := &veDcdn.CreateCertBindInput{
|
||||
CertSource: ve.String("volc"),
|
||||
CertId: ve.String(upres.CertId),
|
||||
DomainNames: ve.StringSlice([]string{domain}),
|
||||
}
|
||||
createCertBindResp, err := d.sdkClient.CreateCertBind(createCertBindReq)
|
||||
if err != nil {
|
||||
return nil, xerrors.Wrap(err, "failed to execute sdk request 'dcdn.CreateCertBind'")
|
||||
} else {
|
||||
d.logger.Logt("已绑定证书", createCertBindResp)
|
||||
}
|
||||
|
||||
return &deployer.DeployResult{}, nil
|
||||
}
|
||||
|
||||
func createSdkClient(accessKeyId, accessKeySecret, region string) (*veDcdn.DCDN, error) {
|
||||
if region == "" {
|
||||
region = "cn-beijing" // 证书中心默认区域:北京
|
||||
}
|
||||
|
||||
config := ve.NewConfig().WithRegion(region).WithAkSk(accessKeyId, accessKeySecret)
|
||||
|
||||
session, err := veSession.NewSession(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := veDcdn.New(session)
|
||||
return client, nil
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package volcenginedcdn_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
provider "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/volcengine-dcdn"
|
||||
)
|
||||
|
||||
var (
|
||||
fInputCertPath string
|
||||
fInputKeyPath string
|
||||
fAccessKeyId string
|
||||
fAccessKeySecret string
|
||||
fDomain string
|
||||
)
|
||||
|
||||
func init() {
|
||||
argsPrefix := "CERTIMATE_DEPLOYER_VOLCENGINEDCDN_"
|
||||
|
||||
flag.StringVar(&fInputCertPath, argsPrefix+"INPUTCERTPATH", "", "")
|
||||
flag.StringVar(&fInputKeyPath, argsPrefix+"INPUTKEYPATH", "", "")
|
||||
flag.StringVar(&fAccessKeyId, argsPrefix+"ACCESSKEYID", "", "")
|
||||
flag.StringVar(&fAccessKeySecret, argsPrefix+"ACCESSKEYSECRET", "", "")
|
||||
flag.StringVar(&fDomain, argsPrefix+"DOMAIN", "", "")
|
||||
}
|
||||
|
||||
/*
|
||||
Shell command to run this test:
|
||||
|
||||
go test -v ./volcengine_dcdn_test.go -args \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINEDCDN_INPUTCERTPATH="/path/to/your-input-cert.pem" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINEDCDN_INPUTKEYPATH="/path/to/your-input-key.pem" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINEDCDN_ACCESSKEYID="your-access-key-id" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINEDCDN_ACCESSKEYSECRET="your-access-key-secret" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINEDCDN_DOMAIN="example.com"
|
||||
*/
|
||||
func TestDeploy(t *testing.T) {
|
||||
flag.Parse()
|
||||
|
||||
t.Run("Deploy", func(t *testing.T) {
|
||||
t.Log(strings.Join([]string{
|
||||
"args:",
|
||||
fmt.Sprintf("INPUTCERTPATH: %v", fInputCertPath),
|
||||
fmt.Sprintf("INPUTKEYPATH: %v", fInputKeyPath),
|
||||
fmt.Sprintf("ACCESSKEYID: %v", fAccessKeyId),
|
||||
fmt.Sprintf("ACCESSKEYSECRET: %v", fAccessKeySecret),
|
||||
fmt.Sprintf("DOMAIN: %v", fDomain),
|
||||
}, "\n"))
|
||||
|
||||
deployer, err := provider.New(&provider.VolcEngineDCDNDeployerConfig{
|
||||
AccessKeyId: fAccessKeyId,
|
||||
AccessKeySecret: fAccessKeySecret,
|
||||
Domain: fDomain,
|
||||
})
|
||||
if err != nil {
|
||||
t.Errorf("err: %+v", err)
|
||||
return
|
||||
}
|
||||
|
||||
fInputCertData, _ := os.ReadFile(fInputCertPath)
|
||||
fInputKeyData, _ := os.ReadFile(fInputKeyPath)
|
||||
res, err := deployer.Deploy(context.Background(), string(fInputCertData), string(fInputKeyData))
|
||||
if err != nil {
|
||||
t.Errorf("err: %+v", err)
|
||||
return
|
||||
}
|
||||
|
||||
t.Logf("ok: %v", res)
|
||||
})
|
||||
}
|
||||
@@ -17,10 +17,10 @@ import (
|
||||
)
|
||||
|
||||
type VolcEngineLiveDeployerConfig struct {
|
||||
// 火山引擎 AccessKey。
|
||||
AccessKey string `json:"accessKey"`
|
||||
// 火山引擎 SecretKey。
|
||||
SecretKey string `json:"secretKey"`
|
||||
// 火山引擎 AccessKeyId。
|
||||
AccessKeyId string `json:"accessKeyId"`
|
||||
// 火山引擎 AccessKeySecret。
|
||||
AccessKeySecret string `json:"accessKeySecret"`
|
||||
// 加速域名(支持泛域名)。
|
||||
Domain string `json:"domain"`
|
||||
}
|
||||
@@ -48,12 +48,12 @@ func NewWithLogger(config *VolcEngineLiveDeployerConfig, logger logger.Logger) (
|
||||
}
|
||||
|
||||
client := veLive.NewInstance()
|
||||
client.SetAccessKey(config.AccessKey)
|
||||
client.SetSecretKey(config.SecretKey)
|
||||
client.SetAccessKey(config.AccessKeyId)
|
||||
client.SetSecretKey(config.AccessKeySecret)
|
||||
|
||||
uploader, err := providerLive.New(&providerLive.VolcEngineLiveUploaderConfig{
|
||||
AccessKeyId: config.AccessKey,
|
||||
AccessKeySecret: config.SecretKey,
|
||||
AccessKeyId: config.AccessKeyId,
|
||||
AccessKeySecret: config.AccessKeySecret,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, xerrors.Wrap(err, "failed to create ssl uploader")
|
||||
|
||||
@@ -12,11 +12,11 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
fInputCertPath string
|
||||
fInputKeyPath string
|
||||
fAccessKey string
|
||||
fSecretKey string
|
||||
fDomain string
|
||||
fInputCertPath string
|
||||
fInputKeyPath string
|
||||
fAccessKeyId string
|
||||
fAccessKeySecret string
|
||||
fDomain string
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -24,8 +24,8 @@ func init() {
|
||||
|
||||
flag.StringVar(&fInputCertPath, argsPrefix+"INPUTCERTPATH", "", "")
|
||||
flag.StringVar(&fInputKeyPath, argsPrefix+"INPUTKEYPATH", "", "")
|
||||
flag.StringVar(&fAccessKey, argsPrefix+"ACCESSKEY", "", "")
|
||||
flag.StringVar(&fSecretKey, argsPrefix+"SECRETKEY", "", "")
|
||||
flag.StringVar(&fAccessKeyId, argsPrefix+"ACCESSKEYID", "", "")
|
||||
flag.StringVar(&fAccessKeySecret, argsPrefix+"ACCESSKEYSECRET", "", "")
|
||||
flag.StringVar(&fDomain, argsPrefix+"DOMAIN", "", "")
|
||||
}
|
||||
|
||||
@@ -35,8 +35,8 @@ Shell command to run this test:
|
||||
go test -v ./volcengine_live_test.go -args \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINELIVE_INPUTCERTPATH="/path/to/your-input-cert.pem" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINELIVE_INPUTKEYPATH="/path/to/your-input-key.pem" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINELIVE_ACCESSKEY="your-access-key" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINELIVE_SECRETKEY="your-secret-key" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINELIVE_ACCESSKEYID="your-access-key-id" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINELIVE_ACCESSKEYSECRET="your-access-key-secret" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINELIVE_DOMAIN="example.com"
|
||||
*/
|
||||
func TestDeploy(t *testing.T) {
|
||||
@@ -47,15 +47,15 @@ func TestDeploy(t *testing.T) {
|
||||
"args:",
|
||||
fmt.Sprintf("INPUTCERTPATH: %v", fInputCertPath),
|
||||
fmt.Sprintf("INPUTKEYPATH: %v", fInputKeyPath),
|
||||
fmt.Sprintf("ACCESSKEY: %v", fAccessKey),
|
||||
fmt.Sprintf("SECRETKEY: %v", fSecretKey),
|
||||
fmt.Sprintf("ACCESSKEYID: %v", fAccessKeyId),
|
||||
fmt.Sprintf("ACCESSKEYSECRET: %v", fAccessKeySecret),
|
||||
fmt.Sprintf("DOMAIN: %v", fDomain),
|
||||
}, "\n"))
|
||||
|
||||
deployer, err := provider.New(&provider.VolcEngineLiveDeployerConfig{
|
||||
AccessKey: fAccessKey,
|
||||
SecretKey: fSecretKey,
|
||||
Domain: fDomain,
|
||||
AccessKeyId: fAccessKeyId,
|
||||
AccessKeySecret: fAccessKeySecret,
|
||||
Domain: fDomain,
|
||||
})
|
||||
if err != nil {
|
||||
t.Errorf("err: %+v", err)
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
package volcenginetos
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
xerrors "github.com/pkg/errors"
|
||||
veTos "github.com/volcengine/ve-tos-golang-sdk/v2/tos"
|
||||
|
||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||
"github.com/usual2970/certimate/internal/pkg/core/logger"
|
||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||
providerCertCenter "github.com/usual2970/certimate/internal/pkg/core/uploader/providers/volcengine-certcenter"
|
||||
)
|
||||
|
||||
type VolcEngineTOSDeployerConfig struct {
|
||||
// 火山引擎 AccessKeyId。
|
||||
AccessKeyId string `json:"accessKeyId"`
|
||||
// 火山引擎 AccessKeySecret。
|
||||
AccessKeySecret string `json:"accessKeySecret"`
|
||||
// 火山引擎地域。
|
||||
Region string `json:"region"`
|
||||
// 存储桶名。
|
||||
Bucket string `json:"bucket"`
|
||||
// 自定义域名(不支持泛域名)。
|
||||
Domain string `json:"domain"`
|
||||
}
|
||||
|
||||
type VolcEngineTOSDeployer struct {
|
||||
config *VolcEngineTOSDeployerConfig
|
||||
logger logger.Logger
|
||||
sdkClient *veTos.ClientV2
|
||||
sslUploader uploader.Uploader
|
||||
}
|
||||
|
||||
var _ deployer.Deployer = (*VolcEngineTOSDeployer)(nil)
|
||||
|
||||
func New(config *VolcEngineTOSDeployerConfig) (*VolcEngineTOSDeployer, error) {
|
||||
return NewWithLogger(config, logger.NewNilLogger())
|
||||
}
|
||||
|
||||
func NewWithLogger(config *VolcEngineTOSDeployerConfig, logger logger.Logger) (*VolcEngineTOSDeployer, error) {
|
||||
if config == nil {
|
||||
return nil, errors.New("config is nil")
|
||||
}
|
||||
|
||||
if logger == nil {
|
||||
return nil, errors.New("logger is nil")
|
||||
}
|
||||
|
||||
client, err := createSdkClient(config.AccessKeyId, config.AccessKeySecret, config.Region)
|
||||
if err != nil {
|
||||
return nil, xerrors.Wrap(err, "failed to create sdk client")
|
||||
}
|
||||
|
||||
uploader, err := providerCertCenter.New(&providerCertCenter.VolcEngineCertCenterUploaderConfig{
|
||||
AccessKeyId: config.AccessKeyId,
|
||||
AccessKeySecret: config.AccessKeySecret,
|
||||
Region: config.Region,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, xerrors.Wrap(err, "failed to create ssl uploader")
|
||||
}
|
||||
|
||||
return &VolcEngineTOSDeployer{
|
||||
logger: logger,
|
||||
config: config,
|
||||
sdkClient: client,
|
||||
sslUploader: uploader,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (d *VolcEngineTOSDeployer) Deploy(ctx context.Context, certPem string, privkeyPem string) (*deployer.DeployResult, error) {
|
||||
if d.config.Bucket == "" {
|
||||
return nil, errors.New("config `bucket` is required")
|
||||
}
|
||||
if d.config.Domain == "" {
|
||||
return nil, errors.New("config `domain` is required")
|
||||
}
|
||||
|
||||
// 上传证书到证书中心
|
||||
upres, err := d.sslUploader.Upload(ctx, certPem, privkeyPem)
|
||||
if err != nil {
|
||||
return nil, xerrors.Wrap(err, "failed to upload certificate file")
|
||||
}
|
||||
|
||||
d.logger.Logt("certificate file uploaded", upres)
|
||||
|
||||
// 设置自定义域名
|
||||
// REF: https://www.volcengine.com/docs/6559/1250189
|
||||
putBucketCustomDomainReq := &veTos.PutBucketCustomDomainInput{
|
||||
Bucket: d.config.Bucket,
|
||||
Rule: veTos.CustomDomainRule{
|
||||
Domain: d.config.Domain,
|
||||
CertID: upres.CertId,
|
||||
},
|
||||
}
|
||||
putBucketCustomDomainResp, err := d.sdkClient.PutBucketCustomDomain(context.TODO(), putBucketCustomDomainReq)
|
||||
if err != nil {
|
||||
return nil, xerrors.Wrap(err, "failed to execute sdk request 'tos.PutBucketCustomDomain'")
|
||||
} else {
|
||||
d.logger.Logt("已设置自定义域名", putBucketCustomDomainResp)
|
||||
}
|
||||
|
||||
return &deployer.DeployResult{}, nil
|
||||
}
|
||||
|
||||
func createSdkClient(accessKeyId, accessKeySecret, region string) (*veTos.ClientV2, error) {
|
||||
endpoint := fmt.Sprintf("tos-%s.ivolces.com", region)
|
||||
|
||||
client, err := veTos.NewClientV2(
|
||||
endpoint,
|
||||
veTos.WithRegion(region),
|
||||
veTos.WithCredentials(veTos.NewStaticCredentials(accessKeyId, accessKeySecret)),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return client, nil
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package volcenginetos_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
provider "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/volcengine-tos"
|
||||
)
|
||||
|
||||
var (
|
||||
fInputCertPath string
|
||||
fInputKeyPath string
|
||||
fAccessKeyId string
|
||||
fAccessKeySecret string
|
||||
fRegion string
|
||||
fBucket string
|
||||
fDomain string
|
||||
)
|
||||
|
||||
func init() {
|
||||
argsPrefix := "CERTIMATE_DEPLOYER_VOLCENGINETOS_"
|
||||
|
||||
flag.StringVar(&fInputCertPath, argsPrefix+"INPUTCERTPATH", "", "")
|
||||
flag.StringVar(&fInputKeyPath, argsPrefix+"INPUTKEYPATH", "", "")
|
||||
flag.StringVar(&fAccessKeyId, argsPrefix+"ACCESSKEYID", "", "")
|
||||
flag.StringVar(&fAccessKeySecret, argsPrefix+"ACCESSKEYSECRET", "", "")
|
||||
flag.StringVar(&fRegion, argsPrefix+"REGION", "", "")
|
||||
flag.StringVar(&fBucket, argsPrefix+"BUCKET", "", "")
|
||||
flag.StringVar(&fDomain, argsPrefix+"DOMAIN", "", "")
|
||||
}
|
||||
|
||||
/*
|
||||
Shell command to run this test:
|
||||
|
||||
go test -v ./volcengine_tos_test.go -args \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINETOS_INPUTCERTPATH="/path/to/your-input-cert.pem" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINETOS_INPUTKEYPATH="/path/to/your-input-key.pem" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINETOS_ACCESSKEYID="your-access-key-id" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINETOS_ACCESSKEYSECRET="your-access-key-secret" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINETOS_REGION="cn-beijing" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINETOS_BUCKET="your-tos-bucket" \
|
||||
--CERTIMATE_DEPLOYER_VOLCENGINETOS_DOMAIN="example.com"
|
||||
*/
|
||||
func TestDeploy(t *testing.T) {
|
||||
flag.Parse()
|
||||
|
||||
t.Run("Deploy", func(t *testing.T) {
|
||||
t.Log(strings.Join([]string{
|
||||
"args:",
|
||||
fmt.Sprintf("INPUTCERTPATH: %v", fInputCertPath),
|
||||
fmt.Sprintf("INPUTKEYPATH: %v", fInputKeyPath),
|
||||
fmt.Sprintf("ACCESSKEYID: %v", fAccessKeyId),
|
||||
fmt.Sprintf("ACCESSKEYSECRET: %v", fAccessKeySecret),
|
||||
fmt.Sprintf("REGION: %v", fRegion),
|
||||
fmt.Sprintf("BUCKET: %v", fBucket),
|
||||
fmt.Sprintf("DOMAIN: %v", fDomain),
|
||||
}, "\n"))
|
||||
|
||||
deployer, err := provider.New(&provider.VolcEngineTOSDeployerConfig{
|
||||
AccessKeyId: fAccessKeyId,
|
||||
AccessKeySecret: fAccessKeySecret,
|
||||
Domain: fDomain,
|
||||
})
|
||||
if err != nil {
|
||||
t.Errorf("err: %+v", err)
|
||||
return
|
||||
}
|
||||
|
||||
fInputCertData, _ := os.ReadFile(fInputCertPath)
|
||||
fInputKeyData, _ := os.ReadFile(fInputKeyPath)
|
||||
res, err := deployer.Deploy(context.Background(), string(fInputCertData), string(fInputKeyData))
|
||||
if err != nil {
|
||||
t.Errorf("err: %+v", err)
|
||||
return
|
||||
}
|
||||
|
||||
t.Logf("ok: %v", res)
|
||||
})
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func New(config *HuaweiCloudELBUploaderConfig) (*HuaweiCloudELBUploader, error)
|
||||
config.Region,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, xerrors.Wrap(err, "failed to create sdk client: %w")
|
||||
return nil, xerrors.Wrap(err, "failed to create sdk client")
|
||||
}
|
||||
|
||||
return &HuaweiCloudELBUploader{
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package volcenginecertcenter
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
xerrors "github.com/pkg/errors"
|
||||
ve "github.com/volcengine/volcengine-go-sdk/volcengine"
|
||||
veSession "github.com/volcengine/volcengine-go-sdk/volcengine/session"
|
||||
|
||||
"github.com/usual2970/certimate/internal/pkg/core/uploader"
|
||||
veCertCenter "github.com/usual2970/certimate/internal/pkg/vendors/volcengine-sdk/certcenter"
|
||||
)
|
||||
|
||||
type VolcEngineCertCenterUploaderConfig struct {
|
||||
// 火山引擎 AccessKeyId。
|
||||
AccessKeyId string `json:"accessKeyId"`
|
||||
// 火山引擎 AccessKeySecret。
|
||||
AccessKeySecret string `json:"accessKeySecret"`
|
||||
// 火山引擎地域。
|
||||
Region string `json:"region"`
|
||||
}
|
||||
|
||||
type VolcEngineCertCenterUploader struct {
|
||||
config *VolcEngineCertCenterUploaderConfig
|
||||
sdkClient *veCertCenter.CertCenter
|
||||
}
|
||||
|
||||
var _ uploader.Uploader = (*VolcEngineCertCenterUploader)(nil)
|
||||
|
||||
func New(config *VolcEngineCertCenterUploaderConfig) (*VolcEngineCertCenterUploader, error) {
|
||||
if config == nil {
|
||||
return nil, errors.New("config is nil")
|
||||
}
|
||||
|
||||
client, err := createSdkClient(config.AccessKeyId, config.AccessKeySecret, config.Region)
|
||||
if err != nil {
|
||||
return nil, xerrors.Wrap(err, "failed to create sdk client")
|
||||
}
|
||||
|
||||
return &VolcEngineCertCenterUploader{
|
||||
config: config,
|
||||
sdkClient: client,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (u *VolcEngineCertCenterUploader) Upload(ctx context.Context, certPem string, privkeyPem string) (res *uploader.UploadResult, err error) {
|
||||
// 上传证书
|
||||
// REF: https://www.volcengine.com/docs/6638/1365580
|
||||
importCertificateReq := &veCertCenter.ImportCertificateInput{
|
||||
CertificateInfo: &veCertCenter.ImportCertificateInputCertificateInfo{
|
||||
CertificateChain: ve.String(certPem),
|
||||
PrivateKey: ve.String(privkeyPem),
|
||||
},
|
||||
Repeatable: ve.Bool(false),
|
||||
}
|
||||
importCertificateResp, err := u.sdkClient.ImportCertificate(importCertificateReq)
|
||||
if err != nil {
|
||||
return nil, xerrors.Wrap(err, "failed to execute sdk request 'certcenter.ImportCertificate'")
|
||||
}
|
||||
|
||||
var certId string
|
||||
if importCertificateResp.InstanceId != nil {
|
||||
certId = *importCertificateResp.InstanceId
|
||||
}
|
||||
if importCertificateResp.RepeatId != nil {
|
||||
certId = *importCertificateResp.RepeatId
|
||||
}
|
||||
return &uploader.UploadResult{
|
||||
CertId: certId,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func createSdkClient(accessKeyId, accessKeySecret, region string) (*veCertCenter.CertCenter, error) {
|
||||
if region == "" {
|
||||
region = "cn-beijing" // 证书中心默认区域:北京
|
||||
}
|
||||
|
||||
config := ve.NewConfig().WithRegion(region).WithAkSk(accessKeyId, accessKeySecret)
|
||||
|
||||
session, err := veSession.NewSession(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := veCertCenter.New(session)
|
||||
return client, nil
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package volcenginecertcenter_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
provider "github.com/usual2970/certimate/internal/pkg/core/uploader/providers/volcengine-certcenter"
|
||||
)
|
||||
|
||||
var (
|
||||
fInputCertPath string
|
||||
fInputKeyPath string
|
||||
fAccessKeyId string
|
||||
fAccessKeySecret string
|
||||
)
|
||||
|
||||
func init() {
|
||||
argsPrefix := "CERTIMATE_UPLOADER_VOLCENGINECERTCENTER_"
|
||||
|
||||
flag.StringVar(&fInputCertPath, argsPrefix+"INPUTCERTPATH", "", "")
|
||||
flag.StringVar(&fInputKeyPath, argsPrefix+"INPUTKEYPATH", "", "")
|
||||
flag.StringVar(&fAccessKeyId, argsPrefix+"ACCESSKEYID", "", "")
|
||||
flag.StringVar(&fAccessKeySecret, argsPrefix+"ACCESSKEYSECRET", "", "")
|
||||
}
|
||||
|
||||
/*
|
||||
Shell command to run this test:
|
||||
|
||||
go test -v ./volcengine_certcenter_test.go -args \
|
||||
--CERTIMATE_UPLOADER_VOLCENGINECERTCENTER_INPUTCERTPATH="/path/to/your-input-cert.pem" \
|
||||
--CERTIMATE_UPLOADER_VOLCENGINECERTCENTER_INPUTKEYPATH="/path/to/your-input-key.pem" \
|
||||
--CERTIMATE_UPLOADER_VOLCENGINECERTCENTER_ACCESSKEYID="your-access-key-id" \
|
||||
--CERTIMATE_UPLOADER_VOLCENGINECERTCENTER_ACCESSKEYSECRET="your-access-key-secret"
|
||||
*/
|
||||
func TestDeploy(t *testing.T) {
|
||||
flag.Parse()
|
||||
|
||||
t.Run("Deploy", func(t *testing.T) {
|
||||
t.Log(strings.Join([]string{
|
||||
"args:",
|
||||
fmt.Sprintf("INPUTCERTPATH: %v", fInputCertPath),
|
||||
fmt.Sprintf("INPUTKEYPATH: %v", fInputKeyPath),
|
||||
fmt.Sprintf("ACCESSKEYID: %v", fAccessKeyId),
|
||||
fmt.Sprintf("ACCESSKEYSECRET: %v", fAccessKeySecret),
|
||||
}, "\n"))
|
||||
|
||||
uploader, err := provider.New(&provider.VolcEngineCertCenterUploaderConfig{
|
||||
AccessKeyId: fAccessKeyId,
|
||||
AccessKeySecret: fAccessKeySecret,
|
||||
})
|
||||
if err != nil {
|
||||
t.Errorf("err: %+v", err)
|
||||
return
|
||||
}
|
||||
|
||||
fInputCertData, _ := os.ReadFile(fInputCertPath)
|
||||
fInputKeyData, _ := os.ReadFile(fInputKeyPath)
|
||||
res, err := uploader.Upload(context.Background(), string(fInputCertData), string(fInputKeyData))
|
||||
if err != nil {
|
||||
t.Errorf("err: %+v", err)
|
||||
return
|
||||
}
|
||||
|
||||
sres, _ := json.Marshal(res)
|
||||
t.Logf("ok: %s", string(sres))
|
||||
})
|
||||
}
|
||||
@@ -184,6 +184,7 @@ func GetValueOrDefaultAsBool(dict map[string]any, key string, defaultValue bool)
|
||||
}
|
||||
|
||||
// 将字典解码为指定类型的结构体。
|
||||
// 与 [json.Unmarshal] 类似,但传入的是一个 [map[string]interface{}] 对象而非 JSON 格式的字符串。
|
||||
//
|
||||
// 入参:
|
||||
// - dict: 字典。
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package huaweicloudcdnsdk
|
||||
package cdn
|
||||
|
||||
import (
|
||||
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core"
|
||||
@@ -1,4 +1,4 @@
|
||||
package huaweicloudcdnsdk
|
||||
package cdn
|
||||
|
||||
import (
|
||||
hcCdnModel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2/model"
|
||||
129
internal/pkg/vendors/volcengine-sdk/certcenter/api_import_certificate.go
vendored
Normal file
129
internal/pkg/vendors/volcengine-sdk/certcenter/api_import_certificate.go
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
package certcenter
|
||||
|
||||
import (
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine"
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine/request"
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine/response"
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine/volcengineutil"
|
||||
)
|
||||
|
||||
const opImportCertificateCommon = "ImportCertificate"
|
||||
|
||||
func (c *CertCenter) ImportCertificateCommonRequest(input *map[string]interface{}) (req *request.Request, output *map[string]interface{}) {
|
||||
op := &request.Operation{
|
||||
Name: opImportCertificateCommon,
|
||||
HTTPMethod: "POST",
|
||||
HTTPPath: "/",
|
||||
}
|
||||
|
||||
if input == nil {
|
||||
input = &map[string]interface{}{}
|
||||
}
|
||||
|
||||
output = &map[string]interface{}{}
|
||||
req = c.newRequest(op, input, output)
|
||||
|
||||
req.HTTPRequest.Header.Set("Content-Type", "application/json; charset=utf-8")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c *CertCenter) ImportCertificateCommon(input *map[string]interface{}) (*map[string]interface{}, error) {
|
||||
req, out := c.ImportCertificateCommonRequest(input)
|
||||
return out, req.Send()
|
||||
}
|
||||
|
||||
func (c *CertCenter) ImportCertificateCommonWithContext(ctx volcengine.Context, input *map[string]interface{}, opts ...request.Option) (*map[string]interface{}, error) {
|
||||
req, out := c.ImportCertificateCommonRequest(input)
|
||||
req.SetContext(ctx)
|
||||
req.ApplyOptions(opts...)
|
||||
return out, req.Send()
|
||||
}
|
||||
|
||||
const opImportCertificate = "ImportCertificate"
|
||||
|
||||
func (c *CertCenter) ImportCertificateRequest(input *ImportCertificateInput) (req *request.Request, output *ImportCertificateOutput) {
|
||||
op := &request.Operation{
|
||||
Name: opImportCertificate,
|
||||
HTTPMethod: "POST",
|
||||
HTTPPath: "/",
|
||||
}
|
||||
|
||||
if input == nil {
|
||||
input = &ImportCertificateInput{}
|
||||
}
|
||||
|
||||
output = &ImportCertificateOutput{}
|
||||
req = c.newRequest(op, input, output)
|
||||
|
||||
req.HTTPRequest.Header.Set("Content-Type", "application/json; charset=utf-8")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c *CertCenter) ImportCertificate(input *ImportCertificateInput) (*ImportCertificateOutput, error) {
|
||||
req, out := c.ImportCertificateRequest(input)
|
||||
return out, req.Send()
|
||||
}
|
||||
|
||||
func (c *CertCenter) ImportCertificateWithContext(ctx volcengine.Context, input *ImportCertificateInput, opts ...request.Option) (*ImportCertificateOutput, error) {
|
||||
req, out := c.ImportCertificateRequest(input)
|
||||
req.SetContext(ctx)
|
||||
req.ApplyOptions(opts...)
|
||||
return out, req.Send()
|
||||
}
|
||||
|
||||
type ImportCertificateInput struct {
|
||||
_ struct{} `type:"structure" json:",omitempty"`
|
||||
|
||||
Tag *string `type:"string" json:",omitempty"`
|
||||
|
||||
ProjectName *string `type:"string" json:",omitempty"`
|
||||
|
||||
Repeatable *bool `type:"boolean" json:",omitempty"`
|
||||
|
||||
NoVerifyAndFixChain *bool `type:"boolean" json:",omitempty"`
|
||||
|
||||
CertificateInfo *ImportCertificateInputCertificateInfo `type:"structure" json:",omitempty"`
|
||||
|
||||
Tags *[]ImportCertificateInputTag `type:"list" json:",omitempty"`
|
||||
}
|
||||
|
||||
func (s ImportCertificateInput) String() string {
|
||||
return volcengineutil.Prettify(s)
|
||||
}
|
||||
|
||||
func (s *ImportCertificateInput) Validate() error {
|
||||
invalidParams := request.ErrInvalidParams{Context: "ImportCertificateInput"}
|
||||
|
||||
if invalidParams.Len() > 0 {
|
||||
return invalidParams
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type ImportCertificateInputCertificateInfo struct {
|
||||
CertificateChain *string `type:"string" json:",omitempty"`
|
||||
|
||||
PrivateKey *string `type:"string" json:",omitempty"`
|
||||
}
|
||||
|
||||
type ImportCertificateInputTag struct {
|
||||
Key *string `type:"string" json:",omitempty" required:"true"`
|
||||
|
||||
Value *string `type:"string" json:",omitempty" required:"true"`
|
||||
}
|
||||
|
||||
type ImportCertificateOutput struct {
|
||||
_ struct{} `type:"structure" json:",omitempty"`
|
||||
|
||||
Metadata *response.ResponseMetadata
|
||||
|
||||
InstanceId *string `type:"string" json:",omitempty"`
|
||||
|
||||
RepeatId *string `type:"string" json:",omitempty"`
|
||||
}
|
||||
|
||||
func (s ImportCertificateOutput) String() string {
|
||||
return volcengineutil.Prettify(s)
|
||||
}
|
||||
14
internal/pkg/vendors/volcengine-sdk/certcenter/interface.go
vendored
Normal file
14
internal/pkg/vendors/volcengine-sdk/certcenter/interface.go
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
package certcenter
|
||||
|
||||
import (
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine"
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine/request"
|
||||
)
|
||||
|
||||
type CertCenterAPI interface {
|
||||
ImportCertificate(*ImportCertificateInput) (*ImportCertificateOutput, error)
|
||||
ImportCertificateWithContext(volcengine.Context, *ImportCertificateInput, ...request.Option) (*ImportCertificateOutput, error)
|
||||
ImportCertificateRequest(*ImportCertificateInput) (*request.Request, *ImportCertificateOutput)
|
||||
}
|
||||
|
||||
var _ CertCenterAPI = (*CertCenter)(nil)
|
||||
71
internal/pkg/vendors/volcengine-sdk/certcenter/service.go
vendored
Normal file
71
internal/pkg/vendors/volcengine-sdk/certcenter/service.go
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
package certcenter
|
||||
|
||||
import (
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine"
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine/client"
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine/client/metadata"
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine/corehandlers"
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine/request"
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine/signer/volc"
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine/volcenginequery"
|
||||
)
|
||||
|
||||
type CertCenter struct {
|
||||
*client.Client
|
||||
}
|
||||
|
||||
var initClient func(*client.Client)
|
||||
|
||||
var initRequest func(*request.Request)
|
||||
|
||||
const (
|
||||
ServiceName = "certificate_service"
|
||||
EndpointsID = ServiceName
|
||||
ServiceID = "certificate_service"
|
||||
)
|
||||
|
||||
func New(p client.ConfigProvider, cfgs ...*volcengine.Config) *CertCenter {
|
||||
c := p.ClientConfig(EndpointsID, cfgs...)
|
||||
return newClient(*c.Config, c.Handlers, c.Endpoint, c.SigningRegion, c.SigningName)
|
||||
}
|
||||
|
||||
func newClient(cfg volcengine.Config, handlers request.Handlers, endpoint, signingRegion, signingName string) *CertCenter {
|
||||
svc := &CertCenter{
|
||||
Client: client.New(
|
||||
cfg,
|
||||
metadata.ClientInfo{
|
||||
ServiceName: ServiceName,
|
||||
ServiceID: ServiceID,
|
||||
SigningName: signingName,
|
||||
SigningRegion: signingRegion,
|
||||
Endpoint: endpoint,
|
||||
APIVersion: "2024-10-01",
|
||||
},
|
||||
handlers,
|
||||
),
|
||||
}
|
||||
|
||||
svc.Handlers.Build.PushBackNamed(corehandlers.SDKVersionUserAgentHandler)
|
||||
svc.Handlers.Build.PushBackNamed(corehandlers.AddHostExecEnvUserAgentHandler)
|
||||
svc.Handlers.Sign.PushBackNamed(volc.SignRequestHandler)
|
||||
svc.Handlers.Build.PushBackNamed(volcenginequery.BuildHandler)
|
||||
svc.Handlers.Unmarshal.PushBackNamed(volcenginequery.UnmarshalHandler)
|
||||
svc.Handlers.UnmarshalMeta.PushBackNamed(volcenginequery.UnmarshalMetaHandler)
|
||||
svc.Handlers.UnmarshalError.PushBackNamed(volcenginequery.UnmarshalErrorHandler)
|
||||
|
||||
if initClient != nil {
|
||||
initClient(svc.Client)
|
||||
}
|
||||
|
||||
return svc
|
||||
}
|
||||
|
||||
func (c *CertCenter) newRequest(op *request.Operation, params, data interface{}) *request.Request {
|
||||
req := c.NewRequest(op, params, data)
|
||||
|
||||
if initRequest != nil {
|
||||
initRequest(req)
|
||||
}
|
||||
|
||||
return req
|
||||
}
|
||||
Reference in New Issue
Block a user