Skip to content

Commit

Permalink
update: htpasswd stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
codekow committed Oct 8, 2024
1 parent 852882a commit 218f604
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
kind: Secret
apiVersion: v1
kind: Secret
metadata:
name: htpasswd-local
namespace: openshift-config
Expand Down
6 changes: 3 additions & 3 deletions scripts/library/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ until_true(){

retry(){
local n=1
local max=12
local max=9
local delay=20

echo "Running:" "${@}"
echo "Repeat: x${max}"
echo "Retry: x${max}"
echo "Delay: ${delay}s"

# until "${@}" 1>&2
until "${@}"
do
if [[ $n -lt $max ]]; then
((n++))
echo "Retry after $delay sec"
echo "Retry #$n - waiting ${delay}s"
sleep $delay
else
echo "Failed after $n attempts."
Expand Down
24 changes: 24 additions & 0 deletions scripts/library/htpasswd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@ htpasswd_ocp_set_file(){
--from-file=htpasswd="${HTPASSWD_FILE}"
}

htpasswd_validate_user(){
USER=${1:-admin}
PASS=${2:-admin}
KUBECONFIG=${KUBECONFIG:-~/.kube/config}
TMP_CONFIG=scratch/kubeconfig.XXX

echo "This may take a few minutes..."
echo "Press <ctrl> + c to cancel"

# login to ocp
cp "${KUBECONFIG}" "${TMP_CONFIG}"

retry oc --kubeconfig "${TMP_CONFIG}" login \
-u "${USER}" -p "${PASS}" > /dev/null 2>&1 || return 1

# verify user is present
oc get user "${USER}" || return 1

# cleanup tmp config
rm "${TMP_CONFIG}"

echo "Login validated: ${USER}"
}

which age 2>/dev/null || return 0

htpasswd_encrypt_file(){
Expand Down

0 comments on commit 218f604

Please sign in to comment.