add hetznercloud DNS provider

This commit is contained in:
Johannes Zellner
2025-10-10 11:18:04 +02:00
parent c0ea5c31eb
commit 5ba30d0236
6 changed files with 256 additions and 8 deletions

View File

@@ -20,7 +20,8 @@ const assert = require('node:assert'),
superagent = require('@cloudron/superagent'),
waitForDns = require('./waitfordns.js');
const ENDPOINT = 'https://dns.hetzner.com/api/v1';
// const ENDPOINT = 'https://dns.hetzner.com/api/v1';
const ENDPOINT = 'https://api.hetzner.cloud/v1';
function formatError(response) {
return `Hetzner DNS error ${response.status} ${response.text}`;
@@ -40,7 +41,7 @@ async function getZone(domainConfig, zoneName) {
assert.strictEqual(typeof zoneName, 'string');
const [error, response] = await safe(superagent.get(`${ENDPOINT}/zones`)
.set('Auth-API-Token', domainConfig.token)
.set('Authorization', `Bearer ${domainConfig.token}`)
.query({ search_name: zoneName })
.timeout(30 * 1000)
.retry(5)
@@ -70,7 +71,8 @@ async function getZoneRecords(domainConfig, zone, name, type) {
while (true) {
const [error, response] = await safe(superagent.get(`${ENDPOINT}/records`)
.set('Auth-API-Token', domainConfig.token)
.set('Authorization', `Bearer ${domainConfig.token}`)
// .set('Auth-API-Token', domainConfig.token)
.query({ zone_id: zone.id, page, per_page: perPage })
.timeout(30 * 1000)
.retry(5)
@@ -122,7 +124,8 @@ async function upsert(domainObject, location, type, values) {
if (i >= records.length) {
const [error, response] = await safe(superagent.post(`${ENDPOINT}/records`)
.set('Auth-API-Token', domainConfig.token)
.set('Authorization', `Bearer ${domainConfig.token}`)
// .set('Auth-API-Token', domainConfig.token)
.send(data)
.timeout(30 * 1000)
.retry(5)
@@ -134,7 +137,8 @@ async function upsert(domainObject, location, type, values) {
if (response.status !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response));
} else {
const [error, response] = await safe(superagent.put(`${ENDPOINT}/records/${records[i].id}`)
.set('Auth-API-Token', domainConfig.token)
.set('Authorization', `Bearer ${domainConfig.token}`)
// .set('Auth-API-Token', domainConfig.token)
.send(data)
.timeout(30 * 1000)
.retry(5)
@@ -151,7 +155,8 @@ async function upsert(domainObject, location, type, values) {
for (let j = values.length + 1; j < records.length; j++) {
const [error] = await safe(superagent.del(`${ENDPOINT}/records/${records[j].id}`)
.set('Auth-API-Token', domainConfig.token)
.set('Authorization', `Bearer ${domainConfig.token}`)
// .set('Auth-API-Token', domainConfig.token)
.timeout(30 * 1000)
.retry(5)
.ok(() => true));
@@ -196,7 +201,8 @@ async function del(domainObject, location, type, values) {
for (const r of matchingRecords) {
const [error, response] = await safe(superagent.del(`${ENDPOINT}/records/${r.id}`)
.set('Auth-API-Token', domainConfig.token)
.set('Authorization', `Bearer ${domainConfig.token}`)
// .set('Auth-API-Token', domainConfig.token)
.timeout(30 * 1000)
.retry(5)
.ok(() => true));