mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-16 07:16:38 +00:00
[management] Add custom dns zones (#4849)
This commit is contained in:
@@ -59,9 +59,13 @@ type Client struct {
|
||||
Routes *RoutesAPI
|
||||
|
||||
// DNS NetBird DNS APIs
|
||||
// see more: https://docs.netbird.io/api/resources/routes
|
||||
// see more: https://docs.netbird.io/api/resources/dns
|
||||
DNS *DNSAPI
|
||||
|
||||
// DNSZones NetBird DNS Zones APIs
|
||||
// see more: https://docs.netbird.io/api/resources/dns-zones
|
||||
DNSZones *DNSZonesAPI
|
||||
|
||||
// GeoLocation NetBird Geo Location APIs
|
||||
// see more: https://docs.netbird.io/api/resources/geo-locations
|
||||
GeoLocation *GeoLocationAPI
|
||||
@@ -113,6 +117,7 @@ func (c *Client) initialize() {
|
||||
c.Networks = &NetworksAPI{c}
|
||||
c.Routes = &RoutesAPI{c}
|
||||
c.DNS = &DNSAPI{c}
|
||||
c.DNSZones = &DNSZonesAPI{c}
|
||||
c.GeoLocation = &GeoLocationAPI{c}
|
||||
c.Events = &EventsAPI{c}
|
||||
}
|
||||
|
||||
170
shared/management/client/rest/dns_zones.go
Normal file
170
shared/management/client/rest/dns_zones.go
Normal file
@@ -0,0 +1,170 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/netbirdio/netbird/shared/management/http/api"
|
||||
)
|
||||
|
||||
// DNSZonesAPI APIs for DNS Zones Management, do not use directly
|
||||
type DNSZonesAPI struct {
|
||||
c *Client
|
||||
}
|
||||
|
||||
// ListZones list all DNS zones
|
||||
// See more: https://docs.netbird.io/api/resources/dns-zones#list-all-dns-zones
|
||||
func (a *DNSZonesAPI) ListZones(ctx context.Context) ([]api.Zone, error) {
|
||||
resp, err := a.c.NewRequest(ctx, "GET", "/api/dns/zones", nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.Body != nil {
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
ret, err := parseResponse[[]api.Zone](resp)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
// GetZone get DNS zone info
|
||||
// See more: https://docs.netbird.io/api/resources/dns-zones#retrieve-a-dns-zone
|
||||
func (a *DNSZonesAPI) GetZone(ctx context.Context, zoneID string) (*api.Zone, error) {
|
||||
resp, err := a.c.NewRequest(ctx, "GET", "/api/dns/zones/"+zoneID, nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.Body != nil {
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
ret, err := parseResponse[api.Zone](resp)
|
||||
return &ret, err
|
||||
}
|
||||
|
||||
// CreateZone create new DNS zone
|
||||
// See more: https://docs.netbird.io/api/resources/dns-zones#create-a-dns-zone
|
||||
func (a *DNSZonesAPI) CreateZone(ctx context.Context, request api.PostApiDnsZonesJSONRequestBody) (*api.Zone, error) {
|
||||
requestBytes, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := a.c.NewRequest(ctx, "POST", "/api/dns/zones", bytes.NewReader(requestBytes), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.Body != nil {
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
ret, err := parseResponse[api.Zone](resp)
|
||||
return &ret, err
|
||||
}
|
||||
|
||||
// UpdateZone update DNS zone info
|
||||
// See more: https://docs.netbird.io/api/resources/dns-zones#update-a-dns-zone
|
||||
func (a *DNSZonesAPI) UpdateZone(ctx context.Context, zoneID string, request api.PutApiDnsZonesZoneIdJSONRequestBody) (*api.Zone, error) {
|
||||
requestBytes, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := a.c.NewRequest(ctx, "PUT", "/api/dns/zones/"+zoneID, bytes.NewReader(requestBytes), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.Body != nil {
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
ret, err := parseResponse[api.Zone](resp)
|
||||
return &ret, err
|
||||
}
|
||||
|
||||
// DeleteZone delete DNS zone
|
||||
// See more: https://docs.netbird.io/api/resources/dns-zones#delete-a-dns-zone
|
||||
func (a *DNSZonesAPI) DeleteZone(ctx context.Context, zoneID string) error {
|
||||
resp, err := a.c.NewRequest(ctx, "DELETE", "/api/dns/zones/"+zoneID, nil, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if resp.Body != nil {
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListRecords list all DNS records in a zone
|
||||
// See more: https://docs.netbird.io/api/resources/dns-zones#list-all-dns-records
|
||||
func (a *DNSZonesAPI) ListRecords(ctx context.Context, zoneID string) ([]api.DNSRecord, error) {
|
||||
resp, err := a.c.NewRequest(ctx, "GET", "/api/dns/zones/"+zoneID+"/records", nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.Body != nil {
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
ret, err := parseResponse[[]api.DNSRecord](resp)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
// GetRecord get DNS record info
|
||||
// See more: https://docs.netbird.io/api/resources/dns-zones#retrieve-a-dns-record
|
||||
func (a *DNSZonesAPI) GetRecord(ctx context.Context, zoneID, recordID string) (*api.DNSRecord, error) {
|
||||
resp, err := a.c.NewRequest(ctx, "GET", "/api/dns/zones/"+zoneID+"/records/"+recordID, nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.Body != nil {
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
ret, err := parseResponse[api.DNSRecord](resp)
|
||||
return &ret, err
|
||||
}
|
||||
|
||||
// CreateRecord create new DNS record in a zone
|
||||
// See more: https://docs.netbird.io/api/resources/dns-zones#create-a-dns-record
|
||||
func (a *DNSZonesAPI) CreateRecord(ctx context.Context, zoneID string, request api.PostApiDnsZonesZoneIdRecordsJSONRequestBody) (*api.DNSRecord, error) {
|
||||
requestBytes, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := a.c.NewRequest(ctx, "POST", "/api/dns/zones/"+zoneID+"/records", bytes.NewReader(requestBytes), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.Body != nil {
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
ret, err := parseResponse[api.DNSRecord](resp)
|
||||
return &ret, err
|
||||
}
|
||||
|
||||
// UpdateRecord update DNS record info
|
||||
// See more: https://docs.netbird.io/api/resources/dns-zones#update-a-dns-record
|
||||
func (a *DNSZonesAPI) UpdateRecord(ctx context.Context, zoneID, recordID string, request api.PutApiDnsZonesZoneIdRecordsRecordIdJSONRequestBody) (*api.DNSRecord, error) {
|
||||
requestBytes, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := a.c.NewRequest(ctx, "PUT", "/api/dns/zones/"+zoneID+"/records/"+recordID, bytes.NewReader(requestBytes), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.Body != nil {
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
ret, err := parseResponse[api.DNSRecord](resp)
|
||||
return &ret, err
|
||||
}
|
||||
|
||||
// DeleteRecord delete DNS record
|
||||
// See more: https://docs.netbird.io/api/resources/dns-zones#delete-a-dns-record
|
||||
func (a *DNSZonesAPI) DeleteRecord(ctx context.Context, zoneID, recordID string) error {
|
||||
resp, err := a.c.NewRequest(ctx, "DELETE", "/api/dns/zones/"+zoneID+"/records/"+recordID, nil, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if resp.Body != nil {
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
460
shared/management/client/rest/dns_zones_test.go
Normal file
460
shared/management/client/rest/dns_zones_test.go
Normal file
@@ -0,0 +1,460 @@
|
||||
//go:build integration
|
||||
// +build integration
|
||||
|
||||
package rest_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/netbirdio/netbird/shared/management/client/rest"
|
||||
"github.com/netbirdio/netbird/shared/management/http/api"
|
||||
"github.com/netbirdio/netbird/shared/management/http/util"
|
||||
)
|
||||
|
||||
var (
|
||||
testZone = api.Zone{
|
||||
Id: "zone123",
|
||||
Name: "test-zone",
|
||||
Domain: "example.com",
|
||||
Enabled: true,
|
||||
EnableSearchDomain: false,
|
||||
DistributionGroups: []string{"group1"},
|
||||
}
|
||||
|
||||
testDNSRecord = api.DNSRecord{
|
||||
Id: "record123",
|
||||
Name: "www",
|
||||
Content: "192.168.1.1",
|
||||
Type: api.DNSRecordTypeA,
|
||||
Ttl: 300,
|
||||
}
|
||||
)
|
||||
|
||||
func TestDNSZone_List_200(t *testing.T) {
|
||||
withMockClient(func(c *rest.Client, mux *http.ServeMux) {
|
||||
mux.HandleFunc("/api/dns/zones", func(w http.ResponseWriter, r *http.Request) {
|
||||
assert.Equal(t, "GET", r.Method)
|
||||
retBytes, _ := json.Marshal([]api.Zone{testZone})
|
||||
_, err := w.Write(retBytes)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
ret, err := c.DNSZones.ListZones(context.Background())
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, ret, 1)
|
||||
assert.Equal(t, testZone, ret[0])
|
||||
})
|
||||
}
|
||||
|
||||
func TestDNSZone_List_Err(t *testing.T) {
|
||||
withMockClient(func(c *rest.Client, mux *http.ServeMux) {
|
||||
mux.HandleFunc("/api/dns/zones", func(w http.ResponseWriter, r *http.Request) {
|
||||
retBytes, _ := json.Marshal(util.ErrorResponse{Message: "No", Code: 400})
|
||||
w.WriteHeader(400)
|
||||
_, err := w.Write(retBytes)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
ret, err := c.DNSZones.ListZones(context.Background())
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, "No", err.Error())
|
||||
assert.Empty(t, ret)
|
||||
})
|
||||
}
|
||||
|
||||
func TestDNSZone_Get_200(t *testing.T) {
|
||||
withMockClient(func(c *rest.Client, mux *http.ServeMux) {
|
||||
mux.HandleFunc("/api/dns/zones/zone123", func(w http.ResponseWriter, r *http.Request) {
|
||||
assert.Equal(t, "GET", r.Method)
|
||||
retBytes, _ := json.Marshal(testZone)
|
||||
_, err := w.Write(retBytes)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
ret, err := c.DNSZones.GetZone(context.Background(), "zone123")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testZone, *ret)
|
||||
})
|
||||
}
|
||||
|
||||
func TestDNSZone_Get_Err(t *testing.T) {
|
||||
withMockClient(func(c *rest.Client, mux *http.ServeMux) {
|
||||
mux.HandleFunc("/api/dns/zones/zone123", func(w http.ResponseWriter, r *http.Request) {
|
||||
retBytes, _ := json.Marshal(util.ErrorResponse{Message: "Not found", Code: 404})
|
||||
w.WriteHeader(404)
|
||||
_, err := w.Write(retBytes)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
ret, err := c.DNSZones.GetZone(context.Background(), "zone123")
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, "Not found", err.Error())
|
||||
assert.Empty(t, ret)
|
||||
})
|
||||
}
|
||||
|
||||
func TestDNSZone_Create_200(t *testing.T) {
|
||||
withMockClient(func(c *rest.Client, mux *http.ServeMux) {
|
||||
mux.HandleFunc("/api/dns/zones", func(w http.ResponseWriter, r *http.Request) {
|
||||
assert.Equal(t, "POST", r.Method)
|
||||
reqBytes, err := io.ReadAll(r.Body)
|
||||
require.NoError(t, err)
|
||||
var req api.PostApiDnsZonesJSONRequestBody
|
||||
err = json.Unmarshal(reqBytes, &req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "test-zone", req.Name)
|
||||
assert.Equal(t, "example.com", req.Domain)
|
||||
retBytes, _ := json.Marshal(testZone)
|
||||
_, err = w.Write(retBytes)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
enabled := true
|
||||
ret, err := c.DNSZones.CreateZone(context.Background(), api.PostApiDnsZonesJSONRequestBody{
|
||||
Name: "test-zone",
|
||||
Domain: "example.com",
|
||||
Enabled: &enabled,
|
||||
EnableSearchDomain: false,
|
||||
DistributionGroups: []string{"group1"},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testZone, *ret)
|
||||
})
|
||||
}
|
||||
|
||||
func TestDNSZone_Create_Err(t *testing.T) {
|
||||
withMockClient(func(c *rest.Client, mux *http.ServeMux) {
|
||||
mux.HandleFunc("/api/dns/zones", func(w http.ResponseWriter, r *http.Request) {
|
||||
retBytes, _ := json.Marshal(util.ErrorResponse{Message: "Invalid request", Code: 400})
|
||||
w.WriteHeader(400)
|
||||
_, err := w.Write(retBytes)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
ret, err := c.DNSZones.CreateZone(context.Background(), api.PostApiDnsZonesJSONRequestBody{
|
||||
Name: "test-zone",
|
||||
Domain: "example.com",
|
||||
})
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, "Invalid request", err.Error())
|
||||
assert.Nil(t, ret)
|
||||
})
|
||||
}
|
||||
|
||||
func TestDNSZone_Update_200(t *testing.T) {
|
||||
withMockClient(func(c *rest.Client, mux *http.ServeMux) {
|
||||
mux.HandleFunc("/api/dns/zones/zone123", func(w http.ResponseWriter, r *http.Request) {
|
||||
assert.Equal(t, "PUT", r.Method)
|
||||
reqBytes, err := io.ReadAll(r.Body)
|
||||
require.NoError(t, err)
|
||||
var req api.PutApiDnsZonesZoneIdJSONRequestBody
|
||||
err = json.Unmarshal(reqBytes, &req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "updated-zone", req.Name)
|
||||
retBytes, _ := json.Marshal(testZone)
|
||||
_, err = w.Write(retBytes)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
enabled := true
|
||||
ret, err := c.DNSZones.UpdateZone(context.Background(), "zone123", api.PutApiDnsZonesZoneIdJSONRequestBody{
|
||||
Name: "updated-zone",
|
||||
Domain: "example.com",
|
||||
Enabled: &enabled,
|
||||
EnableSearchDomain: false,
|
||||
DistributionGroups: []string{"group1"},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testZone, *ret)
|
||||
})
|
||||
}
|
||||
|
||||
func TestDNSZone_Update_Err(t *testing.T) {
|
||||
withMockClient(func(c *rest.Client, mux *http.ServeMux) {
|
||||
mux.HandleFunc("/api/dns/zones/zone123", func(w http.ResponseWriter, r *http.Request) {
|
||||
retBytes, _ := json.Marshal(util.ErrorResponse{Message: "Invalid request", Code: 400})
|
||||
w.WriteHeader(400)
|
||||
_, err := w.Write(retBytes)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
ret, err := c.DNSZones.UpdateZone(context.Background(), "zone123", api.PutApiDnsZonesZoneIdJSONRequestBody{
|
||||
Name: "updated-zone",
|
||||
Domain: "example.com",
|
||||
})
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, "Invalid request", err.Error())
|
||||
assert.Nil(t, ret)
|
||||
})
|
||||
}
|
||||
|
||||
func TestDNSZone_Delete_200(t *testing.T) {
|
||||
withMockClient(func(c *rest.Client, mux *http.ServeMux) {
|
||||
mux.HandleFunc("/api/dns/zones/zone123", func(w http.ResponseWriter, r *http.Request) {
|
||||
assert.Equal(t, "DELETE", r.Method)
|
||||
w.WriteHeader(200)
|
||||
})
|
||||
err := c.DNSZones.DeleteZone(context.Background(), "zone123")
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestDNSZone_Delete_Err(t *testing.T) {
|
||||
withMockClient(func(c *rest.Client, mux *http.ServeMux) {
|
||||
mux.HandleFunc("/api/dns/zones/zone123", func(w http.ResponseWriter, r *http.Request) {
|
||||
retBytes, _ := json.Marshal(util.ErrorResponse{Message: "Not found", Code: 404})
|
||||
w.WriteHeader(404)
|
||||
_, err := w.Write(retBytes)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
err := c.DNSZones.DeleteZone(context.Background(), "zone123")
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, "Not found", err.Error())
|
||||
})
|
||||
}
|
||||
|
||||
func TestDNSRecord_List_200(t *testing.T) {
|
||||
withMockClient(func(c *rest.Client, mux *http.ServeMux) {
|
||||
mux.HandleFunc("/api/dns/zones/zone123/records", func(w http.ResponseWriter, r *http.Request) {
|
||||
assert.Equal(t, "GET", r.Method)
|
||||
retBytes, _ := json.Marshal([]api.DNSRecord{testDNSRecord})
|
||||
_, err := w.Write(retBytes)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
ret, err := c.DNSZones.ListRecords(context.Background(), "zone123")
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, ret, 1)
|
||||
assert.Equal(t, testDNSRecord, ret[0])
|
||||
})
|
||||
}
|
||||
|
||||
func TestDNSRecord_List_Err(t *testing.T) {
|
||||
withMockClient(func(c *rest.Client, mux *http.ServeMux) {
|
||||
mux.HandleFunc("/api/dns/zones/zone123/records", func(w http.ResponseWriter, r *http.Request) {
|
||||
retBytes, _ := json.Marshal(util.ErrorResponse{Message: "Zone not found", Code: 404})
|
||||
w.WriteHeader(404)
|
||||
_, err := w.Write(retBytes)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
ret, err := c.DNSZones.ListRecords(context.Background(), "zone123")
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, "Zone not found", err.Error())
|
||||
assert.Empty(t, ret)
|
||||
})
|
||||
}
|
||||
|
||||
func TestDNSRecord_Get_200(t *testing.T) {
|
||||
withMockClient(func(c *rest.Client, mux *http.ServeMux) {
|
||||
mux.HandleFunc("/api/dns/zones/zone123/records/record123", func(w http.ResponseWriter, r *http.Request) {
|
||||
assert.Equal(t, "GET", r.Method)
|
||||
retBytes, _ := json.Marshal(testDNSRecord)
|
||||
_, err := w.Write(retBytes)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
ret, err := c.DNSZones.GetRecord(context.Background(), "zone123", "record123")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testDNSRecord, *ret)
|
||||
})
|
||||
}
|
||||
|
||||
func TestDNSRecord_Get_Err(t *testing.T) {
|
||||
withMockClient(func(c *rest.Client, mux *http.ServeMux) {
|
||||
mux.HandleFunc("/api/dns/zones/zone123/records/record123", func(w http.ResponseWriter, r *http.Request) {
|
||||
retBytes, _ := json.Marshal(util.ErrorResponse{Message: "Not found", Code: 404})
|
||||
w.WriteHeader(404)
|
||||
_, err := w.Write(retBytes)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
ret, err := c.DNSZones.GetRecord(context.Background(), "zone123", "record123")
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, "Not found", err.Error())
|
||||
assert.Empty(t, ret)
|
||||
})
|
||||
}
|
||||
|
||||
func TestDNSRecord_Create_200(t *testing.T) {
|
||||
withMockClient(func(c *rest.Client, mux *http.ServeMux) {
|
||||
mux.HandleFunc("/api/dns/zones/zone123/records", func(w http.ResponseWriter, r *http.Request) {
|
||||
assert.Equal(t, "POST", r.Method)
|
||||
reqBytes, err := io.ReadAll(r.Body)
|
||||
require.NoError(t, err)
|
||||
var req api.PostApiDnsZonesZoneIdRecordsJSONRequestBody
|
||||
err = json.Unmarshal(reqBytes, &req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "www", req.Name)
|
||||
assert.Equal(t, "192.168.1.1", req.Content)
|
||||
assert.Equal(t, api.DNSRecordTypeA, req.Type)
|
||||
retBytes, _ := json.Marshal(testDNSRecord)
|
||||
_, err = w.Write(retBytes)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
ret, err := c.DNSZones.CreateRecord(context.Background(), "zone123", api.PostApiDnsZonesZoneIdRecordsJSONRequestBody{
|
||||
Name: "www",
|
||||
Content: "192.168.1.1",
|
||||
Type: api.DNSRecordTypeA,
|
||||
Ttl: 300,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testDNSRecord, *ret)
|
||||
})
|
||||
}
|
||||
|
||||
func TestDNSRecord_Create_Err(t *testing.T) {
|
||||
withMockClient(func(c *rest.Client, mux *http.ServeMux) {
|
||||
mux.HandleFunc("/api/dns/zones/zone123/records", func(w http.ResponseWriter, r *http.Request) {
|
||||
retBytes, _ := json.Marshal(util.ErrorResponse{Message: "Invalid record", Code: 400})
|
||||
w.WriteHeader(400)
|
||||
_, err := w.Write(retBytes)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
ret, err := c.DNSZones.CreateRecord(context.Background(), "zone123", api.PostApiDnsZonesZoneIdRecordsJSONRequestBody{
|
||||
Name: "www",
|
||||
Content: "192.168.1.1",
|
||||
Type: api.DNSRecordTypeA,
|
||||
Ttl: 300,
|
||||
})
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, "Invalid record", err.Error())
|
||||
assert.Nil(t, ret)
|
||||
})
|
||||
}
|
||||
|
||||
func TestDNSRecord_Update_200(t *testing.T) {
|
||||
withMockClient(func(c *rest.Client, mux *http.ServeMux) {
|
||||
mux.HandleFunc("/api/dns/zones/zone123/records/record123", func(w http.ResponseWriter, r *http.Request) {
|
||||
assert.Equal(t, "PUT", r.Method)
|
||||
reqBytes, err := io.ReadAll(r.Body)
|
||||
require.NoError(t, err)
|
||||
var req api.PutApiDnsZonesZoneIdRecordsRecordIdJSONRequestBody
|
||||
err = json.Unmarshal(reqBytes, &req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "api", req.Name)
|
||||
assert.Equal(t, "192.168.1.2", req.Content)
|
||||
retBytes, _ := json.Marshal(testDNSRecord)
|
||||
_, err = w.Write(retBytes)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
ret, err := c.DNSZones.UpdateRecord(context.Background(), "zone123", "record123", api.PutApiDnsZonesZoneIdRecordsRecordIdJSONRequestBody{
|
||||
Name: "api",
|
||||
Content: "192.168.1.2",
|
||||
Type: api.DNSRecordTypeA,
|
||||
Ttl: 300,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testDNSRecord, *ret)
|
||||
})
|
||||
}
|
||||
|
||||
func TestDNSRecord_Update_Err(t *testing.T) {
|
||||
withMockClient(func(c *rest.Client, mux *http.ServeMux) {
|
||||
mux.HandleFunc("/api/dns/zones/zone123/records/record123", func(w http.ResponseWriter, r *http.Request) {
|
||||
retBytes, _ := json.Marshal(util.ErrorResponse{Message: "Invalid record", Code: 400})
|
||||
w.WriteHeader(400)
|
||||
_, err := w.Write(retBytes)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
ret, err := c.DNSZones.UpdateRecord(context.Background(), "zone123", "record123", api.PutApiDnsZonesZoneIdRecordsRecordIdJSONRequestBody{
|
||||
Name: "api",
|
||||
Content: "192.168.1.2",
|
||||
Type: api.DNSRecordTypeA,
|
||||
Ttl: 300,
|
||||
})
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, "Invalid record", err.Error())
|
||||
assert.Nil(t, ret)
|
||||
})
|
||||
}
|
||||
|
||||
func TestDNSRecord_Delete_200(t *testing.T) {
|
||||
withMockClient(func(c *rest.Client, mux *http.ServeMux) {
|
||||
mux.HandleFunc("/api/dns/zones/zone123/records/record123", func(w http.ResponseWriter, r *http.Request) {
|
||||
assert.Equal(t, "DELETE", r.Method)
|
||||
w.WriteHeader(200)
|
||||
})
|
||||
err := c.DNSZones.DeleteRecord(context.Background(), "zone123", "record123")
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestDNSRecord_Delete_Err(t *testing.T) {
|
||||
withMockClient(func(c *rest.Client, mux *http.ServeMux) {
|
||||
mux.HandleFunc("/api/dns/zones/zone123/records/record123", func(w http.ResponseWriter, r *http.Request) {
|
||||
retBytes, _ := json.Marshal(util.ErrorResponse{Message: "Not found", Code: 404})
|
||||
w.WriteHeader(404)
|
||||
_, err := w.Write(retBytes)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
err := c.DNSZones.DeleteRecord(context.Background(), "zone123", "record123")
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, "Not found", err.Error())
|
||||
})
|
||||
}
|
||||
|
||||
func TestDNSZones_Integration(t *testing.T) {
|
||||
enabled := true
|
||||
zoneReq := api.ZoneRequest{
|
||||
Name: "test-zone",
|
||||
Domain: "test.example.com",
|
||||
Enabled: &enabled,
|
||||
EnableSearchDomain: false,
|
||||
DistributionGroups: []string{"cs1tnh0hhcjnqoiuebeg"},
|
||||
}
|
||||
|
||||
recordReq := api.DNSRecordRequest{
|
||||
Name: "api.test.example.com",
|
||||
Content: "192.168.1.100",
|
||||
Type: api.DNSRecordTypeA,
|
||||
Ttl: 300,
|
||||
}
|
||||
|
||||
withBlackBoxServer(t, func(c *rest.Client) {
|
||||
zone, err := c.DNSZones.CreateZone(context.Background(), zoneReq)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "test-zone", zone.Name)
|
||||
assert.Equal(t, "test.example.com", zone.Domain)
|
||||
|
||||
zones, err := c.DNSZones.ListZones(context.Background())
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, *zone, zones[0])
|
||||
|
||||
getZone, err := c.DNSZones.GetZone(context.Background(), zone.Id)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, *zone, *getZone)
|
||||
|
||||
zoneReq.Name = "updated-zone"
|
||||
updatedZone, err := c.DNSZones.UpdateZone(context.Background(), zone.Id, zoneReq)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "updated-zone", updatedZone.Name)
|
||||
|
||||
record, err := c.DNSZones.CreateRecord(context.Background(), zone.Id, recordReq)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "api.test.example.com", record.Name)
|
||||
assert.Equal(t, "192.168.1.100", record.Content)
|
||||
|
||||
records, err := c.DNSZones.ListRecords(context.Background(), zone.Id)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, *record, records[0])
|
||||
|
||||
getRecord, err := c.DNSZones.GetRecord(context.Background(), zone.Id, record.Id)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, *record, *getRecord)
|
||||
|
||||
recordReq.Name = "www.test.example.com"
|
||||
updatedRecord, err := c.DNSZones.UpdateRecord(context.Background(), zone.Id, record.Id, recordReq)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "www.test.example.com", updatedRecord.Name)
|
||||
|
||||
err = c.DNSZones.DeleteRecord(context.Background(), zone.Id, record.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
records, err = c.DNSZones.ListRecords(context.Background(), zone.Id)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, records, 0)
|
||||
|
||||
err = c.DNSZones.DeleteZone(context.Background(), zone.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
zones, err = c.DNSZones.ListZones(context.Background())
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, zones, 0)
|
||||
})
|
||||
}
|
||||
@@ -25,6 +25,8 @@ tags:
|
||||
description: Interact with and view information about routes.
|
||||
- name: DNS
|
||||
description: Interact with and view information about DNS configuration.
|
||||
- name: DNS Zones
|
||||
description: Interact with and view information about custom DNS zones.
|
||||
- name: Events
|
||||
description: View information about the account and network events.
|
||||
- name: Accounts
|
||||
@@ -1779,6 +1781,100 @@ components:
|
||||
example: ch8i4ug6lnn4g9hqv7m0
|
||||
required:
|
||||
- disabled_management_groups
|
||||
ZoneRequest:
|
||||
type: object
|
||||
properties:
|
||||
name:
|
||||
description: Zone name identifier
|
||||
type: string
|
||||
maxLength: 255
|
||||
minLength: 1
|
||||
example: Office Zone
|
||||
domain:
|
||||
description: Zone domain (FQDN)
|
||||
type: string
|
||||
example: example.com
|
||||
enabled:
|
||||
description: Zone status
|
||||
type: boolean
|
||||
default: true
|
||||
enable_search_domain:
|
||||
description: Enable this zone as a search domain
|
||||
type: boolean
|
||||
example: false
|
||||
distribution_groups:
|
||||
description: Group IDs that defines groups of peers that will resolve this zone
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
example: ch8i4ug6lnn4g9hqv7m0
|
||||
required:
|
||||
- name
|
||||
- domain
|
||||
- enable_search_domain
|
||||
- distribution_groups
|
||||
Zone:
|
||||
allOf:
|
||||
- type: object
|
||||
properties:
|
||||
id:
|
||||
description: Zone ID
|
||||
type: string
|
||||
example: ch8i4ug6lnn4g9hqv7m0
|
||||
records:
|
||||
description: DNS records associated with this zone
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/DNSRecord'
|
||||
required:
|
||||
- id
|
||||
- enabled
|
||||
- records
|
||||
- $ref: '#/components/schemas/ZoneRequest'
|
||||
DNSRecordType:
|
||||
type: string
|
||||
description: DNS record type
|
||||
enum:
|
||||
- A
|
||||
- AAAA
|
||||
- CNAME
|
||||
example: A
|
||||
DNSRecordRequest:
|
||||
type: object
|
||||
properties:
|
||||
name:
|
||||
description: FQDN for the DNS record. Must be a subdomain within or match the zone's domain.
|
||||
type: string
|
||||
example: www.example.com
|
||||
type:
|
||||
$ref: '#/components/schemas/DNSRecordType'
|
||||
content:
|
||||
description: DNS record content (IP address for A/AAAA, domain for CNAME)
|
||||
type: string
|
||||
maxLength: 255
|
||||
minLength: 1
|
||||
example: 192.168.1.1
|
||||
ttl:
|
||||
description: Time to live in seconds
|
||||
type: integer
|
||||
minimum: 0
|
||||
example: 300
|
||||
required:
|
||||
- name
|
||||
- type
|
||||
- content
|
||||
- ttl
|
||||
DNSRecord:
|
||||
allOf:
|
||||
- type: object
|
||||
properties:
|
||||
id:
|
||||
description: DNS record ID
|
||||
type: string
|
||||
example: ch8i4ug6lnn4g9hqv7m0
|
||||
required:
|
||||
- id
|
||||
- $ref: '#/components/schemas/DNSRecordRequest'
|
||||
Event:
|
||||
type: object
|
||||
properties:
|
||||
@@ -4733,6 +4829,347 @@ paths:
|
||||
"$ref": "#/components/responses/forbidden"
|
||||
'500':
|
||||
"$ref": "#/components/responses/internal_error"
|
||||
/api/dns/zones:
|
||||
get:
|
||||
summary: List all DNS Zones
|
||||
description: Returns a list of all custom DNS zones
|
||||
tags: [ DNS Zones ]
|
||||
security:
|
||||
- BearerAuth: [ ]
|
||||
- TokenAuth: [ ]
|
||||
responses:
|
||||
'200':
|
||||
description: A JSON Array of DNS Zones
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Zone'
|
||||
'401':
|
||||
"$ref": "#/components/responses/requires_authentication"
|
||||
'403':
|
||||
"$ref": "#/components/responses/forbidden"
|
||||
'500':
|
||||
"$ref": "#/components/responses/internal_error"
|
||||
post:
|
||||
summary: Create a DNS Zone
|
||||
description: Creates a new custom DNS zone
|
||||
tags: [ DNS Zones ]
|
||||
security:
|
||||
- BearerAuth: [ ]
|
||||
- TokenAuth: [ ]
|
||||
requestBody:
|
||||
description: A DNS zone object
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: '#/components/schemas/ZoneRequest'
|
||||
responses:
|
||||
'200':
|
||||
description: A JSON Object of the created DNS Zone
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Zone'
|
||||
'400':
|
||||
"$ref": "#/components/responses/bad_request"
|
||||
'401':
|
||||
"$ref": "#/components/responses/requires_authentication"
|
||||
'403':
|
||||
"$ref": "#/components/responses/forbidden"
|
||||
'500':
|
||||
"$ref": "#/components/responses/internal_error"
|
||||
/api/dns/zones/{zoneId}:
|
||||
get:
|
||||
summary: Retrieve a DNS Zone
|
||||
description: Returns information about a specific DNS zone
|
||||
tags: [ DNS Zones ]
|
||||
security:
|
||||
- BearerAuth: [ ]
|
||||
- TokenAuth: [ ]
|
||||
parameters:
|
||||
- in: path
|
||||
name: zoneId
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
description: The unique identifier of a zone
|
||||
example: chacbco6lnnbn6cg5s91
|
||||
responses:
|
||||
'200':
|
||||
description: A JSON Object of a DNS Zone
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Zone'
|
||||
'400':
|
||||
"$ref": "#/components/responses/bad_request"
|
||||
'401':
|
||||
"$ref": "#/components/responses/requires_authentication"
|
||||
'403':
|
||||
"$ref": "#/components/responses/forbidden"
|
||||
'404':
|
||||
"$ref": "#/components/responses/not_found"
|
||||
'500':
|
||||
"$ref": "#/components/responses/internal_error"
|
||||
put:
|
||||
summary: Update a DNS Zone
|
||||
description: Updates a custom DNS zone
|
||||
tags: [ DNS Zones ]
|
||||
security:
|
||||
- BearerAuth: [ ]
|
||||
- TokenAuth: [ ]
|
||||
parameters:
|
||||
- in: path
|
||||
name: zoneId
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
description: The unique identifier of a zone
|
||||
example: chacbco6lnnbn6cg5s91
|
||||
requestBody:
|
||||
description: A DNS zone object
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: '#/components/schemas/ZoneRequest'
|
||||
responses:
|
||||
'200':
|
||||
description: A JSON Object of the updated DNS Zone
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Zone'
|
||||
'400':
|
||||
"$ref": "#/components/responses/bad_request"
|
||||
'401':
|
||||
"$ref": "#/components/responses/requires_authentication"
|
||||
'403':
|
||||
"$ref": "#/components/responses/forbidden"
|
||||
'404':
|
||||
"$ref": "#/components/responses/not_found"
|
||||
'500':
|
||||
"$ref": "#/components/responses/internal_error"
|
||||
delete:
|
||||
summary: Delete a DNS Zone
|
||||
description: Deletes a custom DNS zone
|
||||
tags: [ DNS Zones ]
|
||||
security:
|
||||
- BearerAuth: [ ]
|
||||
- TokenAuth: [ ]
|
||||
parameters:
|
||||
- in: path
|
||||
name: zoneId
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
description: The unique identifier of a zone
|
||||
example: chacbco6lnnbn6cg5s91
|
||||
responses:
|
||||
'200':
|
||||
description: Zone deletion successful
|
||||
'400':
|
||||
"$ref": "#/components/responses/bad_request"
|
||||
'401':
|
||||
"$ref": "#/components/responses/requires_authentication"
|
||||
'403':
|
||||
"$ref": "#/components/responses/forbidden"
|
||||
'404':
|
||||
"$ref": "#/components/responses/not_found"
|
||||
'500':
|
||||
"$ref": "#/components/responses/internal_error"
|
||||
/api/dns/zones/{zoneId}/records:
|
||||
get:
|
||||
summary: List all DNS Records
|
||||
description: Returns a list of all DNS records in a zone
|
||||
tags: [ DNS Zones ]
|
||||
security:
|
||||
- BearerAuth: [ ]
|
||||
- TokenAuth: [ ]
|
||||
parameters:
|
||||
- in: path
|
||||
name: zoneId
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
description: The unique identifier of a zone
|
||||
example: chacbco6lnnbn6cg5s91
|
||||
responses:
|
||||
'200':
|
||||
description: A JSON Array of DNS Records
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/DNSRecord'
|
||||
'401':
|
||||
"$ref": "#/components/responses/requires_authentication"
|
||||
'403':
|
||||
"$ref": "#/components/responses/forbidden"
|
||||
'404':
|
||||
"$ref": "#/components/responses/not_found"
|
||||
'500':
|
||||
"$ref": "#/components/responses/internal_error"
|
||||
post:
|
||||
summary: Create a DNS Record
|
||||
description: Creates a new DNS record in a zone
|
||||
tags: [ DNS Zones ]
|
||||
security:
|
||||
- BearerAuth: [ ]
|
||||
- TokenAuth: [ ]
|
||||
parameters:
|
||||
- in: path
|
||||
name: zoneId
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
description: The unique identifier of a zone
|
||||
example: chacbco6lnnbn6cg5s91
|
||||
requestBody:
|
||||
description: A DNS record object
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: '#/components/schemas/DNSRecordRequest'
|
||||
responses:
|
||||
'200':
|
||||
description: A JSON Object of the created DNS Record
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/DNSRecord'
|
||||
'400':
|
||||
"$ref": "#/components/responses/bad_request"
|
||||
'401':
|
||||
"$ref": "#/components/responses/requires_authentication"
|
||||
'403':
|
||||
"$ref": "#/components/responses/forbidden"
|
||||
'404':
|
||||
"$ref": "#/components/responses/not_found"
|
||||
'500':
|
||||
"$ref": "#/components/responses/internal_error"
|
||||
/api/dns/zones/{zoneId}/records/{recordId}:
|
||||
get:
|
||||
summary: Retrieve a DNS Record
|
||||
description: Returns information about a specific DNS record
|
||||
tags: [ DNS Zones ]
|
||||
security:
|
||||
- BearerAuth: [ ]
|
||||
- TokenAuth: [ ]
|
||||
parameters:
|
||||
- in: path
|
||||
name: zoneId
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
description: The unique identifier of a zone
|
||||
example: chacbco6lnnbn6cg5s91
|
||||
- in: path
|
||||
name: recordId
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
description: The unique identifier of a DNS record
|
||||
example: chacbco6lnnbn6cg5s92
|
||||
responses:
|
||||
'200':
|
||||
description: A JSON Object of a DNS Record
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/DNSRecord'
|
||||
'400':
|
||||
"$ref": "#/components/responses/bad_request"
|
||||
'401':
|
||||
"$ref": "#/components/responses/requires_authentication"
|
||||
'403':
|
||||
"$ref": "#/components/responses/forbidden"
|
||||
'404':
|
||||
"$ref": "#/components/responses/not_found"
|
||||
'500':
|
||||
"$ref": "#/components/responses/internal_error"
|
||||
put:
|
||||
summary: Update a DNS Record
|
||||
description: Updates a DNS record in a zone
|
||||
tags: [ DNS Zones ]
|
||||
security:
|
||||
- BearerAuth: [ ]
|
||||
- TokenAuth: [ ]
|
||||
parameters:
|
||||
- in: path
|
||||
name: zoneId
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
description: The unique identifier of a zone
|
||||
example: chacbco6lnnbn6cg5s91
|
||||
- in: path
|
||||
name: recordId
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
description: The unique identifier of a DNS record
|
||||
example: chacbco6lnnbn6cg5s92
|
||||
requestBody:
|
||||
description: A DNS record object
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: '#/components/schemas/DNSRecordRequest'
|
||||
responses:
|
||||
'200':
|
||||
description: A JSON Object of the updated DNS Record
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/DNSRecord'
|
||||
'400':
|
||||
"$ref": "#/components/responses/bad_request"
|
||||
'401':
|
||||
"$ref": "#/components/responses/requires_authentication"
|
||||
'403':
|
||||
"$ref": "#/components/responses/forbidden"
|
||||
'404':
|
||||
"$ref": "#/components/responses/not_found"
|
||||
'500':
|
||||
"$ref": "#/components/responses/internal_error"
|
||||
delete:
|
||||
summary: Delete a DNS Record
|
||||
description: Deletes a DNS record from a zone
|
||||
tags: [ DNS Zones ]
|
||||
security:
|
||||
- BearerAuth: [ ]
|
||||
- TokenAuth: [ ]
|
||||
parameters:
|
||||
- in: path
|
||||
name: zoneId
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
description: The unique identifier of a zone
|
||||
example: chacbco6lnnbn6cg5s91
|
||||
- in: path
|
||||
name: recordId
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
description: The unique identifier of a DNS record
|
||||
example: chacbco6lnnbn6cg5s92
|
||||
responses:
|
||||
'200':
|
||||
description: Record deletion successful
|
||||
'400':
|
||||
"$ref": "#/components/responses/bad_request"
|
||||
'401':
|
||||
"$ref": "#/components/responses/requires_authentication"
|
||||
'403':
|
||||
"$ref": "#/components/responses/forbidden"
|
||||
'404':
|
||||
"$ref": "#/components/responses/not_found"
|
||||
'500':
|
||||
"$ref": "#/components/responses/internal_error"
|
||||
/api/events/audit:
|
||||
get:
|
||||
summary: List all Audit Events
|
||||
|
||||
@@ -12,6 +12,13 @@ const (
|
||||
TokenAuthScopes = "TokenAuth.Scopes"
|
||||
)
|
||||
|
||||
// Defines values for DNSRecordType.
|
||||
const (
|
||||
DNSRecordTypeA DNSRecordType = "A"
|
||||
DNSRecordTypeAAAA DNSRecordType = "AAAA"
|
||||
DNSRecordTypeCNAME DNSRecordType = "CNAME"
|
||||
)
|
||||
|
||||
// Defines values for EventActivityCode.
|
||||
const (
|
||||
EventActivityCodeAccountCreate EventActivityCode = "account.create"
|
||||
@@ -427,6 +434,42 @@ type CreateSetupKeyRequest struct {
|
||||
UsageLimit int `json:"usage_limit"`
|
||||
}
|
||||
|
||||
// DNSRecord defines model for DNSRecord.
|
||||
type DNSRecord struct {
|
||||
// Content DNS record content (IP address for A/AAAA, domain for CNAME)
|
||||
Content string `json:"content"`
|
||||
|
||||
// Id DNS record ID
|
||||
Id string `json:"id"`
|
||||
|
||||
// Name FQDN for the DNS record. Must be a subdomain within or match the zone's domain.
|
||||
Name string `json:"name"`
|
||||
|
||||
// Ttl Time to live in seconds
|
||||
Ttl int `json:"ttl"`
|
||||
|
||||
// Type DNS record type
|
||||
Type DNSRecordType `json:"type"`
|
||||
}
|
||||
|
||||
// DNSRecordRequest defines model for DNSRecordRequest.
|
||||
type DNSRecordRequest struct {
|
||||
// Content DNS record content (IP address for A/AAAA, domain for CNAME)
|
||||
Content string `json:"content"`
|
||||
|
||||
// Name FQDN for the DNS record. Must be a subdomain within or match the zone's domain.
|
||||
Name string `json:"name"`
|
||||
|
||||
// Ttl Time to live in seconds
|
||||
Ttl int `json:"ttl"`
|
||||
|
||||
// Type DNS record type
|
||||
Type DNSRecordType `json:"type"`
|
||||
}
|
||||
|
||||
// DNSRecordType DNS record type
|
||||
type DNSRecordType string
|
||||
|
||||
// DNSSettings defines model for DNSSettings.
|
||||
type DNSSettings struct {
|
||||
// DisabledManagementGroups Groups whose DNS management is disabled
|
||||
@@ -1999,6 +2042,48 @@ type UserRequest struct {
|
||||
Role string `json:"role"`
|
||||
}
|
||||
|
||||
// Zone defines model for Zone.
|
||||
type Zone struct {
|
||||
// DistributionGroups Group IDs that defines groups of peers that will resolve this zone
|
||||
DistributionGroups []string `json:"distribution_groups"`
|
||||
|
||||
// Domain Zone domain (FQDN)
|
||||
Domain string `json:"domain"`
|
||||
|
||||
// EnableSearchDomain Enable this zone as a search domain
|
||||
EnableSearchDomain bool `json:"enable_search_domain"`
|
||||
|
||||
// Enabled Zone status
|
||||
Enabled bool `json:"enabled"`
|
||||
|
||||
// Id Zone ID
|
||||
Id string `json:"id"`
|
||||
|
||||
// Name Zone name identifier
|
||||
Name string `json:"name"`
|
||||
|
||||
// Records DNS records associated with this zone
|
||||
Records []DNSRecord `json:"records"`
|
||||
}
|
||||
|
||||
// ZoneRequest defines model for ZoneRequest.
|
||||
type ZoneRequest struct {
|
||||
// DistributionGroups Group IDs that defines groups of peers that will resolve this zone
|
||||
DistributionGroups []string `json:"distribution_groups"`
|
||||
|
||||
// Domain Zone domain (FQDN)
|
||||
Domain string `json:"domain"`
|
||||
|
||||
// EnableSearchDomain Enable this zone as a search domain
|
||||
EnableSearchDomain bool `json:"enable_search_domain"`
|
||||
|
||||
// Enabled Zone status
|
||||
Enabled *bool `json:"enabled,omitempty"`
|
||||
|
||||
// Name Zone name identifier
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// GetApiEventsNetworkTrafficParams defines parameters for GetApiEventsNetworkTraffic.
|
||||
type GetApiEventsNetworkTrafficParams struct {
|
||||
// Page Page number
|
||||
@@ -2083,6 +2168,18 @@ type PutApiDnsNameserversNsgroupIdJSONRequestBody = NameserverGroupRequest
|
||||
// PutApiDnsSettingsJSONRequestBody defines body for PutApiDnsSettings for application/json ContentType.
|
||||
type PutApiDnsSettingsJSONRequestBody = DNSSettings
|
||||
|
||||
// PostApiDnsZonesJSONRequestBody defines body for PostApiDnsZones for application/json ContentType.
|
||||
type PostApiDnsZonesJSONRequestBody = ZoneRequest
|
||||
|
||||
// PutApiDnsZonesZoneIdJSONRequestBody defines body for PutApiDnsZonesZoneId for application/json ContentType.
|
||||
type PutApiDnsZonesZoneIdJSONRequestBody = ZoneRequest
|
||||
|
||||
// PostApiDnsZonesZoneIdRecordsJSONRequestBody defines body for PostApiDnsZonesZoneIdRecords for application/json ContentType.
|
||||
type PostApiDnsZonesZoneIdRecordsJSONRequestBody = DNSRecordRequest
|
||||
|
||||
// PutApiDnsZonesZoneIdRecordsRecordIdJSONRequestBody defines body for PutApiDnsZonesZoneIdRecordsRecordId for application/json ContentType.
|
||||
type PutApiDnsZonesZoneIdRecordsRecordIdJSONRequestBody = DNSRecordRequest
|
||||
|
||||
// PostApiGroupsJSONRequestBody defines body for PostApiGroups for application/json ContentType.
|
||||
type PostApiGroupsJSONRequestBody = GroupRequest
|
||||
|
||||
|
||||
@@ -252,3 +252,13 @@ func NewOperationNotFoundError(operation operations.Operation) error {
|
||||
func NewRouteNotFoundError(routeID string) error {
|
||||
return Errorf(NotFound, "route: %s not found", routeID)
|
||||
}
|
||||
|
||||
// NewZoneNotFoundError creates a new Error with NotFound type for a missing dns zone.
|
||||
func NewZoneNotFoundError(zoneID string) error {
|
||||
return Errorf(NotFound, "zone: %s not found", zoneID)
|
||||
}
|
||||
|
||||
// NewDNSRecordNotFoundError creates a new Error with NotFound type for a missing dns record.
|
||||
func NewDNSRecordNotFoundError(recordID string) error {
|
||||
return Errorf(NotFound, "dns record: %s not found", recordID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user