Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions aliSimple.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

const defRegID string = "cn-hangzhou"
const addrOfAPI string = "%s://alidns.aliyuncs.com/"
const dbgTAG string = "DEBUG:>\t"

// CredInfo implements param of the crediential
type CredInfo struct {
Expand Down Expand Up @@ -89,7 +88,7 @@ func (c *mClient) applyReq(cxt context.Context, method string, body io.Reader) (

func (c *aliClient) getAliClientSche(cred *CredInfo, scheme string) (*aliClient, error) {
if cred == nil {
return &aliClient{}, errors.New("alicloud: credentials missing")
return &aliClient{}, errors.New("alidns: credentials missing")
}
if scheme == "" {
scheme = "http"
Expand All @@ -115,13 +114,11 @@ func (c *aliClient) getAliClientSche(cred *CredInfo, scheme string) (*aliClient,

func (c *aliClient) signReq(method string) error {
if c.sigPwd == "" || len(c.reqMap) == 0 {
return errors.New("alicloud: AccessKeySecret or Request(includes AccessKeyId) is Misssing")
return errors.New("alidns: AccessKeySecret or Request(includes AccessKeyId) is Misssing")
}
sort.Sort(byKey(c.reqMap))
str := c.reqMapToStr()
fmt.Println(dbgTAG+"Request map to str:", str)
str = c.reqStrToSign(str, method)
fmt.Println(dbgTAG+"URL to sign:", str)
c.sigStr = signStr(str, c.sigPwd)
return nil
}
Expand Down
3 changes: 3 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func (p *Provider) setDomainRecord(ctx context.Context, rc aliDomaRecord) (recID
p.client.mutex.Lock()
defer p.client.mutex.Unlock()
p.getClientWithZone(rc.DName)
if rc.TTL <= 0 {
rc.TTL = 600
}
p.client.aClient.addReqBody("Action", "UpdateDomainRecord")
p.client.aClient.addReqBody("RecordId", rc.RecID)
p.client.aClient.addReqBody("RR", rc.Rr)
Expand Down
22 changes: 6 additions & 16 deletions provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ func (p *Provider) DeleteRecords(ctx context.Context, zone string, recs []libdns
var rls []libdns.Record
for _, rec := range recs {
ar := alidnsRecordWithZone(rec, zone)
if len(ar.RecID) == 0 {
r0, err := p.queryDomainRecord(ctx, ar.Rr, ar.DName, ar.DTyp)
ar.RecID = r0.RecID
if err != nil {
return nil, err
}
}
_, err := p.delDomainRecord(ctx, ar)
if err != nil {
return nil, err
Expand All @@ -71,23 +64,20 @@ func (p *Provider) GetRecords(ctx context.Context, zone string) ([]libdns.Record
// or creating new ones. It returns the updated records.
func (p *Provider) SetRecords(ctx context.Context, zone string, recs []libdns.Record) ([]libdns.Record, error) {
var rls []libdns.Record
var err error
for _, rec := range recs {
ar := alidnsRecordWithZone(rec, zone)
if len(ar.RecID) == 0 {
r0, err := p.queryDomainRecord(ctx, ar.Rr, ar.DName, ar.DTyp)
if ar.RecID == "" {
ar.RecID, err = p.addDomainRecord(ctx, ar)
if err != nil {
ar.RecID, err = p.addDomainRecord(ctx, ar)
} else {
ar.RecID = r0.RecID
return nil, err
}
} else {
_, err = p.setDomainRecord(ctx, ar)
if err != nil {
return nil, err
}
}
_, err := p.setDomainRecord(ctx, ar)
if err != nil {
return nil, err
}
rls = append(rls, ar.LibdnsRecord())
}
return rls, nil
Expand Down