Rewrite BMS skill from bash to Python
This commit is contained in:
@@ -1,96 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
# bms-lookup.sh — Fetch lookup tables (statuses, priorities, queues, etc.)
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
BMS_API_BASE="${BMS_API_BASE:-https://api.bms.kaseya.com}"
|
||||
|
||||
die() { echo "ERROR: $*" >&2; exit 1; }
|
||||
|
||||
get_token() {
|
||||
bash "${SCRIPT_DIR}/bms-auth.sh" get-token
|
||||
}
|
||||
|
||||
bms_curl() {
|
||||
local path="$1"; shift
|
||||
local token
|
||||
token=$(get_token)
|
||||
curl -sf -X GET \
|
||||
"${BMS_API_BASE}${path}" \
|
||||
-H "Authorization: Bearer ${token}" \
|
||||
-H "Accept: application/json" \
|
||||
"$@"
|
||||
}
|
||||
|
||||
format_lookup() {
|
||||
jq -r '
|
||||
(.Data // .Items // .) |
|
||||
if type == "array" then .[]
|
||||
else .
|
||||
end |
|
||||
"\(.Id // .id)\t\(.Name // .name // .Text // .text // "(unnamed)")"
|
||||
' | sort -n | column -t -s $'\t'
|
||||
}
|
||||
|
||||
cmd_lookup() {
|
||||
local table="$1"
|
||||
case "$table" in
|
||||
statuses|status)
|
||||
echo "=== Ticket Statuses ===" >&2
|
||||
bms_curl "/v2/system/statuses/lookup" | format_lookup
|
||||
;;
|
||||
priorities|priority)
|
||||
echo "=== Priorities ===" >&2
|
||||
bms_curl "/v2/system/priorities/lookup" | format_lookup
|
||||
;;
|
||||
queues|queue)
|
||||
echo "=== Queues ===" >&2
|
||||
bms_curl "/v2/system/queues/lookup" | format_lookup
|
||||
;;
|
||||
issue-types|issuetypes)
|
||||
echo "=== Issue Types ===" >&2
|
||||
bms_curl "/v2/system/issuetypes/lookup" | format_lookup
|
||||
;;
|
||||
sources|source)
|
||||
die "Ticket source lookup endpoint is not exposed in the public BMS v2 Swagger. Use tenant-specific documentation or known SourceId values."
|
||||
;;
|
||||
ticket-types|tickettypes)
|
||||
die "Ticket type lookup endpoint is not exposed in the public BMS v2 Swagger. Use tenant-specific documentation or known TypeId values."
|
||||
;;
|
||||
assignees|assignee|technicians)
|
||||
echo "=== Assignees / Technicians ===" >&2
|
||||
bms_curl "/v2/hr/assignees/lookup" | format_lookup
|
||||
;;
|
||||
slas|sla)
|
||||
echo "=== SLAs ===" >&2
|
||||
bms_curl "/v2/system/slas/lookup" | format_lookup
|
||||
;;
|
||||
work-types|worktypes)
|
||||
echo "=== Work Types ===" >&2
|
||||
bms_curl "/v2/system/worktypes/lookup" | format_lookup
|
||||
;;
|
||||
note-types|notetypes)
|
||||
die "Note type lookup endpoint is not exposed in the public BMS v2 Swagger. Use tenant-specific documentation or known note TypeId values."
|
||||
;;
|
||||
all)
|
||||
cmd_lookup statuses
|
||||
echo
|
||||
cmd_lookup priorities
|
||||
echo
|
||||
cmd_lookup queues
|
||||
echo
|
||||
cmd_lookup issue-types
|
||||
echo
|
||||
cmd_lookup assignees
|
||||
;;
|
||||
*)
|
||||
die "Unknown lookup table: $table
|
||||
Available: statuses, priorities, queues, issue-types, sources, ticket-types, assignees, slas, work-types, note-types, all"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
table="${1:-}"
|
||||
[[ -n "$table" ]] || die "Usage: bms lookup <statuses|priorities|queues|issue-types|sources|ticket-types|assignees|slas|work-types|note-types|all>"
|
||||
cmd_lookup "$table"
|
||||
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
export PYTHONPATH="${REPO_ROOT}/src${PYTHONPATH:+:$PYTHONPATH}"
|
||||
cat >&2 <<'EOF'
|
||||
Lookup subcommands from the old bash implementation were removed in the Python rewrite.
|
||||
Use:
|
||||
bms accounts
|
||||
bms locations --account <id>
|
||||
bms templates tickets list
|
||||
bms templates notes list
|
||||
bms templates timelogs list
|
||||
For ticket/status IDs, use your tenant's known IDs or extend the Python service with tenant-specific lookups.
|
||||
EOF
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user