Skip to content

Commit 61c8079

Browse files
committed
cert-resource-record-valid: Check DNS record
DNS record required for auto-renew of ACM cert
1 parent a4cd3ef commit 61c8079

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

lib/cert-functions

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,36 @@ cert-chain() {
130130
done
131131
}
132132

133+
cert-resource-record-valid() {
134+
135+
# cert-resource-record-valid - Check if a specified DNS resource record matches the expected value and includes input validation.
136+
#
137+
# Usage: cert-resource-record-valid <name> <type> <value>
138+
139+
[[ "$#" -ne 3 ]] && __bma_usage "<name> <type> <value" && return 1
140+
141+
local name="$1"
142+
local type="$2"
143+
local value="$3"
144+
145+
# Perform the DNS query
146+
local output=$(dig +noall +answer "$name" "$type")
147+
148+
# Print the output of the DNS query
149+
echo "Query output:"
150+
echo "$output"
151+
152+
# Check if the expected value is in the output
153+
if echo "$output" | grep -q "$value"; then
154+
echo "The DNS record is valid."
155+
return 0
156+
else
157+
echo "The DNS record is invalid or does not exist."
158+
return 1
159+
fi
160+
}
161+
162+
133163
# openssl verify -CAfile trusted-ca.crt -untrusted chain.crt cert.crt
134164

135165
cert-verify() {

0 commit comments

Comments
 (0)