fix: parse OCI inventory JSON safely
This commit is contained in:
parent
21586b7f71
commit
a300a50663
|
|
@ -3531,7 +3531,8 @@ oci_status() {
|
|||
--query 'data[].{NAME:name,ID:id,STATE:"lifecycle-state"}' --output table 2>/dev/null || echo 'unavailable'
|
||||
local compartment_ids resource_compartments current_compartment
|
||||
compartment_ids="$("${oci_bin}" iam compartment list --compartment-id "${tenancy}" \
|
||||
--compartment-id-in-subtree true --all --query 'data[].id' --raw-output 2>/dev/null || true)"
|
||||
--compartment-id-in-subtree true --all --output json 2>/dev/null \
|
||||
| python3 -c 'import json,sys; print("\\n".join(x["id"] for x in json.load(sys.stdin).get("data", [])))' 2>/dev/null || true)"
|
||||
resource_compartments="${tenancy}"$'\n'"${compartment_ids}"
|
||||
printf '%s\n' '-- compute instances (all compartments)'
|
||||
while IFS= read -r current_compartment; do
|
||||
|
|
@ -3601,7 +3602,8 @@ oci_doctor() {
|
|||
fi
|
||||
|
||||
states="$("${oci_bin}" compute instance list --compartment-id "${compartment}" --all \
|
||||
--query 'data[]."lifecycle-state"' --raw-output 2>/dev/null || true)"
|
||||
--output json 2>/dev/null \
|
||||
| python3 -c 'import json,sys; print("\\n".join(x["lifecycle-state"] for x in json.load(sys.stdin).get("data", [])))' 2>/dev/null || true)"
|
||||
if [[ -n "${states}" ]]; then
|
||||
bad_state="$(printf '%s\n' "${states}" | grep -Ev '^(RUNNING|STOPPED|STOPPING|STARTING|TERMINATED|TERMINATING|PROVISIONING)$' || true)"
|
||||
if [[ -n "${bad_state}" ]]; then
|
||||
|
|
|
|||
Loading…
Reference in New Issue