Skip to content

Commit

Permalink
Add option to specify key and additional errors
Browse files Browse the repository at this point in the history
  • Loading branch information
PhongT16 committed Jul 5, 2024
1 parent 856e271 commit 2840efb
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions bin/sso_bypass.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
MODE="false"
# KEY="password"

get_netrc_value() {
local _machine=$1
local _key=$2

awk -v machine="$_machine" -v key="$_key" '
$1 == "machine" && $2 == machine {found=1}
found && $1 == key {print $2; exit}
Expand All @@ -13,7 +15,7 @@ get_netrc_value() {
is_object_null() {
local _obj=$1
if [ -z "$_obj" ]; then
echo "Error: Either Base URL or Access Token was not provided"
echo "Error: Either Base URL, key type, or Access Token was not provided"
echo "Run with -h option for help."
exit 1
fi
Expand All @@ -38,15 +40,16 @@ verify_auth_fallback_status() {
echo "SSO Bypass unsuccessfully enabled"
exit 1
else
echo "SSO Bypass unsuccessfully enabled"
echo "SSO Bypass unsuccessfully disabled"
exit 1
fi
}

request_auth_fallback() {
is_object_null "$MACHINE"
is_object_null "$KEY"
local _endpoint="https://"$MACHINE"/rest/authconfig/1.0/sso"
local _token=$(get_netrc_value "$MACHINE" "password")
local _token=$(get_netrc_value "$MACHINE" "$KEY")
is_object_null "$_token"

local _status=$(curl -s --location --request PATCH "$_endpoint" \
Expand All @@ -66,25 +69,30 @@ ${_prg}
Enable/Disable SSO Bypass on Confluence
Require: Save auth in .netrc
SYNOPSYS
${_prg} [OPTIONS] [BASE URL]
${_prg} [OPTIONS] [BASE URL] [KEY TYPE]
Ex. ${_prg} -e confluence.com
Ex. ${_prg} -e confluence.com account
OPTIONS
-h --help Print this help
-e --enable Turn on SSO Bypass
-d --disable Turn off SSO Bypass
ENDHERE
}

if [[ $# -eq 0 ]]; then
echo "Error: No options were included"
echo "Run with -h option for help."
exit 1
fi

ENDWHILE=0
while [[ $# -gt 0 ]] && [[ ENDWHILE -eq 0 ]] ; do
case $1 in
-h| --help) print_usage; exit 1;;
-e| --enable) MACHINE="$2"; MODE="true"; request_auth_fallback;;
-d| --disable) MACHINE="$2"; MODE="false"; request_auth_fallback;;
--) ENDWHILE=1;;
-*) echo "Invalid option '$1'"; exit 1;;
*) ENDWHILE=1; break;;
-e| --enable) MACHINE="$2"; KEY="$3"; MODE="true"; request_auth_fallback;;
-d| --disable) MACHINE="$2"; KEY="$3"; MODE="false"; request_auth_fallback;;
*) echo "Invalid option '$1'"; exit 1;;
esac
shift
done
done

0 comments on commit 2840efb

Please sign in to comment.