Skip to content

Commit

Permalink
fix(bodiless-psh): hide git credential on platform.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Dewen Li committed Apr 25, 2022
1 parent b08c9df commit 531888a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
19 changes: 18 additions & 1 deletion edit/platform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fi

# Expects the following env variables:
# APP_VOLUME - the absolute path of the writable volume
# APP_GIT_REMOTE_URL - the path to the bitbucket git repository
# APP_GIT_REMOTE_URL - the path to the git repository
# APP_GIT_USER - the user for git operations
# APP_GIT_PW - the password for git operations
# PLATFORM_APP_DIR - the absolute path to the application directory. provided by platform.sh
Expand All @@ -30,6 +30,7 @@ CMD_GIT=/usr/bin/git
TMP_DIR=${APP_VOLUME}/../tmp
ROOT_DIR=${APP_VOLUME}/root
NPM_CACHE_DIR=${APP_VOLUME}/.npm
GIT_STORE_CREDENTIAL=${APP_VOLUME}/.credential

invoke () {
if [[ $(type $1 2>&1) =~ "function" ]]; then
Expand Down Expand Up @@ -148,6 +149,7 @@ full_deploy () {
${CMD_GIT} -c credential.helper="!f() { echo username=${APP_GIT_USER}; echo password=${APP_GIT_PW}; }; f" clone -b ${PLATFORM_BRANCH} ${APP_GIT_REMOTE_URL} ${ROOT_DIR}
cd ${ROOT_DIR}
fi
git_store_credential
${CMD_GIT} config user.email "${APP_GIT_USER_EMAIL}"
${CMD_GIT} config user.name "${APP_GIT_USER}"
}
Expand All @@ -163,6 +165,21 @@ init_npmrc () {
fi
}

git_store_credential () {
# process credential store only for http based url
if [[ ${APP_GIT_REMOTE_URL} =~ ^http ]] ;
then
# get host name
GIT_HOST=$(echo ${APP_GIT_REMOTE_URL} | awk -F/ '{print $3}')
# remove user info, if any
GIT_HOST="${GIT_HOST#*:*@}"
echo 'https://'${APP_GIT_USER}':'${APP_GIT_PW}'@'${GIT_HOST} > ${GIT_STORE_CREDENTIAL}
# set owner permission only
chmod 600 ${GIT_STORE_CREDENTIAL}
git config --local credential.helper 'store --file='${GIT_STORE_CREDENTIAL}
fi
}

check_branch () {
if [[ ${PLATFORM_BRANCH} =~ ^pr- ]]; then
if [[ ${APP_GIT_REMOTE_URL} =~ github\.com ]]; then
Expand Down
19 changes: 18 additions & 1 deletion packages/bodiless-psh/resources/edit/platform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fi

# Expects the following env variables:
# APP_VOLUME - the absolute path of the writable volume
# APP_GIT_REMOTE_URL - the path to the bitbucket git repository
# APP_GIT_REMOTE_URL - the path to the git repository
# APP_GIT_USER - the user for git operations
# APP_GIT_PW - the password for git operations
# PLATFORM_APP_DIR - the absolute path to the application directory. provided by platform.sh
Expand All @@ -30,6 +30,7 @@ CMD_GIT=/usr/bin/git
TMP_DIR=${APP_VOLUME}/../tmp
ROOT_DIR=${APP_VOLUME}/root
NPM_CACHE_DIR=${APP_VOLUME}/.npm
GIT_STORE_CREDENTIAL=${APP_VOLUME}/.credential

invoke () {
if [[ $(type $1 2>&1) =~ "function" ]]; then
Expand Down Expand Up @@ -146,6 +147,7 @@ full_deploy () {
${CMD_GIT} -c credential.helper="!f() { echo username=${APP_GIT_USER}; echo password=${APP_GIT_PW}; }; f" clone -b ${PLATFORM_BRANCH} ${APP_GIT_REMOTE_URL} ${ROOT_DIR}
cd ${ROOT_DIR}
fi
git_store_credential
${CMD_GIT} config user.email "${APP_GIT_USER_EMAIL}"
${CMD_GIT} config user.name "${APP_GIT_USER}"
}
Expand All @@ -161,6 +163,21 @@ init_npmrc () {
fi
}

git_store_credential () {
# process credential store only for http based url
if [[ ${APP_GIT_REMOTE_URL} =~ ^http ]] ;
then
# get host name
GIT_HOST=$(echo ${APP_GIT_REMOTE_URL} | awk -F/ '{print $3}')
# remove user info, if any
GIT_HOST="${GIT_HOST#*:*@}"
echo 'https://'${APP_GIT_USER}':'${APP_GIT_PW}'@'${GIT_HOST} > ${GIT_STORE_CREDENTIAL}
# set owner permission only
chmod 600 ${GIT_STORE_CREDENTIAL}
git config --local credential.helper 'store --file='${GIT_STORE_CREDENTIAL}
fi
}

check_branch () {
if [[ ${PLATFORM_BRANCH} =~ ^pr- ]]; then
if [[ ${APP_GIT_REMOTE_URL} =~ github\.com ]]; then
Expand Down

0 comments on commit 531888a

Please sign in to comment.