mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
PORKBUN: Add registrar support (#2542)
Co-authored-by: Tom Limoncelli <tlimoncelli@stackoverflow.com>
This commit is contained in:
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"sort"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -18,7 +19,7 @@ type porkbunProvider struct {
|
||||
secretKey string
|
||||
}
|
||||
|
||||
type requestParams map[string]string
|
||||
type requestParams map[string]any
|
||||
|
||||
type errorResponse struct {
|
||||
Status string `json:"status"`
|
||||
@ -40,6 +41,11 @@ type recordResponse struct {
|
||||
Records []domainRecord `json:"records"`
|
||||
}
|
||||
|
||||
type nsResponse struct {
|
||||
Status string `json:"status"`
|
||||
Nameservers []string `json:"ns"`
|
||||
}
|
||||
|
||||
func (c *porkbunProvider) post(endpoint string, params requestParams) ([]byte, error) {
|
||||
params["apikey"] = c.apiKey
|
||||
params["secretapikey"] = c.secretKey
|
||||
@ -82,7 +88,7 @@ func (c *porkbunProvider) ping() error {
|
||||
|
||||
func (c *porkbunProvider) createRecord(domain string, rec requestParams) error {
|
||||
if _, err := c.post("/dns/create/"+domain, rec); err != nil {
|
||||
return fmt.Errorf("failed create record (porkbun): %s", err)
|
||||
return fmt.Errorf("failed create record (porkbun): %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -90,14 +96,14 @@ func (c *porkbunProvider) createRecord(domain string, rec requestParams) error {
|
||||
func (c *porkbunProvider) deleteRecord(domain string, recordID string) error {
|
||||
params := requestParams{}
|
||||
if _, err := c.post(fmt.Sprintf("/dns/delete/%s/%s", domain, recordID), params); err != nil {
|
||||
return fmt.Errorf("failed delete record (porkbun): %s", err)
|
||||
return fmt.Errorf("failed delete record (porkbun): %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *porkbunProvider) modifyRecord(domain string, recordID string, rec requestParams) error {
|
||||
if _, err := c.post(fmt.Sprintf("/dns/edit/%s/%s", domain, recordID), rec); err != nil {
|
||||
return fmt.Errorf("failed update (porkbun): %s", err)
|
||||
return fmt.Errorf("failed update (porkbun): %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -106,7 +112,7 @@ func (c *porkbunProvider) getRecords(domain string) ([]domainRecord, error) {
|
||||
params := requestParams{}
|
||||
var bodyString, err = c.post("/dns/retrieve/"+domain, params)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed fetching record list from porkbun: %s", err)
|
||||
return nil, fmt.Errorf("failed fetching record list from porkbun: %w", err)
|
||||
}
|
||||
|
||||
var dr recordResponse
|
||||
@ -121,3 +127,26 @@ func (c *porkbunProvider) getRecords(domain string) ([]domainRecord, error) {
|
||||
}
|
||||
return records, nil
|
||||
}
|
||||
|
||||
func (c *porkbunProvider) getNameservers(domain string) ([]string, error) {
|
||||
params := requestParams{}
|
||||
var bodyString, err = c.post(fmt.Sprintf("/domain/getNs/%s", domain), params)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed fetching nameserver list from porkbun: %w", err)
|
||||
}
|
||||
|
||||
var ns nsResponse
|
||||
json.Unmarshal(bodyString, &ns)
|
||||
|
||||
sort.Strings(ns.Nameservers)
|
||||
return ns.Nameservers, nil
|
||||
}
|
||||
|
||||
func (c *porkbunProvider) updateNameservers(ns []string, domain string) error {
|
||||
params := requestParams{}
|
||||
params["ns"] = ns
|
||||
if _, err := c.post(fmt.Sprintf("/domain/updateNs/%s", domain), params); err != nil {
|
||||
return fmt.Errorf("failed NS update (porkbun): %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user