o: fix approve/deny to handle array of pending requests
This commit is contained in:
parent
995db45444
commit
1663d2d212
|
|
@ -316,24 +316,37 @@ cmd_approve() {
|
|||
local bypass_path="session/$CTX_SESSION/bypass"
|
||||
local pending
|
||||
pending=$(ollie-9p read "$bypass_path" 2>/dev/null || true)
|
||||
if [[ -z "$pending" ]]; then
|
||||
if [[ -z "$pending" || "$pending" == "[]" || "$pending" == "null" ]]; then
|
||||
echo "no pending bypass request"
|
||||
return 0
|
||||
fi
|
||||
local id
|
||||
id=$(echo "$pending" | jq -r '.id' 2>/dev/null)
|
||||
|
||||
# Normalize to array
|
||||
local arr
|
||||
arr=$(echo "$pending" | jq 'if type == "array" then . else [.] end' 2>/dev/null)
|
||||
|
||||
# Find the request to approve
|
||||
local req
|
||||
if [[ -n "$req_id" ]]; then
|
||||
req=$(echo "$arr" | jq -r --arg id "$req_id" '.[] | select(.id == $id)' 2>/dev/null)
|
||||
if [[ -z "$req" ]]; then
|
||||
echo "error: no pending request with id $req_id" >&2
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
req=$(echo "$arr" | jq -r '.[0]' 2>/dev/null)
|
||||
fi
|
||||
|
||||
local id cmd cwd
|
||||
id=$(echo "$req" | jq -r '.id' 2>/dev/null)
|
||||
cmd=$(echo "$req" | jq -r '.cmd | split("\n")[0]' 2>/dev/null)
|
||||
cwd=$(echo "$req" | jq -r '.cwd' 2>/dev/null)
|
||||
|
||||
if [[ -z "$id" || "$id" == "null" ]]; then
|
||||
echo "error: could not parse bypass request" >&2
|
||||
exit 1
|
||||
fi
|
||||
# If request ID specified, verify it matches
|
||||
if [[ -n "$req_id" && "$req_id" != "$id" ]]; then
|
||||
echo "error: request id mismatch (pending: $id, requested: $req_id)" >&2
|
||||
exit 1
|
||||
fi
|
||||
local cmd cwd
|
||||
cmd=$(echo "$pending" | jq -r '.cmd' 2>/dev/null)
|
||||
cwd=$(echo "$pending" | jq -r '.cwd' 2>/dev/null)
|
||||
|
||||
echo "[$id] approving: $cmd"
|
||||
echo " cwd: $cwd"
|
||||
printf '%s approve' "$id" | ollie-9p write "$bypass_path"
|
||||
|
|
@ -350,24 +363,37 @@ cmd_deny() {
|
|||
local bypass_path="session/$CTX_SESSION/bypass"
|
||||
local pending
|
||||
pending=$(ollie-9p read "$bypass_path" 2>/dev/null || true)
|
||||
if [[ -z "$pending" ]]; then
|
||||
if [[ -z "$pending" || "$pending" == "[]" || "$pending" == "null" ]]; then
|
||||
echo "no pending bypass request"
|
||||
return 0
|
||||
fi
|
||||
local id
|
||||
id=$(echo "$pending" | jq -r '.id' 2>/dev/null)
|
||||
|
||||
# Normalize to array
|
||||
local arr
|
||||
arr=$(echo "$pending" | jq 'if type == "array" then . else [.] end' 2>/dev/null)
|
||||
|
||||
# Find the request to deny
|
||||
local req
|
||||
if [[ -n "$req_id" ]]; then
|
||||
req=$(echo "$arr" | jq -r --arg id "$req_id" '.[] | select(.id == $id)' 2>/dev/null)
|
||||
if [[ -z "$req" ]]; then
|
||||
echo "error: no pending request with id $req_id" >&2
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
req=$(echo "$arr" | jq -r '.[0]' 2>/dev/null)
|
||||
fi
|
||||
|
||||
local id cmd cwd
|
||||
id=$(echo "$req" | jq -r '.id' 2>/dev/null)
|
||||
cmd=$(echo "$req" | jq -r '.cmd | split("\n")[0]' 2>/dev/null)
|
||||
cwd=$(echo "$req" | jq -r '.cwd' 2>/dev/null)
|
||||
|
||||
if [[ -z "$id" || "$id" == "null" ]]; then
|
||||
echo "error: could not parse bypass request" >&2
|
||||
exit 1
|
||||
fi
|
||||
# If request ID specified, verify it matches
|
||||
if [[ -n "$req_id" && "$req_id" != "$id" ]]; then
|
||||
echo "error: request id mismatch (pending: $id, requested: $req_id)" >&2
|
||||
exit 1
|
||||
fi
|
||||
local cmd cwd
|
||||
cmd=$(echo "$pending" | jq -r '.cmd' 2>/dev/null)
|
||||
cwd=$(echo "$pending" | jq -r '.cwd' 2>/dev/null)
|
||||
|
||||
echo "[$id] denying: $cmd"
|
||||
echo " cwd: $cwd"
|
||||
printf '%s deny' "$id" | ollie-9p write "$bypass_path"
|
||||
|
|
|
|||
Loading…
Reference in New Issue