|
| 1 | +# http.net DNS for `libdns` |
| 2 | + |
| 3 | +[](https://pkg.go.dev/github.com/libdns/httpnet) |
| 4 | + |
| 5 | +This package implements the [libdns](https://github.com/libdns/libdns) interfaces for [http.net](https://www.http.net), allowing DNS records to be managed via the http.net partner API. |
| 6 | + |
| 7 | +## Authenticating |
| 8 | + |
| 9 | +Create an API token in the [http.net partner portal](https://partner.http.net) |
| 10 | +(API documentation: <https://www.http.net/docs/api/>) and pass it to the |
| 11 | +provider: |
| 12 | + |
| 13 | +```go |
| 14 | +import "github.com/libdns/httpnet" |
| 15 | + |
| 16 | +provider := &httpnet.Provider{ |
| 17 | + AuthToken: "your-api-token", |
| 18 | +} |
| 19 | + |
| 20 | +records, err := provider.GetRecords(context.Background(), "example.com.") |
| 21 | +``` |
| 22 | + |
| 23 | +The `Provider` implements `RecordGetter`, `RecordAppender`, `RecordSetter`, `RecordDeleter`, and `ZoneLister`. |
| 24 | + |
| 25 | +Any DNS record type accepted by the http.net API is supported: records are |
| 26 | +parsed into the matching typed `libdns.Record` (`libdns.Address`, `libdns.MX`, |
| 27 | +`libdns.TXT`, …) via `libdns.RR.Parse()`. |
| 28 | + |
| 29 | +## Caveats |
| 30 | + |
| 31 | +### TTL floor |
| 32 | + |
| 33 | +The http.net API enforces a 60-second minimum TTL. Lower values (including zero) |
| 34 | +are silently raised to 60 before being sent, to avoid request rejection. |
| 35 | + |
| 36 | +### Asynchronous writes |
| 37 | + |
| 38 | +Write operations may return a `pending` status with an empty record list. The |
| 39 | +provider handles this by performing a follow-up read, so callers still receive |
| 40 | +records with their assigned IDs. |
| 41 | + |
| 42 | +### Atomicity |
| 43 | + |
| 44 | +Updates within a single call are applied atomically by `recordsUpdate`, but |
| 45 | +concurrent modifications from separate processes to the same RRset may result |
| 46 | +in inconsistent state. Ensure concurrent processes operate on different RRsets. |
| 47 | + |
| 48 | +## Testing |
| 49 | + |
| 50 | +Unit tests run against an in-process mock server and require no credentials: |
| 51 | + |
| 52 | +```bash |
| 53 | +go test ./... |
| 54 | +``` |
| 55 | + |
| 56 | +Integration tests against the live http.net API are opt-in via environment |
| 57 | +variables: |
| 58 | + |
| 59 | +```bash |
| 60 | +export HTTPNET_AUTH_TOKEN=<your-api-token> |
| 61 | +export HTTPNET_TEST_ZONE=example.com. # a zone you control; trailing dot required |
| 62 | +go test -v ./... |
| 63 | +``` |
| 64 | + |
| 65 | +Tests that find these variables unset are skipped automatically. |
| 66 | + |
| 67 | +## License |
| 68 | + |
| 69 | +MIT |
0 commit comments