mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
Rename provider handles to *Provider (#914)
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
// Api layer for CloDNS
|
||||
type api struct {
|
||||
type cloudnsProvider struct {
|
||||
domainIndex map[string]string
|
||||
nameserversNames []string
|
||||
creds struct {
|
||||
@@ -81,7 +81,7 @@ var allowedTTLValues = []uint32{
|
||||
2419200, // 4 weeks
|
||||
}
|
||||
|
||||
func (c *api) fetchAvailableNameservers() error {
|
||||
func (c *cloudnsProvider) fetchAvailableNameservers() error {
|
||||
c.nameserversNames = nil
|
||||
|
||||
var bodyString, err = c.get("/dns/available-name-servers.json", requestParams{})
|
||||
@@ -101,7 +101,7 @@ func (c *api) fetchAvailableNameservers() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *api) fetchDomainList() error {
|
||||
func (c *cloudnsProvider) fetchDomainList() error {
|
||||
c.domainIndex = map[string]string{}
|
||||
rowsPerPage := 100
|
||||
page := 1
|
||||
@@ -129,7 +129,7 @@ func (c *api) fetchDomainList() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *api) createDomain(domain string) error {
|
||||
func (c *cloudnsProvider) createDomain(domain string) error {
|
||||
params := requestParams{
|
||||
"domain-name": domain,
|
||||
"zone-type": "master",
|
||||
@@ -140,7 +140,7 @@ func (c *api) createDomain(domain string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *api) createRecord(domainID string, rec requestParams) error {
|
||||
func (c *cloudnsProvider) createRecord(domainID string, rec requestParams) error {
|
||||
rec["domain-name"] = domainID
|
||||
if _, err := c.get("/dns/add-record.json", rec); err != nil {
|
||||
return fmt.Errorf("failed create record (ClouDNS): %s", err)
|
||||
@@ -148,7 +148,7 @@ func (c *api) createRecord(domainID string, rec requestParams) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *api) deleteRecord(domainID string, recordID string) error {
|
||||
func (c *cloudnsProvider) deleteRecord(domainID string, recordID string) error {
|
||||
params := requestParams{
|
||||
"domain-name": domainID,
|
||||
"record-id": recordID,
|
||||
@@ -159,7 +159,7 @@ func (c *api) deleteRecord(domainID string, recordID string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *api) modifyRecord(domainID string, recordID string, rec requestParams) error {
|
||||
func (c *cloudnsProvider) modifyRecord(domainID string, recordID string, rec requestParams) error {
|
||||
rec["domain-name"] = domainID
|
||||
rec["record-id"] = recordID
|
||||
if _, err := c.get("/dns/mod-record.json", rec); err != nil {
|
||||
@@ -168,7 +168,7 @@ func (c *api) modifyRecord(domainID string, recordID string, rec requestParams)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *api) getRecords(id string) ([]domainRecord, error) {
|
||||
func (c *cloudnsProvider) getRecords(id string) ([]domainRecord, error) {
|
||||
params := requestParams{"domain-name": id}
|
||||
|
||||
var bodyString, err = c.get("/dns/records.json", params)
|
||||
@@ -186,7 +186,7 @@ func (c *api) getRecords(id string) ([]domainRecord, error) {
|
||||
return records, nil
|
||||
}
|
||||
|
||||
func (c *api) get(endpoint string, params requestParams) ([]byte, error) {
|
||||
func (c *cloudnsProvider) get(endpoint string, params requestParams) ([]byte, error) {
|
||||
client := &http.Client{}
|
||||
req, _ := http.NewRequest("GET", "https://api.cloudns.net"+endpoint, nil)
|
||||
q := req.URL.Query()
|
||||
|
||||
@@ -24,7 +24,7 @@ Info required in `creds.json`:
|
||||
|
||||
// NewCloudns creates the provider.
|
||||
func NewCloudns(m map[string]string, metadata json.RawMessage) (providers.DNSServiceProvider, error) {
|
||||
c := &api{}
|
||||
c := &cloudnsProvider{}
|
||||
|
||||
c.creds.id, c.creds.password = m["auth-id"], m["auth-password"]
|
||||
if c.creds.id == "" || c.creds.password == "" {
|
||||
@@ -57,7 +57,7 @@ func init() {
|
||||
}
|
||||
|
||||
// GetNameservers returns the nameservers for a domain.
|
||||
func (c *api) GetNameservers(domain string) ([]*models.Nameserver, error) {
|
||||
func (c *cloudnsProvider) GetNameservers(domain string) ([]*models.Nameserver, error) {
|
||||
if len(c.nameserversNames) == 0 {
|
||||
c.fetchAvailableNameservers()
|
||||
}
|
||||
@@ -65,7 +65,7 @@ func (c *api) GetNameservers(domain string) ([]*models.Nameserver, error) {
|
||||
}
|
||||
|
||||
// GetDomainCorrections returns the corrections for a domain.
|
||||
func (c *api) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
|
||||
func (c *cloudnsProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
|
||||
dc, err := dc.Copy()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -150,7 +150,7 @@ func (c *api) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correctio
|
||||
}
|
||||
|
||||
// GetZoneRecords gets the records of a zone and returns them in RecordConfig format.
|
||||
func (c *api) GetZoneRecords(domain string) (models.Records, error) {
|
||||
func (c *cloudnsProvider) GetZoneRecords(domain string) (models.Records, error) {
|
||||
records, err := c.getRecords(domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -163,7 +163,7 @@ func (c *api) GetZoneRecords(domain string) (models.Records, error) {
|
||||
}
|
||||
|
||||
// EnsureDomainExists returns an error if domain doesn't exist.
|
||||
func (c *api) EnsureDomainExists(domain string) error {
|
||||
func (c *cloudnsProvider) EnsureDomainExists(domain string) error {
|
||||
if err := c.fetchDomainList(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user