|
1 | 1 | package internal |
2 | 2 |
|
| 3 | +import "strconv" |
| 4 | + |
| 5 | +const ( |
| 6 | + DefaultApiUrl = "https://api.hetzner.cloud/v1" |
| 7 | + DefaultSecretKey = "api-token" |
| 8 | + DefaultTxtTTL = 120 |
| 9 | +) |
| 10 | + |
3 | 11 | type Config struct { |
4 | | - ApiKey, ZoneName, ApiUrl string |
| 12 | + ApiKey string |
| 13 | + ZoneName string |
| 14 | + ZoneId int64 |
| 15 | + ApiUrl string |
| 16 | + SecretKey string |
5 | 17 | } |
6 | 18 |
|
7 | | -type RecordResponse struct { |
8 | | - Records []Record `json:"records"` |
9 | | - Meta Meta `json:"meta"` |
| 19 | +func (c *Config) ZoneIdStr() string { |
| 20 | + return strconv.FormatInt(c.ZoneId, 10) |
10 | 21 | } |
11 | 22 |
|
12 | | -type ZoneResponse struct { |
| 23 | +type ZoneListResponse struct { |
13 | 24 | Zones []Zone `json:"zones"` |
14 | | - Meta Meta `json:"meta"` |
15 | 25 | } |
16 | 26 |
|
17 | | -type Meta struct { |
18 | | - Pagination Pagination `json:"pagination"` |
| 27 | +type ZoneResponse struct { |
| 28 | + Zone Zone `json:"zone"` |
| 29 | +} |
| 30 | + |
| 31 | +type Zone struct { |
| 32 | + Id int64 `json:"id"` |
| 33 | + Name string `json:"name"` |
| 34 | + TTL int `json:"ttl"` |
| 35 | + RecordCount int `json:"record_count"` |
19 | 36 | } |
20 | 37 |
|
21 | | -type Pagination struct { |
22 | | - Page int `json:"page"` |
23 | | - PerPage int `json:"per_page"` |
24 | | - LastPage int `json:"last_page"` |
25 | | - TotalEntries int `json:"total_entries"` |
| 38 | +type RRSetListResponse struct { |
| 39 | + RRSets []RRSet `json:"rrsets"` |
26 | 40 | } |
27 | 41 |
|
28 | | -type Record struct { |
29 | | - Type string `json:"type"` |
30 | | - Id string `json:"id"` |
31 | | - Created string `json:"created"` |
32 | | - Modified string `json:"modified"` |
33 | | - ZoneId string `json:"zone_id"` |
34 | | - Name string `json:"name"` |
35 | | - Value string `json:"value"` |
36 | | - Ttl int `json:"ttl"` |
| 42 | +type RRSetResponse struct { |
| 43 | + RRSet RRSet `json:"rrset"` |
37 | 44 | } |
38 | 45 |
|
39 | | -type Zone struct { |
40 | | - Id string `json:"id"` |
41 | | - Created string `json:"created"` |
42 | | - Modified string `json:"modified"` |
43 | | - LegacyDnsHost string `json:"legacy_dns_host"` |
44 | | - LegacyNs []string `json:"legacy_ns"` |
45 | | - Name string `json:"name"` |
46 | | - Ns []string `json:"ns"` |
47 | | - Owner string `json:"owner"` |
48 | | - Paused bool `json:"paused"` |
49 | | - Permission string `json:"permission"` |
50 | | - Project string `json:"project"` |
51 | | - Registrar string `json:"registrar"` |
52 | | - Status string `json:"status"` |
53 | | - Ttl int `json:"ttl"` |
54 | | - Verified string `json:"verified"` |
55 | | - RecordsCount int `json:"records_count"` |
56 | | - IsSecondaryDns bool `json:"is_secondary_dns"` |
57 | | - TxtVerification Verification `json:"txt_verification"` |
58 | | -} |
59 | | - |
60 | | -type Verification struct { |
61 | | - Name string `json:"name"` |
62 | | - Token string `json:"token"` |
| 46 | +type RRSet struct { |
| 47 | + Id string `json:"id"` |
| 48 | + Name string `json:"name"` |
| 49 | + Type string `json:"type"` |
| 50 | + TTL *int `json:"ttl"` |
| 51 | + Records []RRSetRecord `json:"records"` |
| 52 | + Zone int64 `json:"zone"` |
| 53 | +} |
| 54 | + |
| 55 | +type RRSetRecord struct { |
| 56 | + Value string `json:"value"` |
| 57 | + Comment string `json:"comment,omitempty"` |
| 58 | +} |
| 59 | + |
| 60 | +type RRSetCreateRequest struct { |
| 61 | + Name string `json:"name"` |
| 62 | + Type string `json:"type"` |
| 63 | + TTL *int `json:"ttl,omitempty"` |
| 64 | + Records []RRSetRecord `json:"records"` |
| 65 | +} |
| 66 | + |
| 67 | +type RRSetAddRecordsRequest struct { |
| 68 | + Records []RRSetRecord `json:"records"` |
| 69 | + TTL *int `json:"ttl,omitempty"` |
| 70 | +} |
| 71 | + |
| 72 | +type RRSetRemoveRecordsRequest struct { |
| 73 | + Records []RRSetRecord `json:"records"` |
| 74 | +} |
| 75 | + |
| 76 | +type ErrorResponse struct { |
| 77 | + Error ErrorDetail `json:"error"` |
| 78 | +} |
| 79 | + |
| 80 | +type ErrorDetail struct { |
| 81 | + Code string `json:"code"` |
| 82 | + Message string `json:"message"` |
63 | 83 | } |
0 commit comments