domains.go raw

   1  package linodego
   2  
   3  import (
   4  	"context"
   5  )
   6  
   7  // Domain represents a Domain object
   8  type Domain struct {
   9  	//	This Domain's unique ID
  10  	ID int `json:"id"`
  11  
  12  	// The domain this Domain represents. These must be unique in our system; you cannot have two Domains representing the same domain.
  13  	Domain string `json:"domain"`
  14  
  15  	// If this Domain represents the authoritative source of information for the domain it describes, or if it is a read-only copy of a master (also called a slave).
  16  	Type DomainType `json:"type"` // Enum:"master" "slave"
  17  
  18  	// Deprecated: The group this Domain belongs to. This is for display purposes only.
  19  	Group string `json:"group"`
  20  
  21  	// Used to control whether this Domain is currently being rendered.
  22  	Status DomainStatus `json:"status"` // Enum:"disabled" "active" "edit_mode" "has_errors"
  23  
  24  	// A description for this Domain. This is for display purposes only.
  25  	Description string `json:"description"`
  26  
  27  	// Start of Authority email address. This is required for master Domains.
  28  	SOAEmail string `json:"soa_email"`
  29  
  30  	// The interval, in seconds, at which a failed refresh should be retried.
  31  	// Valid values are 300, 3600, 7200, 14400, 28800, 57600, 86400, 172800, 345600, 604800, 1209600, and 2419200 - any other value will be rounded to the nearest valid value.
  32  	RetrySec int `json:"retry_sec"`
  33  
  34  	// The IP addresses representing the master DNS for this Domain.
  35  	MasterIPs []string `json:"master_ips"`
  36  
  37  	// The list of IPs that may perform a zone transfer for this Domain. This is potentially dangerous, and should be set to an empty list unless you intend to use it.
  38  	AXfrIPs []string `json:"axfr_ips"`
  39  
  40  	// An array of tags applied to this object. Tags are for organizational purposes only.
  41  	Tags []string `json:"tags"`
  42  
  43  	// The amount of time in seconds that may pass before this Domain is no longer authoritative. Valid values are 300, 3600, 7200, 14400, 28800, 57600, 86400, 172800, 345600, 604800, 1209600, and 2419200 - any other value will be rounded to the nearest valid value.
  44  	ExpireSec int `json:"expire_sec"`
  45  
  46  	// The amount of time in seconds before this Domain should be refreshed. Valid values are 300, 3600, 7200, 14400, 28800, 57600, 86400, 172800, 345600, 604800, 1209600, and 2419200 - any other value will be rounded to the nearest valid value.
  47  	RefreshSec int `json:"refresh_sec"`
  48  
  49  	// "Time to Live" - the amount of time in seconds that this Domain's records may be cached by resolvers or other domain servers. Valid values are 300, 3600, 7200, 14400, 28800, 57600, 86400, 172800, 345600, 604800, 1209600, and 2419200 - any other value will be rounded to the nearest valid value.
  50  	TTLSec int `json:"ttl_sec"`
  51  }
  52  
  53  // DomainZoneFile represents the Zone File of a Domain
  54  type DomainZoneFile struct {
  55  	ZoneFile []string `json:"zone_file"`
  56  }
  57  
  58  // DomainCreateOptions fields are those accepted by CreateDomain
  59  type DomainCreateOptions struct {
  60  	// The domain this Domain represents. These must be unique in our system; you cannot have two Domains representing the same domain.
  61  	Domain string `json:"domain"`
  62  
  63  	// If this Domain represents the authoritative source of information for the domain it describes, or if it is a read-only copy of a master (also called a slave).
  64  	// Enum:"master" "slave"
  65  	Type DomainType `json:"type"`
  66  
  67  	// Deprecated: The group this Domain belongs to. This is for display purposes only.
  68  	Group string `json:"group,omitempty"`
  69  
  70  	// Used to control whether this Domain is currently being rendered.
  71  	// Enum:"disabled" "active" "edit_mode" "has_errors"
  72  	Status DomainStatus `json:"status,omitempty"`
  73  
  74  	// A description for this Domain. This is for display purposes only.
  75  	Description string `json:"description,omitempty"`
  76  
  77  	// Start of Authority email address. This is required for master Domains.
  78  	SOAEmail string `json:"soa_email,omitempty"`
  79  
  80  	// The interval, in seconds, at which a failed refresh should be retried.
  81  	// Valid values are 300, 3600, 7200, 14400, 28800, 57600, 86400, 172800, 345600, 604800, 1209600, and 2419200 - any other value will be rounded to the nearest valid value.
  82  	RetrySec int `json:"retry_sec,omitempty"`
  83  
  84  	// The IP addresses representing the master DNS for this Domain.
  85  	MasterIPs []string `json:"master_ips"`
  86  
  87  	// The list of IPs that may perform a zone transfer for this Domain. This is potentially dangerous, and should be set to an empty list unless you intend to use it.
  88  	AXfrIPs []string `json:"axfr_ips"`
  89  
  90  	// An array of tags applied to this object. Tags are for organizational purposes only.
  91  	Tags []string `json:"tags"`
  92  
  93  	// The amount of time in seconds that may pass before this Domain is no longer authoritative. Valid values are 300, 3600, 7200, 14400, 28800, 57600, 86400, 172800, 345600, 604800, 1209600, and 2419200 - any other value will be rounded to the nearest valid value.
  94  	ExpireSec int `json:"expire_sec,omitempty"`
  95  
  96  	// The amount of time in seconds before this Domain should be refreshed. Valid values are 300, 3600, 7200, 14400, 28800, 57600, 86400, 172800, 345600, 604800, 1209600, and 2419200 - any other value will be rounded to the nearest valid value.
  97  	RefreshSec int `json:"refresh_sec,omitempty"`
  98  
  99  	// "Time to Live" - the amount of time in seconds that this Domain's records may be cached by resolvers or other domain servers. Valid values are 300, 3600, 7200, 14400, 28800, 57600, 86400, 172800, 345600, 604800, 1209600, and 2419200 - any other value will be rounded to the nearest valid value.
 100  	TTLSec int `json:"ttl_sec,omitempty"`
 101  }
 102  
 103  // DomainUpdateOptions converts a Domain to DomainUpdateOptions for use in UpdateDomain
 104  type DomainUpdateOptions struct {
 105  	// The domain this Domain represents. These must be unique in our system; you cannot have two Domains representing the same domain.
 106  	Domain string `json:"domain,omitempty"`
 107  
 108  	// If this Domain represents the authoritative source of information for the domain it describes, or if it is a read-only copy of a master (also called a slave).
 109  	// Enum:"master" "slave"
 110  	Type DomainType `json:"type,omitempty"`
 111  
 112  	// Deprecated: The group this Domain belongs to. This is for display purposes only.
 113  	Group string `json:"group,omitempty"`
 114  
 115  	// Used to control whether this Domain is currently being rendered.
 116  	// Enum:"disabled" "active" "edit_mode" "has_errors"
 117  	Status DomainStatus `json:"status,omitempty"`
 118  
 119  	// A description for this Domain. This is for display purposes only.
 120  	Description string `json:"description,omitempty"`
 121  
 122  	// Start of Authority email address. This is required for master Domains.
 123  	SOAEmail string `json:"soa_email,omitempty"`
 124  
 125  	// The interval, in seconds, at which a failed refresh should be retried.
 126  	// Valid values are 300, 3600, 7200, 14400, 28800, 57600, 86400, 172800, 345600, 604800, 1209600, and 2419200 - any other value will be rounded to the nearest valid value.
 127  	RetrySec int `json:"retry_sec,omitempty"`
 128  
 129  	// The IP addresses representing the master DNS for this Domain.
 130  	MasterIPs []string `json:"master_ips"`
 131  
 132  	// The list of IPs that may perform a zone transfer for this Domain. This is potentially dangerous, and should be set to an empty list unless you intend to use it.
 133  	AXfrIPs []string `json:"axfr_ips"`
 134  
 135  	// An array of tags applied to this object. Tags are for organizational purposes only.
 136  	Tags []string `json:"tags"`
 137  
 138  	// The amount of time in seconds that may pass before this Domain is no longer authoritative. Valid values are 300, 3600, 7200, 14400, 28800, 57600, 86400, 172800, 345600, 604800, 1209600, and 2419200 - any other value will be rounded to the nearest valid value.
 139  	ExpireSec int `json:"expire_sec,omitempty"`
 140  
 141  	// The amount of time in seconds before this Domain should be refreshed. Valid values are 300, 3600, 7200, 14400, 28800, 57600, 86400, 172800, 345600, 604800, 1209600, and 2419200 - any other value will be rounded to the nearest valid value.
 142  	RefreshSec int `json:"refresh_sec,omitempty"`
 143  
 144  	// "Time to Live" - the amount of time in seconds that this Domain's records may be cached by resolvers or other domain servers. Valid values are 300, 3600, 7200, 14400, 28800, 57600, 86400, 172800, 345600, 604800, 1209600, and 2419200 - any other value will be rounded to the nearest valid value.
 145  	TTLSec int `json:"ttl_sec,omitempty"`
 146  }
 147  
 148  // DomainType constants start with DomainType and include Linode API Domain Type values
 149  type DomainType string
 150  
 151  // DomainType constants reflect the DNS zone type of a Domain
 152  const (
 153  	DomainTypeMaster DomainType = "master"
 154  	DomainTypeSlave  DomainType = "slave"
 155  )
 156  
 157  // DomainStatus constants start with DomainStatus and include Linode API Domain Status values
 158  type DomainStatus string
 159  
 160  // DomainStatus constants reflect the current status of a Domain
 161  const (
 162  	DomainStatusDisabled  DomainStatus = "disabled"
 163  	DomainStatusActive    DomainStatus = "active"
 164  	DomainStatusEditMode  DomainStatus = "edit_mode"
 165  	DomainStatusHasErrors DomainStatus = "has_errors"
 166  )
 167  
 168  type DomainCloneOptions struct {
 169  	Domain string `json:"domain"`
 170  }
 171  
 172  type DomainImportOptions struct {
 173  	Domain           string `json:"domain"`
 174  	RemoteNameserver string `json:"remove_nameserver"`
 175  }
 176  
 177  // GetUpdateOptions converts a Domain to DomainUpdateOptions for use in UpdateDomain
 178  func (d Domain) GetUpdateOptions() (du DomainUpdateOptions) {
 179  	du.Domain = d.Domain
 180  	du.Type = d.Type
 181  	du.Group = d.Group
 182  	du.Status = d.Status
 183  	du.Description = d.Description
 184  	du.SOAEmail = d.SOAEmail
 185  	du.RetrySec = d.RetrySec
 186  	du.MasterIPs = d.MasterIPs
 187  	du.AXfrIPs = d.AXfrIPs
 188  	du.Tags = d.Tags
 189  	du.ExpireSec = d.ExpireSec
 190  	du.RefreshSec = d.RefreshSec
 191  	du.TTLSec = d.TTLSec
 192  
 193  	return du
 194  }
 195  
 196  // ListDomains lists Domains
 197  func (c *Client) ListDomains(ctx context.Context, opts *ListOptions) ([]Domain, error) {
 198  	return getPaginatedResults[Domain](ctx, c, "domains", opts)
 199  }
 200  
 201  // GetDomain gets the domain with the provided ID
 202  func (c *Client) GetDomain(ctx context.Context, domainID int) (*Domain, error) {
 203  	e := formatAPIPath("domains/%d", domainID)
 204  	return doGETRequest[Domain](ctx, c, e)
 205  }
 206  
 207  // CreateDomain creates a Domain
 208  func (c *Client) CreateDomain(ctx context.Context, opts DomainCreateOptions) (*Domain, error) {
 209  	return doPOSTRequest[Domain](ctx, c, "domains", opts)
 210  }
 211  
 212  // UpdateDomain updates the Domain with the specified id
 213  func (c *Client) UpdateDomain(ctx context.Context, domainID int, opts DomainUpdateOptions) (*Domain, error) {
 214  	e := formatAPIPath("domains/%d", domainID)
 215  	return doPUTRequest[Domain](ctx, c, e, opts)
 216  }
 217  
 218  // DeleteDomain deletes the Domain with the specified id
 219  func (c *Client) DeleteDomain(ctx context.Context, domainID int) error {
 220  	e := formatAPIPath("domains/%d", domainID)
 221  	return doDELETERequest(ctx, c, e)
 222  }
 223  
 224  // GetDomainZoneFile gets the zone file for the last rendered zone for the specified domain.
 225  func (c *Client) GetDomainZoneFile(ctx context.Context, domainID int) (*DomainZoneFile, error) {
 226  	e := formatAPIPath("domains/%d/zone-file", domainID)
 227  	return doGETRequest[DomainZoneFile](ctx, c, e)
 228  }
 229  
 230  // CloneDomain clones a Domain and all associated DNS records from a Domain that is registered in Linode's DNS manager.
 231  func (c *Client) CloneDomain(ctx context.Context, domainID int, opts DomainCloneOptions) (*Domain, error) {
 232  	e := formatAPIPath("domains/%d/clone", domainID)
 233  	return doPOSTRequest[Domain](ctx, c, e, opts)
 234  }
 235  
 236  // ImportDomain imports a domain zone from a remote nameserver.
 237  func (c *Client) ImportDomain(ctx context.Context, opts DomainImportOptions) (*Domain, error) {
 238  	return doPOSTRequest[Domain](ctx, c, "domains/import", opts)
 239  }
 240