From 101e15af7f9ae55818db7ed8624db0bebfe855c4 Mon Sep 17 00:00:00 2001 From: FND Date: Tue, 25 Oct 2011 07:48:06 +0200 Subject: [PATCH 1/3] reading username and token from separate config file keeps sensitive/proprietary credentials out of .gitconfig --- gist.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gist.sh b/gist.sh index e0b14ac..9e204c6 100755 --- a/gist.sh +++ b/gist.sh @@ -191,9 +191,9 @@ gist_post () if [ "$_ANON" != "1" ]; then require git - USER=$(git config --global github.user) + USER=`head -n1 ~/.githubconfig` USERAVAIL=$? - TOKEN=$(git config --global github.token) + TOKEN=`tail -n1 ~/.githubconfig` TOKENAVAIL=$? if [ $USERAVAIL -eq 0 -a $TOKENAVAIL -eq 0 ]; then AUTH="--data-urlencode login=$USER --data-urlencode token=$TOKEN" From 4825e466f3c5501eadb2ace2f791ac3b5608d2f5 Mon Sep 17 00:00:00 2001 From: FND Date: Tue, 25 Oct 2011 18:35:09 +0200 Subject: [PATCH 2/3] added alternatives for retrieving GitHub credentials environment variables take precedence over ~/.gitconfig takes precedence over git config --- gist.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/gist.sh b/gist.sh index 9e204c6..44eeb99 100755 --- a/gist.sh +++ b/gist.sh @@ -191,11 +191,19 @@ gist_post () if [ "$_ANON" != "1" ]; then require git - USER=`head -n1 ~/.githubconfig` - USERAVAIL=$? - TOKEN=`tail -n1 ~/.githubconfig` - TOKENAVAIL=$? - if [ $USERAVAIL -eq 0 -a $TOKENAVAIL -eq 0 ]; then + CFG_FILE="$HOME/.githubconfig" + if [ -n "$GITHUB_USER" -a -n "$GITHUB_TOKEN" ]; then + USER="$GITHUB_USER" + TOKEN="$GITHUB_TOKEN" + elif [ -f "$cfg_file" ]; then + USER=$(head -n1 "$cfg_file") + TOKEN=$(tail -n1 "$cfg_file") + else + USER=$(git config --global github.user) + TOKEN=$(git config --global github.token) + fi + + if [ -n "$USER" -a -n "$TOKEN" ]; then AUTH="--data-urlencode login=$USER --data-urlencode token=$TOKEN" fi fi From e84c7ae8fdb8c5acb6074d64ef5e287cebaddb34 Mon Sep 17 00:00:00 2001 From: FND Date: Tue, 25 Oct 2011 18:42:03 +0200 Subject: [PATCH 3/3] fixed variable name while I don't like uppercase variables for this, it's better to be consistent --- gist.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gist.sh b/gist.sh index 44eeb99..977e5d9 100755 --- a/gist.sh +++ b/gist.sh @@ -195,9 +195,9 @@ gist_post () if [ -n "$GITHUB_USER" -a -n "$GITHUB_TOKEN" ]; then USER="$GITHUB_USER" TOKEN="$GITHUB_TOKEN" - elif [ -f "$cfg_file" ]; then - USER=$(head -n1 "$cfg_file") - TOKEN=$(tail -n1 "$cfg_file") + elif [ -f "$CFG_FILE" ]; then + USER=$(head -n1 "$CFG_FILE") + TOKEN=$(tail -n1 "$CFG_FILE") else USER=$(git config --global github.user) TOKEN=$(git config --global github.token)