Skip to content

Commit dedf034

Browse files
authored
feat(Script): initial github-get-consumed-licenses.sh (#8)
1 parent 7026dd3 commit dedf034

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
###
5+
## GLOBAL VARIABLES
6+
###
7+
GITHUB_TOKEN=${GITHUB_TOKEN:-''}
8+
ENTERPRISE=${ENTERPRISE:-''}
9+
API_URL_PREFIX=${API_URL_PREFIX:-'https://api.github.com'}
10+
11+
if [ -z "${GITHUB_TOKEN}" ]
12+
then
13+
echo "GITHUB_TOKEN is empty. Please set your token and try again"
14+
exit 1
15+
fi
16+
17+
get_licenses () {
18+
PAYLOAD=$(curl -s -L -H "Authorization: Bearer ${GITHUB_TOKEN}" -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" "${API_URL_PREFIX}/enterprises/${ENTERPRISE}/consumed-licenses")
19+
SEATS_CONSUMED=$(echo "$PAYLOAD" | jq -r .total_seats_consumed)
20+
SEATS_PURCHASED=$(echo "$PAYLOAD" | jq -r .total_seats_purchased)
21+
echo "Total seats consumed: $SEATS_CONSUMED"
22+
echo "Total seats purchased: $SEATS_PURCHASED"
23+
}
24+
25+
get_licenses

0 commit comments

Comments
 (0)