Skip to content

Commit 69fc825

Browse files
committed
Updated to V4 of Linode API
1 parent 32a649f commit 69fc825

2 files changed

Lines changed: 22 additions & 26 deletions

File tree

dns_scripts/dns_add_linode

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
fulldomain="${1}"
44
token="${2}"
5-
api_url="https://api.linode.com/api/"
5+
api_url="https://api.linode.com/v4"
66
api_key=${LINODE_KEY:-''}
77

88
# Verify that required parameters are set
@@ -19,26 +19,25 @@ if [[ -z "$LINODE_KEY" ]]; then
1919
exit 1
2020
fi
2121

22-
domain_root=$(echo "$fulldomain" | awk -F\. '{print $(NF-1) FS $NF}')
22+
domain_root=${fulldomain#*.}
2323
domain=${fulldomain%.$domain_root}
2424
txtname="_acme-challenge.$domain"
2525

2626
# Get Domain ID
27-
response=$(curl --silent -X POST "$api_url" \
28-
-H "Accept: application/json" -H "User-Agent: getssl/0.1" -H "application/x-www-form-urlencoded" \
29-
-d "api_key=${api_key}&api_action=domain.list" )
30-
domain_id=$(echo "$response" | egrep -o "{\"DOMAIN\":\"$domain_root\".*\"DOMAINID\":([0-9]+)" | egrep -o "[0-9]+$")
27+
response=$(curl --silent ${api_url}/domains \
28+
-H "User-Agent: getssl/0.1" -H "Authorization: Bearer ${api_key}")
29+
domain_id=$(echo "$response" | jq ".data[] | select (.domain==\"$domain_root\") | .id")
3130
if [[ $domain_id == "" ]]; then
3231
echo "Failed to fetch DomainID"
3332
exit 1
3433
fi
3534

3635
# Create TXT record
37-
response=$(curl --silent -X POST "$api_url" \
38-
-H "Accept: application/json" -H "User-Agent: getssl/0.1" -H "application/x-www-form-urlencoded" \
39-
-d "api_key=$api_key&api_action=domain.resource.create&DomainID=$domain_id&Type=TXT&Name=$txtname&Target=$token" )
40-
errors=$(echo "$response" | egrep -o "\"ERRORARRAY\":\[.*\]")
41-
if [[ $errors != "\"ERRORARRAY\":[]" ]]; then
36+
response=$(curl --silent -X POST ${api_url}/domains/${domain_id}/records \
37+
-H "Content-Type: application/json" -H "User-Agent: getssl/0.1" -H "Authorization: Bearer ${api_key}" \
38+
-d '{"type": "TXT", "name": "'${txtname}'", "target": "'$token'", "ttl_sec": 30}')
39+
errors=$(echo "$response" | jq ".errors[]?.reason")
40+
if [[ $errors != "" ]]; then
4241
echo "Something went wrong: $errors"
4342
exit 1
4443
fi

dns_scripts/dns_del_linode

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
fulldomain="${1}"
4-
api_url="https://api.linode.com/api/"
4+
api_url="https://api.linode.com/v4"
55
api_key=${LINODE_KEY:-''}
66

77
# Verify that required parameters are set
@@ -14,36 +14,33 @@ if [[ -z "$LINODE_KEY" ]]; then
1414
exit 1
1515
fi
1616

17-
domain_root=$(echo "$fulldomain" | awk -F\. '{print $(NF-1) FS $NF}')
17+
domain_root=${fulldomain#*.}
1818
domain=${fulldomain%.$domain_root}
1919
txtname="_acme-challenge.$domain"
2020

2121
# Get Domain ID
22-
response=$(curl --silent -X POST "$api_url" \
23-
-H "Accept: application/json" -H "User-Agent: getssl/0.1" -H "application/x-www-form-urlencoded" \
24-
-d "api_key=${api_key}&api_action=domain.list" )
25-
domain_id=$(echo "$response" | egrep -o "{\"DOMAIN\":\"$domain_root\".*\"DOMAINID\":([0-9]+)" | egrep -o "[0-9]+$")
22+
response=$(curl --silent ${api_url}/domains \
23+
-H "User-Agent: getssl/0.1" -H "Authorization: Bearer ${api_key}")
24+
domain_id=$(echo "$response" | jq ".data[] | select (.domain==\"$domain_root\") | .id")
2625
if [[ $domain_id == "" ]]; then
2726
echo "Failed to fetch DomainID"
2827
exit 1
2928
fi
3029

3130
# Get Resource ID
32-
response=$(curl --silent -X POST "$api_url" \
33-
-H "Accept: application/json" -H "User-Agent: getssl/0.1" -H "application/x-www-form-urlencoded" \
34-
-d "api_key=${api_key}&api_action=domain.resource.list&DomainID=$domain_id" )
35-
resource_id=$(echo "$response" | egrep -o "\"RESOURCEID\":[0-9]+,\"TYPE\":\"TXT\",\"NAME\":\"$txtname\"" | egrep -o "\"RESOURCEID\":[0-9]+" | egrep -o "[0-9]+$")
31+
response=$(curl --silent ${api_url}/domains/${domain_id}/records \
32+
-H "User-Agent: getssl/0.1" -H "Authorization: Bearer ${api_key}")
33+
resource_id=$(echo "$response" | jq ".data[] | select (.name==\"$txtname\") | .id")
3634
if [[ $resource_id == "" ]]; then
3735
echo "Failed to fetch ResourceID"
3836
exit 1
3937
fi
4038

4139
# Delete TXT record
42-
response=$(curl --silent -X POST "$api_url" \
43-
-H "Accept: application/json" -H "User-Agent: getssl/0.1" -H "application/x-www-form-urlencoded" \
44-
-d "api_key=$api_key&api_action=domain.resource.delete&DomainID=$domain_id&ResourceID=$resource_id" )
45-
errors=$(echo "$response" | egrep -o "\"ERRORARRAY\":\[.*\]")
46-
if [[ $errors != "\"ERRORARRAY\":[]" ]]; then
40+
response=$(curl --silent -X DELETE ${api_url}/domains/${domain_id}/records/${resource_id} \
41+
-H "User-Agent: getssl/0.1" -H "Authorization: Bearer ${api_key}")
42+
errors=$(echo "$response" | jq ".errors[]?.reason")
43+
if [[ $errors != "" ]]; then
4744
echo "Something went wrong: $errors"
4845
exit 1
4946
fi

0 commit comments

Comments
 (0)