Skip to content

Commit 2cede8e

Browse files
committed
Ensure -noinput is applied correctly
Follow-up to: * #10131 * #10257
1 parent 01092ff commit 2cede8e

File tree

2 files changed

+101
-5
lines changed

2 files changed

+101
-5
lines changed

deps/rabbit/scripts/rabbitmq-diagnostics

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@ set -a
2222

2323
maybe_noinput='noinput'
2424

25-
if [ "$1" = 'observer' ]
26-
then
27-
maybe_noinput='input'
28-
fi
25+
case "$1" in
26+
observer)
27+
maybe_noinput='input'
28+
;;
29+
remote_shell)
30+
maybe_noinput='input'
31+
;;
32+
*)
33+
maybe_noinput='noinput'
34+
;;
35+
esac
2936

3037
run_escript "${ESCRIPT_DIR:?must be defined}"/rabbitmq-diagnostics "$maybe_noinput" "$@"

deps/rabbit/scripts/rabbitmqctl

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,93 @@ set -a
2020
# shellcheck source=./rabbitmq-env
2121
. "${0%/*}"/rabbitmq-env
2222

23-
run_escript "${ESCRIPT_DIR:?must be defined}"/rabbitmqctl 'noinput' "$@"
23+
echo "ARGLEN: $#"
24+
echo "ARG0: $0"
25+
echo "ARG1: $1"
26+
echo "ARG2: $2"
27+
echo "ARG3: $3"
28+
echo "ARG4: $4"
29+
echo "ARG5: $5"
30+
31+
set -x
32+
33+
_tmp_help_requested='false'
34+
35+
for _tmp_argument in "$@"
36+
do
37+
if [ "$_tmp_argument" = '--help' ]
38+
then
39+
_tmp_help_requested='true'
40+
break
41+
fi
42+
done
43+
44+
if [ "$1" = 'help' ] || [ "$_tmp_help_requested" = 'true' ]
45+
then
46+
# In this case, we do not require input and can exit early since
47+
# help was requested
48+
#
49+
run_escript "${ESCRIPT_DIR:?must be defined}"/rabbitmqctl 'noinput' "$@"
50+
exit "$?"
51+
fi
52+
53+
unset _tmp_help_requested
54+
55+
maybe_noinput='noinput'
56+
57+
case "$1" in
58+
add_user)
59+
if [ "$#" -eq 2 ]
60+
then
61+
# In this case, input is required to provide the password:
62+
#
63+
# rabbitmqctl add_user bob
64+
#
65+
maybe_noinput='input'
66+
elif [ "$#" -eq 3 ]
67+
then
68+
# In these cases, input depends on the arguments provided:
69+
#
70+
# rabbitmqctl add_user bob --pre-hashed-password (input needed)
71+
# rabbitmqctl add_user bob bobpassword (NO input needed)
72+
# rabbitmqctl add_user --pre-hashed-password bob (input needed)
73+
#
74+
for _tmp_argument in "$@"
75+
do
76+
if [ "$_tmp_argument" = '--pre-hashed-password' ]
77+
then
78+
maybe_noinput='input'
79+
break
80+
fi
81+
done
82+
elif [ "$#" -gt 3 ]
83+
then
84+
# If there are 4 or more arguments, no input is needed:
85+
#
86+
# rabbitmqctl add_user bob --pre-hashed-password HASHVALUE
87+
# rabbitmqctl add_user bob bobpassword IGNORED
88+
# rabbitmqctl add_user --pre-hashed-password bob HASHVALUE
89+
#
90+
maybe_noinput='noinput'
91+
fi
92+
;;
93+
change_password)
94+
maybe_noinput='input'
95+
if [ "$#" -gt 2 ]
96+
then
97+
# If there are 3 or more arguments, no input is needed:
98+
#
99+
# rabbitmqctl change_password sue foobar
100+
# rabbitmqctl change_password sue newpassword IGNORED
101+
#
102+
maybe_noinput='noinput'
103+
fi
104+
;;
105+
*)
106+
maybe_noinput='noinput'
107+
;;
108+
esac
109+
110+
unset _tmp_argument
111+
112+
run_escript "${ESCRIPT_DIR:?must be defined}"/rabbitmqctl "$maybe_noinput" "$@"

0 commit comments

Comments
 (0)