Merge pull request #6440 from jf-lines/dns_infomaniak_API_v2
Some checks failed
DNS / CheckToken (push) Has been cancelled
Build DockerHub / CheckToken (push) Has been cancelled
Shellcheck / ShellCheck (push) Has been cancelled
Shellcheck / shfmt (push) Has been cancelled
DNS / Fail (push) Has been cancelled
DNS / Docker (push) Has been cancelled
DNS / MacOS (push) Has been cancelled
DNS / Windows (push) Has been cancelled
DNS / FreeBSD (push) Has been cancelled
DNS / OpenBSD (push) Has been cancelled
DNS / NetBSD (push) Has been cancelled
DNS / DragonFlyBSD (push) Has been cancelled
DNS / Solaris (push) Has been cancelled
DNS / Omnios (push) Has been cancelled
DNS / OpenIndiana (push) Has been cancelled
DNS / Haiku (push) Has been cancelled
Build DockerHub / build (push) Has been cancelled

dns_infomaniak: upgraded to API v2. v1 is deprecated.
This commit is contained in:
neil
2026-02-01 17:15:02 +01:00
committed by GitHub

View File

@@ -6,14 +6,16 @@ Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi2#dns_infomaniak
Options: Options:
INFOMANIAK_API_TOKEN API Token INFOMANIAK_API_TOKEN API Token
Issues: github.com/acmesh-official/acme.sh/issues/3188 Issues: github.com/acmesh-official/acme.sh/issues/3188
' '
# To use this API you need visit the API dashboard of your account # To use this API you need visit the API dashboard of your account.
# once logged into https://manager.infomaniak.com add /api/dashboard to the URL
#
# Note: the URL looks like this: # Note: the URL looks like this:
# https://manager.infomaniak.com/v3/<account_id>/api/dashboard # https://manager.infomaniak.com/v3/<account_id>/ng/profile/user/token/list
# Then generate a token with the scope Domain # Then generate a token with following scopes :
# - domain:read
# - dns:read
# - dns:write
# this is given as an environment variable INFOMANIAK_API_TOKEN # this is given as an environment variable INFOMANIAK_API_TOKEN
# base variables # base variables
@@ -65,33 +67,32 @@ dns_infomaniak_add() {
_debug fulldomain "$fulldomain" _debug fulldomain "$fulldomain"
_debug txtvalue "$txtvalue" _debug txtvalue "$txtvalue"
fqdn=${fulldomain#_acme-challenge.}
# guess which base domain to add record to # guess which base domain to add record to
zone_and_id=$(_find_zone "$fqdn") zone=$(_get_zone "$fulldomain")
if [ -z "$zone_and_id" ]; then if [ -z "$zone" ]; then
_err "cannot find zone to modify" _err "cannot find zone:<${zone}> to modify"
return 1 return 1
fi fi
zone=${zone_and_id% *}
domain_id=${zone_and_id#* }
# extract first part of domain # extract first part of domain
key=${fulldomain%."$zone"} key=${fulldomain%."$zone"}
_debug "zone:$zone id:$domain_id key:$key" _debug "key:$key"
_debug "txtvalue: $txtvalue"
# payload # payload
data="{\"type\": \"TXT\", \"source\": \"$key\", \"target\": \"$txtvalue\", \"ttl\": $INFOMANIAK_TTL}" data="{\"type\": \"TXT\", \"source\": \"$key\", \"target\": \"$txtvalue\", \"ttl\": $INFOMANIAK_TTL}"
# API call # API call
response=$(_post "$data" "${INFOMANIAK_API_URL}/1/domain/$domain_id/dns/record") response=$(_post "$data" "${INFOMANIAK_API_URL}/2/zones/${zone}/records")
if [ -n "$response" ] && echo "$response" | _contains '"result":"success"'; then if [ -n "$response" ]; then
_info "Record added" if [ ! "$(echo "$response" | _contains '"result":"success"')" ]; then
_debug "Response: $response" _info "Record added"
return 0 _debug "response: $response"
return 0
fi
fi fi
_err "could not create record" _err "Could not create record."
_debug "Response: $response" _debug "Response: $response"
return 1 return 1
} }
@@ -106,7 +107,7 @@ dns_infomaniak_rm() {
if [ -z "$INFOMANIAK_API_TOKEN" ]; then if [ -z "$INFOMANIAK_API_TOKEN" ]; then
INFOMANIAK_API_TOKEN="" INFOMANIAK_API_TOKEN=""
_err "Please provide a valid Infomaniak API token in variable INFOMANIAK_API_TOKEN" _err "Please provide a valid Infomaniak API token in variable INFOMANIAK_API_TOKEN."
return 1 return 1
fi fi
@@ -138,63 +139,53 @@ dns_infomaniak_rm() {
_debug fulldomain "$fulldomain" _debug fulldomain "$fulldomain"
_debug txtvalue "$txtvalue" _debug txtvalue "$txtvalue"
fqdn=${fulldomain#_acme-challenge.}
# guess which base domain to add record to # guess which base domain to add record to
zone_and_id=$(_find_zone "$fqdn") zone=$(_get_zone "$fulldomain")
if [ -z "$zone_and_id" ]; then if [ -z "$zone" ]; then
_err "cannot find zone to modify" _err "cannot find zone:<$zone> to modify"
return 1 return 1
fi fi
zone=${zone_and_id% *}
domain_id=${zone_and_id#* }
# extract first part of domain # extract first part of domain
key=${fulldomain%."$zone"} key=${fulldomain%."$zone"}
key=$(echo "$key" | _lower_case)
_debug "zone:$zone id:$domain_id key:$key" _debug "zone:$zone"
_debug "key:$key"
# find previous record # find previous record
# shellcheck disable=SC1004 # shellcheck disable=SC2086
record_id=$(_get "${INFOMANIAK_API_URL}/1/domain/$domain_id/dns/record" | sed 's/.*"data":\[\(.*\)\]}/\1/; s/},{/}\ response=$(_get "${INFOMANIAK_API_URL}/2/zones/${zone}/records" | sed 's/.*"data":\[\(.*\)\]}/\1/; s/},{/}{/g')
{/g' | sed -n 's/.*"id":"*\([0-9]*\)"*.*"source_idn":"'"$fulldomain"'".*"target_idn":"'"$txtvalue"'".*/\1/p') record_id=$(echo "$response" | sed -n 's/.*"id":"*\([0-9]*\)"*.*"source":"'"$key"'".*"target":"\\"'"$txtvalue"'\\"".*/\1/p')
if [ -z "$record_id" ]; then _debug "key: $key"
_err "could not find record to delete" _debug "txtvalue: $txtvalue"
return 1
fi
_debug "record_id: $record_id" _debug "record_id: $record_id"
# API call if [ -z "$record_id" ]; then
response=$(_post "" "${INFOMANIAK_API_URL}/1/domain/$domain_id/dns/record/$record_id" "" DELETE) _err "could not find record to delete"
if [ -n "$response" ] && echo "$response" | _contains '"result":"success"'; then _debug "response: $response"
_info "Record deleted" return 1
return 0
fi fi
_err "could not delete record"
# API call
response=$(_post "" "${INFOMANIAK_API_URL}/2/zones/${zone}/records/${record_id}" "" DELETE)
if [ -n "$response" ]; then
if [ ! "$(echo "$response" | _contains '"result":"success"')" ]; then
_info "Record deleted"
return 0
fi
fi
_err "Could not delete record."
_debug "Response: $response"
return 1 return 1
} }
#################### Private functions below ################################## #################### Private functions below ##################################
_get_domain_id() { _get_zone() {
domain="$1" domain="$1"
# Whatever the domain is, you can get the fqdn with the following.
# shellcheck disable=SC1004 # shellcheck disable=SC1004
_get "${INFOMANIAK_API_URL}/1/product?service_name=domain&customer_name=$domain" | sed 's/.*"data":\[{\(.*\)}\]}/\1/; s/,/\ response=$(_get "${INFOMANIAK_API_URL}/2/domains/${domain}/zones" | sed 's/.*\[{"fqdn"\:"\(.*\)/\1/')
/g' | sed -n 's/^"id":\(.*\)/\1/p' echo "${response%%\"*}"
}
_find_zone() {
zone="$1"
# find domain in list, removing . parts sequentialy
while _contains "$zone" '\.'; do
_debug "testing $zone"
id=$(_get_domain_id "$zone")
if [ -n "$id" ]; then
echo "$zone $id"
return
fi
zone=${zone#*.}
done
} }