Fix auth token parsing, remove column dependency, add --status open for non-closed tickets
This commit is contained in:
@@ -29,9 +29,9 @@ token_is_valid() {
|
||||
save_token() {
|
||||
local response="$1"
|
||||
local access_token refresh_token expires_in expires_at
|
||||
access_token=$(echo "$response" | jq -r '.AccessToken // .access_token // empty')
|
||||
refresh_token=$(echo "$response" | jq -r '.RefreshToken // .refresh_token // empty')
|
||||
expires_in=$(echo "$response" | jq -r '.ExpiresIn // .expires_in // 3600')
|
||||
access_token=$(echo "$response" | jq -r '.result.AccessToken // .result.accessToken // .result.access_token // empty')
|
||||
refresh_token=$(echo "$response" | jq -r '.result.RefreshToken // .result.refreshToken // .result.refresh_token // empty')
|
||||
expires_in=$(echo "$response" | jq -r '.result.ExpiresIn // .result.expires_in // 3600')
|
||||
expires_at=$(( $(date +%s) + expires_in ))
|
||||
|
||||
[[ -n "$access_token" ]] || die "No access token in auth response: $response"
|
||||
@@ -65,11 +65,13 @@ cmd_auth_login() {
|
||||
require_env BMS_USERNAME
|
||||
require_env BMS_PASSWORD
|
||||
echo "Authenticating with username/password..." >&2
|
||||
response=$(curl -sf -X POST "${BMS_API_BASE}/v2/security/authenticate" \
|
||||
local curl_args=(-s -X POST "${BMS_API_BASE}/v2/security/authenticate" \
|
||||
-F "GrantType=password" \
|
||||
-F "UserName=${BMS_USERNAME}" \
|
||||
-F "Password=${BMS_PASSWORD}" \
|
||||
-F "Tenant=${BMS_TENANT}") || die "Authentication request failed"
|
||||
-F "Tenant=${BMS_TENANT}")
|
||||
[[ -n "${BMS_MFA_CODE:-}" ]] && curl_args+=(-F "MFACode=${BMS_MFA_CODE}")
|
||||
response=$(curl "${curl_args[@]}") || die "Authentication request failed"
|
||||
fi
|
||||
|
||||
save_token "$response"
|
||||
|
||||
0
scripts/bms-templates.sh
Normal file → Executable file
0
scripts/bms-templates.sh
Normal file → Executable file
13
scripts/bms-tickets.sh
Normal file → Executable file
13
scripts/bms-tickets.sh
Normal file → Executable file
@@ -30,10 +30,10 @@ bms_curl() {
|
||||
# Pretty-print a ticket list
|
||||
format_ticket_list() {
|
||||
jq -r '
|
||||
(.Data // .Items // .) |
|
||||
if type == "array" then .[] else . end |
|
||||
"\(.TicketNumber // .Id)\t[\(.StatusName // "?")] \(.Title)\t| \(.AccountName // "?")\t| Assignee: \(.AssigneeName // "unassigned")\t| Priority: \(.PriorityName // "?")"
|
||||
' | column -t -s $'\t'
|
||||
(.result // .) |
|
||||
if type == "array" then .[] else empty end |
|
||||
"\(.ticketNumber // .Id)\t[\(.statusName // "?")] \(.title // "?")\t| \(.accountName // "?")\t| Assignee: \(.assigneeName // "unassigned")\t| Priority: \(.priorityName // "?")"
|
||||
' | sed 's/\t/ /g'
|
||||
}
|
||||
|
||||
format_ticket_detail() {
|
||||
@@ -82,6 +82,11 @@ cmd_list() {
|
||||
# Build filter JSON
|
||||
local filter="{"
|
||||
local sep=""
|
||||
if [[ "$status" == "open" ]]; then
|
||||
filter+="\"StatusNames\":\"Escalated,Open,Waiting for Customer,Waiting for Product(s),Waiting for Vendor\""
|
||||
sep=","
|
||||
status=""
|
||||
fi
|
||||
[[ -n "$status" ]] && { filter+="${sep}\"StatusNames\":\"${status}\""; sep=","; }
|
||||
[[ -n "$assignee" ]] && { filter+="${sep}\"AssigneeName\":\"${assignee}\""; sep=","; }
|
||||
[[ -n "$from" ]] && { filter+="${sep}\"CreatedOnFrom\":\"${from}T00:00:00\""; sep=","; }
|
||||
|
||||
0
scripts/bms.sh
Normal file → Executable file
0
scripts/bms.sh
Normal file → Executable file
23
scripts/patch.py
Normal file
23
scripts/patch.py
Normal file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
path = "/workspace/skills/bms/scripts/bms-tickets.sh"
|
||||
with open(path, "r") as f:
|
||||
lines = f.readlines()
|
||||
|
||||
# Find the line that is exactly ' local sep=""\n'
|
||||
for i, line in enumerate(lines):
|
||||
if line.strip() == 'local sep=""':
|
||||
insert_idx = i + 1
|
||||
new_lines = [
|
||||
' if [[ "$status" == "open" ]]; then\n',
|
||||
' filter+="\\"StatusNames\\":\\"Escalated,Open,Waiting for Customer,Waiting for Product(s),Waiting for Vendor\\""\n',
|
||||
' sep=","\n',
|
||||
' status=""\n',
|
||||
' fi\n',
|
||||
]
|
||||
lines[insert_idx:insert_idx] = new_lines
|
||||
break
|
||||
|
||||
with open(path, "w") as f:
|
||||
f.writelines(lines)
|
||||
print("Patched after local sep line")
|
||||
Reference in New Issue
Block a user