Skip to content

Commit

Permalink
Add Abroad CDN support.
Browse files Browse the repository at this point in the history
  • Loading branch information
tamperMonkeyZQ committed May 8, 2024
1 parent 1d02320 commit 2a9514a
Show file tree
Hide file tree
Showing 19 changed files with 2,482 additions and 118 deletions.
25 changes: 22 additions & 3 deletions baiducloud/connectivity/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/baidubce/bce-sdk-go/services/cce"
ccev2 "github.com/baidubce/bce-sdk-go/services/cce/v2"
"github.com/baidubce/bce-sdk-go/services/cdn"
"github.com/baidubce/bce-sdk-go/services/cdn/abroad"
"github.com/baidubce/bce-sdk-go/services/cert"
"github.com/baidubce/bce-sdk-go/services/cfc"
"github.com/baidubce/bce-sdk-go/services/cfs"
Expand Down Expand Up @@ -63,6 +64,7 @@ type BaiduClient struct {
dtsConn *dts.Client
iamConn *iam.Client
cdnConn *cdn.Client
abroadCdnConn *abroad.Client
localDNSConn *localDns.Client
smsConn *sms.Client
bbcConn *bbc.Client
Expand All @@ -83,7 +85,7 @@ type ApiVersion string

var goSdkMutex = sync.RWMutex{} // The Go SDK is not thread-safe

var providerVersion = "1.20.6"
var providerVersion = "1.13.0"

// Client for BaiduCloudClient
func (c *Config) Client() (*BaiduClient, error) {
Expand Down Expand Up @@ -471,6 +473,23 @@ func (client *BaiduClient) WithCdnClient(do func(*cdn.Client) (interface{}, erro
return do(client.cdnConn)
}

func (client *BaiduClient) WithAbroadCdnClient(do func(*abroad.Client) (interface{}, error)) (interface{}, error) {
goSdkMutex.Lock()
defer goSdkMutex.Unlock()

// Initialize the abroad CDN client if necessary
if client.abroadCdnConn == nil {
client.WithCommonClient(AbroadCDNCode)
abroadCDNClient, err := abroad.NewClient(client.Credentials.AccessKeyId, client.Credentials.SecretAccessKey, client.Endpoint)
if err != nil {
return nil, err
}
abroadCDNClient.Config.UserAgent = buildUserAgent()
client.abroadCdnConn = abroadCDNClient
}
return do(client.abroadCdnConn)
}

func (client *BaiduClient) WithLocalDnsClient(do func(*localDns.Client) (interface{}, error)) (interface{}, error) {
goSdkMutex.Lock()
defer goSdkMutex.Unlock()
Expand Down Expand Up @@ -603,7 +622,7 @@ func (client *BaiduClient) WithBLSClient(do func(*bls.Client) (interface{}, erro
goSdkMutex.Lock()
defer goSdkMutex.Unlock()

// Initialize the BLS client if necessary
// Initialize the LOCALDNS client if necessary
if client.blsConn == nil {
client.WithCommonClient(BLSCode)
blsClient, err := bls.NewClient(client.Credentials.AccessKeyId, client.Credentials.SecretAccessKey, client.Endpoint)
Expand Down Expand Up @@ -674,7 +693,7 @@ func (client *BaiduClient) WithEtClient(do func(*et.Client) (interface{}, error)

func (client *BaiduClient) WithDNSClient(do func(*dns.Client) (interface{}, error)) (interface{}, error) {
goSdkMutex.Lock()
// Initialize the VPN client if necessary
// Initialize the DNS client if necessary
if client.dnsConn == nil {
client.WithCommonClient(DNSCode)
dnsClient, err := dns.NewClient(client.Credentials.AccessKeyId, client.Credentials.SecretAccessKey, client.Endpoint)
Expand Down
82 changes: 46 additions & 36 deletions baiducloud/connectivity/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
DTSCode = ServiceCode("DTS")
IAMCode = ServiceCode("IAM")
CDNCode = ServiceCode("CDN")
AbroadCDNCode = ServiceCode("ABROADCDN")
LOCALDNSCode = ServiceCode("LOCALDNS")
BBCCode = ServiceCode("BBC")
VPNCode = ServiceCode("VPN")
Expand Down Expand Up @@ -133,10 +134,11 @@ const (
DefaultSINRegionVPNEndPoint = "bcc.sin.baidubce.com"
DefaultSINRegionEniEndPoint = "bcc.sin.baidubce.com"

DefaultCERTEndPoint = "certificate.baidubce.com"
DefaultIAMEndPoint = "iam.bj.baidubce.com"
DefaultCDNEndPoint = "cdn.baidubce.com"
DefaultDNSEndPoint = "dns.baidubce.com"
DefaultCERTEndPoint = "certificate.baidubce.com"
DefaultIAMEndPoint = "iam.bj.baidubce.com"
DefaultCDNEndPoint = "cdn.baidubce.com"
DefaultAbroadCDNEndPoint = "cdn.baidubce.com"
DefaultDNSEndPoint = "dns.baidubce.com"
)

var (
Expand All @@ -154,10 +156,11 @@ var (

// Region BJ Service Endpoints
RegionBJEndpoints = map[ServiceCode]string{
CERTCode: DefaultCERTEndPoint,
IAMCode: DefaultIAMEndPoint,
CDNCode: DefaultCDNEndPoint,
DNSCode: DefaultDNSEndPoint,
CERTCode: DefaultCERTEndPoint,
IAMCode: DefaultIAMEndPoint,
CDNCode: DefaultCDNEndPoint,
AbroadCDNCode: DefaultAbroadCDNEndPoint,
DNSCode: DefaultDNSEndPoint,

BCCCode: DefaultBJRegionBccEndPoint,
BBCCode: DefaultBJRegionBbcEndPoint,
Expand Down Expand Up @@ -188,10 +191,11 @@ var (

// Region BD Service Endpoints
RegionBDEndpoints = map[ServiceCode]string{
CERTCode: DefaultCERTEndPoint,
IAMCode: DefaultIAMEndPoint,
CDNCode: DefaultCDNEndPoint,
DNSCode: DefaultDNSEndPoint,
CERTCode: DefaultCERTEndPoint,
IAMCode: DefaultIAMEndPoint,
CDNCode: DefaultCDNEndPoint,
AbroadCDNCode: DefaultAbroadCDNEndPoint,
DNSCode: DefaultDNSEndPoint,

BCCCode: DefaultBDRegionBccEndPoint,
VPCCode: DefaultBDRegionBccEndPoint,
Expand All @@ -208,10 +212,11 @@ var (

// Region GZ Service Endpoints
RegionGZEndpoints = map[ServiceCode]string{
CERTCode: DefaultCERTEndPoint,
IAMCode: DefaultIAMEndPoint,
CDNCode: DefaultCDNEndPoint,
DNSCode: DefaultDNSEndPoint,
CERTCode: DefaultCERTEndPoint,
IAMCode: DefaultIAMEndPoint,
CDNCode: DefaultCDNEndPoint,
AbroadCDNCode: DefaultAbroadCDNEndPoint,
DNSCode: DefaultDNSEndPoint,

BCCCode: DefaultGZRegionBccEndPoint,
VPNCode: DefaultGZRegionVpnEndPoint,
Expand All @@ -236,10 +241,11 @@ var (

// Region SU Service Endpoints
RegionSUEndpoints = map[ServiceCode]string{
CERTCode: DefaultCERTEndPoint,
IAMCode: DefaultIAMEndPoint,
CDNCode: DefaultCDNEndPoint,
DNSCode: DefaultDNSEndPoint,
CERTCode: DefaultCERTEndPoint,
IAMCode: DefaultIAMEndPoint,
CDNCode: DefaultCDNEndPoint,
AbroadCDNCode: DefaultAbroadCDNEndPoint,
DNSCode: DefaultDNSEndPoint,

BCCCode: DefaultSURegionBccEndPoint,
BBCCode: DefaultSURegionBbcEndPoint,
Expand All @@ -266,10 +272,11 @@ var (

// Region FSH Service Endpoints
RegionFSHEndpoints = map[ServiceCode]string{
CERTCode: DefaultCERTEndPoint,
IAMCode: DefaultIAMEndPoint,
CDNCode: DefaultCDNEndPoint,
DNSCode: DefaultDNSEndPoint,
CERTCode: DefaultCERTEndPoint,
IAMCode: DefaultIAMEndPoint,
CDNCode: DefaultCDNEndPoint,
AbroadCDNCode: DefaultAbroadCDNEndPoint,
DNSCode: DefaultDNSEndPoint,

BCCCode: DefaultFSHRegionBccEndPoint,
VPNCode: DefaultFSHRegionVPNEndPoint,
Expand All @@ -280,10 +287,11 @@ var (

// Region FWH Service Endpoints
RegionFWHEndpoints = map[ServiceCode]string{
CERTCode: DefaultCERTEndPoint,
IAMCode: DefaultIAMEndPoint,
CDNCode: DefaultCDNEndPoint,
DNSCode: DefaultDNSEndPoint,
CERTCode: DefaultCERTEndPoint,
IAMCode: DefaultIAMEndPoint,
CDNCode: DefaultCDNEndPoint,
AbroadCDNCode: DefaultAbroadCDNEndPoint,
DNSCode: DefaultDNSEndPoint,

BCCCode: DefaultFWHRegionBccEndPoint,
BBCCode: DefaultFWHRegionBbcEndPoint,
Expand All @@ -308,10 +316,11 @@ var (

// Region HKG Service Endpoints
RegionHKGEndpoints = map[ServiceCode]string{
CERTCode: DefaultCERTEndPoint,
IAMCode: DefaultIAMEndPoint,
CDNCode: DefaultCDNEndPoint,
DNSCode: DefaultDNSEndPoint,
CERTCode: DefaultCERTEndPoint,
IAMCode: DefaultIAMEndPoint,
CDNCode: DefaultCDNEndPoint,
AbroadCDNCode: DefaultAbroadCDNEndPoint,
DNSCode: DefaultDNSEndPoint,

BCCCode: DefaultHKGRegionBccEndPoint,
BBCCode: DefaultHKGRegionBbcEndPoint,
Expand All @@ -332,10 +341,11 @@ var (

// Region SIN Service Endpoints
RegionSINEndpoints = map[ServiceCode]string{
CERTCode: DefaultCERTEndPoint,
IAMCode: DefaultIAMEndPoint,
CDNCode: DefaultCDNEndPoint,
DNSCode: DefaultDNSEndPoint,
CERTCode: DefaultCERTEndPoint,
IAMCode: DefaultIAMEndPoint,
CDNCode: DefaultCDNEndPoint,
AbroadCDNCode: DefaultAbroadCDNEndPoint,
DNSCode: DefaultDNSEndPoint,

BCCCode: DefaultSINRegionBccEndPoint,
VPCCode: DefaultSINRegionBccEndPoint,
Expand Down
Loading

0 comments on commit 2a9514a

Please sign in to comment.