Skip to content

Commit

Permalink
CLOUDNS: add LOC support
Browse files Browse the repository at this point in the history
  • Loading branch information
hmoffatt committed Sep 27, 2024
1 parent d6d50fc commit 0c65eb0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion documentation/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ If a feature is definitively not supported for whatever reason, we would also li
| [`BIND`](provider/bind.md) ||||||||||||||||||||||||
| [`BUNNY_DNS`](provider/bunny_dns.md) ||||||||||||||||||||||||
| [`CLOUDFLAREAPI`](provider/cloudflareapi.md) ||||||||||||||||||||||||
| [`CLOUDNS`](provider/cloudns.md) ||||||||| |||||||||||||||
| [`CLOUDNS`](provider/cloudns.md) ||||||||| |||||||||||||||
| [`CSCGLOBAL`](provider/cscglobal.md) ||||||||||||||||||||||||
| [`DESEC`](provider/desec.md) ||||||||||||||||||||||||
| [`DIGITALOCEAN`](provider/digitalocean.md) ||||||||||||||||||||||||
Expand Down
12 changes: 12 additions & 0 deletions providers/cloudns/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ type domainRecord struct {
DsAlgorithm string `json:"dsalgorithm,omitempty"`
DsDigestType string `json:"digest_type,omitempty"`
DsDigest string `json:"dsdigest,omitempty"`
LocLatDeg string `json:"lat_deg,omitempty"`
LocLatMin string `json:"lat_min,omitempty"`
LocLatSec string `json:"lat_sec,omitempty"`
LocLatDir string `json:"lat_dir,omitempty"`
LocLongDeg string `json:"long_deg,omitempty"`
LocLongMin string `json:"long_min,omitempty"`
LocLongSec string `json:"long_sec,omitempty"`
LocLongDir string `json:"long_dir,omitempty"`
LocAltitude string `json:"altitude,omitempty"`
LocSize string `json:"size,omitempty"`
LocHPrecision string `json:"h_precision,omitempty"`
LocVPrecision string `json:"v_precision,omitempty"`
}

type recordResponse map[string]domainRecord
Expand Down
31 changes: 30 additions & 1 deletion providers/cloudns/cloudnsProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var features = providers.DocumentationNotes{
providers.CanUseCAA: providers.Can(),
providers.CanUseDNAME: providers.Can(),
providers.CanUseDSForChildren: providers.Can(),
providers.CanUseLOC: providers.Cannot(),
providers.CanUseLOC: providers.Can(),
providers.CanUsePTR: providers.Can(),
providers.CanUseSRV: providers.Can(),
providers.CanUseSSHFP: providers.Can(),
Expand Down Expand Up @@ -340,13 +340,28 @@ func toRc(domain string, r *domainRecord) *models.RecordConfig {
case "CLOUD_WR":
rc.Type = "WR"
rc.SetTarget(r.Target)
case "LOC":
loc := fmt.Sprintf("%s %s %s %s %s %s %s %s %s %s %s %s",
r.LocLatDeg, r.LocLatMin, r.LocLatSec, r.LocLatDir,
r.LocLongDeg, r.LocLongMin, r.LocLongSec, r.LocLongDir,
r.LocAltitude, r.LocSize, r.LocHPrecision, r.LocVPrecision)
rc.SetTargetLOCString(r.Target, loc)
default:
rc.SetTarget(r.Target)
}

return rc
}

func formatLocParam(param string) string {
param = strings.Split(param, "m")[0]
// API misbehaves with a parameter of "0.00" and treats it as the default, so convert to "0" for this case only
if param == "0.00" {
param = "0"
}
return param
}

// toReq takes a RecordConfig and turns it into the native format used by the API.
func toReq(rc *models.RecordConfig) (requestParams, error) {
req := requestParams{
Expand Down Expand Up @@ -388,6 +403,20 @@ func toReq(rc *models.RecordConfig) (requestParams, error) {
req["algorithm"] = strconv.Itoa(int(rc.DsAlgorithm))
req["digest-type"] = strconv.Itoa(int(rc.DsDigestType))
req["record"] = rc.DsDigest
case "LOC":
parts := strings.Fields(rc.GetTargetCombined())
req["lat-deg"] = parts[0]
req["lat-min"] = parts[1]
req["lat-sec"] = parts[2]
req["lat-dir"] = parts[3]
req["long-deg"] = parts[4]
req["long-min"] = parts[5]
req["long-sec"] = parts[6]
req["long-dir"] = parts[7]
req["altitude"] = formatLocParam(parts[8])
req["size"] = formatLocParam(parts[9])
req["h-precision"] = formatLocParam(parts[10])
req["v-precision"] = formatLocParam(parts[11])
default:
return nil, fmt.Errorf("ClouDNS.toReq rtype %q unimplemented", rc.Type)
}
Expand Down

0 comments on commit 0c65eb0

Please sign in to comment.