-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbluexp_organization_delete
More file actions
executable file
·85 lines (80 loc) · 3.05 KB
/
bluexp_organization_delete
File metadata and controls
executable file
·85 lines (80 loc) · 3.05 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
#
# This script deletes an organization from a BlueXP account.
#
################################################################################
# Display usage information then exists the script.
################################################################################
usage () {
cat 1>&2 <<EOF
Usage: $(basename $0) -t REFRESH_TOKEN -o ORGANIZATION_ID
Where: REFRESH_TOKEN - Is a refresh token used to obtain an access token needed
to run the Workload Factory APIs. You can obtain a refresh
token by going to https://services.cloud.netapp.com/refresh-token
ORGANIZATION_ID - Is the Id of the organization to delete.
Instead of passing parameters on the command line, you can set the following
environment variables:
export REFRESH_TOKEN=<REFRESH_TOKEN>
EOF
exit 1
}
################################################################################
# Main logic starts here.
################################################################################
tmpout=$(mktemp /tmp/delete_organization_to_bluexp-out.XXXXXX)
tmperr=$(mktemp /tmp/delete_organization_to_bluexp-err.XXXXXX)
trap 'rm -f $tmpout $tmperr' exit
#
# Source the wf_utils file.
wf_utils=$(command -v wf_utils)
if [ -z "$wf_utils" ]; then
if [ ! -x "./wf_utils" ]; then
cat >&2 <<EOF
Error: The 'wf_utils' script was not found in the current directory or in the command search path.
It is required to run this script. You can download it from:
https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
EOF
exit 1
else
wf_utils=./wf_utils
fi
fi
. "$wf_utils"
#
# Parse the command line options.
while getopts "ht:o:" opt; do
case ${opt} in
t) REFRESH_TOKEN=$OPTARG ;;
o) ORGANIZATION_ID=$OPTARG ;;
*) usage ;;
esac
done
#
# Declare an array of required options and the error message to display if they are not set.
declare -A required_options
required_options["REFRESH_TOKEN"]='Error: A BlueXP refresh token is required to run this script. It can be obtained from this web page:
https://services.cloud.netapp.com/refresh-token\n\n'
required_options["ORGANIZATION_ID"]='Error: You must provide the name of the organization you want to delete.
You can get the list of organization you have access to by running the "list_bluexp_accts" script
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
check_required_options
#
# Check that the required commands are available.
for cmd in jq curl; do
if ! command -v $cmd &> /dev/null; then
echo "Error: The required command '$cmd' was not found. Please install it." >&2
exit 1
fi
done
#
# Get an access token.
token=$(get_token)
if [ -z "$token" ]; then
echo "Failed to get a token."
exit 1
fi
#
# Add the organization to the BlueXP workspace.
echo -n "Deleting organization ${ORGANIZATION_ID}..."
run_curl "DELETE" "$token" "https://api.bluexp.netapp.com/v1/management/organizations/$ORGANIZATION_ID" $tmpout $tmperr
echo "Done."