Library for working with Hetzner DNS API
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.5 KiB

  1. package hclouddns
  2. // RecordType supported by Hetzner
  3. type RecordType string
  4. const (
  5. A RecordType = "A"
  6. AAAA RecordType = "AAAA"
  7. CNAME RecordType = "CNAME"
  8. MX RecordType = "MX"
  9. NS RecordType = "NS"
  10. TXT RecordType = "TXT"
  11. RP RecordType = "RP"
  12. SOA RecordType = "SOA"
  13. HINFO RecordType = "HINFO"
  14. SRV RecordType = "SRV"
  15. DANE RecordType = "DANE"
  16. TLSA RecordType = "TLSA"
  17. DS RecordType = "DS"
  18. CAA RecordType = "CAA"
  19. )
  20. type HCloudClientAdapter interface {
  21. GetZone(ID string) (HCloudAnswerGetZone, error)
  22. GetZones(params HCloudGetZonesParams) (HCloudAnswerGetZones, error)
  23. UpdateZone(zone HCloudZone) (HCloudAnswerGetZone, error)
  24. DeleteZone(ID string) (HCloudAnswerDeleteZone, error)
  25. CreateZone(zone HCloudZone) (HCloudAnswerGetZone, error)
  26. ImportZoneString(zoneID string, zonePlainText string) (HCloudAnswerGetZone, error)
  27. ExportZoneToString(zoneID string) (HCloudAnswerGetZonePlainText, error)
  28. ValidateZoneString(zonePlainText string) (HCloudAnswerZoneValidate, error)
  29. GetRecord(ID string) (HCloudAnswerGetRecord, error)
  30. GetRecords(params HCloudGetRecordsParams) (HCloudAnswerGetRecords, error)
  31. UpdateRecord(record HCloudRecord) (HCloudAnswerGetRecord, error)
  32. DeleteRecord(ID string) (HCloudAnswerDeleteRecord, error)
  33. CreateRecord(record HCloudRecord) (HCloudAnswerGetRecord, error)
  34. CreateRecordBulk(record []HCloudRecord) (HCloudAnswerCreateRecords, error)
  35. UpdateRecordBulk(record []HCloudRecord) (HCloudAnswerUpdateRecords, error)
  36. }
  37. type HCloudClient struct {
  38. Token string `yaml:"token"`
  39. }
  40. // Hetzner errors roundabout. Fuck you Hetzner.
  41. type HCloudError struct {
  42. Code int `json:"code,omitempty"`
  43. Message string `json:"message,omitempty"`
  44. }
  45. // sometime can be returned HCloudError
  46. type HCloudAnswerError struct {
  47. Error HCloudError `json:"error,omitempty"`
  48. }
  49. // or plain string
  50. type HCloudAnswerErrorString struct {
  51. Error string `json:"error,omitempty"`
  52. }
  53. type HCloudRecord struct {
  54. RecordType RecordType `json:"type"`
  55. ID string `json:"id"`
  56. Created string `json:"created"`
  57. Modified string `json:"modified"`
  58. ZoneID string `json:"zone_id"`
  59. Name string `json:"name"`
  60. Value string `json:"value"`
  61. TTL int `json:"ttl"`
  62. }
  63. type HCloudMeta struct {
  64. Pagination struct {
  65. Page int `json:"page"`
  66. PerPage int `json:"per_page"`
  67. LastPage int `json:"last_page"`
  68. TotalEntries int `json:"total_entries"`
  69. } `json:"pagination,omitempty"`
  70. }
  71. type HCloudZone struct {
  72. ID string `json:"id,omitempty"`
  73. Created string `json:"created,omitempty"`
  74. Modified string `json:"modified,omitempty"`
  75. LegacyDNSHost string `json:"legacy_dns_host,omitempty"`
  76. LegacyNS []string `json:"legacy_ns,omitempty"`
  77. Name string `json:"name,omitempty"`
  78. NS []string `json:"ns,omitempty"`
  79. Owner string `json:"owner,omitempty"`
  80. Paused bool `json:"paused,omitempty"`
  81. Permission string `json:"permission,omitempty"`
  82. Project string `json:"project,omitempty"`
  83. Registrar string `json:"registrar,omitempty"`
  84. Status string `json:"status,omitempty"`
  85. TTL int `json:"ttl,omitempty"`
  86. Verified string `json:"verified,omitempty"`
  87. RecordsCount int `json:"records_count,omitempty"`
  88. IsSecondaryDNS bool `json:"is_secondary_dns,omitempty"`
  89. TXTverification struct {
  90. Name string `json:"name,omitempty"`
  91. Token string `json:"token,omitempty"`
  92. } `json:"txt_verification,omitempty"`
  93. }