-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathgraphql-create-ip-allow-list-entry.sh
executable file
·59 lines (47 loc) · 1.26 KB
/
graphql-create-ip-allow-list-entry.sh
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
. ./.gh-api-examples.conf
# https://docs.github.com/en/graphql/reference/mutations#createipallowlistentry
echo "Audit log entry: action:ip_allow_list_entry.create" >&2
org=${1:-$org}
if [[ -z $2 ]]; then
ip_address=$(curl -s ifconfig.me/ip)
else
ip_address=$2
fi
owner_id=$(bash graphql-list-ip-allow-list-entries.sh | jq -r '.data.organization.id')
graphql_query=tmp/graphql_query.txt
rm -f ${graphql_query}
cat <<EOF >$graphql_query
mutation {
createIpAllowListEntry(input: {ownerId: "$owner_id", allowListValue: "$ip_address", isActive: true}) {
ipAllowListEntry {
id
allowListValue
createdAt
isActive
name
owner {
__typename
... on Enterprise {
name
}
... on Organization {
name
}
}
updatedAt
}
}
}
EOF
json_file=tmp/graphql-payload.json
rm -f ${json_file}
jq -n \
--arg graphql_query "$(cat $graphql_query)" \
'{query: $graphql_query}' > ${json_file}
curl ${curl_custom_flags} \
-H "Accept: application/vnd.github.v3+json" \
-H 'Accept: application/vnd.github.audit-log-preview+json' \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
${GITHUB_APIV4_BASE_URL} -d @${json_file} | jq
rm -f ${graphql_query}
rm -f ${json_file}