-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub
63 lines (56 loc) · 1.52 KB
/
github
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
###############################################################################
# function errecho
#
# This function outputs everything sent to it to STDERR (standard error output).
###############################################################################
function errecho() {
printf "%s\n" "$*" 1>&2
}
###############################################################################
# function iam_list_users
#
# List the IAM users in the account.
#
# Returns:
# The list of users names
# And:
# 0 - If the user already exists.
# 1 - If the user doesn't exist.
###############################################################################
function iam_list_users() {
local option OPTARG # Required to use getopts command in a function.
local error_code
# bashsupport disable=BP5008
function usage() {
echo "function iam_list_users"
echo "Lists the AWS Identity and Access Management (IAM) user in the account."
echo ""
}
# Retrieve the calling parameters.
while getopts "h" option; do
case "${option}" in
h)
usage
return 0
;;
\?)
echo "Invalid parameter"
usage
return 1
;;
esac
done
export OPTIND=1
local response
response=$(aws iam list-users \
--output text \
--query "Users[].UserName")
error_code=${?}
if [[ $error_code -ne 0 ]]; then
aws_cli_error_log $error_code
errecho "ERROR: AWS reports list-users operation failed.$response"
return 1
fi
echo "$response"
return 0
}