Skip to content

Commit b9a7384

Browse files
authored
Merge pull request #892 from Ayesh/hetzner-cloud-dns
DNS: Add Hetzner cloud
2 parents 0a2940d + 8dea611 commit b9a7384

4 files changed

Lines changed: 140 additions & 13 deletions

File tree

dns_scripts/dns_add_hetzner_cloud

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env bash
2+
3+
fulldomain="${1}"
4+
token="${2}"
5+
api_url="https://api.hetzner.cloud/v1"
6+
api_key=${HETZNER_KEY:-''}
7+
zone_id=${HETZNER_ZONE_ID:-''}
8+
zone_name=${HETZNER_ZONE_NAME:-''}
9+
10+
# Verify that required parameters are set
11+
if [[ -z "$fulldomain" ]]; then
12+
echo "DNS script requires full domain name as first parameter"
13+
exit 1
14+
fi
15+
if [[ -z "$token" ]]; then
16+
echo "DNS script requires challenge token as second parameter"
17+
exit 1
18+
fi
19+
if [[ -z "$HETZNER_KEY" ]]; then
20+
echo "HETZNER_KEY variable not set"
21+
exit 1
22+
fi
23+
if [[ -z "$HETZNER_ZONE_ID" && -z "$HETZNER_ZONE_NAME" ]] ; then
24+
echo "HETZNER_ZONE_ID and HETZNER_ZONE_NAME variables not set"
25+
exit 1
26+
fi
27+
28+
# Get Zone ID if not set
29+
if [[ -z "$HETZNER_ZONE_ID" ]] ; then
30+
zone_id=$(curl --silent -X GET "$api_url/zones?name=$zone_name" -H 'Authorization: Bearer '"$api_key"'' | jq -r '.zones[0].id')
31+
if [[ "$zone_id" == "null" ]] ; then
32+
echo "Zone ID not found"
33+
exit 1
34+
fi
35+
fi
36+
37+
# Get Zone name if not set
38+
if [[ -z "$zone_name" ]] ; then
39+
zone_name=$(curl --silent -X GET "$api_url/zones/$zone_id" -H 'Authorization: Bearer '"$api_key"'' | jq -r '.zone.name')
40+
if [[ "$zone_name" == "null" ]] ; then
41+
echo "Zone name not found"
42+
exit 1
43+
fi
44+
fi
45+
46+
txtname="_acme-challenge.$fulldomain"
47+
txtname="${txtname%."$zone_name"}"
48+
49+
payload=$(jq -n \
50+
--arg token "$token" \
51+
'{
52+
ttl: 60,
53+
records: [
54+
{ value: ("\"" + $token + "\"") }
55+
]
56+
}')
57+
58+
# Create TXT record
59+
response=$(curl -s -o /dev/null -w '%{http_code}' \
60+
-X POST "$api_url/zones/$zone_id/rrsets/$txtname/TXT/actions/add_records" \
61+
-H "Content-Type: application/json" \
62+
-H "Authorization: Bearer $api_key" \
63+
-d "$payload")
64+
65+
if [[ "$response" != "201" ]] ; then
66+
echo "Record not created"
67+
echo "Response code: $response"
68+
exit 1
69+
fi

dns_scripts/dns_del_hetzner_cloud

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
3+
fulldomain="${1}"
4+
token="${2}"
5+
api_url="https://api.hetzner.cloud/v1"
6+
api_key=${HETZNER_KEY:-''}
7+
zone_id=${HETZNER_ZONE_ID:-''}
8+
zone_name=${HETZNER_ZONE_NAME:-''}
9+
10+
# Verify that required parameters are set
11+
if [[ -z "$fulldomain" ]]; then
12+
echo "DNS script requires full domain name as first parameter"
13+
exit 1
14+
fi
15+
if [[ -z "$token" ]]; then
16+
echo "DNS script requires challenge token as second parameter"
17+
exit 1
18+
fi
19+
if [[ -z "$HETZNER_KEY" ]]; then
20+
echo "HETZNER_KEY variable not set"
21+
exit 1
22+
fi
23+
if [[ -z "$HETZNER_ZONE_ID" && -z "$HETZNER_ZONE_NAME" ]] ; then
24+
echo "HETZNER_ZONE_ID and HETZNER_ZONE_NAME variables not set"
25+
exit 1
26+
fi
27+
28+
# Get Zone ID if not set
29+
if [[ -z "$HETZNER_ZONE_ID" ]] ; then
30+
zone_id=$(curl --silent -X GET "$api_url/zones?name=$zone_name" -H 'Authorization: Bearer '"$api_key"'' | jq -r '.zones[0].id')
31+
if [[ "$zone_id" == "null" ]] ; then
32+
echo "Zone by name not found"
33+
exit 1
34+
fi
35+
fi
36+
37+
# Get Zone name if not set
38+
if [[ -z "$zone_name" ]] ; then
39+
zone_name=$(curl --silent -X GET "$api_url/zones/$zone_id" -H 'Authorization: Bearer '"$api_key"'' | jq -r '.zone.name')
40+
if [[ "$zone_name" == "null" ]] ; then
41+
echo "Zone name not found"
42+
exit 1
43+
fi
44+
fi
45+
46+
txtname="_acme-challenge.$fulldomain"
47+
txtname="${txtname%."$zone_name"}"
48+
49+
# Delete TXT record
50+
payload=$(jq -n \
51+
--arg token "$token" \
52+
'{
53+
records: [
54+
{ value: ("\"" + $token + "\"") }
55+
]
56+
}')
57+
58+
response=$(curl -s -w '%{http_code}' \
59+
-X POST "$api_url/zones/$zone_id/rrsets/$txtname/TXT/actions/remove_records" \
60+
-H "Content-Type: application/json" \
61+
-H "Authorization: Bearer $api_key" \
62+
-d "$payload" \
63+
-o /dev/null)
64+
65+
if [[ "$response" != "201" ]] ; then
66+
echo "Record not deleted"
67+
echo "Response code: $response"
68+
exit 1
69+
fi
70+

test/u6-test-combined-directory.bats

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CA="https://api.test4.buypass.no/acme"
99

1010
# This is run for every test
1111
setup() {
12+
skip "buypass.no has stopped selling SSL certificates"
1213
[ ! -f $BATS_RUN_TMPDIR/failed.skip ] || skip "skipping tests after first failure"
1314

1415
. /getssl/getssl --source

test/u9-test-ca-newlines.bats

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ setup() {
1010
[ ! -f $BATS_RUN_TMPDIR/failed.skip ] || skip "skipping tests after first failure"
1111

1212
. /getssl/getssl --source
13-
# find_dns_utils
1413
_USE_DEBUG=1
1514
}
1615

@@ -42,15 +41,3 @@ teardown() {
4241
assert_not_equal $URL_newNonce $URL_newOrder
4342
assert_not_equal $URL_newOrder $URL_revole
4443
}
45-
46-
47-
@test "Check obtain_ca_resource_locations for BuyPass (no newlines)" {
48-
# BuyPass CA splits the directory with commas
49-
CA="https://api.test4.buypass.no/acme"
50-
obtain_ca_resource_locations
51-
52-
assert_equal $API 2
53-
assert_not_equal $URL_newAccount $URL_newNonce
54-
assert_not_equal $URL_newNonce $URL_newOrder
55-
assert_not_equal $URL_newOrder $URL_revole
56-
}

0 commit comments

Comments
 (0)