Kaynağa Gözat

update requests for bind api

Alexander Belanger 4 yıl önce
ebeveyn
işleme
8b175bae63

+ 27 - 9
internal/integrations/bind/bind.go

@@ -28,24 +28,42 @@ func NewClient(serverURL, apiKey string) *Client {
 	return &Client{apiKey, serverURL, httpClient}
 }
 
-// CNAMEData represents the data required to create or delete a CNAME record
+// RecordData represents the data required to create or delete an A/CNAME record
 // for the nameserver
-type CNAMEData struct {
-	Host     string `json:"host"`
+type RecordData struct {
+	Value    string `json:"value"`
+	Type     string `json:"type"`
 	Hostname string `json:"hostname"`
 }
 
 // CreateCNAMERecord creates a new CNAME record for the nameserver
-func (c *Client) CreateCNAMERecord(data *CNAMEData) error {
-	return c.sendRequest("POST", data)
+func (c *Client) CreateCNAMERecord(value, hostname string) error {
+	return c.sendRequest("POST", &RecordData{
+		Value:    value,
+		Type:     "CNAME",
+		Hostname: hostname,
+	})
 }
 
-// DeleteCNAMERecord deletes a new CNAME record for the nameserver
-func (c *Client) DeleteCNAMERecord(data *CNAMEData) error {
-	return c.sendRequest("DELETE", data)
+// CreateARecord creates a new A record for the nameserver
+func (c *Client) CreateARecord(value, hostname string) error {
+	return c.sendRequest("POST", &RecordData{
+		Value:    value,
+		Type:     "A",
+		Hostname: hostname,
+	})
 }
 
-func (c *Client) sendRequest(method string, data *CNAMEData) error {
+// DeleteARecord deletes a new A record for the nameserver
+func (c *Client) DeleteARecord(value, hostname string) error {
+	return c.sendRequest("DELETE", &RecordData{
+		Value:    value,
+		Type:     "A",
+		Hostname: hostname,
+	})
+}
+
+func (c *Client) sendRequest(method string, data *RecordData) error {
 	reqURL, err := url.Parse(c.serverURL)
 
 	if err != nil {

+ 2 - 6
internal/kubernetes/domain/domain.go

@@ -85,12 +85,8 @@ func (e *DNSRecord) CreateDomain(bindClient *bind.Client) error {
 	domain := fmt.Sprintf("%s.%s", e.SubdomainPrefix, e.RootDomain)
 
 	if isIPv4 {
-		// TODO: create A record
-		panic("unsupported")
+		return bindClient.CreateARecord(e.Endpoint, domain)
 	}
 
-	return bindClient.CreateCNAMERecord(&bind.CNAMEData{
-		Host:     e.Endpoint,
-		Hostname: domain,
-	})
+	return bindClient.CreateCNAMERecord(e.Endpoint, domain)
 }