Skip to content

Commit

Permalink
Merge pull request #1151 from Cyb3r-Jak3/dns-comments-tags
Browse files Browse the repository at this point in the history
Support for DNS comments and tags
  • Loading branch information
jacobbednarz authored Dec 28, 2022
2 parents ad9f553 + 0efc211 commit 2061a27
Show file tree
Hide file tree
Showing 8 changed files with 341 additions and 119 deletions.
15 changes: 15 additions & 0 deletions .changelog/1151.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```release-note:enhancement
dns: add support for tags and comments
```

```release-note:breaking-change
dns: method signatures have been updated to align with the upcoming client conventions
```

```release-note:breaking-change
dns: `DNSRecords` has been renamed to `ListDNSRecords`
```

```release-note:breaking-change
dns: `DNSRecord` has been renamed to `GetDNSRecord`
```
33 changes: 20 additions & 13 deletions cmd/flarectl/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ func dnsCreate(c *cli.Context) error {
return err
}

record := cloudflare.DNSRecord{
record := cloudflare.CreateDNSRecordParams{
Name: name,
Type: strings.ToUpper(rtype),
Content: content,
TTL: ttl,
Proxied: &proxy,
Priority: &priority,
}
resp, err := api.CreateDNSRecord(context.Background(), zoneID, record)
resp, err := api.CreateDNSRecord(context.Background(), cloudflare.ZoneIdentifier(zoneID), record)
if err != nil {
fmt.Fprintln(os.Stderr, "Error creating DNS record: ", err)
return err
Expand Down Expand Up @@ -84,11 +84,7 @@ func dnsCreateOrUpdate(c *cli.Context) error {
return err
}

// Look for an existing record
rr := cloudflare.DNSRecord{
Name: name + "." + zone,
}
records, err := api.DNSRecords(context.Background(), zoneID, rr)
records, _, err := api.ListDNSRecords(context.Background(), cloudflare.ZoneIdentifier(zoneID), cloudflare.ListDNSRecordsParams{Name: name + "." + zone})
if err != nil {
fmt.Fprintln(os.Stderr, "Error fetching DNS records: ", err)
return err
Expand All @@ -101,32 +97,43 @@ func dnsCreateOrUpdate(c *cli.Context) error {
// has multiple RRs we'll just update the first one.
for _, r := range records {
if r.Type == rtype {
rr := cloudflare.UpdateDNSRecordParams{}
rr.ID = r.ID
rr.Type = r.Type
rr.Content = content
rr.TTL = ttl
rr.Proxied = &proxy
rr.Priority = &priority

err := api.UpdateDNSRecord(context.Background(), zoneID, r.ID, rr)
err := api.UpdateDNSRecord(context.Background(), cloudflare.ZoneIdentifier(zoneID), rr)
if err != nil {
fmt.Println("Error updating DNS record:", err)
return err
}
resp = &cloudflare.DNSRecordResponse{
Result: rr,
Result: cloudflare.DNSRecord{
ID: rr.ID,
Name: rr.Name,
Type: rr.Type,
Content: rr.Content,
TTL: rr.TTL,
Proxiable: rr.Proxiable,
Proxied: &proxy,
Locked: rr.Locked,
},
}
}
}
} else {
// Record doesn't exist - create it
rr := cloudflare.CreateDNSRecordParams{}
rr.Type = rtype
rr.Content = content
rr.TTL = ttl
rr.Proxied = &proxy
rr.Priority = &priority
// TODO: Print the response.
resp, err = api.CreateDNSRecord(context.Background(), zoneID, rr)
resp, err = api.CreateDNSRecord(context.Background(), cloudflare.ZoneIdentifier(zoneID), rr)
if err != nil {
fmt.Println("Error creating DNS record:", err)
return err
Expand Down Expand Up @@ -162,7 +169,7 @@ func dnsUpdate(c *cli.Context) error {
return err
}

record := cloudflare.DNSRecord{
record := cloudflare.UpdateDNSRecordParams{
ID: recordID,
Name: name,
Type: strings.ToUpper(rtype),
Expand All @@ -171,7 +178,7 @@ func dnsUpdate(c *cli.Context) error {
Proxied: &proxy,
Priority: &priority,
}
err = api.UpdateDNSRecord(context.Background(), zoneID, recordID, record)
err = api.UpdateDNSRecord(context.Background(), cloudflare.ZoneIdentifier(zoneID), record)
if err != nil {
fmt.Fprintln(os.Stderr, "Error updating DNS record: ", err)
return err
Expand All @@ -194,7 +201,7 @@ func dnsDelete(c *cli.Context) error {
return err
}

err = api.DeleteDNSRecord(context.Background(), zoneID, recordID)
err = api.DeleteDNSRecord(context.Background(), cloudflare.ZoneIdentifier(zoneID), recordID)
if err != nil {
fmt.Fprintln(os.Stderr, "Error deleting DNS record: ", err)
return err
Expand Down
8 changes: 4 additions & 4 deletions cmd/flarectl/zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ func zoneRecords(c *cli.Context) error {
return err
}

// Create a an empty record for searching for records
rr := cloudflare.DNSRecord{}
// Create an empty record for searching for records
rr := cloudflare.ListDNSRecordsParams{}
var records []cloudflare.DNSRecord
if c.String("id") != "" {
rec, err := api.DNSRecord(context.Background(), zoneID, c.String("id"))
rec, err := api.GetDNSRecord(context.Background(), cloudflare.ZoneIdentifier(zoneID), c.String("id"))
if err != nil {
fmt.Println(err)
return err
Expand All @@ -300,7 +300,7 @@ func zoneRecords(c *cli.Context) error {
rr.Content = c.String("content")
}
var err error
records, err = api.DNSRecords(context.Background(), zoneID, rr)
records, _, err = api.ListDNSRecords(context.Background(), cloudflare.ZoneIdentifier(zoneID), rr)
if err != nil {
fmt.Println(err)
return err
Expand Down
Loading

0 comments on commit 2061a27

Please sign in to comment.