mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
PORKBUN: support diff2 and two small changes (#1855)
This commit is contained in:
@@ -54,7 +54,7 @@ func (c *porkbunProvider) post(endpoint string, params requestParams) ([]byte, e
|
||||
|
||||
// If request sending too fast, the server will fail with the following error:
|
||||
// porkbun API error: Create error: We were unable to create the DNS record.
|
||||
time.Sleep(300 * time.Millisecond)
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
|
@@ -100,7 +100,7 @@ func (c *porkbunProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode
|
||||
}
|
||||
|
||||
var corrections []*models.Correction
|
||||
if !diff2.EnableDiff2 || true { // Remove "|| true" when diff2 version arrives
|
||||
if !diff2.EnableDiff2 {
|
||||
|
||||
differ := diff.New(dc)
|
||||
_, create, del, modify, err := differ.IncrementalDiff(existingRecords)
|
||||
@@ -143,7 +143,7 @@ func (c *porkbunProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode
|
||||
}
|
||||
|
||||
corr := &models.Correction{
|
||||
Msg: fmt.Sprintf("%s, porkbun ID: %s: ", m.String(), id),
|
||||
Msg: fmt.Sprintf("%s, porkbun ID: %s", m.String(), id),
|
||||
F: func() error {
|
||||
return c.modifyRecord(dc.Name, id, req)
|
||||
},
|
||||
@@ -154,7 +154,47 @@ func (c *porkbunProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode
|
||||
return corrections, nil
|
||||
}
|
||||
|
||||
// Insert Future diff2 version here.
|
||||
changes, err := diff2.ByRecord(existingRecords, dc, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, change := range changes {
|
||||
var corr *models.Correction
|
||||
switch change.Type {
|
||||
case diff2.CREATE:
|
||||
req, err := toReq(change.New[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
corr = &models.Correction{
|
||||
Msg: change.Msgs[0],
|
||||
F: func() error {
|
||||
return c.createRecord(dc.Name, req)
|
||||
},
|
||||
}
|
||||
case diff2.CHANGE:
|
||||
id := change.Old[0].Original.(*domainRecord).ID
|
||||
req, err := toReq(change.New[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
corr = &models.Correction{
|
||||
Msg: fmt.Sprintf("%s, porkbun ID: %s", change.Msgs[0], id),
|
||||
F: func() error {
|
||||
return c.modifyRecord(dc.Name, id, req)
|
||||
},
|
||||
}
|
||||
case diff2.DELETE:
|
||||
id := change.Old[0].Original.(*domainRecord).ID
|
||||
corr = &models.Correction{
|
||||
Msg: fmt.Sprintf("%s, porkbun ID: %s", change.Msgs[0], id),
|
||||
F: func() error {
|
||||
return c.deleteRecord(dc.Name, id)
|
||||
},
|
||||
}
|
||||
}
|
||||
corrections = append(corrections, corr)
|
||||
}
|
||||
|
||||
return corrections, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user