From 615990b92a5c7066f51c9e4563fcda2deff351d0 Mon Sep 17 00:00:00 2001 From: Martin Lablans <6804500+lablans@users.noreply.github.com> Date: Tue, 28 Jan 2025 14:53:49 +0100 Subject: [PATCH] Use secret-sync for gitpassword (#257) --------- Co-authored-by: Tim Schumacher Co-authored-by: Jan <59206115+Threated@users.noreply.github.com> Co-authored-by: Tim Schumacher --- lib/functions.sh | 2 +- lib/gitlab-token-helper.sh | 11 ++++++++++ lib/gitpassword.sh | 41 ----------------------------------- lib/update-bridgehead.sh | 44 ++++++++++++++++++++++++++++++++------ 4 files changed, 50 insertions(+), 48 deletions(-) create mode 100755 lib/gitlab-token-helper.sh delete mode 100755 lib/gitpassword.sh diff --git a/lib/functions.sh b/lib/functions.sh index 3fcae38..ed57293 100644 --- a/lib/functions.sh +++ b/lib/functions.sh @@ -116,7 +116,7 @@ assertVarsNotEmpty() { MISSING_VARS="" for VAR in $@; do - if [ -z "${!VAR}" ]; then + if [ -z "${!VAR}" ]; then MISSING_VARS+="$VAR " fi done diff --git a/lib/gitlab-token-helper.sh b/lib/gitlab-token-helper.sh new file mode 100755 index 0000000..e618029 --- /dev/null +++ b/lib/gitlab-token-helper.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +[ "$1" = "get" ] || exit + +source /var/cache/bridgehead/secrets/gitlab_token + +# Any non-empty username works, only the token matters +cat << EOF +username=bk +password=$BRIDGEHEAD_CONFIG_REPO_TOKEN +EOF \ No newline at end of file diff --git a/lib/gitpassword.sh b/lib/gitpassword.sh deleted file mode 100755 index 17756d6..0000000 --- a/lib/gitpassword.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -if [ "$1" != "get" ]; then - echo "Usage: $0 get" - exit 1 -fi - -baseDir() { - # see https://stackoverflow.com/questions/59895 - SOURCE=${BASH_SOURCE[0]} - while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink - DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd ) - SOURCE=$(readlink "$SOURCE") - [[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located - done - DIR=$( cd -P "$( dirname "$SOURCE" )/.." >/dev/null 2>&1 && pwd ) - echo $DIR -} - -BASE=$(baseDir) -cd $BASE - -source lib/functions.sh - -assertVarsNotEmpty SITE_ID || fail_and_report 1 "gitpassword.sh failed: SITE_ID is empty." - -PARAMS="$(cat)" -GITHOST=$(echo "$PARAMS" | grep "^host=" | sed 's/host=\(.*\)/\1/g') - -fetchVarsFromVault GIT_PASSWORD - -if [ -z "${GIT_PASSWORD}" ]; then - fail_and_report 1 "gitpassword.sh failed: Git password not found." -fi - -cat <