forked from mozilla/github-org-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_PAT_owner
executable file
·64 lines (51 loc) · 1.52 KB
/
get_PAT_owner
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash
USAGE="usage: ${0##*/} [PAT]
Return the owner & permissions associated with the PAT
Passing the PAT via the environment variable PAT is prefered and takes
precedence. The PAT should be passed as an argument as a CI variable reference,
only where the CI system guarantees the value will not be displayed in any log.
ENVIRONMENT:
PAT The GitHub token to audit
"
# Defaults
token="${PAT:-}"
if [ -n "$DEBUG" ]; then
PS4=':${LINENO}+'
set -x
fi
# boilerplate
warn() { for m; do echo "$m" ; done 1>&2 ; }
die() { warn "$@" ; exit 2 ; }
usage() { warn "$@" "${USAGE:-}"; test $# -eq 0 ; exit $? ; }
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help) usage ;;
-*) usage "Unknown option '$1'" ;;
*) break
esac
shift
done
MIN_ARGS=0
MAX_ARGS=1
[[ $# -lt $MIN_ARGS || $# -gt $MAX_ARGS ]] && usage "Wrong number of args $#"
if [[ -z $token ]]; then
if [[ $# -eq 1 ]]; then
token="$1"
else
usage "No PAT supplied"
fi
elif [[ $# -eq 1 ]]; then
warn "WARNING: Ignoring command line arguement, using environment variable PAT"
fi
resp=$(curl --silent --show-error \
--include \
-H "Authorization: token $token" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/user)
#echo "$resp"
oauth=$(echo "$resp" | grep -i ^X-OAuth-Scopes)
login=$(echo "$resp" | grep -i -w login | cut -d: -f2)
id_v4=$(echo "$resp" | grep -i -w node_id | cut -d: -f2)
echo "The PAT is owned by $login $id_v4
and has the following permissions:
$oauth"