Skip to content

Commit ca35e8c

Browse files
committed
Fix zone_id extraction to query correct zone
1 parent eeb91de commit ca35e8c

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

dnsapi/dns_infoblox_uddi.sh

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,14 @@ dns_infoblox_uddi_add() {
7373
return 1
7474
fi
7575

76-
zone_id=$(echo "$zone_result" | _egrep_o '"id":"dns/auth_zone/[^"]*"' | _egrep_o 'dns/auth_zone/[^"]*' | _head_n 1)
76+
# Fetch exact zone_id for the matched fqdn using server-side filtering
77+
filter="fqdn eq '$zone_fqdn.' or fqdn eq '$zone_fqdn'"
78+
filter_encoded=$(_url_encode "$filter")
79+
zone_query="$zone_url?_filter=$filter_encoded"
80+
_debug "Fetching zone_id with filter: $zone_query"
81+
zone_lookup="$(_get "$zone_query")"
82+
_debug2 "zone_lookup: $zone_lookup"
83+
zone_id=$(echo "$zone_lookup" | _egrep_o '"id":"dns/auth_zone/[^\"]*"' | _head_n 1 | sed 's/.*"id":"\([^\"]*\)".*/\1/')
7784

7885
_debug "zone_id: $zone_id"
7986

@@ -164,7 +171,14 @@ dns_infoblox_uddi_rm() {
164171
return 1
165172
fi
166173

167-
zone_id=$(echo "$zone_result" | _egrep_o '"id":"dns/auth_zone/[^"]*"' | _egrep_o 'dns/auth_zone/[^"]*' | _head_n 1)
174+
# Fetch exact zone_id for the matched fqdn using server-side filtering
175+
filter="fqdn eq '$zone_fqdn.' or fqdn eq '$zone_fqdn'"
176+
filter_encoded=$(_url_encode "$filter")
177+
zone_query="$zone_url?_filter=$filter_encoded"
178+
_debug "Fetching zone_id with filter: $zone_query"
179+
zone_lookup="$(_get "$zone_query")"
180+
_debug2 "zone_lookup: $zone_lookup"
181+
zone_id=$(echo "$zone_lookup" | _egrep_o '"id":"dns/auth_zone/[^\"]*"' | _head_n 1 | sed 's/.*"id":"\([^\"]*\)".*/\1/')
168182

169183
_debug "zone_id: $zone_id"
170184

@@ -177,7 +191,7 @@ dns_infoblox_uddi_rm() {
177191
name_in_zone=$(echo "$fulldomain" | sed "s/\.$zone_fqdn\$//" | sed 's/\.$//')
178192
_debug "name_in_zone: $name_in_zone"
179193

180-
filter="type eq 'TXT' and name_in_zone eq '$name_in_zone' and zone eq '$zone_id'"
194+
filter="type eq 'TXT' and name_in_zone eq '$name_in_zone' and zone eq '$zone_id' and rdata.text eq '$txtvalue'"
181195
filter_encoded=$(_url_encode "$filter")
182196
geturl="https://$Infoblox_Portal/api/ddi/v1/dns/record?_filter=$filter_encoded"
183197
_debug "GET URL: $geturl"
@@ -186,7 +200,7 @@ dns_infoblox_uddi_rm() {
186200
_debug "GET result: $result"
187201

188202
if echo "$result" | grep -q '"results":'; then
189-
record_id=$(echo "$result" | _egrep_o '"id":"dns/record/[^"]*"' | _egrep_o 'dns/record/[^"]*' | _head_n 1)
203+
record_id=$(echo "$result" | _egrep_o '"id":"dns/record/[^\"]*"' | _head_n 1 | sed 's/.*"id":"\([^\"]*\)".*/\1/')
190204
_debug "Found record_id: $record_id"
191205

192206
if [ -n "$record_id" ]; then

0 commit comments

Comments
 (0)