Skip to content

Commit

Permalink
perf(huaweicloud): Safe*()
Browse files Browse the repository at this point in the history
  • Loading branch information
yzy613 committed Mar 11, 2024
1 parent 89d9289 commit 739f138
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 24 deletions.
76 changes: 53 additions & 23 deletions internal/client/huaweicloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,26 @@ func (hc *HuaweiCloud) Run(enabled common.Enable, ipv4, ipv6 string) (msg []stri
}

func (hc *HuaweiCloud) getZoneId() (err error) {
auth := basic.NewCredentialsBuilder().
auth, err := basic.NewCredentialsBuilder().
WithAk(hc.AccessKeyId).
WithSk(hc.SecretAccessKey).
Build()
SafeBuild()
if err != nil {
return
}

dnsClient := dns.NewDnsClient(
dns.DnsClientBuilder().
WithRegion(region.ValueOf("cn-east-3")).
WithCredential(auth).
Build())
hr, err := region.SafeValueOf("cn-east-3")
if err != nil {
return
}
hhc, err := dns.DnsClientBuilder().
WithRegion(hr).
WithCredential(auth).
SafeBuild()
if err != nil {
return
}
dnsClient := dns.NewDnsClient(hhc)

request := &model.ListPublicZonesRequest{}
response, err := dnsClient.ListPublicZones(request)
Expand All @@ -112,16 +122,26 @@ func (hc *HuaweiCloud) getZoneId() (err error) {
}

func (hc *HuaweiCloud) getParseRecord(domain, recordType string) (recordSetId, recordIP string, err error) {
auth := basic.NewCredentialsBuilder().
auth, err := basic.NewCredentialsBuilder().
WithAk(hc.AccessKeyId).
WithSk(hc.SecretAccessKey).
Build()
SafeBuild()
if err != nil {
return
}

dnsClient := dns.NewDnsClient(
dns.DnsClientBuilder().
WithRegion(region.ValueOf("cn-east-3")).
WithCredential(auth).
Build())
hr, err := region.SafeValueOf("cn-east-3")
if err != nil {
return
}
hhc, err := dns.DnsClientBuilder().
WithRegion(hr).
WithCredential(auth).
SafeBuild()
if err != nil {
return
}
dnsClient := dns.NewDnsClient(hhc)

request := &model.ListRecordSetsByZoneRequest{}
request.ZoneId = hc.ZoneId
Expand All @@ -145,25 +165,35 @@ func (hc *HuaweiCloud) getParseRecord(domain, recordType string) (recordSetId, r
}

func (hc *HuaweiCloud) updateParseRecord(ipAddr, recordSetId, recordType, domain string) (err error) {
auth := basic.NewCredentialsBuilder().
auth, err := basic.NewCredentialsBuilder().
WithAk(hc.AccessKeyId).
WithSk(hc.SecretAccessKey).
Build()
SafeBuild()
if err != nil {
return
}

dnsClient := dns.NewDnsClient(
dns.DnsClientBuilder().
WithRegion(region.ValueOf("cn-east-3")).
WithCredential(auth).
Build())
hr, err := region.SafeValueOf("cn-east-3")
if err != nil {
return
}
hhc, err := dns.DnsClientBuilder().
WithRegion(hr).
WithCredential(auth).
SafeBuild()
if err != nil {
return
}
dnsClient := dns.NewDnsClient(hhc)

request := &model.UpdateRecordSetRequest{}
request.ZoneId = hc.ZoneId
request.RecordsetId = recordSetId
var listRecordsbody = []string{
var listRecordsBody = []string{
ipAddr,
}
request.Body = &model.UpdateRecordSetReq{
Records: &listRecordsbody,
Records: &listRecordsBody,
Type: recordType,
Name: domain,
}
Expand Down
2 changes: 1 addition & 1 deletion internal/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

const (
LocalVersion = "1.5.6"
LocalVersion = "1.5.7"
DefaultAPIUrl = "https://yzyweb.cn/ddns-watchdog"
DefaultIPv6APIUrl = "https://yzyweb.cn/ddns-watchdog6"
ProjectUrl = "https://github.com/yzy613/ddns-watchdog"
Expand Down

0 comments on commit 739f138

Please sign in to comment.