Add DNS Record
This commit is contained in:
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"enabled": "false|true",
|
|
||||||
"key": ".{1,128}",
|
|
||||||
"port": "[0-9]{1,8}",
|
|
||||||
"priority": ".{1,128}",
|
|
||||||
"record_type": "A|AAAA|CNAME|MX|NS|PTR|SOA|SRV|TXT",
|
|
||||||
"ttl": "[0-9]{1,10}",
|
|
||||||
"value": ".{1,256}",
|
|
||||||
"weight": "[0-9]{1,10}"
|
|
||||||
}
|
|
||||||
@@ -74,7 +74,7 @@ func (l *firmwareUpdateApiResponseEmbeddedFirmwareDataLink) UnmarshalJSON(j []by
|
|||||||
}
|
}
|
||||||
|
|
||||||
type firmwareUpdateApiResponseEmbeddedFirmwareLinks struct {
|
type firmwareUpdateApiResponseEmbeddedFirmwareLinks struct {
|
||||||
Data firmwareUpdateApiResponseEmbeddedFirmwareDataLink `json:"data"`
|
Data firmwareUpdateApiResponseEmbeddedFirmwareDataLink `json:"data,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func firmwareUpdateApiFilter(key, value string) string {
|
func firmwareUpdateApiFilter(key, value string) string {
|
||||||
|
|||||||
9
unifi/dns_record.generated.go
generated
9
unifi/dns_record.generated.go
generated
@@ -28,7 +28,7 @@ type DNSRecord struct {
|
|||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
Key string `json:"key,omitempty"` // .{1,128}
|
Key string `json:"key,omitempty"` // .{1,128}
|
||||||
Port int `json:"port,omitempty"`
|
Port int `json:"port,omitempty"`
|
||||||
Priority string `json:"priority,omitempty"` // .{1,128}
|
Priority int `json:"priority,omitempty"` // .{1,128}
|
||||||
RecordType string `json:"record_type,omitempty"` // A|AAAA|CNAME|MX|NS|PTR|SOA|SRV|TXT
|
RecordType string `json:"record_type,omitempty"` // A|AAAA|CNAME|MX|NS|PTR|SOA|SRV|TXT
|
||||||
Ttl int `json:"ttl,omitempty"`
|
Ttl int `json:"ttl,omitempty"`
|
||||||
Value string `json:"value,omitempty"` // .{1,256}
|
Value string `json:"value,omitempty"` // .{1,256}
|
||||||
@@ -59,17 +59,14 @@ func (dst *DNSRecord) UnmarshalJSON(b []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) listDNSRecord(ctx context.Context, site string) ([]DNSRecord, error) {
|
func (c *Client) listDNSRecord(ctx context.Context, site string) ([]DNSRecord, error) {
|
||||||
var respBody struct {
|
var respBody []DNSRecord
|
||||||
Meta meta `json:"meta"`
|
|
||||||
Data []DNSRecord `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
err := c.do(ctx, "GET", fmt.Sprintf("%s/site/%s/static-dns", c.apiV2Path, site), nil, &respBody)
|
err := c.do(ctx, "GET", fmt.Sprintf("%s/site/%s/static-dns", c.apiV2Path, site), nil, &respBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return respBody.Data, nil
|
return respBody, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) getDNSRecord(ctx context.Context, site, id string) (*DNSRecord, error) {
|
func (c *Client) getDNSRecord(ctx context.Context, site, id string) (*DNSRecord, error) {
|
||||||
|
|||||||
@@ -5,24 +5,64 @@ package unifi
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Client) ListDNSRecord(ctx context.Context, site string) ([]DNSRecord, error) {
|
func (c *Client) ListDNSRecord(ctx context.Context, site string) ([]DNSRecord, error) {
|
||||||
return c.listDNSRecord(ctx, site)
|
var respBody []DNSRecord
|
||||||
|
|
||||||
|
err := c.do(ctx, "GET", fmt.Sprintf("%s/site/%s/static-dns", c.apiV2Path, site), nil, &respBody)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return respBody, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) GetDNSRecord(ctx context.Context, site, id string) (*DNSRecord, error) {
|
func (c *Client) GetDNSRecord(ctx context.Context, site, id string) (*DNSRecord, error) {
|
||||||
return c.getDNSRecord(ctx, site, id)
|
var respBody DNSRecord
|
||||||
|
|
||||||
|
err := c.do(ctx, "GET", fmt.Sprintf("%s/site/%s/static-dns/%s", c.apiV2Path, site, id), nil, &respBody)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// if len(respBody.Data) != 1 {
|
||||||
|
// return nil, &NotFoundError{}
|
||||||
|
// }
|
||||||
|
|
||||||
|
// d := respBody.Data[0]
|
||||||
|
return &respBody, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) DeleteDNSRecord(ctx context.Context, site, id string) error {
|
func (c *Client) DeleteDNSRecord(ctx context.Context, site, id string) error {
|
||||||
return c.deleteDNSRecord(ctx, site, id)
|
err := c.do(ctx, "DELETE", fmt.Sprintf("%s/site/%s/static-dns/%s", c.apiV2Path, site, id), struct{}{}, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) CreateDNSRecord(ctx context.Context, site string, d *DNSRecord) (*DNSRecord, error) {
|
func (c *Client) CreateDNSRecord(ctx context.Context, site string, d *DNSRecord) (*DNSRecord, error) {
|
||||||
return c.createDNSRecord(ctx, site, d)
|
var respBody DNSRecord
|
||||||
|
err := c.do(ctx, "POST", fmt.Sprintf("%s/site/%s/static-dns", c.apiV2Path, site), d, &respBody)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &respBody, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) UpdateDNSRecord(ctx context.Context, site string, d *DNSRecord) (*DNSRecord, error) {
|
func (c *Client) UpdateDNSRecord(ctx context.Context, site string, d *DNSRecord) (*DNSRecord, error) {
|
||||||
return c.updateDNSRecord(ctx, site, d)
|
var respBody DNSRecord
|
||||||
|
|
||||||
|
err := c.do(ctx, "PUT", fmt.Sprintf("%s/site/%s/static-dns/%s", c.apiV2Path, site, d.ID), d, &respBody)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// if len(respBody) != nil {
|
||||||
|
// return nil, &NotFoundError{}
|
||||||
|
// }
|
||||||
|
|
||||||
|
return &respBody, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user