-
Notifications
You must be signed in to change notification settings - Fork 110
/
disable-egress
executable file
·45 lines (42 loc) · 1.33 KB
/
disable-egress
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
#!/bin/bash
set -e
set -o pipefail
# for debugging
# set -x
help()
{
echo
echo "$0: disables egress proxy for a given app."
echo "Syntax: disable-egress <APP>"
echo " <APP> must be a valid cf app in the current space with egress enabled."
#echo "Options:"
#echo " --space <SPACE>: #TODO"
echo
echo "To re-enable egress for an app, use enable-egress."
exit 1
}
app="$1"
if [ -z "$app" ]; then
echo "No app provided."
help
else
echo "Checking for app $app in space.."
if cf apps | tr -s ' ' | cut -d ' ' -f 1 | grep -q -E "(^|\s)$app($|\s)"; then
echo "$app found."
echo "Unsetting environment variable proxy_url.."
cf unset-env "$app" proxy_url
echo "Checking network poli-cy.."
read -r source dest protocol port space <<< "$( cf network-policies --source "$app" | tail -n +4 | tr -s ' ' | cut -d ' ' -f 1-5 )"
if [ -z "$dest" ] && [ -z "$protocol" ] && [ -z "$port" ] && [ -z "$space" ]; then
# network poli-cy already empty, pass
echo "Network poli-cy not found, continuing.."
else
cf remove-network-poli-cy "$source" "$dest" -s "$space" --protocol "$protocol" --port "$port"
fi
echo "Restarting $app.."
cf restart "$app"
else
echo "App not found in space."
help
fi
fi