dnszone_get.go raw

   1  package bunny
   2  
   3  import (
   4  	"context"
   5  	"fmt"
   6  )
   7  
   8  // Constants for the Type field of a DNS Record.
   9  const (
  10  	DNSRecordTypeA     int = 0
  11  	DNSRecordTypeAAAA  int = 1
  12  	DNSRecordTypeCNAME int = 2
  13  	DNSRecordTypeTXT   int = 3
  14  	DNSRecordTypeMX    int = 4
  15  	DNSRecordTypeRDR   int = 5 // Bunny.NET Redirect custom record
  16  	DNSRecordTypePZ    int = 7 // Bunny.NET Pull Zone custom record
  17  	DNSRecordTypeSRV   int = 8
  18  	DNSRecordTypeCAA   int = 9
  19  	DNSRecordTypePTR   int = 10
  20  	DNSRecordTypeSCR   int = 11 // Bunny.NET Script custom record
  21  	DNSRecordTypeNS    int = 12
  22  )
  23  
  24  // DNSZone represents the response of the List and Get DNS Zone API endpoint.
  25  //
  26  // Bunny.net API docs: https://docs.bunny.net/reference/dnszonepublic_index2 https://docs.bunny.net/reference/dnszonepublic_index
  27  //
  28  // Timestamps formatted in YYYY-MM-DDTHH:MM:SS style.
  29  // Golang time layout: 2006-01-02T15:04:05.
  30  type DNSZone struct {
  31  	ID *int64 `json:"Id,omitempty"`
  32  
  33  	Domain                        *string     `json:"Domain,omitempty"`
  34  	Records                       []DNSRecord `json:"Records,omitempty"`
  35  	DateModified                  *string     `json:"DateModified,omitempty"` // Timestamp
  36  	DateCreated                   *string     `json:"DateCreated,omitempty"`  // Timestamp
  37  	NameserversDetected           *bool       `json:"NameserversDetected,omitempty"`
  38  	CustomNameserversEnabled      *bool       `json:"CustomNameserversEnabled,omitempty"`
  39  	Nameserver1                   *string     `json:"Nameserver1,omitempty"`
  40  	Nameserver2                   *string     `json:"Nameserver2,omitempty"`
  41  	SoaEmail                      *string     `json:"SoaEmail,omitempty"`
  42  	NameserversNextCheck          *string     `json:"NameserversNextCheck,omitempty"` // Timestamp
  43  	LoggingEnabled                *bool       `json:"LoggingEnabled,omitempty"`
  44  	LoggingIPAnonymizationEnabled *bool       `json:"LoggingIPAnonymizationEnabled,omitempty"`
  45  	LogAnonymizationType          *int        `json:"LogAnonymizationType,omitempty"`
  46  }
  47  
  48  // DNSRecord represents individual DNS records for a DNS Zone.
  49  //
  50  // Bunny.net API docs: https://docs.bunny.net/reference/dnszonepublic_index2 https://docs.bunny.net/reference/dnszonepublic_index
  51  type DNSRecord struct {
  52  	ID                     *int64                  `json:"Id,omitempty"`
  53  	Type                   *int                    `json:"Type,omitempty"`
  54  	TTL                    *int32                  `json:"Ttl,omitempty"`
  55  	Value                  *string                 `json:"Value,omitempty"`
  56  	Name                   *string                 `json:"Name,omitempty"`
  57  	Weight                 *int32                  `json:"Weight,omitempty"`
  58  	Priority               *int32                  `json:"Priority,omitempty"`
  59  	Port                   *int32                  `json:"Port,omitempty"`
  60  	Flags                  *int                    `json:"Flags,omitempty"`
  61  	Tag                    *string                 `json:"Tag,omitempty"`
  62  	Accelerated            *bool                   `json:"Accelerated,omitempty"`
  63  	AcceleratedPullZoneID  *int64                  `json:"AcceleratedPullZoneId,omitempty"`
  64  	LinkName               *string                 `json:"LinkName,omitempty"`
  65  	IPGeoLocationInfo      *IPGeoLocationInfo      `json:"IPGeoLocationInfo,omitempty"`
  66  	MonitorStatus          *int                    `json:"MonitorStatus,omitempty"`
  67  	MonitorType            *int                    `json:"MonitorType,omitempty"`
  68  	GeolocationLatitude    *float64                `json:"GeolocationLatitude,omitempty"`
  69  	GeolocationLongitude   *float64                `json:"GeolocationLongitude,omitempty"`
  70  	EnvironmentalVariables []EnvironmentalVariable `json:"EnvironmentalVariables,omitempty"`
  71  	LatencyZone            *string                 `json:"LatencyZone,omitempty"`
  72  	SmartRoutingType       *int                    `json:"SmartRoutingType,omitempty"`
  73  	Disabled               *bool                   `json:"Disabled,omitempty"`
  74  }
  75  
  76  // IPGeoLocationInfo represents the geolocation data attached to a DNS record.
  77  type IPGeoLocationInfo struct {
  78  	CountryCode      *string `json:"CountryCode,omitempty"`
  79  	Country          *string `json:"Country,omitempty"`
  80  	ASN              *int64  `json:"ASN,omitempty"`
  81  	OrganizationName *string `json:"OrganizationName,omitempty"`
  82  	City             *string `json:"City,omitempty"`
  83  }
  84  
  85  // EnvironmentalVariable represents the environmental variables attached to a DNS record.
  86  type EnvironmentalVariable struct {
  87  	Name  *string `json:"Name,omitempty"`
  88  	Value *string `json:"Value,omitempty"`
  89  }
  90  
  91  // Get retrieves the DNS Zone with the given id.
  92  //
  93  // Bunny.net API docs: https://docs.bunny.net/reference/dnszonepublic_index2
  94  func (s *DNSZoneService) Get(ctx context.Context, id int64) (*DNSZone, error) {
  95  	path := fmt.Sprintf("dnszone/%d", id)
  96  	return resourceGet[DNSZone](ctx, s.client, path, nil)
  97  }
  98