diff --git a/dns.go b/dns.go index feab5e9..9b0534c 100644 --- a/dns.go +++ b/dns.go @@ -26,7 +26,7 @@ type DNSService interface { DeleteZone(ctx context.Context, zoneID string) error CreateRecord(ctx context.Context, zoneID string, crpl interface{}) (*Record, error) GetRecord(ctx context.Context, recordID string) (*Record, error) - UpdateRecord(ctx context.Context, recordID string, urpl *UpdateRecordPayload) (*ExtendedRecord, error) + UpdateRecord(ctx context.Context, recordID string, urpl interface{}) (*Record, error) DeleteRecord(ctx context.Context, recordID string) error } diff --git a/dns_record.go b/dns_record.go index 044cd2b..cc460a8 100644 --- a/dns_record.go +++ b/dns_record.go @@ -12,44 +12,20 @@ type WrappedRecordPayload struct { Record interface{} `json:"record"` } -// Addrs - contains the list of addresses in regions. -type Addrs struct { - HN []string `json:"HN"` - HCM []string `json:"HCM"` - SG []string `json:"SG"` - USA []string `json:"USA"` -} - -// RoutingData - contains the routing data for version 4 and 6 addresses. -type RoutingData struct { - AddrsV4 Addrs `json:"addrs_v4,omitempty"` - AddrsV6 Addrs `json:"addrs_v6,omitempty"` -} - -// RoutingPolicyData - contains the routing policy data for version 4 and 6 addresses and the health check information. -type RoutingPolicyData struct { - RoutingData RoutingData `json:"routing_data,omitempty"` - HealthCheck HealthCheck `json:"healthcheck,omitempty"` -} - -// HealthCheck - contains the health check information. -type HealthCheck struct { - TCPConnect TCPHealthCheck `json:"tcp_connect,omitempty"` - HTTPStatus HTTPHealthCheck `json:"http_status,omitempty"` -} - -// TCPHealthCheck - contains the TCP health check information. -type TCPHealthCheck struct { - TCPPort int `json:"tcp_port,omitempty"` +// MXData - contains the data for an MX record. +type MXData struct { + Value string `json:"value"` + Priority int `json:"priority"` } -// HTTPHealthCheck - contains the HTTP health check information. -type HTTPHealthCheck struct { - HTTPPort int `json:"http_port,omitempty"` - URLPath string `json:"url_path,omitempty"` - VHost string `json:"vhost,omitempty"` - OkCodes []int `json:"ok_codes,omitempty"` - Interval int `json:"interval,omitempty"` +// SRVData - contains the data for an SRV record. +type SRVData struct { + Port int `json:"port"` + Priority int `json:"priority"` + Protocol string `json:"protocol"` + Service string `json:"service"` + Target string `json:"target"` + Weight int `json:"weight"` } // BaseCreateRecordPayload - contains the base payload for creating a record. @@ -65,58 +41,54 @@ type CreateNormalRecordPayload struct { Data []string `json:"data"` } -// CreatePolicyRecordPayload - contains the payload for creating a policy record. -type CreatePolicyRecordPayload struct { - BaseCreateRecordPayload - RoutingPolicyData RoutingPolicyData `json:"routing_policy_data"` -} - // CreateMXRecordPayload - contains the payload for creating an MX record. type CreateMXRecordPayload struct { BaseCreateRecordPayload Data []MXData `json:"data"` } -// MXData - contains the data for an MX record. -type MXData struct { - Value string `json:"value"` - Priority int `json:"priority"` +// CreateSRVRecordPayload - contains the payload for creating an SRV record. +type CreateSRVRecordPayload struct { + BaseCreateRecordPayload + Data []SRVData `json:"data"` } -// RecordData - contains the data for a record. -type RecordData struct { - Value string `json:"value"` - Priority int `json:"priority"` +// BaseUpdateRecordPayload - contains the payload for updating a record. +type BaseUpdateRecordPayload struct { + ID string `json:"id,omitempty"` + Name string `json:"name,omitempty"` + Type string `json:"type,omitempty"` + TTL int `json:"ttl,omitempty"` +} +type UpdateNormalRecordPayload struct { + BaseUpdateRecordPayload + Data []string `json:"data"` } -// UpdateRecordPayload - contains the payload for updating a record. -type UpdateRecordPayload struct { - Name string `json:"name,omitempty"` - Type string `json:"type,omitempty"` - TTL int `json:"ttl,omitempty"` - Data []MXData `json:"data,omitempty"` - RoutingPolicyData RoutingPolicyData `json:"routing_policy_data,omitempty"` +// CreateMXRecordPayload - contains the payload for creating an MX record. +type UpdateMXRecordPayload struct { + BaseUpdateRecordPayload + Data []MXData `json:"data"` } -// Record - contains the information of a record. -type Record struct { - ID string `json:"id"` - Name string `json:"name"` - Delete int `json:"deleted"` - CreatedAt string `json:"created_at"` - UpdatedAt string `json:"updated_at"` - TenantID string `json:"tenant_id"` - ZoneID string `json:"zone_id"` - Type string `json:"type"` - TTL int `json:"ttl"` - Data []interface{} `json:"data"` - RoutingPolicyData RoutingPolicyData `json:"routing_policy_data"` +// UpdateSRVRecordPayload - contains the payload for creating an SRV record. +type UpdateSRVRecordPayload struct { + BaseUpdateRecordPayload + Data []SRVData `json:"data"` } -// ExtendedRecord - contains the extended information of a record. -type ExtendedRecord struct { - Record - Data []RecordData `json:"data"` +// Record - contains the information of a record. +type Record struct { + ID string `json:"id"` + Name string `json:"name"` + Delete int `json:"deleted"` + CreatedAt string `json:"created_at"` + UpdatedAt string `json:"updated_at"` + TenantID string `json:"tenant_id"` + ZoneID string `json:"zone_id"` + Type string `json:"type"` + TTL int `json:"ttl"` + Data []interface{} `json:"data"` } // Records - contains the list of records. @@ -168,8 +140,11 @@ func (d *dnsService) GetRecord(ctx context.Context, recordID string) (*Record, e } // UpdateRecord - Update a DNS record -func (d *dnsService) UpdateRecord(ctx context.Context, recordID string, urpl *UpdateRecordPayload) (*ExtendedRecord, error) { - req, err := d.client.NewRequest(ctx, http.MethodPut, dnsName, d.recordItemPath(recordID), urpl) +func (d *dnsService) UpdateRecord(ctx context.Context, recordID string, urpl interface{}) (*Record, error) { + payload := WrappedRecordPayload{ + Record: urpl, + } + req, err := d.client.NewRequest(ctx, http.MethodPut, dnsName, d.recordItemPath(recordID), &payload) if err != nil { return nil, err } @@ -178,7 +153,7 @@ func (d *dnsService) UpdateRecord(ctx context.Context, recordID string, urpl *Up return nil, err } defer resp.Body.Close() - var data *ExtendedRecord + var data *Record if err := json.NewDecoder(resp.Body).Decode(&data); err != nil { return nil, err } diff --git a/dns_test.go b/dns_test.go index 2a480ef..5979f35 100644 --- a/dns_test.go +++ b/dns_test.go @@ -81,7 +81,7 @@ func TestCreateZone(t *testing.T) { "id": "47b9147c-7332-4dd8-b56e-56c3a30d6bd5", "name": "ddddafs.com", "type": "NS", - "ttl": "3600", + "ttl": 3600, "data": [ "ns4.bizflycloud.vn.", "ns5.bizflycloud.vn.", @@ -93,7 +93,7 @@ func TestCreateZone(t *testing.T) { "id": "30ac3108-ac5e-43e8-9eea-1743d6770aa5", "name": "ddddafs.com", "type": "SOA", - "ttl": "3600", + "ttl": 3600, "data": [ "ns4.bizflycloud.vn." ], @@ -249,7 +249,7 @@ func TestUpdateRecord(t *testing.T) { var d dnsService mux.HandleFunc(testlib.DNSURL(d.recordItemPath("0ed9f98b-7991-4d49-929f-801f246d21f3")), func(writer http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPut, r.Method) - var payload *UpdateRecordPayload + var payload *UpdateMXRecordPayload require.NoError(t, json.NewDecoder(r.Body).Decode(&payload)) resp := `{ "id": "0ed9f98b-7991-4d49-929f-801f246d21f3", @@ -275,10 +275,12 @@ func TestUpdateRecord(t *testing.T) { }` _, _ = fmt.Fprint(writer, resp) }) - payload := UpdateRecordPayload{ - Name: "mx", - Type: "MX", - TTL: 300, + payload := UpdateMXRecordPayload{ + BaseUpdateRecordPayload: BaseUpdateRecordPayload{ + Name: "mx", + Type: "MX", + TTL: 300, + }, Data: []MXData{ MXData{ Value: "imap1.vccloud.vn", @@ -289,7 +291,6 @@ func TestUpdateRecord(t *testing.T) { Priority: 2, }, }, - RoutingPolicyData: RoutingPolicyData{}, } zone, err := client.DNS.UpdateRecord(ctx, "0ed9f98b-7991-4d49-929f-801f246d21f3", &payload) require.NoError(t, err) diff --git a/dns_zone.go b/dns_zone.go index 109f157..1b67b1a 100644 --- a/dns_zone.go +++ b/dns_zone.go @@ -13,14 +13,6 @@ type Meta struct { Page int `json:"page"` } -// RecordSet - contains the information of a record set -type RecordSet struct { - ID string `json:"id"` - Name string `json:"name"` - Type string `json:"type"` - TTL string `json:"ttl"` -} - // Zone - contains the information of a zone type Zone struct { ID string `json:"id"` @@ -42,7 +34,7 @@ type WrappedZonePayload struct { // ExtendedZone - contains the information of a zone and embedded record sets type ExtendedZone struct { Zone - RecordsSet []RecordSet `json:"record_set"` + RecordsSet []Record `json:"record_set"` } // ListZoneResp - contains the response of list zones and metadata